summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Swift/QtUI/QtChatTabs.cpp26
-rw-r--r--Swift/QtUI/QtChatTabs.h5
-rw-r--r--Swift/QtUI/QtTabbable.h1
3 files changed, 26 insertions, 6 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;
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();
};
}