diff options
-rw-r--r-- | Swift/QtUI/Trellis/QtDNDTabBar.cpp | 16 | ||||
-rw-r--r-- | Swift/QtUI/Trellis/QtDNDTabBar.h | 9 |
2 files changed, 19 insertions, 6 deletions
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 @@ -5,16 +5,16 @@ */ #include <Swift/QtUI/Trellis/QtDNDTabBar.h> #include <cassert> -#include <QMouseEvent> -#include <QDropEvent> #include <QDrag> +#include <QDropEvent> #include <QMimeData> +#include <QMouseEvent> #include <QPainter> #include <QTabWidget> namespace Swift { QtDNDTabBar::QtDNDTabBar(QWidget* parent) : QTabBar(parent) { @@ -47,12 +47,24 @@ QSize QtDNDTabBar::sizeHint() const { if (hint.isEmpty()) { hint = QSize(parentWidget()->width(), defaultTabHeight); } 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<QtDNDTabBar*>(dragEnterEvent->source()); if (sourceTabBar) { dragEnterEvent->acceptProposedAction(); } } 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,8 +1,8 @@ /* - * Copyright (c) 2014 Isode Limited. + * Copyright (c) 2014-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once @@ -23,15 +23,16 @@ class QtDNDTabBar : public QTabBar { virtual QSize sizeHint() const; signals: 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; int dragIndex; QString dragText; QWidget* dragWidget; |