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 /Swift/QtUI/QtChatTabs.cpp
parenta2e0cf9108081663607706f661f411a5fcf86e1d (diff)
parent73fa400641352d2f397b2e4a8589bf6ce80c7beb (diff)
downloadswift-contrib-f1c690a5352ee77282bbbd145a3fe0137aceb160.zip
swift-contrib-f1c690a5352ee77282bbbd145a3fe0137aceb160.tar.bz2
Merge branch 'tabs'
Diffstat (limited to 'Swift/QtUI/QtChatTabs.cpp')
-rw-r--r--Swift/QtUI/QtChatTabs.cpp59
1 files changed, 59 insertions, 0 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