summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI/QtChatTabs.cpp')
-rw-r--r--Swift/QtUI/QtChatTabs.cpp40
1 files changed, 36 insertions, 4 deletions
diff --git a/Swift/QtUI/QtChatTabs.cpp b/Swift/QtUI/QtChatTabs.cpp
index 25c7ca2..9063001 100644
--- a/Swift/QtUI/QtChatTabs.cpp
+++ b/Swift/QtUI/QtChatTabs.cpp
@@ -7,6 +7,10 @@
#include "QtChatTabs.h"
#include <algorithm>
+#include <vector>
+
+#include <Swift/Controllers/ChatMessageSummarizer.h>
+#include <Swift/QtUI/QtSwiftUtil.h>
#include <QCloseEvent>
#include <QDesktopWidget>
@@ -35,6 +39,8 @@ QtChatTabs::QtChatTabs() : QWidget() {
#else
#warning Qt 4.5 or later is needed. Trying anyway, some things will be disabled.
#endif
+ connect(tabs_, SIGNAL(currentChanged(int)), this, SLOT(handleTabChange(int)), Qt::UniqueConnection);
+
QVBoxLayout *layout = new QVBoxLayout;
layout->setSpacing(0);
layout->setContentsMargins(0, 3, 0, 0);
@@ -60,6 +66,13 @@ void QtChatTabs::addTab(QtTabbable* tab) {
QSizePolicy policy = sizePolicy();
/* Chat windows like to grow - don't let them */
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+
+ /* Hide previous opened QtChatWindow, so it doesn't receive further QPaint events. */
+ QWidget* old = tabs_->currentWidget();
+ if (old) {
+ old->hide();
+ }
+
tabs_->addTab(tab, tab->windowTitle());
connect(tab, SIGNAL(titleUpdated()), this, SLOT(handleTabTitleUpdated()), Qt::UniqueConnection);
connect(tab, SIGNAL(countUpdated()), this, SLOT(handleTabTitleUpdated()), Qt::UniqueConnection);
@@ -236,16 +249,23 @@ void QtChatTabs::handleTabTitleUpdated(QWidget* widget) {
default : tabTextColor = QColor();
}
tabs_->tabBar()->setTabTextColor(index, tabTextColor);
- int unread = 0;
+
+ std::vector<std::pair<std::string, int> > unreads;
for (int i = 0; i < tabs_->count(); i++) {
QtTabbable* tab = qobject_cast<QtTabbable*>(tabs_->widget(i));
if (tab) {
- unread += tab->getCount();
+ unreads.push_back(std::pair<std::string, int>(Q2PSTRING(tab->windowTitle()), tab->getCount()));
}
}
- QtTabbable* current = qobject_cast<QtTabbable*>(tabs_->currentWidget());
- setWindowTitle(unread > 0 ? QString("(%1) %2").arg(unread).arg(current->windowTitle()) : current->windowTitle());
+ std::string current(Q2PSTRING(qobject_cast<QtTabbable*>(tabs_->currentWidget())->windowTitle()));
+ ChatMessageSummarizer summary;
+ setWindowTitle(summary.getSummary(current, unreads).c_str());
+
+ /* hide() QtChatWindow again, so it won't receive Paint events. */
+ if (widget != tabs_->currentWidget()) {
+ widget->hide();
+ }
}
void QtChatTabs::flash() {
@@ -254,6 +274,18 @@ void QtChatTabs::flash() {
#endif
}
+void QtChatTabs::handleTabChange(int index) {
+ if (index == -1) {
+ return;
+ }
+ /* hide() old tab, show() new tab */
+ QWidget* old_tab = tabs_->currentWidget();
+ old_tab->hide();
+
+ QWidget* new_tab = tabs_->widget(index);
+ new_tab->show();
+}
+
void QtChatTabs::resizeEvent(QResizeEvent*) {
emit geometryChanged();
}