52 #include "kbuttonbox.moc"
53 #include <tdeglobalsettings.h>
55 #include <kpushbutton.h>
56 #include <tqptrlist.h>
59 #define minButtonWidth 50
61 class KButtonBox::Item {
65 unsigned short stretch;
66 unsigned short actual_size;
68 Item(
KPushButton*
const _button) : button(_button) {}
71 template class TQPtrList<KButtonBox::Item>;
73 class KButtonBoxPrivate {
75 unsigned short border;
76 unsigned short autoborder;
77 unsigned short orientation;
79 TQPtrList<KButtonBox::Item> buttons;
83 int border,
int autoborder)
84 : TQWidget(parent), data(new KButtonBoxPrivate)
88 data->orientation = _orientation;
89 data->border = border;
90 data->autoborder = autoborder < 0 ? border : autoborder;
91 data->buttons.setAutoDelete(
true);
99 Item*
const item =
new Item(
new KPushButton(text,
this));
101 item->noexpand = noexpand;
102 data->buttons.append(item);
103 item->button->adjustSize();
105 this->updateGeometry();
111 Item*
const item =
new Item(
new KPushButton(guiitem,
this));
113 item->noexpand = noexpand;
114 data->buttons.append(item);
115 item->button->adjustSize();
117 this->updateGeometry();
124 const TQString & text,
130 TQPushButton * pb =
addButton(text, noexpand);
132 if ((0 != receiver) && (0 != slot))
133 TQObject::connect(pb, TQ_SIGNAL(clicked()), receiver, slot);
146 TQPushButton * pb =
addButton(guiitem, noexpand);
148 if ((0 != receiver) && (0 != slot))
149 TQObject::connect(pb, TQ_SIGNAL(clicked()), receiver, slot);
156 Item*
const item =
new Item(0);
157 item->noexpand =
false;
158 item->stretch = scale;
159 data->buttons.append(item);
167 TQPtrListIterator<KButtonBox::Item> itr(data->buttons);
170 while ( (item = itr.current()) != 0 ) {
171 TQPushButton*
const b = item->button;
174 b->setFixedSize(buttonSizeHint(b));
184 void KButtonBox::placeButtons() {
186 if(data->orientation == TQt::Horizontal) {
188 int fs = width() - 2 * data->border;
191 TQPtrListIterator<KButtonBox::Item> itr(data->buttons);
194 while ( (item = itr.current()) != 0 ) {
195 TQPushButton*
const b = item->button;
201 fs -= data->autoborder;
203 stretch +=item->stretch;
211 int x_pos = data->border;
213 TQPtrListIterator<KButtonBox::Item> itr(data->buttons);
216 while ( (item = itr.current()) != 0 ) {
217 TQPushButton*
const b = item->button;
219 b->move(x_pos, (height() - b->height()) / 2);
221 x_pos += b->width() + data->autoborder;
223 x_pos += (int)((((
double)fs) * item->stretch) / stretch);
232 int fs = height() - 2 * data->border;
235 TQPtrListIterator<KButtonBox::Item> itr(data->buttons);
238 while ( (item = itr.current()) != 0 ) {
239 TQPushButton*
const b = item->button;
241 fs -= b->height() + data->autoborder;
243 stretch +=item->stretch;
251 int y_pos = data->border;
253 TQPtrListIterator<KButtonBox::Item> itr(data->buttons);
256 while ( (item = itr.current()) != 0 ) {
257 TQPushButton*
const b = item->button;
259 b->move((width() - b->width()) / 2, y_pos);
261 y_pos += b->height() + data->autoborder;
263 y_pos += (int)((((
double)fs) * item->stretch) / stretch);
272 void KButtonBox::resizeEvent(TQResizeEvent *) {
280 TQPtrListIterator<KButtonBox::Item> itr(data->buttons);
283 while ( (item = itr.current()) != 0 ) {
284 TQPushButton*
const b = item->button;
286 if(b && !item->noexpand) {
287 const TQSize bs = buttonSizeHint(b);
289 const int bsWidth = bs.width();
290 const int bsHeight = bs.height();
292 if(bsWidth > s.width())
294 if(bsHeight > s.height())
295 s.setHeight(bsHeight);
306 if(data->buttons.isEmpty())
309 dw = 2 * data->border;
313 TQPtrListIterator<KButtonBox::Item> itr(data->buttons);
316 while ( (item = itr.current()) != 0 ) {
317 TQPushButton*
const b = item->button;
322 s = buttonSizeHint(b);
326 if(data->orientation == TQt::Horizontal)
332 dw += data->autoborder;
338 if(data->orientation == TQt::Horizontal)
339 return TQSize(dw, bs.height() + 2 * data->border);
341 return TQSize(bs.width() + 2 * data->border, dw);
345 TQSizePolicy KButtonBox::sizePolicy()
const
347 return data->orientation == TQt::Horizontal?
348 TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Fixed ) :
349 TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Minimum );
357 TQSize KButtonBox::buttonSizeHint(TQPushButton *b)
const {
358 TQSize s = b->sizeHint();
359 const TQSize ms = b->minimumSize();
360 if(s.width() < minButtonWidth)
361 s.setWidth(minButtonWidth);
364 const int msWidth = ms.width();
365 const int msHeight = ms.height();
367 if(msWidth > s.width())
369 if(msHeight > s.height())
370 s.setHeight(msHeight);
375 void KButtonBox::virtual_hook(
int,
void* )
An abstract class for GUI data such as ToolTip and Icon.