3 * Copyright 2001 the LyX Team
4 * Read the file COPYING
13 #include "iconpalette.h"
16 #include <qpushbutton.h>
25 int const button_size = 40;
27 IconPalette::IconPalette(QWidget * parent, char const * name)
28 : QWidget(parent, name), maxcol_(-1)
30 QVBoxLayout * top = new QVBoxLayout(this);
31 QHBoxLayout * row = new QHBoxLayout(top);
32 layout_ = new QGridLayout(row);
38 void IconPalette::add(QPixmap const & pixmap, string name, string tooltip)
40 QPushButton * p = new QPushButton(this);
41 p->setFixedSize(button_size, button_size);
43 QToolTip::add(p, tooltip.c_str());
44 connect(p, SIGNAL(clicked()), this, SLOT(clicked()));
45 buttons_.push_back(make_pair(p, name));
49 void IconPalette::clicked()
51 vector<Button>::const_iterator it(buttons_.begin());
52 vector<Button>::const_iterator const end(buttons_.end());
53 for (; it != end; ++it) {
54 if (sender() == it->first) {
55 emit button_clicked(it->second);
62 void IconPalette::resizeEvent(QResizeEvent * e)
64 QWidget::resizeEvent(e);
66 lyxerr[Debug::GUI] << "resize panel to "
67 << e->size().width() << "," << e->size().height() << endl;
69 int maxcol = e->size().width() / button_size;
71 if (!layout_->isEmpty() && maxcol == maxcol_)
74 int cols(width() / button_size);
75 int rows = max(buttons_.size() / cols, 1U);
76 if (buttons_.size() % cols)
79 lyxerr[Debug::GUI] << "Laying out " << buttons_.size() << " widgets in a "
80 << cols << "x" << rows << " grid." << endl;
82 setUpdatesEnabled(false);
85 QLayoutIterator lit = layout_->iterator();
86 while (lit.current()) {
90 layout_->invalidate();
92 vector<Button>::const_iterator it(buttons_.begin());
93 vector<Button>::const_iterator const end(buttons_.end());
95 for (int i = 0; i < rows; ++i) {
96 for (int j = 0; j < cols; ++j) {
97 layout_->addWidget(it->first, i, j);
106 resize(cols * button_size, rows * button_size);
110 setUpdatesEnabled(true);