52 #include "k3buttonbox.moc"
59 #define minButtonWidth 50
61 class K3ButtonBox::Item {
65 unsigned short stretch;
66 unsigned short actual_size;
73 class K3ButtonBoxPrivate {
75 unsigned short border;
76 unsigned short autoborder;
77 unsigned short orientation;
83 int border,
int autoborder)
84 :
QWidget(parent), data(new K3ButtonBoxPrivate)
88 data->orientation = _orientation;
89 data->border = border;
90 data->autoborder = autoborder < 0 ? border : autoborder;
94 while(!data->buttons.isEmpty())
95 delete data->buttons.takeFirst();
103 item->noexpand = noexpand;
104 data->buttons.append(item);
105 item->button->adjustSize();
115 item->noexpand = noexpand;
116 data->buttons.append(item);
117 item->button->adjustSize();
134 if ((0 != receiver) && (0 != slot))
135 QObject::connect(pb, SIGNAL(clicked()), receiver, slot);
150 if ((0 != receiver) && (0 != slot))
151 QObject::connect(pb, SIGNAL(clicked()), receiver, slot);
159 item->noexpand =
false;
160 item->stretch = scale;
161 data->buttons.append(item);
169 foreach(
Item *item, data->buttons) {
184 if(data->orientation == Qt::Horizontal) {
186 int fs = width() - 2 * data->border;
189 foreach(
Item *item, data->buttons) {
195 if(!(item == data->buttons.last()))
196 fs -= data->autoborder;
198 stretch +=item->stretch;
205 int x_pos = data->border;
207 foreach(
Item *item, data->buttons) {
211 b->move(x_pos, (height() - b->height()) / 2);
213 x_pos += b->width() + data->autoborder;
215 x_pos += (int)((((
double)fs) * item->stretch) / stretch);
223 int fs = height() - 2 * data->border;
226 foreach(
Item *item, data->buttons) {
230 fs -= b->height() + data->autoborder;
232 stretch +=item->stretch;
239 int y_pos = data->border;
241 foreach(
Item *item, data->buttons) {
245 b->move((width() - b->width()) / 2, y_pos);
247 y_pos += b->height() + data->autoborder;
249 y_pos += (int)((((
double)fs) * item->stretch) / stretch);
265 foreach(
Item *item, data->buttons) {
269 if(b && !item->noexpand) {
272 const int bsWidth = bs.width();
273 const int bsHeight = bs.height();
275 if(bsWidth > s.width())
277 if(bsHeight > s.height())
278 s.setHeight(bsHeight);
288 if(data->buttons.isEmpty())
291 dw = 2 * data->border;
295 foreach(
Item *item, data->buttons) {
306 if(data->orientation == Qt::Horizontal)
311 if( !(item == data->buttons.last()) )
312 dw += data->autoborder;
317 if(data->orientation == Qt::Horizontal)
318 return QSize(dw, bs.height() + 2 * data->border);
320 return QSize(bs.width() + 2 * data->border, dw);
326 return data->orientation == Qt::Horizontal?
327 QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed ) :
328 QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Minimum );
337 QSize s = b->sizeHint();
338 const QSize ms = b->minimumSize();
343 const int msWidth = ms.width();
344 const int msHeight = ms.height();
346 if(msWidth > s.width())
348 if(msHeight > s.height())
349 s.setHeight(msHeight);