summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI/QtChatTabs.cpp')
-rw-r--r--Swift/QtUI/QtChatTabs.cpp50
1 files changed, 34 insertions, 16 deletions
diff --git a/Swift/QtUI/QtChatTabs.cpp b/Swift/QtUI/QtChatTabs.cpp
index 9921754..cf335e1 100644
--- a/Swift/QtUI/QtChatTabs.cpp
+++ b/Swift/QtUI/QtChatTabs.cpp
@@ -23,7 +23,9 @@
namespace Swift {
-QtChatTabs::QtChatTabs() : QWidget() {
-#ifndef Q_WS_MAC
+QtChatTabs::QtChatTabs(bool singleWindow) : QWidget(), singleWindow_(singleWindow) {
+#ifndef Q_OS_MAC
setWindowIcon(QIcon(":/logo-chat-16.png"));
+#else
+ setAttribute(Qt::WA_ShowWithoutActivating);
#endif
@@ -36,4 +38,5 @@ QtChatTabs::QtChatTabs() : QWidget() {
/*Closable tabs are only in Qt4.5 and later*/
tabs_->setTabsClosable(true);
+ tabs_->setMovable(true);
connect(tabs_, SIGNAL(tabCloseRequested(int)), this, SLOT(handleTabCloseRequested(int)));
#else
@@ -45,5 +48,4 @@ QtChatTabs::QtChatTabs() : QWidget() {
layout->addWidget(tabs_);
setLayout(layout);
- //resize(400, 300);
}
@@ -109,17 +111,21 @@ void QtChatTabs::handleWantsToActivate() {
void QtChatTabs::handleTabClosing() {
QWidget* widget = qobject_cast<QWidget*>(sender());
- if (!widget) {
- return;
- }
- int index = tabs_->indexOf(widget);
- if (index < 0) {
- return;
- }
+ int index;
+ if (widget && ((index = tabs_->indexOf(widget)) >= 0)) {
tabs_->removeTab(index);
if (tabs_->count() == 0) {
+ if (!singleWindow_) {
hide();
}
+ else {
+ setWindowTitle("");
+ onTitleChanged("");
+ }
+ }
+ else {
handleTabTitleUpdated(tabs_->currentWidget());
}
+ }
+}
void QtChatTabs::handleRequestedPreviousTab() {
@@ -177,8 +183,7 @@ void QtChatTabs::handleTabTitleUpdated(QWidget* widget) {
QString tabText = tabbable->windowTitle().simplified();
-
// look for spectrum-generated and other long JID localparts, and
// try to abbreviate the resulting long tab texts
- QRegExp hasTrailingGarbage("^(.[-\\w\\s&]+)([^\\s\\w].*)$");
+ QRegExp hasTrailingGarbage("^(.[-\\w\\s,&]+)([^\\s\\,w].*)$");
if (hasTrailingGarbage.exactMatch(tabText) &&
hasTrailingGarbage.cap(1).simplified().length() >= 2 &&
@@ -189,8 +194,6 @@ void QtChatTabs::handleTabTitleUpdated(QWidget* widget) {
tabText = hasTrailingGarbage.cap(1).simplified();
}
-
// QTabBar interprets &, so escape that
tabText.replace("&", "&&");
-
// see which alt[a-z] keys other tabs use
bool accelsTaken[26];
@@ -238,5 +241,5 @@ void QtChatTabs::handleTabTitleUpdated(QWidget* widget) {
case QtTabbable::WaitingActivity : tabTextColor = QColor(217, 20, 43); break;
case QtTabbable::ImpendingActivity : tabTextColor = QColor(27, 171, 32); break;
- default : tabTextColor = QColor();
+ case QtTabbable::NoActivity : tabTextColor = QColor(); break;
}
tabs_->tabBar()->setTabTextColor(index, tabTextColor);
@@ -252,5 +255,7 @@ void QtChatTabs::handleTabTitleUpdated(QWidget* widget) {
std::string current(Q2PSTRING(qobject_cast<QtTabbable*>(tabs_->currentWidget())->windowTitle()));
ChatMessageSummarizer summary;
- setWindowTitle(summary.getSummary(current, unreads).c_str());
+ QString title = summary.getSummary(current, unreads).c_str();
+ setWindowTitle(title);
+ emit onTitleChanged(title);
}
@@ -271,5 +276,18 @@ void QtChatTabs::moveEvent(QMoveEvent*) {
void QtChatTabs::checkForFirstShow() {
if (!isVisible()) {
+#ifndef Q_OS_MAC
showMinimized();
+#else
+ /* https://bugreports.qt-project.org/browse/QTBUG-19194
+ * ^ When the above is fixed we can swap the below for just show();
+ * WA_ShowWithoutActivating seems to helpfully not work, so... */
+
+ QWidget* currentWindow = QApplication::activeWindow(); /* Remember who had focus if we're the current application*/
+ show();
+ QCoreApplication::processEvents(); /* Run through the eventloop to clear the show() */
+ if (currentWindow) {
+ currentWindow->activateWindow(); /* Set focus back */
+ }
+#endif
}
}