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 "image.h"
Image::Image(const QString& path, QWidget* parent):
Image::Image(const QString& path, quint16 p_minWidth, QWidget* parent):
QLabel(parent),
pixmap(path),
aspectRatio(0)
aspectRatio(0),
minWidth(p_minWidth)
{
qreal height = pixmap.height();
qreal width = pixmap.width();
aspectRatio = width / height;
setPixmap(pixmap);
setScaledContents(true);
setMinimumHeight(50 / aspectRatio);
setMinimumWidth(50);
}
Image::~Image()
@ -42,7 +36,6 @@ Image::~Image()
int Image::heightForWidth(int width) const
{
int height = width / aspectRatio;
//qDebug() << height << width << aspectRatio;
return height;
}
@ -50,3 +43,27 @@ bool Image::hasHeightForWidth() const
{
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
{
public:
/**
* Default constructor
*/
Image(const QString& path, QWidget* parent = nullptr);
Image(const QString& path, quint16 minWidth = 50, QWidget* parent = nullptr);
/**
* Destructor
*/
~Image();
/**
* @todo write docs
*
* @param TODO
* @return TODO
*/
int heightForWidth(int width) const override;
/**
* @todo write docs
*
* @return TODO
*/
virtual bool hasHeightForWidth() const;
bool hasHeightForWidth() const override;
void setPath(const QString& path);
void setMinWidth(quint16 minWidth);
private:
QPixmap pixmap;
qreal aspectRatio;
quint16 minWidth;
private:
void recalculateAspectRatio();
};
#endif // IMAGE_H

View File

@ -19,13 +19,74 @@
#include "vcard.h"
#include "ui_vcard.h"
VCard::VCard(QWidget* parent):
VCard::VCard(bool edit, QWidget* parent):
QWidget(parent),
m_ui(new Ui::VCard())
m_ui(new Ui::VCard()),
avatar(":/images/logo.svg", 64)
{
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()
{
}
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 <QScopedPointer>
#include "../../global.h"
#include "../utils/image.h"
namespace Ui
{
class VCard;
@ -34,11 +37,20 @@ class VCard : public QWidget
{
Q_OBJECT
public:
VCard(QWidget* parent = nullptr);
VCard(bool edit = false, QWidget* parent = nullptr);
~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:
QScopedPointer<Ui::VCard> m_ui;
Image avatar;
};
#endif // VCARD_H

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>434</width>
<width>544</width>
<height>534</height>
</rect>
</property>
@ -49,7 +49,7 @@
<property name="tabBarAutoHide">
<bool>false</bool>
</property>
<widget class="QWidget" name="General" native="true">
<widget class="QWidget" name="General">
<attribute name="title">
<string>General</string>
</attribute>
@ -433,7 +433,7 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="Contact" native="true">
<widget class="QWidget" name="Contact">
<attribute name="title">
<string>Contact</string>
</attribute>
@ -479,7 +479,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>422</width>
<width>532</width>
<height>410</height>
</rect>
</property>
@ -539,13 +539,36 @@
<item row="0" column="0">
<widget class="QLabel" name="jabberIDLabel">
<property name="text">
<string>JabberID</string>
<string>Jabber ID</string>
</property>
<property name="buddy">
<cstring>jabberID</cstring>
</property>
</widget>
</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>
</item>
<item row="7" column="1">