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 "controllers/ControlMath.h" // for find_xpm
18 #include <QGridLayout>
19 #include <QPushButton>
30 FlowLayout::FlowLayout(QWidget *parent) : QLayout(parent)
37 FlowLayout::~FlowLayout()
40 while ((item = takeAt(0)))
45 void FlowLayout::addItem(QLayoutItem *item)
47 itemList.append(item);
51 int FlowLayout::count() const
53 return itemList.size();
57 QLayoutItem *FlowLayout::itemAt(int index) const
59 return itemList.value(index);
63 QLayoutItem *FlowLayout::takeAt(int index)
65 if (index >= 0 && index < itemList.size())
66 return itemList.takeAt(index);
72 Qt::Orientations FlowLayout::expandingDirections() const
78 bool FlowLayout::hasHeightForWidth() const
84 int FlowLayout::heightForWidth(int width) const
86 int height = doLayout(QRect(0, 0, width, 0), true);
91 void FlowLayout::setGeometry(const QRect &rect)
93 QLayout::setGeometry(rect);
94 doLayout(rect, false);
98 QSize FlowLayout::sizeHint() const
100 // default to (max) 6 columns
101 int const cols = qMin(itemList.size(), 6);
102 int const rows = (itemList.size() - 1 )/6 + 1;
103 return QSize(cols * minimumSize().width() + 1,
104 rows * minimumSize().height() + 1);
108 QSize FlowLayout::minimumSize() const
111 int const n = itemList.size();
112 for (int i = 0; i < n; ++i) {
113 size = size.expandedTo(itemList.at(i)->minimumSize());
119 int FlowLayout::doLayout(const QRect &rect, bool testOnly) const
125 for (int i = 0; i < itemList.size(); ++i) {
126 QLayoutItem * item = itemList.at(i);
127 int nextX = x + item->sizeHint().width() + spacing();
128 if (nextX - spacing() > rect.right() && lineHeight > 0) {
130 y = y + lineHeight + spacing();
131 nextX = x + item->sizeHint().width() + spacing();
136 item->setGeometry(QRect(QPoint(x, y), item->sizeHint()));
139 lineHeight = qMax(lineHeight, item->sizeHint().height());
141 return y + lineHeight - rect.y();
145 IconPalette::IconPalette(QWidget * parent, char const ** entries)
148 FlowLayout * layout_ = new FlowLayout(this);
149 layout_->setSpacing(0);
151 int const button_size = 40;
152 for (int i = 0; *entries[i]; ++i) {
153 QPushButton * p = new QPushButton;
154 p->setFixedSize(button_size, button_size);
155 p->setIcon(QPixmap(toqstr(lyx::frontend::find_xpm(entries[i]))));
156 p->setToolTip(toqstr(string("\\") + entries[i]));
157 connect(p, SIGNAL(clicked()), this, SLOT(clicked()));
158 buttons_.push_back(make_pair(p, entries[i]));
159 layout_->addWidget(p);
162 // FIXME: This is a hack to work around bug 2859
163 // http://bugzilla.lyx.org/show_bug.cgi?id=2859
164 // Short description of the bug:
166 Open the math panel and detach the operator panel by pressing the
167 "Detach Panel" button. The detached panel is then always set too
168 high in the left upper corner of the screen as in the attached
176 void IconPalette::clicked()
178 vector<Button>::const_iterator it = buttons_.begin();
179 vector<Button>::const_iterator const end = buttons_.end();
180 for (; it != end; ++it) {
181 if (sender() == it->first) {
183 button_clicked(it->second);
190 } // namespace frontend
193 #include "iconpalette_moc.cpp"