feat: initial commit for pixel-snapping components and helpers
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
#pragma once
|
||||
|
||||
#include <QPointer>
|
||||
#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 SnapGridLayoutItem : public QQuickGridLayoutItem {
|
||||
public:
|
||||
SnapGridLayoutItem(
|
||||
QQuickItem* item,
|
||||
int row,
|
||||
int column,
|
||||
int rowSpan,
|
||||
int columnSpan,
|
||||
Qt::Alignment alignment,
|
||||
SnapLayout* layout);
|
||||
|
||||
void setGeometry(const QRectF& rect) override;
|
||||
|
||||
private:
|
||||
SnapLayout* m_layout;
|
||||
};
|
||||
|
||||
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 updateAncestorListeners();
|
||||
void clearAncestorListeners();
|
||||
};
|
||||
|
||||
class SnapLayoutPrivate : public QQuickLayoutPrivate {
|
||||
Q_DECLARE_PUBLIC(SnapLayout)
|
||||
|
||||
public:
|
||||
SnapLayoutPrivate() = default;
|
||||
|
||||
void mirrorChange() override;
|
||||
|
||||
QQuickGridLayoutEngine engine;
|
||||
SnapLayoutStyleInfo* styleInfo = nullptr;
|
||||
Qt::Orientation orientation = Qt::Horizontal;
|
||||
Qt::LayoutDirection layoutDirection = Qt::LeftToRight;
|
||||
bool rearranging = false;
|
||||
int recurRearrangeCounter = 0;
|
||||
QList<QQuickItem*> invalidateAfterRearrange;
|
||||
|
||||
QVector<QPointer<QQuickItem>> ancestorListeners;
|
||||
qint64 originResidualX = -1;
|
||||
qint64 originResidualY = -1;
|
||||
};
|
||||
|
||||
} // namespace ZShell::components
|
||||
Reference in New Issue
Block a user