summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2009-06-15 21:31:15 (GMT)
committerKevin Smith <git@kismith.co.uk>2009-06-15 21:31:15 (GMT)
commitaf53136d04a72b05efd8c51cfa5573f97e93c6cf (patch)
treef96f9f75dad886a919d4dce4aad0511db5babfb0 /Swift/QtUI/QtChatTabs.cpp
parent5f1d284169c89c30f061603a9f45ab753f4b8967 (diff)
downloadswift-contrib-af53136d04a72b05efd8c51cfa5573f97e93c6cf.zip
swift-contrib-af53136d04a72b05efd8c51cfa5573f97e93c6cf.tar.bz2
Moving towards allowing tabs to be closed. At the moment they'll then be lost to tabbing forever, though.
Diffstat (limited to 'Swift/QtUI/QtChatTabs.cpp')
-rw-r--r--Swift/QtUI/QtChatTabs.cpp26
1 files changed, 22 insertions, 4 deletions
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<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);
+ tabs_->removeTab(index);
+ widget->hide();
}
-void QtChatTabs::tabTitleUpdated() {
+void QtChatTabs::handleTabTitleUpdated() {
QWidget* widget = qobject_cast<QWidget*>(sender());
if (!widget) {
return;