1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include "declarativemargins_p.h" |
5 | #include <QtCore/QDataStream> |
6 | #include <QtCore/QDebug> |
7 | |
8 | QT_BEGIN_NAMESPACE |
9 | |
10 | /*! |
11 | \qmltype Margins |
12 | \inqmlmodule QtCharts |
13 | |
14 | \brief Defines margins between the edge of the chart rectangle and the plot |
15 | area. |
16 | |
17 | An uncreatable type that is used to define the top, bottom, left, and right |
18 | margins. The margins are used for drawing the title, axes, and legend. |
19 | |
20 | \sa {ChartView::margins}{ChartView.margins} |
21 | */ |
22 | |
23 | /*! |
24 | \qmlproperty int Margins::top |
25 | The top margin. |
26 | */ |
27 | |
28 | /*! |
29 | \qmlproperty int Margins::bottom |
30 | The bottom margin. |
31 | */ |
32 | |
33 | /*! |
34 | \qmlproperty int Margins::left |
35 | The left margin. |
36 | */ |
37 | |
38 | /*! |
39 | \qmlproperty int Margins::right |
40 | The right margin. |
41 | */ |
42 | |
43 | DeclarativeMargins::DeclarativeMargins(QObject *parent) : |
44 | QObject(parent) |
45 | { |
46 | QMargins::setTop(0); |
47 | QMargins::setBottom(0); |
48 | QMargins::setLeft(0); |
49 | QMargins::setRight(0); |
50 | } |
51 | |
52 | void DeclarativeMargins::setTop(int top) |
53 | { |
54 | if (top < 0) { |
55 | qWarning() << "Cannot set top margin to a negative value:" << top; |
56 | } else { |
57 | if (top != QMargins::top()) { |
58 | QMargins::setTop(top); |
59 | emit topChanged(top: QMargins::top(), bottom: QMargins::bottom(), left: QMargins::left(), right: QMargins::right()); |
60 | } |
61 | } |
62 | } |
63 | |
64 | void DeclarativeMargins::setBottom(int bottom) |
65 | { |
66 | if (bottom < 0) { |
67 | qWarning() << "Cannot set bottom margin to a negative value:" << bottom; |
68 | } else { |
69 | if (bottom != QMargins::bottom()) { |
70 | QMargins::setBottom(bottom); |
71 | emit bottomChanged(top: QMargins::top(), bottom: QMargins::bottom(), left: QMargins::left(), right: QMargins::right()); |
72 | } |
73 | } |
74 | } |
75 | |
76 | void DeclarativeMargins::setLeft(int left) |
77 | { |
78 | if (left < 0) { |
79 | qWarning() << "Cannot set left margin to a negative value:" << left; |
80 | } else { |
81 | if (left != QMargins::left()) { |
82 | QMargins::setLeft(left); |
83 | emit leftChanged(top: QMargins::top(), bottom: QMargins::bottom(), left: QMargins::left(), right: QMargins::right()); |
84 | } |
85 | } |
86 | } |
87 | |
88 | void DeclarativeMargins::setRight(int right) |
89 | { |
90 | if (right < 0) { |
91 | qWarning() << "Cannot set left margin to a negative value:" << right; |
92 | } else { |
93 | if (right != QMargins::right()) { |
94 | QMargins::setRight(right); |
95 | emit rightChanged(top: QMargins::top(), bottom: QMargins::bottom(), left: QMargins::left(), right: QMargins::right()); |
96 | } |
97 | } |
98 | } |
99 | |
100 | QT_END_NAMESPACE |
101 | |
102 | #include "moc_declarativemargins_p.cpp" |
103 | |