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.
13 #include "iconpalette.h"
14 #include "qt_helpers.h"
15 #include <QVBoxLayout>
17 #include <QHBoxLayout>
18 #include <QGridLayout>
19 #include <QResizeEvent>
24 #include <qpushbutton.h>
34 int const button_size = 40;
37 IconPalette::IconPalette(QWidget * parent, char const * name)
38 : QWidget(parent, name), maxcol_(-1)
40 QVBoxLayout * top = new QVBoxLayout(this);
41 QHBoxLayout * row = new QHBoxLayout(top);
42 layout_ = new QGridLayout(row);
48 void IconPalette::add(QPixmap const & pixmap, string name, string tooltip)
50 QPushButton * p = new QPushButton(this);
51 p->setFixedSize(button_size, button_size);
53 QToolTip::add(p, toqstr(tooltip));
54 connect(p, SIGNAL(clicked()), this, SLOT(clicked()));
55 buttons_.push_back(make_pair(p, name));
59 void IconPalette::clicked()
61 vector<Button>::const_iterator it(buttons_.begin());
62 vector<Button>::const_iterator const end(buttons_.end());
63 for (; it != end; ++it) {
64 if (sender() == it->first) {
66 button_clicked(it->second);
73 void IconPalette::resizeEvent(QResizeEvent * e)
75 QWidget::resizeEvent(e);
77 lyxerr[Debug::GUI] << "resize panel to "
78 << e->size().width() << ',' << e->size().height() << endl;
80 int maxcol = e->size().width() / button_size;
82 if (!layout_->isEmpty() && maxcol == maxcol_)
85 int cols = max(width() / button_size, 1);
86 int rows = max(int(buttons_.size() / cols), 1);
87 if (buttons_.size() % cols)
90 lyxerr[Debug::GUI] << "Laying out " << buttons_.size() << " widgets in a "
91 << cols << 'x' << rows << " grid." << endl;
93 setUpdatesEnabled(false);
96 QLayoutIterator lit = layout_->iterator();
97 while (lit.current()) {
101 layout_->invalidate();
103 vector<Button>::const_iterator it(buttons_.begin());
104 vector<Button>::const_iterator const end(buttons_.end());
106 for (int i = 0; i < rows; ++i) {
107 for (int j = 0; j < cols; ++j) {
108 layout_->addWidget(it->first, i, j);
117 resize(cols * button_size, rows * button_size);
121 setUpdatesEnabled(true);
125 #include "iconpalette_moc.cpp"