1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
/*
* Copyright (c) 2011 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#include "QtProfileWindow.h"
#include <QImage>
#include <QPixmap>
#include <QSizePolicy>
#include <QGridLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QMovie>
#include "QtSwiftUtil.h"
#include "QtAvatarWidget.h"
namespace Swift {
QtProfileWindow::QtProfileWindow() {
setWindowTitle("Edit Profile");
QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(this->sizePolicy().hasHeightForWidth());
setSizePolicy(sizePolicy);
QVBoxLayout* layout = new QVBoxLayout(this);
layout->setContentsMargins(10, 10, 10, 10);
QHBoxLayout* topLayout = new QHBoxLayout();
avatar = new QtAvatarWidget(this);
topLayout->addWidget(avatar);
QVBoxLayout* fieldsLayout = new QVBoxLayout();
QHBoxLayout* horizontalLayout_2 = new QHBoxLayout();
nicknameLabel = new QLabel("Nickname: ", this);
horizontalLayout_2->addWidget(nicknameLabel);
nickname = new QLineEdit(this);
horizontalLayout_2->addWidget(nickname);
fieldsLayout->addLayout(horizontalLayout_2);
errorLabel = new QLabel(this);
errorLabel->setAlignment(Qt::AlignHCenter);
fieldsLayout->addWidget(errorLabel);
fieldsLayout->addItem(new QSpacerItem(198, 17, QSizePolicy::Minimum, QSizePolicy::Expanding));
topLayout->addLayout(fieldsLayout);
layout->addLayout(topLayout);
QHBoxLayout* horizontalLayout = new QHBoxLayout();
horizontalLayout->setContentsMargins(0, 0, 0, 0);
horizontalLayout->addItem(new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum));
throbberLabel = new QLabel(this);
throbberLabel->setMovie(new QMovie(":/icons/throbber.gif", QByteArray(), this));
horizontalLayout->addWidget(throbberLabel);
saveButton = new QPushButton("Save", this);
connect(saveButton, SIGNAL(clicked()), SLOT(handleSave()));
horizontalLayout->addWidget(saveButton);
fieldsLayout->addLayout(horizontalLayout);
resize(360, 120);
}
void QtProfileWindow::setVCard(Swift::VCard::ref vcard) {
this->vcard = vcard;
nickname->setText(P2QSTRING(vcard->getNickname()));
avatar->setAvatar(vcard->getPhoto(), vcard->getPhotoType());
}
void QtProfileWindow::setEnabled(bool b) {
nickname->setEnabled(b);
nicknameLabel->setEnabled(b);
avatar->setEnabled(b);
saveButton->setEnabled(b);
}
void QtProfileWindow::setProcessing(bool processing) {
if (processing) {
throbberLabel->movie()->start();
throbberLabel->show();
}
else {
throbberLabel->hide();
throbberLabel->movie()->stop();
}
}
void QtProfileWindow::show() {
QWidget::show();
QWidget::activateWindow();
}
void QtProfileWindow::hideEvent(QHideEvent* event) {
QWidget::hideEvent(event);
}
void QtProfileWindow::hide() {
QWidget::hide();
}
void QtProfileWindow::handleSave() {
assert(vcard);
vcard->setNickname(Q2PSTRING(nickname->text()));
vcard->setPhoto(avatar->getAvatarData());
vcard->setPhotoType(avatar->getAvatarType());
onVCardChangeRequest(vcard);
}
void QtProfileWindow::setError(const std::string& error) {
if (!error.empty()) {
errorLabel->setText("<font color='red'>" + P2QSTRING(error) + "</font>");
}
else {
errorLabel->setText("");
}
}
}
|