C++ / fmt (pull_request) Failing after 5s
C++ / build (pull_request) Failing after 10s
C++ / clang-tidy (pull_request) Failing after 10s
JS/TS / fmt (pull_request) Successful in 9s
JS/TS / lint (pull_request) Successful in 25s
Python / static (pull_request) Successful in 34s
Rust / build (pull_request) Successful in 51s
Python / verify (pull_request) Failing after 1m25s
Rust / fmt (pull_request) Successful in 39s
Rust / clippy (pull_request) Successful in 59s
158 lines
4.2 KiB
C++
158 lines
4.2 KiB
C++
#pragma once
|
|
|
|
#include <QHash>
|
|
#include <QPointer>
|
|
#include <QtMath>
|
|
#include <QtGui/private/qabstractlayoutstyleinfo_p.h>
|
|
#include <QtGui/private/qgridlayoutengine_p.h>
|
|
#include <QtQuickLayouts/private/qquickgridlayoutengine_p.h>
|
|
#include <QtQuickLayouts/private/qquicklayout_p.h>
|
|
#include <QtQuick/private/qquickitem_p.h>
|
|
#include <qqmlintegration.h>
|
|
|
|
namespace ZShell::components {
|
|
|
|
class SnapLayout;
|
|
class SnapLayoutPrivate;
|
|
|
|
class SnapLayoutStyleInfo : public QAbstractLayoutStyleInfo {
|
|
public:
|
|
qreal spacing(Qt::Orientation orientation) const override;
|
|
qreal windowMargin(Qt::Orientation orientation) const override;
|
|
bool hasChangedCore() const override;
|
|
};
|
|
|
|
class SnapGridLayoutEngine : public QGridLayoutEngine {
|
|
public:
|
|
SnapGridLayoutEngine() : QGridLayoutEngine(Qt::AlignVCenter, false) {}
|
|
|
|
QQuickGridLayoutItem* findLayoutItem(QQuickItem* item) const {
|
|
for (int i = int(q_items.size()) - 1; i >= 0; --i) {
|
|
QQuickGridLayoutItem* layoutItem =
|
|
static_cast<QQuickGridLayoutItem*>(q_items.at(i));
|
|
if (layoutItem->layoutItem() == item) return layoutItem;
|
|
}
|
|
return nullptr;
|
|
}
|
|
};
|
|
|
|
class SnapGridLayoutItem : public QQuickGridLayoutItem {
|
|
public:
|
|
SnapGridLayoutItem(
|
|
QQuickItem* item,
|
|
int row,
|
|
int column,
|
|
int rowSpan,
|
|
int columnSpan,
|
|
Qt::Alignment alignment);
|
|
|
|
void setGeometry(const QRectF& rect) override;
|
|
|
|
QRectF engineRect;
|
|
bool placed = false;
|
|
};
|
|
|
|
class SnapLayout : public QQuickLayout {
|
|
Q_OBJECT
|
|
QML_ELEMENT
|
|
|
|
Q_PROPERTY(
|
|
Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY
|
|
orientationChanged)
|
|
Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged)
|
|
Q_PROPERTY(
|
|
Qt::LayoutDirection layoutDirection READ layoutDirection WRITE
|
|
setLayoutDirection NOTIFY layoutDirectionChanged)
|
|
Q_PROPERTY(
|
|
bool uniformCellSizes READ uniformCellSizes WRITE setUniformCellSizes
|
|
NOTIFY uniformCellSizesChanged)
|
|
|
|
public:
|
|
explicit SnapLayout(QQuickItem* parent = nullptr);
|
|
~SnapLayout() override;
|
|
|
|
void componentComplete() override;
|
|
QSizeF sizeHint(Qt::SizeHint whichSizeHint) const override;
|
|
void setAlignment(QQuickItem* item, Qt::Alignment align) override;
|
|
void setStretchFactor(
|
|
QQuickItem* item, int stretchFactor, Qt::Orientation orient) override;
|
|
void invalidate(QQuickItem* childItem = nullptr) override;
|
|
void updateLayoutItems() override;
|
|
QQuickItem* itemAt(int index) const override;
|
|
int itemCount() const override;
|
|
void rearrange(const QSizeF& size) override;
|
|
|
|
void itemChange(ItemChange change, const ItemChangeData& value) override;
|
|
|
|
void itemDestroyed(QQuickItem* item) override;
|
|
void itemVisibilityChanged(QQuickItem* item) override;
|
|
void itemGeometryChanged(
|
|
QQuickItem* item,
|
|
QQuickGeometryChange change,
|
|
const QRectF& oldGeometry) override;
|
|
|
|
Qt::Orientation orientation() const;
|
|
void setOrientation(Qt::Orientation orientation);
|
|
|
|
qreal spacing() const;
|
|
void setSpacing(qreal spacing);
|
|
|
|
Qt::LayoutDirection layoutDirection() const;
|
|
void setLayoutDirection(Qt::LayoutDirection direction);
|
|
Qt::LayoutDirection effectiveLayoutDirection() const;
|
|
|
|
bool uniformCellSizes() const;
|
|
void setUniformCellSizes(bool uniformCellSizes);
|
|
|
|
signals:
|
|
void orientationChanged();
|
|
void spacingChanged();
|
|
void layoutDirectionChanged();
|
|
void uniformCellSizesChanged();
|
|
|
|
private:
|
|
Q_DECLARE_PRIVATE(SnapLayout)
|
|
|
|
void insertLayoutItems();
|
|
void removeGridItem(QGridLayoutItem* gridItem);
|
|
|
|
void arrangeChildren();
|
|
|
|
void applySpacing();
|
|
|
|
void updateAncestorListeners();
|
|
void clearAncestorListeners();
|
|
};
|
|
|
|
class SnapLayoutPrivate : public QQuickLayoutPrivate {
|
|
Q_DECLARE_PUBLIC(SnapLayout)
|
|
|
|
public:
|
|
SnapLayoutPrivate() = default;
|
|
|
|
void mirrorChange() override;
|
|
|
|
SnapGridLayoutEngine engine;
|
|
SnapLayoutStyleInfo* styleInfo = nullptr;
|
|
Qt::Orientation orientation = Qt::Horizontal;
|
|
Qt::LayoutDirection layoutDirection = Qt::LeftToRight;
|
|
qreal spacingRequest = qQNaN();
|
|
bool rearranging = false;
|
|
int recurRearrangeCounter = 0;
|
|
QList<QQuickItem*> invalidateAfterRearrange;
|
|
|
|
QVector<QPointer<QQuickItem>> ancestorListeners;
|
|
qint64 originResidualX = -1;
|
|
qint64 originResidualY = -1;
|
|
|
|
struct ChildSize {
|
|
qint64 engineWidth = 0;
|
|
qint64 engineHeight = 0;
|
|
qint64 width = 0;
|
|
qint64 height = 0;
|
|
};
|
|
QHash<QQuickItem*, ChildSize> childSizes;
|
|
};
|
|
|
|
} // namespace ZShell::components
|