1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Charts module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 or (at your option) any later version
20** approved by the KDE Free Qt Foundation. The licenses are as published by
21** the Free Software Foundation and appearing in the file LICENSE.GPL3
22** included in the packaging of this file. Please review the following
23** information to ensure the GNU General Public License requirements will
24** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25**
26** $QT_END_LICENSE$
27**
28****************************************************************************/
29
30#include "declarativemargins_p.h"
31#include <QtCore/QDataStream>
32#include <QtCore/QDebug>
33
34QT_CHARTS_BEGIN_NAMESPACE
35
36/*!
37 \qmltype Margins
38 \inqmlmodule QtCharts
39
40 \brief Defines margins between the edge of the chart rectangle and the plot
41 area.
42
43 An uncreatable type that is used to define the top, bottom, left, and right
44 margins. The margins are used for drawing the title, axes, and legend.
45
46 \sa {ChartView::margins}{ChartView.margins}
47*/
48
49/*!
50 \qmlproperty int Margins::top
51 The top margin.
52*/
53
54/*!
55 \qmlproperty int Margins::bottom
56 The bottom margin.
57*/
58
59/*!
60 \qmlproperty int Margins::left
61 The left margin.
62*/
63
64/*!
65 \qmlproperty int Margins::right
66 The right margin.
67*/
68
69DeclarativeMargins::DeclarativeMargins(QObject *parent) :
70 QObject(parent)
71{
72 QMargins::setTop(0);
73 QMargins::setBottom(0);
74 QMargins::setLeft(0);
75 QMargins::setRight(0);
76}
77
78void DeclarativeMargins::setTop(int top)
79{
80 if (top < 0) {
81 qWarning() << "Cannot set top margin to a negative value:" << top;
82 } else {
83 if (top != QMargins::top()) {
84 QMargins::setTop(top);
85 emit topChanged(top: QMargins::top(), bottom: QMargins::bottom(), left: QMargins::left(), right: QMargins::right());
86 }
87 }
88}
89
90void DeclarativeMargins::setBottom(int bottom)
91{
92 if (bottom < 0) {
93 qWarning() << "Cannot set bottom margin to a negative value:" << bottom;
94 } else {
95 if (bottom != QMargins::bottom()) {
96 QMargins::setBottom(bottom);
97 emit bottomChanged(top: QMargins::top(), bottom: QMargins::bottom(), left: QMargins::left(), right: QMargins::right());
98 }
99 }
100}
101
102void DeclarativeMargins::setLeft(int left)
103{
104 if (left < 0) {
105 qWarning() << "Cannot set left margin to a negative value:" << left;
106 } else {
107 if (left != QMargins::left()) {
108 QMargins::setLeft(left);
109 emit leftChanged(top: QMargins::top(), bottom: QMargins::bottom(), left: QMargins::left(), right: QMargins::right());
110 }
111 }
112}
113
114void DeclarativeMargins::setRight(int right)
115{
116 if (right < 0) {
117 qWarning() << "Cannot set left margin to a negative value:" << right;
118 } else {
119 if (right != QMargins::right()) {
120 QMargins::setRight(right);
121 emit rightChanged(top: QMargins::top(), bottom: QMargins::bottom(), left: QMargins::left(), right: QMargins::right());
122 }
123 }
124}
125
126QT_CHARTS_END_NAMESPACE
127
128#include "moc_declarativemargins_p.cpp"
129

source code of qtcharts/src/chartsqml2/declarativemargins.cpp