summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI')
-rw-r--r--Swift/QtUI/QtMainWindow.cpp13
-rw-r--r--Swift/QtUI/QtMainWindow.h5
-rw-r--r--Swift/QtUI/QtNameWidget.cpp83
-rw-r--r--Swift/QtUI/QtNameWidget.h50
-rw-r--r--Swift/QtUI/QtRosterHeader.cpp59
-rw-r--r--Swift/QtUI/QtRosterHeader.h11
-rw-r--r--Swift/QtUI/SConscript1
7 files changed, 171 insertions, 51 deletions
diff --git a/Swift/QtUI/QtMainWindow.cpp b/Swift/QtUI/QtMainWindow.cpp
index 710ef61..fb84da4 100644
--- a/Swift/QtUI/QtMainWindow.cpp
+++ b/Swift/QtUI/QtMainWindow.cpp
@@ -40,6 +40,7 @@ QtMainWindow::QtMainWindow(UIEventStream* uiEventStream) : QWidget(), MainWindow
meView_ = new QtRosterHeader(this);
mainLayout->addWidget(meView_);
connect(meView_, SIGNAL(onChangeStatusRequest(StatusShow::Type, const QString&)), this, SLOT(handleStatusChanged(StatusShow::Type, const QString&)));
+ connect(meView_, SIGNAL(onChangeNickRequest(const QString&)), this, SLOT(handleChangeNickRequest(const QString&)));
tabs_ = new QtTabWidget(this);
#if QT_VERSION >= 0x040500
@@ -162,8 +163,12 @@ void QtMainWindow::handleShowOfflineToggled(bool state) {
}
}
-void QtMainWindow::setMyName(const String& name) {
- meView_->setName(P2QSTRING(name));
+void QtMainWindow::setMyNick(const String& nick) {
+ meView_->setNick(P2QSTRING(nick));
+}
+
+void QtMainWindow::setMyJID(const JID& jid) {
+ meView_->setJID(P2QSTRING(jid.toBare().toString()));
}
void QtMainWindow::setMyAvatarPath(const String& path) {
@@ -182,5 +187,9 @@ void QtMainWindow::setConnecting() {
meView_->setConnecting();
}
+void QtMainWindow::handleChangeNickRequest(const QString& nick) {
+ onChangeNickRequest(Q2PSTRING(nick));
+}
+
}
diff --git a/Swift/QtUI/QtMainWindow.h b/Swift/QtUI/QtMainWindow.h
index 9e200b1..ccec12c 100644
--- a/Swift/QtUI/QtMainWindow.h
+++ b/Swift/QtUI/QtMainWindow.h
@@ -38,7 +38,8 @@ namespace Swift {
QtMainWindow(UIEventStream* eventStream);
~QtMainWindow();
std::vector<QMenu*> getMenus() {return menus_;}
- void setMyName(const String& name);
+ void setMyNick(const String& name);
+ void setMyJID(const JID& jid);
void setMyAvatarPath(const String& path);
void setMyStatusText(const String& status);
void setMyStatusType(StatusShow::Type type);
@@ -55,6 +56,8 @@ namespace Swift {
void handleAddContactDialogComplete(const JID& contact, const QString& name);
void handleAddActionTriggered(bool checked);
void handleEventCountUpdated(int count);
+ void handleChangeNickRequest(const QString& nick);
+
private:
std::vector<QMenu*> menus_;
QtTreeWidget* treeWidget_;
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);
+}
+
+}
+
+
+
+
diff --git a/Swift/QtUI/QtNameWidget.h b/Swift/QtUI/QtNameWidget.h
new file mode 100644
index 0000000..c1c3e07
--- /dev/null
+++ b/Swift/QtUI/QtNameWidget.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <QWidget>
+
+class QLabel;
+class QStackedWidget;
+
+namespace Swift {
+ class QtElidingLabel;
+ class QtLineEdit;
+
+ class QtNameWidget : public QWidget {
+ Q_OBJECT
+
+ public:
+ QtNameWidget(QWidget *parent);
+
+ void setNick(const QString& text);
+ void setJID(const QString& jid);
+
+ signals:
+ /**
+ * When this is emitted, the widget is disabled until
+ * setNick() is called.
+ */
+ void onChangeNickRequest(const QString& nick);
+
+ private slots:
+ void handleEditComplete();
+ void handleEditCancelled();
+ virtual void mouseDoubleClickEvent(QMouseEvent* event);
+
+ private:
+ void updateText();
+
+ private:
+ QStackedWidget* stack;
+ QtElidingLabel* textLabel;
+ QtLineEdit* nickEdit;
+ QString jid;
+ QString nick;
+ };
+}
+
diff --git a/Swift/QtUI/QtRosterHeader.cpp b/Swift/QtUI/QtRosterHeader.cpp
index e6b5f1b..efc198a 100644
--- a/Swift/QtUI/QtRosterHeader.cpp
+++ b/Swift/QtUI/QtRosterHeader.cpp
@@ -14,8 +14,8 @@
#include <QMouseEvent>
#include "QtStatusWidget.h"
-#include "Swift/QtUI/QtElidingLabel.h"
-
+#include <Swift/QtUI/QtElidingLabel.h>
+#include <Swift/QtUI/QtNameWidget.h>
namespace Swift {
QtRosterHeader::QtRosterHeader(QWidget* parent) : QWidget(parent) {
@@ -39,12 +39,9 @@ QtRosterHeader::QtRosterHeader(QWidget* parent) : QWidget(parent) {
rightLayout->setContentsMargins(4,0,0,0);
topLayout->addLayout(rightLayout);
- nameLabel_ = new QtElidingLabel(this);
- setName("Me");
- QFont font = nameLabel_->font();
- font.setBold(true);
- nameLabel_->setFont(font);
- rightLayout->addWidget(nameLabel_);
+ nameWidget_ = new QtNameWidget(this);
+ connect(nameWidget_, SIGNAL(onChangeNickRequest(const QString&)), this, SIGNAL(onChangeNickRequest(const QString&)));
+ rightLayout->addWidget(nameWidget_);
statusWidget_ = new QtStatusWidget(this);
@@ -95,40 +92,6 @@ void QtRosterHeader::setConnecting() {
statusWidget_->setConnecting();
}
-void QtRosterHeader::setName(const QString& name) {
- name_ = name;
- QString escapedName = name_;
- escapedName.replace("<","&lt;");
-// nameLabel_->setText("<b>" + escapedName + "</b>");
- nameLabel_->setText(escapedName);
-// resizeNameLabel();
-}
-
-// void QtRosterHeader::resizeNameLabel() {
-// QString escapedName = name_;
-// escapedName.replace("<","&lt;");
-// nameLabel_->setText("<b>" + escapedName + "</b>");
-// return;
-// //FIXME: Make this not an infinite loop, so it can be continued.
-
-// int reductionCount = 0;
-// while (nameLabel_->sizeHint().width() + statusWidget_->width() + 30 > width()) {
-// //qDebug() << nameLabel_->sizeHint().width() << " " << statusWidget_->width() << " " << width();
-// reductionCount++;
-// QString reducedName = name_;
-// reducedName.remove(name_.length() - reductionCount, reductionCount);
-// reducedName.replace("<","&lt;");
-// nameLabel_->setText("<b>" + reducedName + + "...</b>");
-// // qDebug() << "Shrunk " << escapedName << " down to " << reducedName;
-// }
-// nameLabel_->setToolTip(name_);
-// }
-
-//void QtRosterHeader::resizeEvent(QResizeEvent* event) {
-// QWidget::resizeEvent(event);
-// resizeNameLabel();
-//}
-
void QtRosterHeader::setAvatar(const QString& path) {
QIcon avatar(path);
if (avatar.isNull()) {
@@ -138,9 +101,15 @@ void QtRosterHeader::setAvatar(const QString& path) {
avatarLabel_->setPixmap(avatar.pixmap(avatarSize_, avatarSize_));
}
-//QSize QtRosterHeader::sizeHint() const {
-// return minimumSizeHint();
-//}
+void QtRosterHeader::setNick(const QString& nick) {
+ nameWidget_->setNick(nick);
+}
+
+void QtRosterHeader::setJID(const QString& jid) {
+ nameWidget_->setJID(jid);
+}
+
+
const int QtRosterHeader::avatarSize_ = 40;
diff --git a/Swift/QtUI/QtRosterHeader.h b/Swift/QtUI/QtRosterHeader.h
index 6330200..cd5f26c 100644
--- a/Swift/QtUI/QtRosterHeader.h
+++ b/Swift/QtUI/QtRosterHeader.h
@@ -21,25 +21,30 @@ class QHBoxLayout;
namespace Swift {
class QtStatusWidget;
- class QtElidingLabel;
+ class QtNameWidget;
class QtRosterHeader : public QWidget {
Q_OBJECT
public:
QtRosterHeader(QWidget* parent = NULL);
void setAvatar(const QString& path);
- void setName(const QString& name);
+
+ void setJID(const QString& jid);
+ void setNick(const QString& nick);
+
void setStatusText(const QString& statusMessage);
void setStatusType(StatusShow::Type type);
void setConnecting();
signals:
void onChangeStatusRequest(StatusShow::Type showType, const QString &statusMessage);
+ void onChangeNickRequest(const QString &nick);
+
private slots:
void handleChangeStatusRequest(StatusShow::Type type, const QString &statusMessage);
private:
QString name_;
QLabel* avatarLabel_;
- QtElidingLabel* nameLabel_;
+ QtNameWidget* nameWidget_;
QtTextEdit* statusEdit_;
QToolBar* toolBar_;
QtStatusWidget* statusWidget_;
diff --git a/Swift/QtUI/SConscript b/Swift/QtUI/SConscript
index 53c023a..864fdb5 100644
--- a/Swift/QtUI/SConscript
+++ b/Swift/QtUI/SConscript
@@ -69,6 +69,7 @@ sources = [
"QtLoginWindowFactory.cpp",
"QtMainWindow.cpp",
"QtMainWindowFactory.cpp",
+ "QtNameWidget.cpp",
"QtSettingsProvider.cpp",
"QtStatusWidget.cpp",
"QtSwift.cpp",