diff options
Diffstat (limited to 'Swift/QtUI')
-rw-r--r-- | Swift/QtUI/QtMainWindow.cpp | 5 | ||||
-rw-r--r-- | Swift/QtUI/QtMainWindow.h | 1 | ||||
-rw-r--r-- | Swift/QtUI/QtNameWidget.cpp | 68 | ||||
-rw-r--r-- | Swift/QtUI/QtNameWidget.h | 25 | ||||
-rw-r--r-- | Swift/QtUI/QtRosterHeader.cpp | 1 | ||||
-rw-r--r-- | Swift/QtUI/QtRosterHeader.h | 1 |
6 files changed, 41 insertions, 60 deletions
diff --git a/Swift/QtUI/QtMainWindow.cpp b/Swift/QtUI/QtMainWindow.cpp index fb84da4..5cbc40c 100644 --- a/Swift/QtUI/QtMainWindow.cpp +++ b/Swift/QtUI/QtMainWindow.cpp @@ -40,7 +40,6 @@ 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 @@ -187,9 +186,5 @@ 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 ccec12c..62aafba 100644 --- a/Swift/QtUI/QtMainWindow.h +++ b/Swift/QtUI/QtMainWindow.h @@ -56,7 +56,6 @@ 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_; diff --git a/Swift/QtUI/QtNameWidget.cpp b/Swift/QtUI/QtNameWidget.cpp index bf38da8..d123bad 100644 --- a/Swift/QtUI/QtNameWidget.cpp +++ b/Swift/QtUI/QtNameWidget.cpp @@ -6,52 +6,25 @@ #include "QtNameWidget.h" -#include <QStackedWidget> #include <QHBoxLayout> +#include <QMenu> #include <QMouseEvent> +#include <QtDebug> #include <Swift/QtUI/QtElidingLabel.h> -#include <Swift/QtUI/QtSwiftUtil.h> -#include <Swift/QtUI/QtLineEdit.h> namespace Swift { -QtNameWidget::QtNameWidget(QWidget *parent) : QWidget(parent) { +QtNameWidget::QtNameWidget(QWidget *parent) : QWidget(parent), mode(ShowNick) { 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); + mainLayout->addWidget(textLabel); } void QtNameWidget::setNick(const QString& nick) { @@ -64,13 +37,40 @@ void QtNameWidget::setJID(const QString& jid) { updateText(); } +void QtNameWidget::mousePressEvent(QMouseEvent* event) { + QMenu menu; + + QAction* showAsNick = new QAction("Show nickname", this); + showAsNick->setCheckable(true); + if (mode == ShowNick) { + showAsNick->setChecked(true); + } + menu.addAction(showAsNick); + + QAction* showAsJID = new QAction("Show ID", this); + showAsJID->setCheckable(true); + if (mode == ShowJID) { + showAsJID->setChecked(true); + } + menu.addAction(showAsJID); + + QAction* result = menu.exec(event->globalPos()); + if (result == showAsJID) { + mode = ShowJID; + } + else { + mode = ShowNick; + } + updateText(); +} + void QtNameWidget::updateText() { QString text; - if (nick.isEmpty()) { - text = jid; + if (mode == ShowNick && !nick.isEmpty()) { + text = nick; } else { - text = nick + " (" + jid + ")"; + text = jid; } text.replace("<","<"); textLabel->setText(text); diff --git a/Swift/QtUI/QtNameWidget.h b/Swift/QtUI/QtNameWidget.h index c1c3e07..52586b7 100644 --- a/Swift/QtUI/QtNameWidget.h +++ b/Swift/QtUI/QtNameWidget.h @@ -8,12 +8,8 @@ #include <QWidget> -class QLabel; -class QStackedWidget; - namespace Swift { class QtElidingLabel; - class QtLineEdit; class QtNameWidget : public QWidget { Q_OBJECT @@ -24,25 +20,18 @@ namespace Swift { 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(); + virtual void mousePressEvent(QMouseEvent* event); private: - QStackedWidget* stack; + enum Mode { + ShowNick, + ShowJID, + }; + + Mode mode; QtElidingLabel* textLabel; - QtLineEdit* nickEdit; QString jid; QString nick; }; diff --git a/Swift/QtUI/QtRosterHeader.cpp b/Swift/QtUI/QtRosterHeader.cpp index efc198a..4649839 100644 --- a/Swift/QtUI/QtRosterHeader.cpp +++ b/Swift/QtUI/QtRosterHeader.cpp @@ -40,7 +40,6 @@ QtRosterHeader::QtRosterHeader(QWidget* parent) : QWidget(parent) { topLayout->addLayout(rightLayout); nameWidget_ = new QtNameWidget(this); - connect(nameWidget_, SIGNAL(onChangeNickRequest(const QString&)), this, SIGNAL(onChangeNickRequest(const QString&))); rightLayout->addWidget(nameWidget_); diff --git a/Swift/QtUI/QtRosterHeader.h b/Swift/QtUI/QtRosterHeader.h index cd5f26c..23e6be0 100644 --- a/Swift/QtUI/QtRosterHeader.h +++ b/Swift/QtUI/QtRosterHeader.h @@ -37,7 +37,6 @@ namespace Swift { 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); |