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;
34 IconPalette::IconPalette(QWidget * parent, char const * name)
35 : QWidget(parent, name), maxcol_(-1)
37 QVBoxLayout * top = new QVBoxLayout(this);
38 QHBoxLayout * row = new QHBoxLayout(top);
39 layout_ = new QGridLayout(row);
45 void IconPalette::add(QPixmap const & pixmap, string name, string tooltip)
47 QPushButton * p = new QPushButton(this);
48 p->setFixedSize(button_size, button_size);
50 QToolTip::add(p, tooltip.c_str());
51 connect(p, SIGNAL(clicked()), this, SLOT(clicked()));
52 buttons_.push_back(make_pair(p, name));
56 void IconPalette::clicked()
58 vector<Button>::const_iterator it(buttons_.begin());
59 vector<Button>::const_iterator const end(buttons_.end());
60 for (; it != end; ++it) {
61 if (sender() == it->first) {
62 emit button_clicked(it->second);
69 void IconPalette::resizeEvent(QResizeEvent * e)
71 QWidget::resizeEvent(e);
73 lyxerr[Debug::GUI] << "resize panel to "
74 << e->size().width() << "," << e->size().height() << endl;
76 int maxcol = e->size().width() / button_size;
78 if (!layout_->isEmpty() && maxcol == maxcol_)
81 int cols(width() / button_size);
82 int rows = max(int(buttons_.size() / cols), 1);
83 if (buttons_.size() % cols)
86 lyxerr[Debug::GUI] << "Laying out " << buttons_.size() << " widgets in a "
87 << cols << "x" << rows << " grid." << endl;
89 setUpdatesEnabled(false);
92 QLayoutIterator lit = layout_->iterator();
93 while (lit.current()) {
97 layout_->invalidate();
99 vector<Button>::const_iterator it(buttons_.begin());
100 vector<Button>::const_iterator const end(buttons_.end());
102 for (int i = 0; i < rows; ++i) {
103 for (int j = 0; j < cols; ++j) {
104 layout_->addWidget(it->first, i, j);
113 resize(cols * button_size, rows * button_size);
117 setUpdatesEnabled(true);