Browse Source

Use a dockwidget instead of custom splitter

tags/1.9.5
falkTX 10 years ago
parent
commit
8901feb42b
3 changed files with 215 additions and 172 deletions
  1. +169
    -160
      resources/ui/carla_host.ui
  2. +39
    -6
      source/carla
  3. +7
    -6
      source/carla_host.py

+ 169
- 160
resources/ui/carla_host.ui View File

@@ -6,176 +6,21 @@
<rect>
<x>0</x>
<y>0</y>
<width>688</width>
<height>355</height>
<width>739</width>
<height>467</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>1</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QWidget" name="layoutWidget">
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="spacing">
<number>1</number>
</property>
<item>
<widget class="QTabWidget" name="tabUtils">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>210</width>
<height>0</height>
</size>
</property>
<property name="acceptDrops">
<bool>false</bool>
</property>
<property name="tabPosition">
<enum>QTabWidget::West</enum>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="disk">
<property name="acceptDrops">
<bool>false</bool>
</property>
<attribute name="title">
<string>Disk</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>1</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QComboBox" name="cb_disk">
<item>
<property name="text">
<string>Home</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QToolButton" name="b_disk_add">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/16x16/list-add.png</normaloff>:/16x16/list-add.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="b_disk_remove">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/16x16/list-remove.png</normaloff>:/16x16/list-remove.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTreeView" name="fileTreeView">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::DragOnly</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<widget class="CanvasPreviewFrame" name="miniCanvasPreview">
<property name="minimumSize">
<size>
<width>210</width>
<height>162</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>162</height>
</size>
</property>
<property name="acceptDrops">
<bool>false</bool>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="centralwidget"/>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>688</width>
<height>17</height>
<width>739</width>
<height>19</height>
</rect>
</property>
<widget class="QMenu" name="menu_File">
@@ -309,6 +154,170 @@
<addaction name="separator"/>
<addaction name="act_settings_configure"/>
</widget>
<widget class="QDockWidget" name="dockWidget">
<property name="features">
<set>QDockWidget::NoDockWidgetFeatures</set>
</property>
<property name="allowedAreas">
<set>Qt::NoDockWidgetArea</set>
</property>
<attribute name="dockWidgetArea">
<number>1</number>
</attribute>
<widget class="QWidget" name="dockWidgetContents">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>1</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="spacing">
<number>1</number>
</property>
<item>
<widget class="QTabWidget" name="tabUtils">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>210</width>
<height>0</height>
</size>
</property>
<property name="acceptDrops">
<bool>false</bool>
</property>
<property name="tabPosition">
<enum>QTabWidget::West</enum>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="disk">
<property name="acceptDrops">
<bool>false</bool>
</property>
<attribute name="title">
<string>Disk</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>1</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QComboBox" name="cb_disk">
<item>
<property name="text">
<string>Home</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QToolButton" name="b_disk_add">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/16x16/list-add.png</normaloff>:/16x16/list-add.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="b_disk_remove">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/16x16/list-remove.png</normaloff>:/16x16/list-remove.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTreeView" name="fileTreeView">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::DragOnly</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<widget class="CanvasPreviewFrame" name="miniCanvasPreview">
<property name="minimumSize">
<size>
<width>210</width>
<height>162</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>162</height>
</size>
</property>
<property name="acceptDrops">
<bool>false</bool>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<zorder>tabUtils</zorder>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
<action name="act_file_new">
<property name="icon">
<iconset resource="../resources.qrc">


+ 39
- 6
source/carla View File

@@ -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()


+ 7
- 6
source/carla_host.py View File

@@ -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 = []


Loading…
Cancel
Save