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"
20 #include "qt_helpers.h"
23 #include <qpushbutton.h>
32 int const button_size = 40;
35 IconPalette::IconPalette(QWidget * parent, char const * name)
36 : QWidget(parent, name), maxcol_(-1)
38 QVBoxLayout * top = new QVBoxLayout(this);
39 QHBoxLayout * row = new QHBoxLayout(top);
40 layout_ = new QGridLayout(row);
46 void IconPalette::add(QPixmap const & pixmap, string name, string tooltip)
48 QPushButton * p = new QPushButton(this);
49 p->setFixedSize(button_size, button_size);
51 QToolTip::add(p, toqstr(tooltip));
52 connect(p, SIGNAL(clicked()), this, SLOT(clicked()));
53 buttons_.push_back(make_pair(p, name));
57 void IconPalette::clicked()
59 vector<Button>::const_iterator it(buttons_.begin());
60 vector<Button>::const_iterator const end(buttons_.end());
61 for (; it != end; ++it) {
62 if (sender() == it->first) {
63 emit button_clicked(it->second);
70 void IconPalette::resizeEvent(QResizeEvent * e)
72 QWidget::resizeEvent(e);
74 lyxerr[Debug::GUI] << "resize panel to "
75 << e->size().width() << ',' << e->size().height() << endl;
77 int maxcol = e->size().width() / button_size;
79 if (!layout_->isEmpty() && maxcol == maxcol_)
82 int cols(width() / button_size);
83 int rows = max(int(buttons_.size() / cols), 1);
84 if (buttons_.size() % cols)
87 lyxerr[Debug::GUI] << "Laying out " << buttons_.size() << " widgets in a "
88 << cols << 'x' << rows << " grid." << endl;
90 setUpdatesEnabled(false);
93 QLayoutIterator lit = layout_->iterator();
94 while (lit.current()) {
98 layout_->invalidate();
100 vector<Button>::const_iterator it(buttons_.begin());
101 vector<Button>::const_iterator const end(buttons_.end());
103 for (int i = 0; i < rows; ++i) {
104 for (int j = 0; j < cols; ++j) {
105 layout_->addWidget(it->first, i, j);
114 resize(cols * button_size, rows * button_size);
118 setUpdatesEnabled(true);