summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2016-08-19 08:47:54 (GMT)
committerTobias Markmann <tm@ayena.de>2016-08-19 08:47:54 (GMT)
commit1a12b42c291784bc097487c4f4533df9efaded11 (patch)
treed027ab5d4071c86c97ffae21fa26199a2374697f /Swift/QtUI/QtTabWidget.cpp
parenta9599ff4edfdc0186b2f5ae3bd22f25cdeb686d1 (diff)
downloadswift-1a12b42c291784bc097487c4f4533df9efaded11.zip
swift-1a12b42c291784bc097487c4f4533df9efaded11.tar.bz2
Support dropping tabs on tab widgets
Previously users could only drag and drop tabs on other tab bars. With this change the user can simply drop the tab on another tab widgets. This works on all QtTabWidgets that have a QtDNDTabBar set, regardless of their number of child widgets. This works by forwarding dragEnverEvent() and dropEvent() calls on the QtTabWidget to the corresponding QtDNDTabBar. Tabs dropped on the tab widget instead of the tab bar are added at the end of the tab bar. Test-Information: Tested with Qt 5.5.1 on OS X 10.11.6 and Windows 7. Change-Id: Ie73e02de24472eab2d20a89c937fb6630b1ef7b8
Diffstat (limited to 'Swift/QtUI/QtTabWidget.cpp')
-rw-r--r--Swift/QtUI/QtTabWidget.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/Swift/QtUI/QtTabWidget.cpp b/Swift/QtUI/QtTabWidget.cpp
index 9f353d7..cda1847 100644
--- a/Swift/QtUI/QtTabWidget.cpp
+++ b/Swift/QtUI/QtTabWidget.cpp
@@ -6,6 +6,8 @@
#include <Swift/QtUI/QtTabWidget.h>
+#include <Swift/QtUI/Trellis/QtDNDTabBar.h>
+
namespace Swift {
QtTabWidget::QtTabWidget(QWidget* parent) : QTabWidget(parent) {
@@ -22,5 +24,26 @@ QTabBar* QtTabWidget::tabBar() {
void QtTabWidget::setTabBar(QTabBar* tabBar) {
QTabWidget::setTabBar(tabBar);
+ if (dynamic_cast<QtDNDTabBar*>(tabBar)) {
+ setAcceptDrops(true);
+ }
+ else {
+ setAcceptDrops(false);
+ }
+}
+
+void QtTabWidget::dragEnterEvent(QDragEnterEvent* event) {
+ QtDNDTabBar* dndTabBar = dynamic_cast<QtDNDTabBar*>(tabBar());
+ if (dndTabBar) {
+ dndTabBar->dragEnterEvent(event);
+ }
}
+
+void QtTabWidget::dropEvent(QDropEvent* event) {
+ QtDNDTabBar* dndTabBar = dynamic_cast<QtDNDTabBar*>(tabBar());
+ if (dndTabBar) {
+ dndTabBar->dropEvent(event);
+ }
+}
+
}