From e63cca4f739edb49eb0166ce2b988439a8a469d4 Mon Sep 17 00:00:00 2001 From: falkTX Date: Fri, 1 Mar 2013 08:39:03 +0000 Subject: [PATCH] More UI work --- .gitignore | 1 + Makefile | 2 +- ...lose_pressed.png => button_close_down.png} | Bin resources/resources.qrc | 2 +- resources/ui/carla_plugin.ui | 35 ++++---- source/carla_shared.py | 15 +++- source/widgets/ledbutton.py | 2 +- source/widgets/pixmapbutton.py | 82 ++++++++++++++++++ 8 files changed, 117 insertions(+), 22 deletions(-) rename resources/bitmaps/{button_close_pressed.png => button_close_down.png} (100%) create mode 100644 source/widgets/pixmapbutton.py diff --git a/.gitignore b/.gitignore index fc64bb39c..dcbc7effd 100644 --- a/.gitignore +++ b/.gitignore @@ -33,6 +33,7 @@ ui_*.py source/digitalpeakmeter.py source/ledbutton.py source/paramspinbox.py +source/pixmapbutton.py source/pixmapdial.py source/pixmapkeyboard.py source/resources_rc.py diff --git a/Makefile b/Makefile index dab616895..290b623af 100644 --- a/Makefile +++ b/Makefile @@ -81,7 +81,7 @@ source/ui_%.py: resources/ui/%.ui # ----------------------------------------------------------------------------------------------------------------------------------------- # Widgets -WIDGETS = source/digitalpeakmeter.py source/ledbutton.py source/paramspinbox.py source/pixmapdial.py source/pixmapkeyboard.py +WIDGETS = source/digitalpeakmeter.py source/ledbutton.py source/paramspinbox.py source/pixmapbutton.py source/pixmapdial.py source/pixmapkeyboard.py WIDGETS: $(WIDGETS) diff --git a/resources/bitmaps/button_close_pressed.png b/resources/bitmaps/button_close_down.png similarity index 100% rename from resources/bitmaps/button_close_pressed.png rename to resources/bitmaps/button_close_down.png diff --git a/resources/resources.qrc b/resources/resources.qrc index 43daf8d97..2c7adcf05 100644 --- a/resources/resources.qrc +++ b/resources/resources.qrc @@ -38,8 +38,8 @@ bitmaps/carla_about.png bitmaps/button_close.png + bitmaps/button_close_down.png bitmaps/button_close_hover.png - bitmaps/button_close_pressed.png bitmaps/button_down.png bitmaps/button_down_hover.png bitmaps/button_edit.png diff --git a/resources/ui/carla_plugin.ui b/resources/ui/carla_plugin.ui index bdece5b85..16d10346f 100644 --- a/resources/ui/carla_plugin.ui +++ b/resources/ui/carla_plugin.ui @@ -6,8 +6,8 @@ 0 0 - 557 - 28 + 538 + 30 @@ -15,7 +15,7 @@ - 1 + 2 0 @@ -30,7 +30,7 @@ 2 - + 24 @@ -46,10 +46,6 @@ - - - :/bitmaps/led-big_on.png:/bitmaps/led-big_on.png - 24 @@ -65,7 +61,7 @@ - + 24 @@ -83,7 +79,7 @@ - :/bitmaps/button_gui_down.png:/bitmaps/button_gui_down.png + :/bitmaps/button_gui.png:/bitmaps/button_gui.png @@ -100,7 +96,7 @@ - + 24 @@ -118,7 +114,7 @@ - :/bitmaps/button_edit_down.png:/bitmaps/button_edit_down.png + :/bitmaps/button_edit.png:/bitmaps/button_edit.png @@ -287,7 +283,7 @@ 0 - + 12 @@ -310,7 +306,7 @@ - + 12 @@ -328,7 +324,7 @@ - :/bitmaps/button_close_pressed.png:/bitmaps/button_close_pressed.png + :/bitmaps/button_close.png:/bitmaps/button_close.png @@ -342,7 +338,7 @@ - + 12 @@ -365,7 +361,7 @@ - + 12 @@ -403,6 +399,11 @@ QPushButton
ledbutton.h
+ + PixmapButton + QPushButton +
pixmapbutton.h
+
diff --git a/source/carla_shared.py b/source/carla_shared.py index c9056e3a1..eda615536 100644 --- a/source/carla_shared.py +++ b/source/carla_shared.py @@ -2154,8 +2154,19 @@ class PluginWidget(QFrame): #else: #self.setWidgetColor(PALETTE_COLOR_NONE) - #self.ui.led_enable.setColor(self.ui.led_enable.BIG_RED) - #self.ui.led_enable.setChecked(False) + self.ui.b_enable.setPixmaps(":/bitmaps/button_gui.png", ":/bitmaps/button_gui_down.png", ":/bitmaps/button_gui_hover.png") + self.ui.b_gui.setPixmaps(":/bitmaps/button_gui.png", ":/bitmaps/button_gui_down.png", ":/bitmaps/button_gui_hover.png") + self.ui.b_edit.setPixmaps(":/bitmaps/button_edit.png", ":/bitmaps/button_edit_down.png", ":/bitmaps/button_edit_hover.png") + + self.ui.b_up.setPixmaps(":/bitmaps/button_up.png", ":/bitmaps/button_up.png", ":/bitmaps/button_up_hover.png") + self.ui.b_down.setPixmaps(":/bitmaps/button_down.png", ":/bitmaps/button_down.png", ":/bitmaps/button_down_hover.png") + self.ui.b_restore.setPixmaps(":/bitmaps/button_restore.png", ":/bitmaps/button_restore.png", ":/bitmaps/button_restore_hover.png") + self.ui.b_close.setPixmaps(":/bitmaps/button_close.png", ":/bitmaps/button_close_down.png", ":/bitmaps/button_close_hover.png") + + # TODO + self.ui.b_up.setEnabled(False) + self.ui.b_down.setEnabled(False) + self.ui.b_restore.setEnabled(False) self.ui.led_control.setColor(self.ui.led_control.YELLOW) self.ui.led_control.setEnabled(False) diff --git a/source/widgets/ledbutton.py b/source/widgets/ledbutton.py index 5ad681cda..cd499072c 100644 --- a/source/widgets/ledbutton.py +++ b/source/widgets/ledbutton.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -# Pixmap Button, a custom Qt4 widget +# LED Button, a custom Qt4 widget # Copyright (C) 2011-2013 Filipe Coelho # # This program is free software; you can redistribute it and/or diff --git a/source/widgets/pixmapbutton.py b/source/widgets/pixmapbutton.py new file mode 100644 index 000000000..aeb353781 --- /dev/null +++ b/source/widgets/pixmapbutton.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# Pixmap Button, a custom Qt4 widget +# Copyright (C) 2013 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 GPL.txt file + +# ------------------------------------------------------------------------------------------------------------ +# Imports (Global) + +from PyQt4.QtCore import QRectF +from PyQt4.QtGui import QPainter, QPixmap, QPushButton + +# ------------------------------------------------------------------------------------------------------------ +# Widget Class + +class PixmapButton(QPushButton): + STATE_NULL = 0 + STATE_NORMAL = 1 + STATE_DOWN = 2 + STATE_HOVER = 3 + + def __init__(self, parent): + QPushButton.__init__(self, parent) + + self.fPixmapNormal = QPixmap() + self.fPixmapDown = QPixmap() + self.fPixmapHover = QPixmap() + self.fPixmapRect = QRectF(0, 0, 0, 0) + + self.fIsHovered = False + + self.setText("") + + def setPixmaps(self, normal, down, hover): + self.fPixmapNormal.load(normal) + self.fPixmapDown.load(down) + self.fPixmapHover.load(hover) + + self.setPixmapSize(self.fPixmapNormal.width()) + + def setPixmapSize(self, size): + self.fPixmapRect = QRectF(0, 0, size, size) + + self.setMinimumWidth(size) + self.setMaximumWidth(size) + self.setMinimumHeight(size) + self.setMaximumHeight(size) + + def enterEvent(self, event): + self.fIsHovered = True + QPushButton.enterEvent(self, event) + + def leaveEvent(self, event): + self.fIsHovered = False + QPushButton.leaveEvent(self, event) + + def paintEvent(self, event): + painter = QPainter(self) + + if not self.isEnabled(): + painter.setOpacity(0.2) + painter.drawPixmap(self.fPixmapRect, self.fPixmapNormal, self.fPixmapRect) + elif self.isChecked() or self.isDown(): + painter.drawPixmap(self.fPixmapRect, self.fPixmapDown, self.fPixmapRect) + elif self.fIsHovered: + painter.drawPixmap(self.fPixmapRect, self.fPixmapHover, self.fPixmapRect) + else: + painter.drawPixmap(self.fPixmapRect, self.fPixmapNormal, self.fPixmapRect) + + event.accept()