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
16 #include "iconpalette.h"
17 #include "qt_helpers.h"
20 #include <qpushbutton.h>
29 int const button_size = 40;
32 IconPalette::IconPalette(QWidget * parent, char const * name)
33 : QWidget(parent, name), maxcol_(-1)
35 QVBoxLayout * top = new QVBoxLayout(this);
36 QHBoxLayout * row = new QHBoxLayout(top);
37 layout_ = new QGridLayout(row);
43 void IconPalette::add(QPixmap const & pixmap, string name, string tooltip)
45 QPushButton * p = new QPushButton(this);
46 p->setFixedSize(button_size, button_size);
48 QToolTip::add(p, toqstr(tooltip));
49 connect(p, SIGNAL(clicked()), this, SLOT(clicked()));
50 buttons_.push_back(make_pair(p, name));
54 void IconPalette::clicked()
56 vector<Button>::const_iterator it(buttons_.begin());
57 vector<Button>::const_iterator const end(buttons_.end());
58 for (; it != end; ++it) {
59 if (sender() == it->first) {
60 emit button_clicked(it->second);
67 void IconPalette::resizeEvent(QResizeEvent * e)
69 QWidget::resizeEvent(e);
71 lyxerr[Debug::GUI] << "resize panel to "
72 << e->size().width() << ',' << e->size().height() << endl;
74 int maxcol = e->size().width() / button_size;
76 if (!layout_->isEmpty() && maxcol == maxcol_)
79 int cols(width() / button_size);
80 int rows = max(int(buttons_.size() / cols), 1);
81 if (buttons_.size() % cols)
84 lyxerr[Debug::GUI] << "Laying out " << buttons_.size() << " widgets in a "
85 << cols << 'x' << rows << " grid." << endl;
87 setUpdatesEnabled(false);
90 QLayoutIterator lit = layout_->iterator();
91 while (lit.current()) {
95 layout_->invalidate();
97 vector<Button>::const_iterator it(buttons_.begin());
98 vector<Button>::const_iterator const end(buttons_.end());
100 for (int i = 0; i < rows; ++i) {
101 for (int j = 0; j < cols; ++j) {
102 layout_->addWidget(it->first, i, j);
111 resize(cols * button_size, rows * button_size);
115 setUpdatesEnabled(true);