blob: bf38da8524ad304728782dea53dd1fb4d0ff4c08 (
plain)
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
|
/*
* Copyright (c) 2010 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#include "QtNameWidget.h"
#include <QStackedWidget>
#include <QHBoxLayout>
#include <QMouseEvent>
#include <Swift/QtUI/QtElidingLabel.h>
#include <Swift/QtUI/QtSwiftUtil.h>
#include <Swift/QtUI/QtLineEdit.h>
namespace Swift {
QtNameWidget::QtNameWidget(QWidget *parent) : QWidget(parent) {
QHBoxLayout* mainLayout = new QHBoxLayout(this);
mainLayout->setSpacing(0);
mainLayout->setContentsMargins(0,0,0,0);
stack = new QStackedWidget(this);
mainLayout->addWidget(stack);
textLabel = new QtElidingLabel(this);
QFont font = textLabel->font();
font.setBold(true);
textLabel->setFont(font);
stack->addWidget(textLabel);
nickEdit = new QtLineEdit(this);
connect(nickEdit, SIGNAL(returnPressed()), this, SLOT(handleEditComplete()));
connect(nickEdit, SIGNAL(escapePressed()), this, SLOT(handleEditCancelled()));
stack->addWidget(nickEdit);
}
void QtNameWidget::mouseDoubleClickEvent(QMouseEvent* event) {
if (stack->currentWidget() != nickEdit) {
if (event->button() == Qt::LeftButton) {
nickEdit->setText(nick);
stack->setCurrentWidget(nickEdit);
}
}
}
void QtNameWidget::handleEditComplete() {
stack->setCurrentWidget(textLabel);
emit onChangeNickRequest(nickEdit->text());
}
void QtNameWidget::handleEditCancelled() {
stack->setCurrentWidget(textLabel);
}
void QtNameWidget::setNick(const QString& nick) {
this->nick = nick;
updateText();
}
void QtNameWidget::setJID(const QString& jid) {
this->jid = jid;
updateText();
}
void QtNameWidget::updateText() {
QString text;
if (nick.isEmpty()) {
text = jid;
}
else {
text = nick + " (" + jid + ")";
}
text.replace("<","<");
textLabel->setText(text);
}
}
|