1 /************************************************************************
3 * Copyright 2010-2011 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_CLASSIC_LAYOUTS_H
23 #define QC_CLASSIC_LAYOUTS_H
26 #include <QResizeEvent>
27 #include "../Common.h"
44 static VSizePolicy
vSizePolicy( QWidget
*w
)
46 QVariant var
= w
->property( "_qc_vSizePolicy" );
47 if( !var
.isValid() ) return StickTop
;
48 return (VSizePolicy
) var
.toInt();
51 static HSizePolicy
hSizePolicy( QWidget
*w
)
53 QVariant var
= w
->property( "_qc_hSizePolicy" );
54 if( !var
.isValid() ) return StickLeft
;
55 return (HSizePolicy
) var
.toInt();
62 DefaultLayout( QWidget
* w
): parent(w
), initialized(false) {}
64 void resize( QResizeEvent
*e
)
75 QPoint dPos
= r
.topLeft() - geom
.topLeft();
76 QSize dSize
= r
.size() - geom
.size();
78 const QObjectList
&children
= parent
->children();
80 Q_FOREACH( QObject
*o
, children
)
82 if(!o
->isWidgetType())
85 QWidget
*child
= static_cast<QWidget
*>(o
);
87 QRect g
= child
->geometry();
93 if( !dPos
.isNull() ) {
98 if( !dSize
.isNull() ) {
99 if( hSizePolicy(child
) == QtCollider::StickRight
)
101 if( vSizePolicy(child
) == QtCollider::StickBottom
)
103 if( hSizePolicy(child
) == QtCollider::HStretch
)
105 if( vSizePolicy(child
) == QtCollider::VStretch
)
109 child
->setGeometry( QRect(x
, y
, w
, h
) );
124 HLayout( QWidget
* w
): parent(w
) {}
126 void resize( QResizeEvent
*e
)
129 geom
.setSize(e
->size());
131 const QObjectList
&children
= parent
->children();
132 int varWidth
= geom
.width();
135 Q_FOREACH( QObject
*o
, children
)
137 if(!o
->isWidgetType()) continue;
138 QWidget
*w
= static_cast<QWidget
*>(o
);
140 if( hSizePolicy(w
) == QtCollider::HStretch
) {
144 QRect r
= w
->geometry();
145 varWidth
-= r
.width();
151 int partWidth
= i
> 0 && varWidth
> 0 ? varWidth
/ i
: 0;
154 Q_FOREACH( QObject
*o
, children
)
156 if(!o
->isWidgetType()) continue;
157 QWidget
*w
= static_cast<QWidget
*>(o
);
159 QRect r
= w
->geometry();
160 r
.setHeight( geom
.height() );
161 r
.moveTo( x
, geom
.top() );
162 if( hSizePolicy(w
) == QtCollider::HStretch
)
163 r
.setWidth( partWidth
);
177 VLayout( QWidget
* w
): parent(w
) {}
179 void resize( QResizeEvent
*e
)
182 geom
.setSize(e
->size());
184 const QObjectList
&children
= parent
->children();
185 int varHeight
= geom
.height();
188 Q_FOREACH( QObject
*o
, children
)
190 if(!o
->isWidgetType()) continue;
191 QWidget
*w
= static_cast<QWidget
*>(o
);
193 if( vSizePolicy(w
) == QtCollider::VStretch
) {
197 QRect r
= w
->geometry();
198 varHeight
-= r
.height();
204 int partHeight
= i
> 0 && varHeight
> 0 ? varHeight
/ i
: 0;
207 Q_FOREACH( QObject
*o
, children
)
209 if(!o
->isWidgetType()) continue;
210 QWidget
*w
= static_cast<QWidget
*>(o
);
212 QRect r
= w
->geometry();
213 r
.setWidth( geom
.width() );
214 r
.moveTo( geom
.left(), y
);
215 if( vSizePolicy(w
) == QtCollider::VStretch
)
216 r
.setHeight( partHeight
);
227 } // namespace QtCollider
229 #endif // QC_CLASSIC_LAYOUTS_H