110 lines
2.8 KiB
C++
110 lines
2.8 KiB
C++
// #include "myflowlayout.hpp"
|
|
// #include "qexception.h"
|
|
// #include "qwidget.h"
|
|
|
|
// MyFlowLayout::MyFlowLayout(QWidget *parent, int margin, int hSpacing, int vSpacing)
|
|
// : QLayout(parent), hSpace(hSpacing), vSpace(vSpacing)
|
|
// {
|
|
|
|
// }
|
|
|
|
// MyFlowLayout::MyFlowLayout(int margin, int hSpacing, int vSpacing)
|
|
// : hSpace(hSpacing), vSpace(vSpacing)
|
|
// {
|
|
|
|
// }
|
|
|
|
// MyFlowLayout::~MyFlowLayout()
|
|
// {
|
|
// for (auto child : itemList)
|
|
// {
|
|
// delete child;
|
|
// }
|
|
// }
|
|
|
|
// void MyFlowLayout::addItem(QLayoutItem* item)
|
|
// {
|
|
// itemList.append(item);
|
|
// }
|
|
|
|
// int MyFlowLayout::horizontalSpacing() const
|
|
// {
|
|
// return hSpace;
|
|
// }
|
|
|
|
// int MyFlowLayout::verticalSpacing() const
|
|
// {
|
|
// return vSpace;
|
|
// }
|
|
|
|
// Qt::Orientations MyFlowLayout::expandingDirections() const
|
|
// {
|
|
// return { };
|
|
// }
|
|
|
|
// bool MyFlowLayout::hasHeightForWidth() const
|
|
// {
|
|
// return true;
|
|
// }
|
|
|
|
// int MyFlowLayout::heightForWidth(int width) const
|
|
// {
|
|
// QRect rect(0, 0, width, 0);
|
|
// return doLayout(rect, false);
|
|
// }
|
|
|
|
// QSize MyFlowLayout::minimumSize() const
|
|
// {
|
|
// QSize size(1,1);
|
|
// for (auto child : itemList)
|
|
// {
|
|
// size = size.expandedTo(child->minimumSize());
|
|
// }
|
|
// return size;
|
|
// }
|
|
|
|
// QLayoutItem* MyFlowLayout::itemAt(int index) const
|
|
// {
|
|
// return itemList.at(index);
|
|
// }
|
|
|
|
// QLayoutItem* MyFlowLayout::takeAt(int index)
|
|
// {
|
|
// return itemList.takeAt(index);
|
|
// }
|
|
|
|
// int MyFlowLayout::doLayout(const QRect &rect, bool apply) const
|
|
// {
|
|
// int left, top, right, bottom;
|
|
// getContentsMargins(&left, &top, &right, &bottom);
|
|
// QRect effectiveRect = rect.adjusted(+left, +top, -right, -bottom);
|
|
// int x = effectiveRect.x();
|
|
// int y = effectiveRect.y();
|
|
// int lineHeight = 0;
|
|
// for (QLayoutItem *item : std::as_const(itemList)) {
|
|
// const QWidget *wid = item->widget();
|
|
// int spaceX = horizontalSpacing();
|
|
// if (spaceX == -1)
|
|
// spaceX = wid->style()->layoutSpacing(
|
|
// QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Horizontal);
|
|
// int spaceY = verticalSpacing();
|
|
// if (spaceY == -1)
|
|
// spaceY = wid->style()->layoutSpacing(
|
|
// QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Vertical);
|
|
// int nextX = x + item->sizeHint().width() + spaceX;
|
|
// if (nextX - spaceX > effectiveRect.right() && lineHeight > 0) {
|
|
// x = effectiveRect.x();
|
|
// y = y + lineHeight + spaceY;
|
|
// nextX = x + item->sizeHint().width() + spaceX;
|
|
// lineHeight = 0;
|
|
// }
|
|
|
|
// if (apply)
|
|
// item->setGeometry(QRect(QPoint(x, y), item->sizeHint()));
|
|
|
|
// x = nextX;
|
|
// lineHeight = qMax(lineHeight, item->sizeHint().height());
|
|
// }
|
|
// return y + lineHeight - rect.y() + bottom;
|
|
// }
|