1
0
forked from blue/squawk

some methods to cVard

This commit is contained in:
Blue 2019-10-21 18:02:41 +03:00
parent e7be046e9f
commit c4d22c9c14
5 changed files with 139 additions and 38 deletions

View File

@ -19,19 +19,13 @@
#include <QDebug> #include <QDebug>
#include "image.h" #include "image.h"
Image::Image(const QString& path, QWidget* parent): Image::Image(const QString& path, quint16 p_minWidth, QWidget* parent):
QLabel(parent), QLabel(parent),
pixmap(path), pixmap(path),
aspectRatio(0) aspectRatio(0),
minWidth(p_minWidth)
{ {
qreal height = pixmap.height();
qreal width = pixmap.width();
aspectRatio = width / height;
setPixmap(pixmap);
setScaledContents(true); setScaledContents(true);
setMinimumHeight(50 / aspectRatio);
setMinimumWidth(50);
} }
Image::~Image() Image::~Image()
@ -42,7 +36,6 @@ Image::~Image()
int Image::heightForWidth(int width) const int Image::heightForWidth(int width) const
{ {
int height = width / aspectRatio; int height = width / aspectRatio;
//qDebug() << height << width << aspectRatio;
return height; return height;
} }
@ -50,3 +43,27 @@ bool Image::hasHeightForWidth() const
{ {
return true; return true;
} }
void Image::recalculateAspectRatio()
{
qreal height = pixmap.height();
qreal width = pixmap.width();
aspectRatio = width / height;
setPixmap(pixmap);
setMinimumHeight(minWidth / aspectRatio);
setMinimumWidth(minWidth);
}
void Image::setMinWidth(quint16 p_minWidth)
{
if (minWidth != p_minWidth) {
minWidth = p_minWidth;
recalculateAspectRatio();
}
}
void Image::setPath(const QString& path)
{
pixmap = QPixmap(path);
recalculateAspectRatio();
}

View File

@ -28,34 +28,22 @@
class Image : public QLabel class Image : public QLabel
{ {
public: public:
/** Image(const QString& path, quint16 minWidth = 50, QWidget* parent = nullptr);
* Default constructor
*/
Image(const QString& path, QWidget* parent = nullptr);
/**
* Destructor
*/
~Image(); ~Image();
/**
* @todo write docs
*
* @param TODO
* @return TODO
*/
int heightForWidth(int width) const override; int heightForWidth(int width) const override;
bool hasHeightForWidth() const override;
/** void setPath(const QString& path);
* @todo write docs void setMinWidth(quint16 minWidth);
*
* @return TODO
*/
virtual bool hasHeightForWidth() const;
private: private:
QPixmap pixmap; QPixmap pixmap;
qreal aspectRatio; qreal aspectRatio;
quint16 minWidth;
private:
void recalculateAspectRatio();
}; };
#endif // IMAGE_H #endif // IMAGE_H

View File

@ -19,13 +19,74 @@
#include "vcard.h" #include "vcard.h"
#include "ui_vcard.h" #include "ui_vcard.h"
VCard::VCard(QWidget* parent): VCard::VCard(bool edit, QWidget* parent):
QWidget(parent), QWidget(parent),
m_ui(new Ui::VCard()) m_ui(new Ui::VCard()),
avatar(":/images/logo.svg", 64)
{ {
m_ui->setupUi(this); m_ui->setupUi(this);
if (edit) {
} else {
m_ui->buttonBox->hide();
m_ui->firstName->setReadOnly(true);
m_ui->middleName->setReadOnly(true);
m_ui->lastName->setReadOnly(true);
m_ui->nickName->setReadOnly(true);
m_ui->birthday->setReadOnly(true);
m_ui->organizationName->setReadOnly(true);
m_ui->organizationDepartment->setReadOnly(true);
m_ui->organizationTitle->setReadOnly(true);
m_ui->organizationRole->setReadOnly(true);
m_ui->description->setReadOnly(true);
m_ui->jabberID->setReadOnly(true);
}
connect(m_ui->buttonBox, &QDialogButtonBox::accepted, this, &VCard::onButtonBoxAccepted);
connect(m_ui->buttonBox, &QDialogButtonBox::rejected, m_ui->buttonBox, &QDialogButtonBox::deleteLater);
} }
VCard::~VCard() VCard::~VCard()
{ {
} }
void VCard::setVCard(const QString& jid, const Shared::VCard& card)
{
m_ui->jabberID->setText(jid);
m_ui->firstName->setText(card.getFirstName());
m_ui->middleName->setText(card.getMiddleName());
m_ui->lastName->setText(card.getLastName());
m_ui->nickName->setText(card.getNickName());
m_ui->birthday->setDate(card.getBirthday());
//m_ui->organizationName->setText(card.get());
//m_ui->organizationDepartment->setText(card.get());
//m_ui->organizationTitle->setText(card.get());
//m_ui->organizationRole->setText(card.get());
m_ui->description->setText(card.getDescription());
QString path;
switch (card.getAvatarType()) {
case Shared::Avatar::empty:
path = QApplication::palette().window().color().lightnessF() > 0.5 ? ":/images/fallback/dark/big/user.svg" : ":/images/fallback/light/big/user.svg";
break;
case Shared::Avatar::autocreated:
case Shared::Avatar::valid:
path = card.getAvatarPath();
break;
}
avatar.setPath(path);
}
void VCard::onButtonBoxAccepted()
{
Shared::VCard card;
card.setFirstName(m_ui->firstName->text());
card.setMiddleName(m_ui->middleName->text());
card.setLastName(m_ui->lastName->text());
card.setNickName(m_ui->nickName->text());
card.setBirthday(m_ui->birthday->date());
card.setDescription(m_ui->description->toPlainText());
emit saveVCard(m_ui->jabberID->text(), card);
}

View File

@ -22,6 +22,9 @@
#include <QWidget> #include <QWidget>
#include <QScopedPointer> #include <QScopedPointer>
#include "../../global.h"
#include "../utils/image.h"
namespace Ui namespace Ui
{ {
class VCard; class VCard;
@ -34,11 +37,20 @@ class VCard : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
VCard(QWidget* parent = nullptr); VCard(bool edit = false, QWidget* parent = nullptr);
~VCard(); ~VCard();
void setVCard(const QString& jid, const Shared::VCard& card);
signals:
void saveVCard(const QString& jid, const Shared::VCard& card);
private slots:
void onButtonBoxAccepted();
private: private:
QScopedPointer<Ui::VCard> m_ui; QScopedPointer<Ui::VCard> m_ui;
Image avatar;
}; };
#endif // VCARD_H #endif // VCARD_H

View File

@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>434</width> <width>544</width>
<height>534</height> <height>534</height>
</rect> </rect>
</property> </property>
@ -49,7 +49,7 @@
<property name="tabBarAutoHide"> <property name="tabBarAutoHide">
<bool>false</bool> <bool>false</bool>
</property> </property>
<widget class="QWidget" name="General" native="true"> <widget class="QWidget" name="General">
<attribute name="title"> <attribute name="title">
<string>General</string> <string>General</string>
</attribute> </attribute>
@ -433,7 +433,7 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="Contact" native="true"> <widget class="QWidget" name="Contact">
<attribute name="title"> <attribute name="title">
<string>Contact</string> <string>Contact</string>
</attribute> </attribute>
@ -479,7 +479,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>422</width> <width>532</width>
<height>410</height> <height>410</height>
</rect> </rect>
</property> </property>
@ -539,13 +539,36 @@
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="jabberIDLabel"> <widget class="QLabel" name="jabberIDLabel">
<property name="text"> <property name="text">
<string>JabberID</string> <string>Jabber ID</string>
</property> </property>
<property name="buddy"> <property name="buddy">
<cstring>jabberID</cstring> <cstring>jabberID</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEdit">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>300</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="urlLabel">
<property name="text">
<string>Web site</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
<item row="7" column="1"> <item row="7" column="1">