8#ifndef _KO_TOOLBOX_LAYOUT_H_
9#define _KO_TOOLBOX_LAYOUT_H_
15#include <QAbstractButton>
16#include <QApplication>
37 qWarning() <<
"Button" <<
button <<
"has a conflicting priority";
42 Q_FOREACH (QWidgetItem *item,
m_items) {
43 if (
m_priorities.value(
static_cast<QAbstractButton*
>(item->widget())) > priority)
61 void addItem(QLayoutItem*)
override { Q_ASSERT(0); }
63 QLayoutItem*
itemAt(
int i)
const override
79 foreach (QWidgetItem* w,
m_items) {
83 if (parentWidget()->isLeftToRight()) {
86 realX =
rect.width() - x - size.width();
88 w->widget()->setGeometry(QRect(realX, y, size.width(), size.height()));
90 if (x + size.width() >
rect.width()) {
96 foreach (QWidgetItem* w,
m_items) {
100 if (parentWidget()->isLeftToRight()) {
103 realX =
rect.width() - x - size.width();
105 w->widget()->setGeometry(QRect(realX, y, size.width(), size.height()));
107 if (y + size.height() >
rect.height()) {
253 , m_orientation(Qt::Vertical)
260 qDeleteAll( m_sections );
267 QSize twoIcons =
static_cast<Section*
> (m_sections[0]->widget())->
iconSize() * 2;
268 const int length = doLayout(QRect(QPoint(), twoIcons),
false);
269 if (m_orientation == Qt::Vertical) {
270 return QSize(twoIcons.width(),
length);
272 return QSize(
length, twoIcons.height());
278 if (m_sections.isEmpty())
280 QSize oneIcon =
static_cast<Section*
> (m_sections[0]->widget())->
iconSize();
286 addChildWidget(section);
290 while (iterator != m_sections.end()) {
291 if (--defaults < 0 &&
static_cast<Section*
> ((*iterator)->widget())->
name() > section->
name())
295 m_sections.insert(iterator,
new QWidgetItem(section));
303 QLayoutItem*
itemAt(
int i)
const override
305 return m_sections.value(i);
308 QLayoutItem*
takeAt(
int i)
override {
return m_sections.takeAt(i); }
310 int count()
const override {
return m_sections.count(); }
314 QLayout::setGeometry(
rect);
315 doLayout(
rect,
true);
321 return m_orientation == Qt::Vertical;
326 if (m_orientation == Qt::Vertical) {
327 const int height = doLayout(QRect(0, 0, width, 0),
false);
331 const int iconHeight =
static_cast<Section*
> (m_sections[0]->widget())->
iconSize().height();
332 for (
int i = 1; i <= 10; i++) {
333 const int testWidth = doLayout(QRect(0, 0, 0, iconHeight * i),
false);
334 if (testWidth <= width) {
335 return iconHeight * i;
352 if (m_orientation == Qt::Horizontal) {
353 const int width = doLayout(QRect(0, 0, 0, height),
false);
362 m_orientation = orientation;
370 if (m_sections.isEmpty()) {
376 const bool isVertical = m_orientation == Qt::Vertical;
380 const int maxWidth = isVertical ?
rect.width() :
rect.height();
382 const int iconWidth = qMax(1, isVertical ?
iconSize.width() :
iconSize.height());
383 const int iconHeight = qMax(1, isVertical ?
iconSize.height() :
iconSize.width());
385 const int maxColumns = qMax(1, (maxWidth / iconWidth));
389 bool firstSection =
true;
390 foreach (QWidgetItem *wi, m_sections) {
393 if (buttonCount == 0) {
396 section->setGeometry(1000, 1000, 0, 0);
402 const int neededRowCount = ((buttonCount-1) / maxColumns) + 1;
405 firstSection =
false;
409 y += iconHeight + spacing();
411 const Section::Separators separator =
418 const int usedColumns = qMin(buttonCount, maxColumns);
419 int narrowSide = usedColumns * iconWidth;
420 int longSide = neededRowCount * iconHeight;
423 if (parentWidget()->isLeftToRight()) {
426 realX =
rect.width() - x - narrowSide;
428 section->setGeometry(realX, y,
429 narrowSide, longSide);
432 if (parentWidget()->isLeftToRight()) {
435 realX =
rect.width() - y - longSide;
437 section->setGeometry(realX, x,
438 longSide, narrowSide);
443 const int lastRowColumnCount = buttonCount - ((neededRowCount-1) * maxColumns);
444 x += (lastRowColumnCount * iconWidth) + spacing();
446 y += (neededRowCount - 1) * iconHeight;
450 return y + iconHeight;
qreal length(const QPointF &vec)
Q_DECLARE_FLAGS(KisUpdaterContextSnapshotEx, KisUpdaterContextSnapshotExTag)
int iconSize(qreal width, qreal height)
void setButtonSize(const QSize size)
QMap< QAbstractButton *, int > m_priorities
const QSize & buttonSize() const
SectionLayout(QWidget *parent)
QLayoutItem * itemAt(int i) const override
int count() const override
~SectionLayout() override
void addButton(QAbstractButton *button, int priority)
void setOrientation(Qt::Orientation orientation)
QList< QWidgetItem * > m_items
QSize sizeHint() const override
void setGeometry(const QRect &rect) override
QLayoutItem * takeAt(int i) override
Qt::Orientation m_orientation
void addItem(QLayoutItem *) override
void addButton(QAbstractButton *button, int priority)
void setButtonSize(QSize size)
Separators separators() const
void setSeparator(Separators separators)
void setOrientation(Qt::Orientation orientation)
int visibleButtonCount() const
void setName(const QString &name)
Q_DECLARE_OPERATORS_FOR_FLAGS(KisBaseRectsWalker::SubtreeVisitFlags)
QString button(const QWheelEvent &ev)