3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS
14 #pragma implementation
19 #include "iconpalette.h"
22 #include <qpushbutton.h>
31 int const button_size = 40;
33 IconPalette::IconPalette(QWidget * parent, char const * name)
34 : QWidget(parent, name), maxcol_(-1)
36 QVBoxLayout * top = new QVBoxLayout(this);
37 QHBoxLayout * row = new QHBoxLayout(top);
38 layout_ = new QGridLayout(row);
44 void IconPalette::add(QPixmap const & pixmap, string name, string tooltip)
46 QPushButton * p = new QPushButton(this);
47 p->setFixedSize(button_size, button_size);
49 QToolTip::add(p, tooltip.c_str());
50 connect(p, SIGNAL(clicked()), this, SLOT(clicked()));
51 buttons_.push_back(make_pair(p, name));
55 void IconPalette::clicked()
57 vector<Button>::const_iterator it(buttons_.begin());
58 vector<Button>::const_iterator const end(buttons_.end());
59 for (; it != end; ++it) {
60 if (sender() == it->first) {
61 emit button_clicked(it->second);
68 void IconPalette::resizeEvent(QResizeEvent * e)
70 QWidget::resizeEvent(e);
72 lyxerr[Debug::GUI] << "resize panel to "
73 << e->size().width() << "," << e->size().height() << endl;
75 int maxcol = e->size().width() / button_size;
77 if (!layout_->isEmpty() && maxcol == maxcol_)
80 int cols(width() / button_size);
81 int rows = max(int(buttons_.size() / cols), 1);
82 if (buttons_.size() % cols)
85 lyxerr[Debug::GUI] << "Laying out " << buttons_.size() << " widgets in a "
86 << cols << "x" << rows << " grid." << endl;
88 setUpdatesEnabled(false);
91 QLayoutIterator lit = layout_->iterator();
92 while (lit.current()) {
96 layout_->invalidate();
98 vector<Button>::const_iterator it(buttons_.begin());
99 vector<Button>::const_iterator const end(buttons_.end());
101 for (int i = 0; i < rows; ++i) {
102 for (int j = 0; j < cols; ++j) {
103 layout_->addWidget(it->first, i, j);
112 resize(cols * button_size, rows * button_size);
116 setUpdatesEnabled(true);