From d490e74fbca3e4ab4a75123dd75dab3bc753c010 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Mon, 15 Jun 2009 21:20:13 +0100 Subject: Early pass at tabs. Doesn't do closing or title updating diff --git a/Swift/QtUI/QtChatTabs.cpp b/Swift/QtUI/QtChatTabs.cpp new file mode 100644 index 0000000..f2349a9 --- /dev/null +++ b/Swift/QtUI/QtChatTabs.cpp @@ -0,0 +1,27 @@ +#pragma once + +#include "QtChatTabs.h" + +#include +#include + +namespace Swift { +QtChatTabs::QtChatTabs() { + tabs_ = new QTabWidget(this); + QVBoxLayout *layout = new QVBoxLayout; + layout->setSpacing(0); + layout->setContentsMargins(0, 3, 0, 0); + layout->addWidget(tabs_); + setLayout(layout); + resize(400, 300); +} + +void QtChatTabs::addTab(QWidget* tab) { + tabs_->addTab(tab, tab->windowTitle()); +} + +void QtChatTabs::tabClosing() { + +} + +} \ No newline at end of file diff --git a/Swift/QtUI/QtChatTabs.h b/Swift/QtUI/QtChatTabs.h new file mode 100644 index 0000000..6da166d --- /dev/null +++ b/Swift/QtUI/QtChatTabs.h @@ -0,0 +1,21 @@ +#pragma once + +#include + +class QTabWidget; + +namespace Swift { + class QtChatTabs : public QWidget { + Q_OBJECT + public: + QtChatTabs(); + void addTab(QWidget* tab); + + private slots: + void tabClosing(); + + private: + QTabWidget* tabs_; + }; +} + diff --git a/Swift/QtUI/QtChatWindowFactory.cpp b/Swift/QtUI/QtChatWindowFactory.cpp index b0b3679..c3c8f67 100644 --- a/Swift/QtUI/QtChatWindowFactory.cpp +++ b/Swift/QtUI/QtChatWindowFactory.cpp @@ -1,15 +1,21 @@ #include "QtChatWindowFactory.h" + +#include "QtChatTabs.h" #include "QtChatWindow.h" #include "QtSwiftUtil.h" #include "QtTreeWidgetFactory.h" + namespace Swift { QtChatWindowFactory::QtChatWindowFactory(QtTreeWidgetFactory *treeWidgetFactory) : treeWidgetFactory_(treeWidgetFactory) { - + tabs_ = new QtChatTabs(); } + ChatWindow* QtChatWindowFactory::createChatWindow(const JID &contact) { QtChatWindow *chatWindow = new QtChatWindow(P2QSTRING(contact.toString()), treeWidgetFactory_); - chatWindow->show(); + tabs_->addTab(chatWindow); + tabs_->show(); + //chatWindow->show(); return chatWindow; } diff --git a/Swift/QtUI/QtChatWindowFactory.h b/Swift/QtUI/QtChatWindowFactory.h index bda4c01..5ef6bdf 100644 --- a/Swift/QtUI/QtChatWindowFactory.h +++ b/Swift/QtUI/QtChatWindowFactory.h @@ -6,12 +6,14 @@ namespace Swift { class QtTreeWidgetFactory; + class QtChatTabs; class QtChatWindowFactory : public ChatWindowFactory { public: QtChatWindowFactory(QtTreeWidgetFactory *treeWidgetFactory); ChatWindow* createChatWindow(const JID &contact); private: - QtTreeWidgetFactory *treeWidgetFactory_; + QtTreeWidgetFactory* treeWidgetFactory_; + QtChatTabs* tabs_; }; } diff --git a/Swift/QtUI/Swift.pro b/Swift/QtUI/Swift.pro index 1c860b4..f831c02 100644 --- a/Swift/QtUI/Swift.pro +++ b/Swift/QtUI/Swift.pro @@ -59,6 +59,7 @@ HEADERS += \ QtTreeWidgetFactory.h \ QtTreeWidgetItem.h \ QtChatView.h \ + QtChatTabs.h \ ChatSnippet.h \ MessageSnippet.h \ SystemMessageSnippet.h @@ -77,6 +78,7 @@ SOURCES += \ QtSwift.cpp \ QtTreeWidget.cpp \ QtChatView.cpp \ + QtChatTabs.cpp \ ChatSnippet.cpp \ MessageSnippet.cpp \ SystemMessageSnippet.cpp -- cgit v0.10.2-6-g49f6 From 2e014f200768c91a1504002af1be5c0ac5eb0f42 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Mon, 15 Jun 2009 21:26:17 +0100 Subject: setDocumentMode for prettier Mac tabs. diff --git a/Swift/QtUI/QtChatTabs.cpp b/Swift/QtUI/QtChatTabs.cpp index f2349a9..cd3aada 100644 --- a/Swift/QtUI/QtChatTabs.cpp +++ b/Swift/QtUI/QtChatTabs.cpp @@ -8,6 +8,10 @@ namespace Swift { QtChatTabs::QtChatTabs() { tabs_ = new QTabWidget(this); +#if QT_VERSION >= 0x040500 + //For Macs, change the tab rendering. + tabs_->setDocumentMode(true); +#endif QVBoxLayout *layout = new QVBoxLayout; layout->setSpacing(0); layout->setContentsMargins(0, 3, 0, 0); -- cgit v0.10.2-6-g49f6 From 5f1d284169c89c30f061603a9f45ab753f4b8967 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Mon, 15 Jun 2009 22:05:33 +0100 Subject: Update tab titles for unread count. 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 #include 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(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 - 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 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& 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 +#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 + + +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 -- cgit v0.10.2-6-g49f6 From af53136d04a72b05efd8c51cfa5573f97e93c6cf Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Mon, 15 Jun 2009 22:31:15 +0100 Subject: Moving towards allowing tabs to be closed. At the moment they'll then be lost to tabbing forever, though. diff --git a/Swift/QtUI/QtChatTabs.cpp b/Swift/QtUI/QtChatTabs.cpp index f52a3fe..78cdf2d 100644 --- a/Swift/QtUI/QtChatTabs.cpp +++ b/Swift/QtUI/QtChatTabs.cpp @@ -7,8 +7,11 @@ namespace Swift { QtChatTabs::QtChatTabs() : QWidget() { tabs_ = new QTabWidget(this); #if QT_VERSION >= 0x040500 - //For Macs, change the tab rendering. + /*For Macs, change the tab rendering.*/ tabs_->setDocumentMode(true); + /*Closable tabs are only in Qt4.5 and later*/ + tabs_->setTabsClosable(true); + connect(tabs_, SIGNAL(tabCloseRequested(int)), this, SLOT(handleTabCloseRequested(int))); #endif QVBoxLayout *layout = new QVBoxLayout; layout->setSpacing(0); @@ -20,14 +23,29 @@ QtChatTabs::QtChatTabs() : QWidget() { void QtChatTabs::addTab(QtTabbable* tab) { tabs_->addTab(tab, tab->windowTitle()); - connect(tab, SIGNAL(titleUpdated()), this, SLOT(tabTitleUpdated())); + connect(tab, SIGNAL(titleUpdated()), this, SLOT(handleTabTitleUpdated())); + connect(tab, SIGNAL(windowClosing()), this, SLOT(handleTabClosing())); } -void QtChatTabs::tabClosing() { +void QtChatTabs::handleTabClosing() { + QWidget* widget = qobject_cast(sender()); + if (!widget) { + return; + } + int index = tabs_->indexOf(widget); + if (index < 0) { + return; + } + tabs_->removeTab(index); +} +void QtChatTabs::handleTabCloseRequested(int index) { + QWidget* widget = tabs_->widget(index); + tabs_->removeTab(index); + widget->hide(); } -void QtChatTabs::tabTitleUpdated() { +void QtChatTabs::handleTabTitleUpdated() { QWidget* widget = qobject_cast(sender()); if (!widget) { return; diff --git a/Swift/QtUI/QtChatTabs.h b/Swift/QtUI/QtChatTabs.h index 39a3e44..37acc91 100644 --- a/Swift/QtUI/QtChatTabs.h +++ b/Swift/QtUI/QtChatTabs.h @@ -12,8 +12,9 @@ namespace Swift { void addTab(QtTabbable* tab); private slots: - void tabClosing(); - void tabTitleUpdated(); + void handleTabClosing(); + void handleTabTitleUpdated(); + void handleTabCloseRequested(int index); private: QTabWidget* tabs_; }; diff --git a/Swift/QtUI/QtTabbable.h b/Swift/QtUI/QtTabbable.h index dfae498..9894bfe 100644 --- a/Swift/QtUI/QtTabbable.h +++ b/Swift/QtUI/QtTabbable.h @@ -11,5 +11,6 @@ namespace Swift { signals: void titleUpdated(); + void windowClosing(); }; } -- cgit v0.10.2-6-g49f6 From 73fa400641352d2f397b2e4a8589bf6ce80c7beb Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Mon, 15 Jun 2009 22:51:45 +0100 Subject: Slightly cleaner close behaviour for tabs - still broken. diff --git a/Swift/QtUI/QtChatTabs.cpp b/Swift/QtUI/QtChatTabs.cpp index 78cdf2d..c7cd7ba 100644 --- a/Swift/QtUI/QtChatTabs.cpp +++ b/Swift/QtUI/QtChatTabs.cpp @@ -41,8 +41,7 @@ void QtChatTabs::handleTabClosing() { void QtChatTabs::handleTabCloseRequested(int index) { QWidget* widget = tabs_->widget(index); - tabs_->removeTab(index); - widget->hide(); + widget->close(); } void QtChatTabs::handleTabTitleUpdated() { diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp index 880678a..9f1f445 100644 --- a/Swift/QtUI/QtChatWindow.cpp +++ b/Swift/QtUI/QtChatWindow.cpp @@ -95,6 +95,7 @@ SecurityLabel QtChatWindow::getSelectedSecurityLabel() { void QtChatWindow::closeEvent(QCloseEvent* event) { onClosed(); + emit windowClosing(); event->accept(); } -- cgit v0.10.2-6-g49f6