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 lyxerr << "resize panel to " << e->size().width() << "," << e->size().height() << endl;
66 int maxcol = e->size().width() / button_size;
68 if (!layout_->isEmpty() && maxcol == maxcol_)
71 lyxerr << "doing layout !" << maxcol << " " << width() << endl;
72 lyxerr << "before is " << maxcol_ << endl;
74 setUpdatesEnabled(false);
77 QLayoutIterator lit = layout_->iterator();
78 while (lit.current()) {
82 layout_->invalidate();
84 vector<Button>::const_iterator it(buttons_.begin());
85 vector<Button>::const_iterator const end(buttons_.end());
90 for (; it != end; ++it) {
91 layout_->addWidget(it->first, row, col++);
100 // this is OK because width won't change, and we have the check above
101 setGeometry(x(), y(), width(), (row + 1) * button_size);
104 lyxerr << "after is " << row << "," << maxcol << endl;
105 setUpdatesEnabled(true);