1 /*
2  * Hydrogen
3  * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4  *
5  * http://www.hydrogen-music.org
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY, without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  */
22 
23 
24 #ifndef BUTTON_H
25 #define BUTTON_H
26 
27 
28 #include <hydrogen/object.h>
29 #include <hydrogen/midi_action.h>
30 
31 #include "MidiLearnable.h"
32 
33 #include <QtGui>
34 #if QT_VERSION >= 0x050000
35 #  include <QtWidgets>
36 #endif
37 
38 class PixmapWidget;
39 
40 /**
41  * Generic Button with pixmaps and text.
42  */
43 class Button : public QWidget, public H2Core::Object, public MidiLearnable
44 {
45     H2_OBJECT
46 	Q_OBJECT
47 
48 	public:
49 		Button(
50 				QWidget *pParent,
51 				const QString& sOnImg,
52 				const QString& sOffImg,
53 				const QString& sOverImg,
54 				QSize size,
55 				bool use_skin_style = false,
56 				bool enable_press_hold = false
57 		);
58 		virtual ~Button();
59 
isPressed()60 		bool isPressed() {	return m_bPressed;	}
61 		void setPressed(bool pressed);
62 
63 		void setText( const QString& sText );
64 		void setFontSize( int size );
65 
66 	signals:
67 		void clicked(Button *pBtn);
68 		void rightClicked(Button *pBtn);
69 		void mousePress(Button *pBtn);
70 
71 	protected slots:
72 		void buttonPressed_timer_timeout();
73 
74 	protected:
75 		bool m_bPressed;
76 
77 		QFont m_textFont;
78 		QString m_sText;
79 
80 		QPixmap m_onPixmap;
81 		QPixmap m_offPixmap;
82 		QPixmap m_overPixmap;
83 
84 	private:
85 		bool m_bMouseOver;
86 		bool __use_skin_style;
87 		bool __enable_press_hold;
88 
89 		void mousePressEvent(QMouseEvent *ev);
90 		void mouseReleaseEvent(QMouseEvent *ev);
91 		void enterEvent(QEvent *ev);
92 		void leaveEvent(QEvent *ev);
93 		void paintEvent( QPaintEvent* ev);
94 
95 		QTimer *m_timer;
96 		int m_timerTimeout;
97 
98 		bool loadImage( const QString& sFilename, QPixmap& pixmap );
99 };
100 
101 
102 
103 
104 /**
105  * A ToggleButton (On/Off).
106  */
107 class ToggleButton : public Button
108 {
109 	Q_OBJECT
110 
111 	public:
112 		ToggleButton( QWidget *pParent, const QString& sOnImg, const QString& sOffImg, const QString& sOverImg, QSize size, bool use_skin_style = false );
113 		~ToggleButton();
114 
115 	private:
116 		void mousePressEvent( QMouseEvent *ev );
117 		void mouseReleaseEvent( QMouseEvent *ev );
118 };
119 
120 
121 #endif
122