summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2009-06-16 21:27:44 (GMT)
committerKevin Smith <git@kismith.co.uk>2009-06-16 21:27:44 (GMT)
commitf1c690a5352ee77282bbbd145a3fe0137aceb160 (patch)
treeee54e5a269295f3010f906097efbf0e3a9ce8dd3
parenta2e0cf9108081663607706f661f411a5fcf86e1d (diff)
parent73fa400641352d2f397b2e4a8589bf6ce80c7beb (diff)
downloadswift-f1c690a5352ee77282bbbd145a3fe0137aceb160.zip
swift-f1c690a5352ee77282bbbd145a3fe0137aceb160.tar.bz2
Merge branch 'tabs'
-rw-r--r--Swift/QtUI/QtChatTabs.cpp59
-rw-r--r--Swift/QtUI/QtChatTabs.h22
-rw-r--r--Swift/QtUI/QtChatWindow.cpp4
-rw-r--r--Swift/QtUI/QtChatWindow.h4
-rw-r--r--Swift/QtUI/QtChatWindowFactory.cpp10
-rw-r--r--Swift/QtUI/QtChatWindowFactory.h4
-rw-r--r--Swift/QtUI/QtTabbable.h16
-rw-r--r--Swift/QtUI/Swift.pro3
8 files changed, 116 insertions, 6 deletions
diff --git a/Swift/QtUI/QtChatTabs.cpp b/Swift/QtUI/QtChatTabs.cpp
new file mode 100644
index 0000000..c7cd7ba
--- /dev/null
+++ b/Swift/QtUI/QtChatTabs.cpp
@@ -0,0 +1,59 @@
+#include "QtChatTabs.h"
+
+#include <QTabWidget>
+#include <QLayout>
+
+namespace Swift {
+QtChatTabs::QtChatTabs() : QWidget() {
+ tabs_ = new QTabWidget(this);
+#if QT_VERSION >= 0x040500
+ /*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);
+ layout->setContentsMargins(0, 3, 0, 0);
+ layout->addWidget(tabs_);
+ setLayout(layout);
+ resize(400, 300);
+}
+
+void QtChatTabs::addTab(QtTabbable* tab) {
+ tabs_->addTab(tab, tab->windowTitle());
+ connect(tab, SIGNAL(titleUpdated()), this, SLOT(handleTabTitleUpdated()));
+ connect(tab, SIGNAL(windowClosing()), this, SLOT(handleTabClosing()));
+}
+
+void QtChatTabs::handleTabClosing() {
+ QWidget* widget = qobject_cast<QWidget*>(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);
+ widget->close();
+}
+
+void QtChatTabs::handleTabTitleUpdated() {
+ 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
new file mode 100644
index 0000000..37acc91
--- /dev/null
+++ b/Swift/QtUI/QtChatTabs.h
@@ -0,0 +1,22 @@
+#pragma once
+
+#include "QtTabbable.h"
+#include <QWidget>
+class QTabWidget;
+
+namespace Swift {
+ class QtChatTabs : public QWidget {
+ Q_OBJECT
+ public:
+ QtChatTabs();
+ void addTab(QtTabbable* tab);
+
+ private slots:
+ void handleTabClosing();
+ void handleTabTitleUpdated();
+ void handleTabCloseRequested(int index);
+ private:
+ QTabWidget* tabs_;
+ };
+}
+
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp
index 1db8dae..9f1f445 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();
@@ -95,6 +95,7 @@ SecurityLabel QtChatWindow::getSelectedSecurityLabel() {
void QtChatWindow::closeEvent(QCloseEvent* event) {
onClosed();
+ emit windowClosing();
event->accept();
}
@@ -117,6 +118,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/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/QtTabbable.h b/Swift/QtUI/QtTabbable.h
new file mode 100644
index 0000000..9894bfe
--- /dev/null
+++ b/Swift/QtUI/QtTabbable.h
@@ -0,0 +1,16 @@
+#pragma once
+
+#include <QWidget>
+
+
+namespace Swift {
+ class QtTabbable : public QWidget {
+ Q_OBJECT
+ protected:
+ QtTabbable() : QWidget() {};
+
+ signals:
+ void titleUpdated();
+ void windowClosing();
+ };
+}
diff --git a/Swift/QtUI/Swift.pro b/Swift/QtUI/Swift.pro
index 1c860b4..2a6c9ba 100644
--- a/Swift/QtUI/Swift.pro
+++ b/Swift/QtUI/Swift.pro
@@ -59,6 +59,8 @@ HEADERS += \
QtTreeWidgetFactory.h \
QtTreeWidgetItem.h \
QtChatView.h \
+ QtChatTabs.h \
+ QtTabbable.h \
ChatSnippet.h \
MessageSnippet.h \
SystemMessageSnippet.h
@@ -77,6 +79,7 @@ SOURCES += \
QtSwift.cpp \
QtTreeWidget.cpp \
QtChatView.cpp \
+ QtChatTabs.cpp \
ChatSnippet.cpp \
MessageSnippet.cpp \
SystemMessageSnippet.cpp