first primitive vcard in graphic interface

This commit is contained in:
Blue 2019-10-22 18:13:56 +03:00
parent c4d22c9c14
commit 2a37f36b83
13 changed files with 208 additions and 75 deletions

View file

@ -19,12 +19,19 @@
#include "vcard.h"
#include "ui_vcard.h"
VCard::VCard(bool edit, QWidget* parent):
VCard::VCard(const QString& jid, bool edit, QWidget* parent):
QWidget(parent),
m_ui(new Ui::VCard()),
avatar(":/images/logo.svg", 64)
avatar(QApplication::palette().window().color().lightnessF() > 0.5 ? ":/images/fallback/dark/big/user.svg" : ":/images/fallback/light/big/user.svg", 256, 256, 256)
{
m_ui->setupUi(this);
m_ui->jabberID->setText(jid);
m_ui->jabberID->setReadOnly(true);
QGridLayout* general = static_cast<QGridLayout*>(m_ui->General->layout());
general->addWidget(&avatar, 2, 2, 1, 1);
avatar.setFrameShape(QFrame::StyledPanel);
avatar.setFrameShadow(QFrame::Sunken);
avatar.setMargin(6);
if (edit) {
@ -40,11 +47,15 @@ VCard::VCard(bool edit, QWidget* parent):
m_ui->organizationTitle->setReadOnly(true);
m_ui->organizationRole->setReadOnly(true);
m_ui->description->setReadOnly(true);
m_ui->jabberID->setReadOnly(true);
m_ui->url->setReadOnly(true);
}
connect(m_ui->buttonBox, &QDialogButtonBox::accepted, this, &VCard::onButtonBoxAccepted);
connect(m_ui->buttonBox, &QDialogButtonBox::rejected, m_ui->buttonBox, &QDialogButtonBox::deleteLater);
int height = m_ui->personalForm->minimumSize().height();
avatar.setMaximumSize(avatar.widthForHeight(height), height);
avatar.setMinimumSize(avatar.widthForHeight(height), height);
}
VCard::~VCard()
@ -54,6 +65,11 @@ VCard::~VCard()
void VCard::setVCard(const QString& jid, const Shared::VCard& card)
{
m_ui->jabberID->setText(jid);
setVCard(card);
}
void VCard::setVCard(const Shared::VCard& card)
{
m_ui->firstName->setText(card.getFirstName());
m_ui->middleName->setText(card.getMiddleName());
m_ui->lastName->setText(card.getLastName());
@ -65,17 +81,24 @@ void VCard::setVCard(const QString& jid, const Shared::VCard& card)
//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";
avatar.setPath(QApplication::palette().window().color().lightnessF() > 0.5 ? ":/images/fallback/dark/big/user.svg" : ":/images/fallback/light/big/user.svg", 256, 256);
break;
case Shared::Avatar::autocreated:
case Shared::Avatar::valid:
path = card.getAvatarPath();
avatar.setPath(card.getAvatarPath());
break;
}
avatar.setPath(path);
int height = m_ui->personalForm->minimumSize().height();
avatar.setMaximumSize(avatar.widthForHeight(height), height);
avatar.setMinimumSize(avatar.widthForHeight(height), height);
}
QString VCard::getJid() const
{
return m_ui->jabberID->text();
}
void VCard::onButtonBoxAccepted()
@ -88,5 +111,5 @@ void VCard::onButtonBoxAccepted()
card.setBirthday(m_ui->birthday->date());
card.setDescription(m_ui->description->toPlainText());
emit saveVCard(m_ui->jabberID->text(), card);
emit saveVCard(card);
}

View file

@ -37,13 +37,15 @@ class VCard : public QWidget
{
Q_OBJECT
public:
VCard(bool edit = false, QWidget* parent = nullptr);
VCard(const QString& jid, bool edit = false, QWidget* parent = nullptr);
~VCard();
void setVCard(const Shared::VCard& card);
void setVCard(const QString& jid, const Shared::VCard& card);
QString getJid() const;
signals:
void saveVCard(const QString& jid, const Shared::VCard& card);
void saveVCard(const Shared::VCard& card);
private slots:
void onButtonBoxAccepted();

View file

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>544</width>
<width>560</width>
<height>534</height>
</rect>
</property>
@ -80,6 +80,12 @@
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-size:16pt; font-weight:600;&quot;&gt;Personal information&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
@ -97,6 +103,9 @@
</item>
<item row="2" column="1">
<layout class="QFormLayout" name="personalForm">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<property name="formAlignment">
<set>Qt::AlignHCenter|Qt::AlignTop</set>
</property>
@ -104,13 +113,13 @@
<widget class="QLineEdit" name="middleName">
<property name="minimumSize">
<size>
<width>150</width>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>300</width>
<width>350</width>
<height>16777215</height>
</size>
</property>
@ -120,13 +129,13 @@
<widget class="QLineEdit" name="firstName">
<property name="minimumSize">
<size>
<width>150</width>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>300</width>
<width>350</width>
<height>16777215</height>
</size>
</property>
@ -166,13 +175,13 @@
<widget class="QLineEdit" name="lastName">
<property name="minimumSize">
<size>
<width>150</width>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>300</width>
<width>350</width>
<height>16777215</height>
</size>
</property>
@ -192,13 +201,13 @@
<widget class="QLineEdit" name="nickName">
<property name="minimumSize">
<size>
<width>150</width>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>300</width>
<width>350</width>
<height>16777215</height>
</size>
</property>
@ -219,35 +228,6 @@
</item>
</layout>
</item>
<item row="2" column="2">
<widget class="QFrame" name="avatarFrame">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="sizeIncrement">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout"/>
</widget>
</item>
<item row="2" column="3" rowspan="7">
<spacer name="generalRightHSpacer">
<property name="orientation">
@ -314,7 +294,7 @@
<item row="0" column="0">
<widget class="QLabel" name="organizationNameLabel">
<property name="text">
<string>Name</string>
<string>Organization name</string>
</property>
<property name="buddy">
<cstring>organizationName</cstring>
@ -325,13 +305,13 @@
<widget class="QLineEdit" name="organizationName">
<property name="minimumSize">
<size>
<width>150</width>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>300</width>
<width>350</width>
<height>16777215</height>
</size>
</property>
@ -340,7 +320,7 @@
<item row="1" column="0">
<widget class="QLabel" name="organizationDepartmentLabel">
<property name="text">
<string>Department</string>
<string>Unit / Department</string>
</property>
<property name="buddy">
<cstring>organizationDepartment</cstring>
@ -351,13 +331,13 @@
<widget class="QLineEdit" name="organizationDepartment">
<property name="minimumSize">
<size>
<width>150</width>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>300</width>
<width>350</width>
<height>16777215</height>
</size>
</property>
@ -366,7 +346,7 @@
<item row="2" column="0">
<widget class="QLabel" name="roleLabel">
<property name="text">
<string>Role</string>
<string>Role / Profession</string>
</property>
<property name="buddy">
<cstring>organizationRole</cstring>
@ -377,13 +357,13 @@
<widget class="QLineEdit" name="organizationRole">
<property name="minimumSize">
<size>
<width>150</width>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>300</width>
<width>350</width>
<height>16777215</height>
</size>
</property>
@ -392,7 +372,7 @@
<item row="3" column="0">
<widget class="QLabel" name="organizationTitleLabel">
<property name="text">
<string>Title</string>
<string>Job title</string>
</property>
<property name="buddy">
<cstring>organizationTitle</cstring>
@ -403,13 +383,13 @@
<widget class="QLineEdit" name="organizationTitle">
<property name="minimumSize">
<size>
<width>150</width>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>300</width>
<width>350</width>
<height>16777215</height>
</size>
</property>
@ -479,7 +459,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>532</width>
<width>548</width>
<height>410</height>
</rect>
</property>
@ -547,7 +527,7 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEdit">
<widget class="QLineEdit" name="url">
<property name="minimumSize">
<size>
<width>150</width>