class library: PriorityQueue - implement removeValue, hide array
[supercollider.git] / QtCollider / widgets / BasicWidgets.h
blob233dc0ccde5ac1bad45d076e43a4360bf4271159
1 /************************************************************************
3 * Copyright 2010 Jakob Leben (jakob.leben@gmail.com)
5 * This file is part of SuperCollider Qt GUI.
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 3 of the License, or
10 * (at your option) any later version.
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.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ************************************************************************/
22 #ifndef _WIDGETS_H
23 #define _WIDGETS_H
25 #include "../QcHelper.h"
26 #include "../layouts/classic_layouts.hpp"
27 #include "QcCanvas.h"
29 #include <QListWidget>
30 #include <QComboBox>
31 #include <QPushButton>
32 #include <QLineEdit>
33 #include <QLabel>
34 #include <QCheckBox>
36 class QcDefaultWidget : public QWidget
38 Q_OBJECT
39 public:
40 QcDefaultWidget() { setLayout( new QcDefaultLayout() ); }
41 Q_INVOKABLE void addChild( QWidget* w ) { layout()->addWidget(w); }
44 class QcHLayoutWidget : public QWidget
46 Q_OBJECT
47 public:
48 QcHLayoutWidget() { setLayout( new QcHLayout() ); }
49 Q_INVOKABLE void addChild( QWidget* w ) { layout()->addWidget(w); }
52 class QcVLayoutWidget : public QWidget
54 Q_OBJECT
55 public:
56 QcVLayoutWidget() { setLayout( new QcVLayout() ); }
57 Q_INVOKABLE void addChild( QWidget* w ) { layout()->addWidget(w); }
61 class QcListWidget : public QListWidget, public QcHelper
63 Q_OBJECT
64 Q_PROPERTY( VariantList items READ dummyVariantList WRITE setItems );
65 Q_PROPERTY( VariantList colors READ dummyVariantList WRITE setColors );
66 Q_PROPERTY( int currentRow READ currentRow WRITE setCurrentRowWithoutAction )
68 public:
69 QcListWidget();
70 void setItems( const VariantList & );
71 void setColors( const VariantList & ) const;
72 void setCurrentRowWithoutAction( int );
73 Q_SIGNALS:
74 void action();
75 void returnPressed();
76 private Q_SLOTS:
77 void onCurrentItemChanged();
78 private:
79 void keyPressEvent( QKeyEvent * );
81 bool _emitAction;
84 class QcPopUpMenu : public QComboBox, public QcHelper
86 Q_OBJECT
87 Q_PROPERTY( VariantList items READ dummyVariantList WRITE setItems );
88 Q_PROPERTY( bool signalReactivation READ signalReactivation WRITE setSignalReactivation )
90 public:
91 QcPopUpMenu();
92 bool signalReactivation() const { return _reactivation; }
93 void setSignalReactivation( bool b ) { _reactivation = b; }
94 Q_SIGNALS:
95 void action();
96 private Q_SLOTS:
97 void doAction(int);
98 private:
99 void setItems( const VariantList & );
100 int lastChoice;
101 bool _reactivation;
104 class QcTextField : public QLineEdit
106 Q_OBJECT
108 public:
109 QcTextField() {
110 connect( this, SIGNAL(returnPressed()), this, SIGNAL(action()) );
112 Q_SIGNALS:
113 void action();
116 class QcButton : public QPushButton, public QcHelper
118 Q_OBJECT
119 Q_PROPERTY( VariantList states READ dummyVariantList WRITE setStates );
120 Q_PROPERTY( int value READ getValue WRITE setValue );
121 public:
122 QcButton();
123 Q_SIGNALS:
124 void action(int);
125 protected:
126 #ifdef Q_WS_MAC
127 bool hitButton( const QPoint & ) const;
128 #endif
129 private Q_SLOTS:
130 void doAction();
131 private:
132 struct State {
133 QString text;
134 QColor textColor;
135 QColor buttonColor;
137 void setStates( const VariantList & );
138 void setValue( int val ) { setState( val ); }
139 int getValue() const { return currentState; }
140 void setState( int );
141 void cycleStates();
142 QList<State> states;
143 int currentState;
144 QPalette defaultPalette;
147 class QcCustomPainted : public QcCanvas, QcHelper
149 Q_OBJECT
150 public:
151 QcCustomPainted() {
152 setLayout( new QcDefaultLayout() );
154 Q_INVOKABLE void addChild( QWidget* w ) { layout()->addWidget(w); }
155 private:
156 // reimplement event handlers just so events don't propagate
157 void mousePressEvent( QMouseEvent * ) {}
158 void mouseReleaseEvent( QMouseEvent * ) {}
159 void mouseMoveEvent( QMouseEvent * ) {}
162 class QcCheckBox : public QCheckBox
164 Q_OBJECT
165 Q_PROPERTY( bool value READ value WRITE setValue );
167 public:
168 QcCheckBox() {
169 connect( this, SIGNAL(clicked()), this, SIGNAL(action()) );
171 Q_SIGNALS:
172 void action();
173 private:
174 bool value() { return isChecked(); }
175 void setValue( bool val ) { setChecked(val); }
178 #endif // _WIDGETS_H