##// END OF EJS Templates
Adjust various margins and paddings....
Miikka Heikkinen -
r2569:f4eaee212ddc
parent child
Show More
@@ -1,149 +1,149
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2013 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef CHARTAXISELEMENT_H
31 31 #define CHARTAXISELEMENT_H
32 32
33 33 #include "qchartglobal.h"
34 34 #include "chartelement_p.h"
35 35 #include "axisanimation_p.h"
36 36 #include <QGraphicsItem>
37 37 #include <QGraphicsLayoutItem>
38 38 #include <QFont>
39 39
40 40 QTCOMMERCIALCHART_BEGIN_NAMESPACE
41 41
42 42 class ChartPresenter;
43 43 class QAbstractAxis;
44 44
45 45 class ChartAxisElement : public ChartElement, public QGraphicsLayoutItem
46 46 {
47 47 Q_OBJECT
48 48 public:
49 49 ChartAxisElement(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis = false);
50 50 ~ChartAxisElement();
51 51
52 52 virtual QRectF gridGeometry() const = 0;
53 53 virtual void setGeometry(const QRectF &axis, const QRectF &grid) = 0;
54 54 virtual bool isEmpty() = 0;
55 55
56 56 void setAnimation(AxisAnimation *animation) { m_animation = animation; }
57 57 AxisAnimation *animation() const { return m_animation; }
58 58
59 59 QAbstractAxis *axis() const { return m_axis; }
60 60 void setLayout(QVector<qreal> &layout) { m_layout = layout; }
61 61 QVector<qreal> &layout() { return m_layout; } // Modifiable reference
62 inline qreal labelPadding() const { return qreal(5.0); }
63 inline qreal titlePadding() const { return qreal(3.0); }
62 inline qreal labelPadding() const { return qreal(1.0); }
63 inline qreal titlePadding() const { return qreal(1.0); }
64 64 void setLabels(const QStringList &labels) { m_labelsList = labels; }
65 65 QStringList labels() const { return m_labelsList; }
66 66
67 67 qreal min() const;
68 68 qreal max() const;
69 69
70 70 QRectF axisGeometry() const { return m_axisRect; }
71 71 void setAxisGeometry(const QRectF &axisGeometry) { m_axisRect = axisGeometry; }
72 72
73 73 void axisSelected();
74 74
75 75 //this flag indicates that axis is used to show intervals it means labels are in between ticks
76 76 bool intervalAxis() const { return m_intervalAxis; }
77 77
78 78 static QStringList createValueLabels(qreal max, qreal min, int ticks, const QString &format);
79 79 static QStringList createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString &format);
80 80 static QStringList createDateTimeLabels(qreal max, qreal min, int ticks, const QString &format);
81 81
82 82 // from QGraphicsLayoutItem
83 83 QRectF boundingRect() const
84 84 {
85 85 return QRectF();
86 86 }
87 87
88 88 // from QGraphicsLayoutItem
89 89 void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*)
90 90 {
91 91 }
92 92
93 93 protected:
94 94 virtual QVector<qreal> calculateLayout() const = 0;
95 95 virtual void updateLayout(QVector<qreal> &layout) = 0;
96 96
97 97 QList<QGraphicsItem *> gridItems() { return m_grid->childItems(); }
98 98 QList<QGraphicsItem *> labelItems() { return m_labels->childItems(); }
99 99 QList<QGraphicsItem *> shadeItems() { return m_shades->childItems(); }
100 100 QList<QGraphicsItem *> arrowItems() { return m_arrow->childItems(); }
101 101 QGraphicsTextItem *titleItem() const { return m_title.data(); }
102 102 QGraphicsItemGroup *gridGroup() { return m_grid.data(); }
103 103 QGraphicsItemGroup *labelGroup() { return m_labels.data(); }
104 104 QGraphicsItemGroup *shadeGroup() { return m_shades.data(); }
105 105 QGraphicsItemGroup *arrowGroup() { return m_arrow.data(); }
106 106
107 107 public Q_SLOTS:
108 108 void handleVisibleChanged(bool visible);
109 109 void handleArrowVisibleChanged(bool visible);
110 110 void handleGridVisibleChanged(bool visible);
111 111 void handleLabelsVisibleChanged(bool visible);
112 112 void handleShadesVisibleChanged(bool visible);
113 113 void handleLabelsAngleChanged(int angle);
114 114 virtual void handleShadesBrushChanged(const QBrush &brush) = 0;
115 115 virtual void handleShadesPenChanged(const QPen &pen) = 0;
116 116 virtual void handleArrowPenChanged(const QPen &pen) = 0;
117 117 virtual void handleGridPenChanged(const QPen &pen) = 0;
118 118 void handleLabelsPenChanged(const QPen &pen);
119 119 void handleLabelsBrushChanged(const QBrush &brush);
120 120 void handleLabelsFontChanged(const QFont &font);
121 121 void handleTitlePenChanged(const QPen &pen);
122 122 void handleTitleBrushChanged(const QBrush &brush);
123 123 void handleTitleFontChanged(const QFont &font);
124 124 void handleTitleTextChanged(const QString &title);
125 125 void handleTitleVisibleChanged(bool visible);
126 126 void handleRangeChanged(qreal min, qreal max);
127 127
128 128 Q_SIGNALS:
129 129 void clicked();
130 130
131 131 private:
132 132 void connectSlots();
133 133
134 134 QAbstractAxis *m_axis;
135 135 AxisAnimation *m_animation;
136 136 QVector<qreal> m_layout;
137 137 QStringList m_labelsList;
138 138 QRectF m_axisRect;
139 139 QScopedPointer<QGraphicsItemGroup> m_grid;
140 140 QScopedPointer<QGraphicsItemGroup> m_arrow;
141 141 QScopedPointer<QGraphicsItemGroup> m_shades;
142 142 QScopedPointer<QGraphicsItemGroup> m_labels;
143 143 QScopedPointer<QGraphicsTextItem> m_title;
144 144 bool m_intervalAxis;
145 145 };
146 146
147 147 QTCOMMERCIALCHART_END_NAMESPACE
148 148
149 149 #endif /* CHARTAXISELEMENT_H */
@@ -1,186 +1,186
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2013 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include <QPainter>
22 22 #include <QGraphicsSceneEvent>
23 23 #include <QGraphicsTextItem>
24 24
25 25 #include "qlegend.h"
26 26 #include "qlegend_p.h"
27 27 #include "qlegendmarker.h"
28 28 #include "qlegendmarker_p.h"
29 29 #include "legendmarkeritem_p.h"
30 30 #include "chartpresenter_p.h"
31 31
32 32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 33
34 34 LegendMarkerItem::LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent) :
35 35 QGraphicsObject(parent),
36 36 m_marker(marker),
37 37 m_markerRect(0,0,10.0,10.0),
38 38 m_boundingRect(0,0,0,0),
39 39 m_textItem(new QGraphicsTextItem(this)),
40 40 m_rectItem(new QGraphicsRectItem(this)),
41 m_margin(4),
42 m_space(4),
41 m_margin(1),
42 m_space(2),
43 43 m_hovering(false),
44 44 m_pressPos(0, 0)
45 45 {
46 46 m_rectItem->setRect(m_markerRect);
47 47 setAcceptHoverEvents(true);
48 48 }
49 49
50 50 LegendMarkerItem::~LegendMarkerItem()
51 51 {
52 52 if (m_hovering) {
53 53 emit m_marker->q_ptr->hovered(false);
54 54 }
55 55 }
56 56
57 57 void LegendMarkerItem::setPen(const QPen &pen)
58 58 {
59 59 m_rectItem->setPen(pen);
60 60 }
61 61
62 62 QPen LegendMarkerItem::pen() const
63 63 {
64 64 return m_rectItem->pen();
65 65 }
66 66
67 67 void LegendMarkerItem::setBrush(const QBrush &brush)
68 68 {
69 69 m_rectItem->setBrush(brush);
70 70 }
71 71
72 72 QBrush LegendMarkerItem::brush() const
73 73 {
74 74 return m_rectItem->brush();
75 75 }
76 76
77 77 void LegendMarkerItem::setFont(const QFont &font)
78 78 {
79 79 m_textItem->setFont(font);
80 80 QFontMetrics fn(font);
81 81 m_markerRect = QRectF(0,0,fn.height()/2,fn.height()/2);
82 82 updateGeometry();
83 83 }
84 84
85 85 QFont LegendMarkerItem::font() const
86 86 {
87 87 return m_textItem->font();
88 88 }
89 89
90 90 void LegendMarkerItem::setLabel(const QString label)
91 91 {
92 92 m_label = label;
93 93 updateGeometry();
94 94 }
95 95
96 96 QString LegendMarkerItem::label() const
97 97 {
98 98 return m_label;
99 99 }
100 100
101 101 void LegendMarkerItem::setLabelBrush(const QBrush &brush)
102 102 {
103 103 m_textItem->setDefaultTextColor(brush.color());
104 104 }
105 105
106 106 QBrush LegendMarkerItem::labelBrush() const
107 107 {
108 108 return QBrush(m_textItem->defaultTextColor());
109 109 }
110 110
111 111 void LegendMarkerItem::setGeometry(const QRectF &rect)
112 112 {
113 113 qreal width = rect.width();
114 114 qreal x = m_margin + m_markerRect.width() + m_space + m_margin;
115 115 QRectF truncatedRect;
116 116
117 117 m_textItem->setHtml(ChartPresenter::truncatedText(m_textItem->font(), m_label, qreal(0.0), width - x, Qt::Horizontal, truncatedRect));
118 118
119 119 qreal y = qMax(m_markerRect.height() + 2 * m_margin, truncatedRect.height() + 2 * m_margin);
120 120
121 121 const QRectF &textRect = m_textItem->boundingRect();
122 122
123 123 m_textItem->setPos(x - m_margin, y / 2 - textRect.height() / 2);
124 124 m_rectItem->setRect(m_markerRect);
125 125 m_rectItem->setPos(m_margin, y / 2 - m_markerRect.height() / 2);
126 126
127 127 prepareGeometryChange();
128 128 m_boundingRect = QRectF(0, 0, x + textRect.width() + m_margin, y);
129 129 }
130 130
131 131 QRectF LegendMarkerItem::boundingRect() const
132 132 {
133 133 return m_boundingRect;
134 134 }
135 135
136 136 void LegendMarkerItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
137 137 {
138 138 Q_UNUSED(option)
139 139 Q_UNUSED(widget)
140 140 Q_UNUSED(painter)
141 141 }
142 142
143 143 QSizeF LegendMarkerItem::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const
144 144 {
145 145 Q_UNUSED(constraint)
146 146
147 147 QSizeF sh;
148 148
149 149 switch (which) {
150 150 case Qt::MinimumSize: {
151 151 QRectF labelRect = ChartPresenter::textBoundingRect(m_textItem->font(), "...");
152 152 sh = QSizeF(labelRect.width() + (2.0 * m_margin) + m_space + m_markerRect.width(),
153 153 qMax(m_markerRect.height(), labelRect.height()) + (2.0 * m_margin));
154 154 break;
155 155 }
156 156 case Qt::PreferredSize: {
157 157 QRectF labelRect = ChartPresenter::textBoundingRect(m_textItem->font(), m_label);
158 158 sh = QSizeF(labelRect.width() + (2.0 * m_margin) + m_space + m_markerRect.width(),
159 159 qMax(m_markerRect.height(), labelRect.height()) + (2.0 * m_margin));
160 160 break;
161 161 }
162 162 default:
163 163 break;
164 164 }
165 165
166 166 return sh;
167 167 }
168 168
169 169 void LegendMarkerItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
170 170 {
171 171 Q_UNUSED(event)
172 172 m_hovering = true;
173 173 emit m_marker->q_ptr->hovered(true);
174 174 }
175 175
176 176 void LegendMarkerItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
177 177 {
178 178 Q_UNUSED(event)
179 179 m_hovering = false;
180 180 emit m_marker->q_ptr->hovered(false);
181 181 }
182 182
183 183
184 184 #include "moc_legendmarkeritem_p.cpp"
185 185
186 186 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now