1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4//
5// W A R N I N G
6// -------------
7//
8// This file is not part of the Qt API. It exists for the convenience
9// of Qt Designer. This header
10// file may change from version to version without notice, or even be removed.
11//
12// We mean it.
13//
14
15#ifndef QDESIGNER_GRID_H
16#define QDESIGNER_GRID_H
17
18#include "shared_global_p.h"
19
20#include <QtCore/qvariant.h>
21
22QT_BEGIN_NAMESPACE
23
24class QWidget;
25class QPaintEvent;
26class QPainter;
27
28namespace qdesigner_internal {
29
30// Designer grid which is able to serialize to QVariantMap
31class QDESIGNER_SHARED_EXPORT Grid
32{
33public:
34 Grid();
35
36 bool fromVariantMap(const QVariantMap& vm);
37
38 void addToVariantMap(QVariantMap& vm, bool forceKeys = false) const;
39 QVariantMap toVariantMap(bool forceKeys = false) const;
40
41 inline bool visible() const { return m_visible; }
42 void setVisible(bool visible) { m_visible = visible; }
43
44 inline bool snapX() const { return m_snapX; }
45 void setSnapX(bool snap) { m_snapX = snap; }
46
47 inline bool snapY() const { return m_snapY; }
48 void setSnapY(bool snap) { m_snapY = snap; }
49
50 inline int deltaX() const { return m_deltaX; }
51 void setDeltaX(int dx) { m_deltaX = dx; }
52
53 inline int deltaY() const { return m_deltaY; }
54 void setDeltaY(int dy) { m_deltaY = dy; }
55
56 void paint(QWidget *widget, QPaintEvent *e) const;
57 void paint(QPainter &p, const QWidget *widget, QPaintEvent *e) const;
58
59 QPoint snapPoint(const QPoint &p) const;
60
61 int widgetHandleAdjustX(int x) const;
62 int widgetHandleAdjustY(int y) const;
63
64 inline bool operator==(const Grid &rhs) const { return equals(rhs); }
65 inline bool operator!=(const Grid &rhs) const { return !equals(rhs); }
66
67private:
68 bool equals(const Grid &rhs) const;
69 int snapValue(int value, int grid) const;
70 bool m_visible;
71 bool m_snapX;
72 bool m_snapY;
73 int m_deltaX;
74 int m_deltaY;
75};
76} // namespace qdesigner_internal
77
78QT_END_NAMESPACE
79
80#endif // QDESIGNER_GRID_H
81

source code of qttools/src/designer/src/lib/shared/grid_p.h