diff --git a/source/frontend/carla_widgets.py b/source/frontend/carla_widgets.py index 1df172fd1..f6883634d 100755 --- a/source/frontend/carla_widgets.py +++ b/source/frontend/carla_widgets.py @@ -33,6 +33,7 @@ import ui_carla_parameter from carla_shared import * from carla_utils import * +from widgets.collapsablewidget import CollapsibleBox from widgets.paramspinbox import CustomInputDialog from widgets.pixmapkeyboard import PixmapKeyboardHArea @@ -1493,8 +1494,8 @@ class PluginEdit(QDialog): groupSymbol, groupName = groupName.split(":",1) groupLayout, groupWidget = groupWidgets.get(groupSymbol, (None, None)) if groupLayout is None: - groupWidget = QGroupBox(groupName, scrollAreaWidget) - groupLayout = QVBoxLayout(groupWidget) + groupWidget = CollapsibleBox(groupName, scrollAreaWidget) + groupLayout = groupWidget.getContentLayout() groupWidget.setPalette(palette2) scrollAreaLayout.addWidget(groupWidget) groupWidgets[groupSymbol] = (groupLayout, groupWidget) diff --git a/source/frontend/widgets/collapsablewidget.py b/source/frontend/widgets/collapsablewidget.py new file mode 100644 index 000000000..9be2fe461 --- /dev/null +++ b/source/frontend/widgets/collapsablewidget.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# Collapsible Box, a custom Qt widget +# Copyright (C) 2019 Filipe Coelho +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License, or any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# For a full copy of the GNU General Public License see the doc/GPL.txt file. + +# ------------------------------------------------------------------------------------------------------------ +# Imports (Global) + +from PyQt5.QtCore import pyqtSlot, Qt +from PyQt5.QtWidgets import QGroupBox, QSizePolicy, QToolButton, QVBoxLayout, QWidget + +# ------------------------------------------------------------------------------------------------------------ +# Widget Class + +class CollapsibleBox(QGroupBox): + def __init__(self, title, parent): + QGroupBox.__init__(self, parent) + + self.toggle_button = QToolButton(self) + self.toggle_button.setText(title) + self.toggle_button.setCheckable(True) + self.toggle_button.setChecked(True) + self.toggle_button.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) + self.toggle_button.setStyleSheet("border: none;") + self.toggle_button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) + self.toggle_button.setArrowType(Qt.RightArrow) + self.toggle_button.toggled.connect(self.toolButtonPressed) + + self.content_area = QWidget(self) + self.content_layout = QVBoxLayout(self.content_area) + self.content_layout.setContentsMargins(0, 0, 0, 0) + self.content_layout.setSpacing(0) + + lay = QVBoxLayout(self) + lay.setContentsMargins(0, 0, 0, 0) + lay.setSpacing(0) + lay.addWidget(self.toggle_button) + lay.addWidget(self.content_area) + + @pyqtSlot(bool) + def toolButtonPressed(self, toggled): + self.content_area.setVisible(toggled) + self.toggle_button.setArrowType(Qt.RightArrow if toggled else Qt.DownArrow) + + def getContentLayout(self): + return self.content_layout