From 8901feb42b754f97a843d43041a2a7425631a6dc Mon Sep 17 00:00:00 2001 From: falkTX Date: Sun, 31 Aug 2014 01:28:26 +0100 Subject: [PATCH] Use a dockwidget instead of custom splitter --- resources/ui/carla_host.ui | 329 +++++++++++++++++++------------------ source/carla | 45 ++++- source/carla_host.py | 13 +- 3 files changed, 215 insertions(+), 172 deletions(-) diff --git a/resources/ui/carla_host.ui b/resources/ui/carla_host.ui index 255a90be7..0f2fdbb98 100644 --- a/resources/ui/carla_host.ui +++ b/resources/ui/carla_host.ui @@ -6,176 +6,21 @@ 0 0 - 688 - 355 + 739 + 467 MainWindow - - - - 0 - - - 1 - - - 0 - - - 0 - - - - - Qt::Horizontal - - - - - 1 - - - - - - 0 - 0 - - - - - 210 - 0 - - - - false - - - QTabWidget::West - - - 0 - - - - false - - - Disk - - - - 0 - - - 0 - - - 0 - - - 0 - - - 1 - - - - - - - - Home - - - - - - - - - - - - :/16x16/list-add.png:/16x16/list-add.png - - - - - - - false - - - - - - - :/16x16/list-remove.png:/16x16/list-remove.png - - - - - - - - - QAbstractItemView::NoEditTriggers - - - true - - - QAbstractItemView::DragOnly - - - - - - - - - - - - 210 - 162 - - - - - 16777215 - 162 - - - - false - - - QFrame::StyledPanel - - - QFrame::Sunken - - - - - - - - - + 0 0 - 688 - 17 + 739 + 19 @@ -309,6 +154,170 @@ + + + QDockWidget::NoDockWidgetFeatures + + + Qt::NoDockWidgetArea + + + 1 + + + + + 0 + + + 0 + + + 1 + + + 0 + + + 0 + + + + + 1 + + + + + + 0 + 0 + + + + + 210 + 0 + + + + false + + + QTabWidget::West + + + 0 + + + + false + + + Disk + + + + 0 + + + 0 + + + 0 + + + 0 + + + 1 + + + + + + + + Home + + + + + + + + + + + + :/16x16/list-add.png:/16x16/list-add.png + + + + + + + false + + + + + + + :/16x16/list-remove.png:/16x16/list-remove.png + + + + + + + + + QAbstractItemView::NoEditTriggers + + + true + + + QAbstractItemView::DragOnly + + + + + + + + + + + + 210 + 162 + + + + + 16777215 + 162 + + + + false + + + QFrame::StyledPanel + + + QFrame::Sunken + + tabUtils + + + + + + + diff --git a/source/carla b/source/carla index 01d9de424..5b714bcd4 100755 --- a/source/carla +++ b/source/carla @@ -25,8 +25,10 @@ from carla_config import * # Imports (Global) if config_UseQt5: + from PyQt5.QtCore import QEvent from PyQt5.QtWidgets import QLabel, QTabWidget else: + from PyQt4.QtCore import QEvent from PyQt4.QtGui import QLabel, QTabWidget # ------------------------------------------------------------------------------------------------------------ @@ -232,6 +234,9 @@ class CarlaHostW(HostWindow): self.fInfoLabel.setAlignment(Qt.AlignRight|Qt.AlignVCenter) self.fInfoLabel.setText("Engine stopped") + self.fDockLocation = Qt.LeftDockWidgetArea + self.fDockFloating = 0 + if MACOS and False: # TODO: check if NOT using pro theme self.fInfoLabel.hide() self.setUnifiedTitleAndToolBarOnMac(True) @@ -239,7 +244,13 @@ class CarlaHostW(HostWindow): # ------------------------------------------------------------- self.ui.act_settings_show_toolbar.triggered.connect(self.slot_toolbarShown) - self.ui.splitter.splitterMoved.connect(self.slot_splitterMoved) + self.ui.dockWidget.dockLocationChanged.connect(self.slot_dockLocationChanged) + self.ui.dockWidget.topLevelChanged.connect(self.slot_dockTopLevelChanged) + + self.ui.dockWidget.installEventFilter(self) + + self.ui.dockWidgetTitleBar = QWidget(self) + self.ui.dockWidget.setTitleBarWidget(self.ui.dockWidgetTitleBar) QTimer.singleShot(0, self.slot_initWidgets) @@ -257,9 +268,17 @@ class CarlaHostW(HostWindow): def updateInfoLabelXandSize(self): tabBar = self.fContainer.tabBar() - x = tabBar.width() + self.ui.tabUtils.width() + 20 + x = tabBar.width() + 20 + width = self.fContainer.width() - tabBar.width() - 20 + + if self.fDockLocation == Qt.LeftDockWidgetArea and self.fDockFloating <= 1: + x += self.ui.dockWidget.width() + self.fInfoLabel.move(x, self.fInfoLabel.y()) - self.fInfoLabel.resize(self.fContainer.width()-tabBar.width()-20, self.fInfoLabel.height()) + self.fInfoLabel.resize(width, self.fInfoLabel.height()) + + if self.fDockFloating == 1: + self.fDockFloating = 2 def updateInfoLabelY(self): tabBar = self.fContainer.tabBar() @@ -275,9 +294,12 @@ class CarlaHostW(HostWindow): @pyqtSlot() def slot_initWidgets(self): tabBar = self.fContainer.tabBar() - x = tabBar.width() + self.ui.tabUtils.width() + 20 + x = tabBar.width() + 20 y = tabBar.mapFromParent(self.ui.centralwidget.pos()).y() + if self.fDockLocation == Qt.LeftDockWidgetArea and self.fDockFloating <= 1: + x += self.ui.tabUtils.width() + self.fInfoLabel.move(x, y) self.fInfoLabel.resize(self.fContainer.width()-tabBar.width()-20, tabBar.height()) @@ -286,8 +308,14 @@ class CarlaHostW(HostWindow): self.fContainer.setCurrentIndex(0) self.fContainer.fixCanvasPreviewSize() - @pyqtSlot() - def slot_splitterMoved(self): + @pyqtSlot(bool) + def slot_dockTopLevelChanged(self, top): + self.fDockFloating = 1 if top else 0 + self.updateInfoLabelXandSize() + + @pyqtSlot(Qt.DockWidgetArea) + def slot_dockLocationChanged(self, area): + self.fDockLocation = area self.updateInfoLabelXandSize() @pyqtSlot() @@ -296,6 +324,11 @@ class CarlaHostW(HostWindow): # ----------------------------------------------------------------- + def eventFilter(self, obj, event): + if obj == self.ui.dockWidget and event.type() == QEvent.Resize: + self.updateInfoLabelXandSize() + return HostWindow.eventFilter(self, obj, event) + def resizeEvent(self, event): HostWindow.resizeEvent(self, event) self.updateInfoLabelXandSize() diff --git a/source/carla_host.py b/source/carla_host.py index 4efec9a11..1a025ccd4 100644 --- a/source/carla_host.py +++ b/source/carla_host.py @@ -379,7 +379,8 @@ class HostWindow(QMainWindow): self.ui.menu_Canvas_Zoom.setVisible(False) self.ui.miniCanvasPreview.hide() - self.ui.splitter.insertWidget(1, self.fContainer) + self.setCentralWidget(self.fContainer) + self.ui.centralwidget = self.fContainer def updateContainer(self, canvasThemeData): canvasWidth, canvasHeight, canvasBg, canvasBrush, canvasPen = canvasThemeData @@ -719,10 +720,10 @@ class HostWindow(QMainWindow): self.ui.act_settings_show_toolbar.setChecked(showToolbar) self.ui.toolBar.setVisible(showToolbar) - if settings.contains("SplitterState"): - self.ui.splitter.restoreState(settings.value("SplitterState", "")) - else: - self.ui.splitter.setSizes([210, 99999]) + #if settings.contains("SplitterState"): + #self.ui.splitter.restoreState(settings.value("SplitterState", "")) + #else: + #self.ui.splitter.setSizes([210, 99999]) diskFolders = toList(settings.value("DiskFolders", [HOME])) @@ -775,7 +776,7 @@ class HostWindow(QMainWindow): settings = QSettings() settings.setValue("Geometry", self.saveGeometry()) - settings.setValue("SplitterState", self.ui.splitter.saveState()) + #settings.setValue("SplitterState", self.ui.splitter.saveState()) settings.setValue("ShowToolbar", self.ui.toolBar.isVisible()) diskFolders = []