summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-12-12 12:29:20 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-12-12 16:00:53 (GMT)
commit4315ccbd51f63e408d69d944f162d0ead4f9addd (patch)
tree046b3734d18c7c5e76040e8798a6f4af5e5045cb /Swift/QtUI/QtNameWidget.cpp
parentaaf38fe2e6804bd87ea5e99a05ed57070cbe1c57 (diff)
downloadswift-4315ccbd51f63e408d69d944f162d0ead4f9addd.zip
swift-4315ccbd51f63e408d69d944f162d0ead4f9addd.tar.bz2
Refactored own nickname handling.
Diffstat (limited to 'Swift/QtUI/QtNameWidget.cpp')
-rw-r--r--Swift/QtUI/QtNameWidget.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/Swift/QtUI/QtNameWidget.cpp b/Swift/QtUI/QtNameWidget.cpp
new file mode 100644
index 0000000..bf38da8
--- /dev/null
+++ b/Swift/QtUI/QtNameWidget.cpp
@@ -0,0 +1,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("<","&lt;");
+ textLabel->setText(text);
+}
+
+}
+
+
+
+