+ vector<Button>::const_iterator it(buttons_.begin());
+ vector<Button>::const_iterator const end(buttons_.end());
+ for (; it != end; ++it) {
+ if (sender() == it->first) {
+ emit button_clicked(it->second);
+ return;
+ }
+ }
+}
+
+
+void IconPalette::resizeEvent(QResizeEvent * e)
+{
+ QWidget::resizeEvent(e);
+
+ lyxerr[Debug::GUI] << "resize panel to "
+ << e->size().width() << "," << e->size().height() << endl;
+
+ int maxcol = e->size().width() / button_size;
+
+ if (!layout_->isEmpty() && maxcol == maxcol_)
+ return;
+
+ int cols(width() / button_size);
+ int rows = max(int(buttons_.size() / cols), 1);
+ if (buttons_.size() % cols)
+ ++rows;
+
+ lyxerr[Debug::GUI] << "Laying out " << buttons_.size() << " widgets in a "
+ << cols << "x" << rows << " grid." << endl;
+
+ setUpdatesEnabled(false);
+
+ // clear layout
+ QLayoutIterator lit = layout_->iterator();
+ while (lit.current()) {
+ lit.takeCurrent();
+ }
+
+ layout_->invalidate();
+
+ vector<Button>::const_iterator it(buttons_.begin());
+ vector<Button>::const_iterator const end(buttons_.end());
+
+ for (int i = 0; i < rows; ++i) {
+ for (int j = 0; j < cols; ++j) {
+ layout_->addWidget(it->first, i, j);
+ ++it;
+ if (it == end)
+ goto out;
+ }
+ }
+
+out:
+
+ resize(cols * button_size, rows * button_size);
+
+ maxcol_ = cols;
+
+ setUpdatesEnabled(true);
+ update();