diff options
author | Kevin Smith <git@kismith.co.uk> | 2009-06-15 21:05:33 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2009-06-15 21:05:33 (GMT) |
commit | 5f1d284169c89c30f061603a9f45ab753f4b8967 (patch) | |
tree | 8e50c8eb3ac5c9e5178983f0bbd7dc69e42311af | |
parent | 2e014f200768c91a1504002af1be5c0ac5eb0f42 (diff) | |
download | swift-5f1d284169c89c30f061603a9f45ab753f4b8967.zip swift-5f1d284169c89c30f061603a9f45ab753f4b8967.tar.bz2 |
Update tab titles for unread count.
-rw-r--r-- | Swift/QtUI/QtChatTabs.cpp | 19 | ||||
-rw-r--r-- | Swift/QtUI/QtChatTabs.h | 6 | ||||
-rw-r--r-- | Swift/QtUI/QtChatWindow.cpp | 3 | ||||
-rw-r--r-- | Swift/QtUI/QtChatWindow.h | 4 | ||||
-rw-r--r-- | Swift/QtUI/QtTabbable.h | 15 | ||||
-rw-r--r-- | Swift/QtUI/Swift.pro | 1 |
6 files changed, 38 insertions, 10 deletions
diff --git a/Swift/QtUI/QtChatTabs.cpp b/Swift/QtUI/QtChatTabs.cpp index cd3aada..f52a3fe 100644 --- a/Swift/QtUI/QtChatTabs.cpp +++ b/Swift/QtUI/QtChatTabs.cpp @@ -1,12 +1,10 @@ -#pragma once - #include "QtChatTabs.h" #include <QTabWidget> #include <QLayout> namespace Swift { -QtChatTabs::QtChatTabs() { +QtChatTabs::QtChatTabs() : QWidget() { tabs_ = new QTabWidget(this); #if QT_VERSION >= 0x040500 //For Macs, change the tab rendering. @@ -20,12 +18,25 @@ QtChatTabs::QtChatTabs() { resize(400, 300); } -void QtChatTabs::addTab(QWidget* tab) { +void QtChatTabs::addTab(QtTabbable* tab) { tabs_->addTab(tab, tab->windowTitle()); + connect(tab, SIGNAL(titleUpdated()), this, SLOT(tabTitleUpdated())); } void QtChatTabs::tabClosing() { } +void QtChatTabs::tabTitleUpdated() { + QWidget* widget = qobject_cast<QWidget*>(sender()); + if (!widget) { + return; + } + int index = tabs_->indexOf(widget); + if (index < 0) { + return; + } + tabs_->setTabText(index, widget->windowTitle()); +} + }
\ No newline at end of file diff --git a/Swift/QtUI/QtChatTabs.h b/Swift/QtUI/QtChatTabs.h index 6da166d..39a3e44 100644 --- a/Swift/QtUI/QtChatTabs.h +++ b/Swift/QtUI/QtChatTabs.h @@ -1,7 +1,7 @@ #pragma once +#include "QtTabbable.h" #include <QWidget> - class QTabWidget; namespace Swift { @@ -9,11 +9,11 @@ namespace Swift { Q_OBJECT public: QtChatTabs(); - void addTab(QWidget* tab); + void addTab(QtTabbable* tab); private slots: void tabClosing(); - + void tabTitleUpdated(); private: QTabWidget* tabs_; }; diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp index 1db8dae..880678a 100644 --- a/Swift/QtUI/QtChatWindow.cpp +++ b/Swift/QtUI/QtChatWindow.cpp @@ -17,7 +17,7 @@ #include <QTime> namespace Swift { -QtChatWindow::QtChatWindow(const QString &contact, QtTreeWidgetFactory *treeWidgetFactory) : QWidget(), contact_(contact), previousMessageWasSelf_(false), previousMessageWasSystem_(false) { +QtChatWindow::QtChatWindow(const QString &contact, QtTreeWidgetFactory *treeWidgetFactory) : QtTabbable(), contact_(contact), previousMessageWasSelf_(false), previousMessageWasSystem_(false) { unreadCount_ = 0; updateTitleWithUnreadCount(); @@ -117,6 +117,7 @@ void QtChatWindow::setUnreadMessageCount(int count) { void QtChatWindow::updateTitleWithUnreadCount() { setWindowTitle(unreadCount_ > 0 ? QString("(%1) %2)").arg(unreadCount_).arg(contact_) : contact_); + emit titleUpdated(); } void QtChatWindow::addMessage(const String &message, const String &senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label) { diff --git a/Swift/QtUI/QtChatWindow.h b/Swift/QtUI/QtChatWindow.h index 8b830d1..e0c7f5d 100644 --- a/Swift/QtUI/QtChatWindow.h +++ b/Swift/QtUI/QtChatWindow.h @@ -3,7 +3,7 @@ #include "Swift/Controllers/ChatWindow.h" -#include <QWidget> +#include "QtTabbable.h" class QTextEdit; class QLineEdit; @@ -14,7 +14,7 @@ namespace Swift { class QtTreeWidget; class QtTreeWidgetFactory; class TreeWidget; - class QtChatWindow : public QWidget, public ChatWindow { + class QtChatWindow : public QtTabbable, public ChatWindow { Q_OBJECT public: QtChatWindow(const QString &contact, QtTreeWidgetFactory* treeWidgetFactory); diff --git a/Swift/QtUI/QtTabbable.h b/Swift/QtUI/QtTabbable.h new file mode 100644 index 0000000..dfae498 --- /dev/null +++ b/Swift/QtUI/QtTabbable.h @@ -0,0 +1,15 @@ +#pragma once + +#include <QWidget> + + +namespace Swift { + class QtTabbable : public QWidget { + Q_OBJECT + protected: + QtTabbable() : QWidget() {}; + + signals: + void titleUpdated(); + }; +} diff --git a/Swift/QtUI/Swift.pro b/Swift/QtUI/Swift.pro index f831c02..2a6c9ba 100644 --- a/Swift/QtUI/Swift.pro +++ b/Swift/QtUI/Swift.pro @@ -60,6 +60,7 @@ HEADERS += \ QtTreeWidgetItem.h \ QtChatView.h \ QtChatTabs.h \ + QtTabbable.h \ ChatSnippet.h \ MessageSnippet.h \ SystemMessageSnippet.h |