From 6c7c1411080dceed313f8d50e43454a160707121 Mon Sep 17 00:00:00 2001 From: Tobias Markmann Date: Mon, 30 Nov 2015 18:27:05 +0100 Subject: Workaround QTabBar early eliding bug on OS X The issue is visible when having two chat windows with the same label. One of them is elided even though enough horizontal space is available. Test-Information: Tested multiple chats including some with the same tab label. Tested many open chat windows overflowing the horizontal space of the tab bar to test scroll behavior on overflow. Verified that the code stops the early eliding bug on OS X 10.10.5 with Qt 5.4.2. Verified that workaround is not needed on Debian 8.2 with Qt 5.4.2. Change-Id: I2dc0d417fb6f402dda2f7575a83ca3faf4eb63cf diff --git a/Swift/QtUI/Trellis/QtDNDTabBar.cpp b/Swift/QtUI/Trellis/QtDNDTabBar.cpp index a6806c6..dbe397b 100644 --- a/Swift/QtUI/Trellis/QtDNDTabBar.cpp +++ b/Swift/QtUI/Trellis/QtDNDTabBar.cpp @@ -8,10 +8,10 @@ #include -#include -#include #include +#include #include +#include #include #include @@ -50,6 +50,18 @@ QSize QtDNDTabBar::sizeHint() const { return hint; } +QSize QtDNDTabBar::tabSizeHint(int index) const { + QSize tabSize = QTabBar::tabSizeHint(index); +#if defined(Q_OS_MAC) + // With multiple tabs having the same label in a QTabBar, the size hint computed by + // Qt on OS X is too small and it is elided even though there is enough horizontal + // space available. We work around this issue by adding the width of a letter to the + // size hint. + tabSize += QSize(QFontMetrics(font()).width("I"), 0); +#endif + return tabSize; +} + void QtDNDTabBar::dragEnterEvent(QDragEnterEvent* dragEnterEvent) { QtDNDTabBar* sourceTabBar = dynamic_cast(dragEnterEvent->source()); if (sourceTabBar) { diff --git a/Swift/QtUI/Trellis/QtDNDTabBar.h b/Swift/QtUI/Trellis/QtDNDTabBar.h index 194cce8..71ca94b 100644 --- a/Swift/QtUI/Trellis/QtDNDTabBar.h +++ b/Swift/QtUI/Trellis/QtDNDTabBar.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Isode Limited. + * Copyright (c) 2014-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -26,9 +26,10 @@ class QtDNDTabBar : public QTabBar { void onDropSucceeded(); protected: - void dragEnterEvent(QDragEnterEvent* dragEnterEvent); - void dropEvent(QDropEvent* dropEvent); - bool event(QEvent* event); + virtual void dragEnterEvent(QDragEnterEvent* dragEnterEvent); + virtual void dropEvent(QDropEvent* dropEvent); + virtual bool event(QEvent* event); + virtual QSize tabSizeHint(int index) const; private: int defaultTabHeight; -- cgit v0.10.2-6-g49f6