cmake: supernova - missing include_directories() for Jack
[supercollider.git] / QtCollider / layouts / layouts.hpp
blobf030743bcbe7065aba4a455979e3cf37fd91cc5f
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 QC_LAYOUTS_H
23 #define QC_LAYOUTS_H
25 #include "../QcObjectFactory.h"
27 #include <QHBoxLayout>
28 #include <QVBoxLayout>
29 #include <QGridLayout>
30 #include <QStackedLayout>
32 template <class LAYOUT> struct QcLayout : public LAYOUT
34 public:
35 VariantList margins() const { return VariantList(); }
37 void setMargins( const VariantList &list ) {
38 if( list.data.size() < 4 ) return;
39 int m[4];
40 for( int i=0; i<4; ++i ) {
41 m[i] = list.data[i].value<int>();
43 LAYOUT::setContentsMargins( m[0], m[1], m[2], m[3] );
47 template <class BOXLAYOUT> class QcBoxLayout : public QcLayout<BOXLAYOUT>
49 public:
50 QcBoxLayout() {}
52 QcBoxLayout( const VariantList & items ) {
53 Q_FOREACH( QVariant v, items.data ) {
54 VariantList item = v.value<VariantList>();
55 addItem( item );
59 void addItem( const VariantList & item ) {
60 if( item.data.size() < 3 ) return;
62 int stretch = item.data[1].toInt();
63 Qt::Alignment alignment = (Qt::Alignment) item.data[2].toInt();
65 QVariant varObject = item.data[0];
67 if( !varObject.isValid() ) {
68 BOXLAYOUT::addStretch( stretch );
69 return;
72 if( varObject.canConvert<int>() ) {
73 int size = varObject.toInt();
74 BOXLAYOUT::addSpacing( size );
75 return;
78 QObjectProxy *p = varObject.value<QObjectProxy*>();
79 if( !p || !p->object() ) return;
81 QWidget *w = qobject_cast<QWidget*>( p->object() );
82 if( w ) {
83 BOXLAYOUT::addWidget( w, stretch, alignment );
84 return;
87 QLayout *l2 = qobject_cast<QLayout*>( p->object() );
88 if(l2) {
89 BOXLAYOUT::addLayout( l2, stretch );
90 return;
94 void insertItem( const VariantList & item ) {
95 if( item.data.size() < 4 ) return;
97 int index = item.data[1].toInt();
98 int stretch = item.data[2].toInt();
99 Qt::Alignment alignment = (Qt::Alignment) item.data[3].toInt();
101 QVariant varObject = item.data[0];
103 if( !varObject.isValid() ) {
104 BOXLAYOUT::insertStretch( index, stretch );
105 return;
108 if( varObject.canConvert<int>() ) {
109 int size = varObject.toInt();
110 BOXLAYOUT::insertSpacing( index, size );
111 return;
114 QObjectProxy *p = varObject.value<QObjectProxy*>();
115 if( !p || !p->object() ) return;
117 QWidget *w = qobject_cast<QWidget*>( p->object() );
118 if( w ) {
119 BOXLAYOUT::insertWidget( index, w, stretch, alignment );
120 return;
123 QLayout *l2 = qobject_cast<QLayout*>( p->object() );
124 if(l2) {
125 BOXLAYOUT::insertLayout( index, l2, stretch );
126 return;
130 void setStretch( QObjectProxy *p, int stretch ) {
131 QWidget *w = qobject_cast<QWidget*>( p->object() );
132 if( w ) {
133 BOXLAYOUT::setStretchFactor( w, stretch );
134 return;
137 QLayout *l = qobject_cast<QLayout*>( p->object() );
138 if(l) {
139 BOXLAYOUT::setStretchFactor( l, stretch );
140 return;
144 void setAlignment( QObjectProxy *p, Qt::Alignment alignment ) {
145 QWidget *w = qobject_cast<QWidget*>( p->object() );
146 if( w ) {
147 BOXLAYOUT::setAlignment( w, alignment );
148 return;
151 QLayout *l = qobject_cast<QLayout*>( p->object() );
152 if(l) {
153 BOXLAYOUT::setAlignment( l, alignment );
154 return;
159 class QcHBoxLayout : public QcBoxLayout<QHBoxLayout>
161 Q_OBJECT
162 Q_PROPERTY( VariantList margins READ margins WRITE setMargins )
163 public:
164 QcHBoxLayout() {}
165 Q_INVOKABLE QcHBoxLayout( const VariantList &items ): QcBoxLayout<QHBoxLayout>(items) {}
166 Q_INVOKABLE void addItem( const VariantList &data ) { QcBoxLayout<QHBoxLayout>::addItem(data); }
167 Q_INVOKABLE void insertItem( const VariantList &data ) { QcBoxLayout<QHBoxLayout>::insertItem(data); }
168 Q_INVOKABLE void setStretch( int index, int stretch ) {
169 QBoxLayout::setStretch( index, stretch );
171 Q_INVOKABLE void setStretch( QObjectProxy *p, int stretch ) {
172 QcBoxLayout<QHBoxLayout>::setStretch( p, stretch );
174 Q_INVOKABLE void setAlignment( int i, int a ) {
175 itemAt(i)->setAlignment( (Qt::Alignment) a );
176 update();
178 Q_INVOKABLE void setAlignment( QObjectProxy *p, int a ) {
179 QcBoxLayout<QHBoxLayout>::setAlignment( p, (Qt::Alignment) a );
183 class QcVBoxLayout : public QcBoxLayout<QVBoxLayout>
185 Q_OBJECT
186 Q_PROPERTY( VariantList margins READ margins WRITE setMargins )
187 public:
188 QcVBoxLayout() {}
189 Q_INVOKABLE QcVBoxLayout( const VariantList &items ): QcBoxLayout<QVBoxLayout>(items) {}
190 Q_INVOKABLE void addItem( const VariantList &data ) { QcBoxLayout<QVBoxLayout>::addItem(data); }
191 Q_INVOKABLE void insertItem( const VariantList &data ) { QcBoxLayout<QVBoxLayout>::insertItem(data); }
192 Q_INVOKABLE void setStretch( int index, int stretch ) {
193 QBoxLayout::setStretch( index, stretch );
195 Q_INVOKABLE void setStretch( QObjectProxy *p, int stretch ) {
196 QcBoxLayout<QVBoxLayout>::setStretch( p, stretch );
198 Q_INVOKABLE void setAlignment( int i, int a ) {
199 itemAt(i)->setAlignment( (Qt::Alignment) a );
200 update();
202 Q_INVOKABLE void setAlignment( QObjectProxy *p, int a ) {
203 QcBoxLayout<QVBoxLayout>::setAlignment( p, (Qt::Alignment) a );
207 class QcGridLayout : public QcLayout<QGridLayout>
209 Q_OBJECT
210 Q_PROPERTY( VariantList margins READ margins WRITE setMargins )
211 Q_PROPERTY( int verticalSpacing READ verticalSpacing WRITE setVerticalSpacing )
212 Q_PROPERTY( int horizontalSpacing READ horizontalSpacing WRITE setHorizontalSpacing )
213 public:
214 Q_INVOKABLE void addItem( const VariantList &dataList );
215 Q_INVOKABLE void setRowStretch( int row, int factor ) {
216 QcLayout<QGridLayout>::setRowStretch( row, factor );
218 Q_INVOKABLE void setColumnStretch( int column, int factor ) {
219 QcLayout<QGridLayout>::setColumnStretch( column, factor );
221 Q_INVOKABLE void setAlignment( int r, int c, int a ) {
222 QLayoutItem *item = itemAtPosition(r,c);
223 if(item) {
224 item->setAlignment( (Qt::Alignment) a );
225 update();
228 Q_INVOKABLE void setAlignment( QObjectProxy *p, int a ) {
229 QWidget *w = qobject_cast<QWidget*>( p->object() );
230 if( w ) {
231 QLayout::setAlignment( w, (Qt::Alignment) a );
232 return;
235 QLayout *l = qobject_cast<QLayout*>( p->object() );
236 if(l) {
237 QLayout::setAlignment( l, (Qt::Alignment) a );
238 return;
241 Q_INVOKABLE int minRowHeight( int row ) {
242 return ( row >= 0 && row < rowCount() ) ? rowMinimumHeight( row ) : 0;
244 Q_INVOKABLE int minColumnWidth( int col ) {
245 return ( col >= 0 && col < columnCount() ) ? columnMinimumWidth( col ) : 0;
247 Q_INVOKABLE void setMinRowHeight( int row, int h ) {
248 setRowMinimumHeight( row, h );
250 Q_INVOKABLE void setMinColumnWidth( int col, int w ) {
251 setColumnMinimumWidth( col, w );
255 #endif