chartaxis_p.h
195 lines
| 5.8 KiB
| text/x-c
|
CLexer
Jani Honkonen
|
r794 | /**************************************************************************** | ||
** | ||||
** Copyright (C) 2012 Digia Plc | ||||
** All rights reserved. | ||||
** For any questions to Digia, please use contact form at http://qt.digia.com | ||||
** | ||||
** This file is part of the Qt Commercial Charts Add-on. | ||||
** | ||||
** $QT_BEGIN_LICENSE$ | ||||
** Licensees holding valid Qt Commercial licenses may use this file in | ||||
** accordance with the Qt Commercial License Agreement provided with the | ||||
** Software or, alternatively, in accordance with the terms contained in | ||||
** a written agreement between you and Digia. | ||||
** | ||||
** If you have questions regarding the use of this file, please use | ||||
** contact form at http://qt.digia.com | ||||
** $QT_END_LICENSE$ | ||||
** | ||||
****************************************************************************/ | ||||
unknown
|
r1366 | // W A R N I N G | ||
// ------------- | ||||
// | ||||
// This file is not part of the QtCommercial Chart API. It exists purely as an | ||||
// implementation detail. This header file may change from version to | ||||
// version without notice, or even be removed. | ||||
// | ||||
// We mean it. | ||||
Michal Klocek
|
r1241 | #ifndef CHARTAXIS_H | ||
#define CHARTAXIS_H | ||||
Michal Klocek
|
r67 | |||
Michal Klocek
|
r855 | #include "qchartglobal.h" | ||
Michal Klocek
|
r1736 | #include "chartelement_p.h" | ||
Michal Klocek
|
r1241 | #include "axisanimation_p.h" | ||
Michal Klocek
|
r67 | #include <QGraphicsItem> | ||
Michal Klocek
|
r1965 | #include <QGraphicsLayoutItem> | ||
Michal Klocek
|
r1534 | #include <QFont> | ||
Michal Klocek
|
r67 | |||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
Michal Klocek
|
r1541 | class QAbstractAxis; | ||
Michal Klocek
|
r530 | class ChartPresenter; | ||
Michal Klocek
|
r140 | |||
Michal Klocek
|
r1965 | class ChartAxis : public ChartElement, public QGraphicsLayoutItem | ||
Michal Klocek
|
r67 | { | ||
Michal Klocek
|
r140 | Q_OBJECT | ||
Michal Klocek
|
r1965 | Q_INTERFACES(QGraphicsLayoutItem) | ||
Michal Klocek
|
r67 | public: | ||
Michal Klocek
|
r2118 | ChartAxis(QAbstractAxis *axis, ChartPresenter *presenter, bool intervalAxis = false); | ||
Michal Klocek
|
r1006 | ~ChartAxis(); | ||
Michal Klocek
|
r67 | |||
Michal Klocek
|
r1729 | void setArrowOpacity(qreal opacity); | ||
qreal arrowOpacity() const; | ||||
void setArrowVisibility(bool visible); | ||||
Michal Klocek
|
r184 | |||
Michal Klocek
|
r176 | void setGridOpacity(qreal opacity); | ||
qreal gridOpacity() const; | ||||
Michal Klocek
|
r1729 | void setGridVisibility(bool visible); | ||
Michal Klocek
|
r140 | |||
Michal Klocek
|
r176 | void setLabelsOpacity(qreal opacity); | ||
qreal labelsOpacity() const; | ||||
Michal Klocek
|
r1729 | void setLabelsVisibility(bool visible); | ||
Michal Klocek
|
r140 | |||
Michal Klocek
|
r176 | void setShadesOpacity(qreal opacity); | ||
qreal shadesOpacity() const; | ||||
Michal Klocek
|
r1729 | void setShadesVisibility(bool visible); | ||
Michal Klocek
|
r67 | |||
Michal Klocek
|
r176 | void setLabelsAngle(int angle); | ||
int labelsAngle()const { return m_labelsAngle; } | ||||
sauimone
|
r745 | void setShadesBrush(const QBrush &brush); | ||
void setShadesPen(const QPen &pen); | ||||
Michal Klocek
|
r140 | |||
Michal Klocek
|
r1729 | void setArrowPen(const QPen &pen); | ||
sauimone
|
r745 | void setGridPen(const QPen &pen); | ||
Michal Klocek
|
r176 | |||
sauimone
|
r745 | void setLabelsPen(const QPen &pen); | ||
void setLabelsBrush(const QBrush &brush); | ||||
void setLabelsFont(const QFont &font); | ||||
Michal Klocek
|
r2105 | void setLabelPadding(int padding); | ||
int labelPadding() const { return m_labelPadding;}; | ||||
Michal Klocek
|
r176 | |||
Michal Klocek
|
r1965 | void setTitlePen(const QPen &pen); | ||
void setTitleBrush(const QBrush &brush); | ||||
void setTitleFont(const QFont &font); | ||||
Jani Honkonen
|
r2104 | void setTitleText(const QString &title); | ||
Michal Klocek
|
r1965 | |||
Michal Klocek
|
r1241 | void setLayout(QVector<qreal> &layout); | ||
QVector<qreal> layout() const { return m_layoutVector; } | ||||
Jani Honkonen
|
r2104 | void setAnimation(AxisAnimation *animation); | ||
ChartAnimation *animation() const { return m_animation; }; | ||||
Michal Klocek
|
r1241 | |||
Michal Klocek
|
r1965 | Qt::Orientation orientation() const; | ||
Michal Klocek
|
r2105 | Qt::Alignment alignment() const; | ||
Michal Klocek
|
r1534 | |||
Michal Klocek
|
r1965 | bool isVisible(); | ||
Michal Klocek
|
r1729 | void hide(); | ||
Michal Klocek
|
r2105 | void setGeometry(const QRectF &axis, const QRectF &grid); | ||
QRectF axisGeometry() const { return m_axisRect; } | ||||
QRectF gridGeometry() const { return m_gridRect; } | ||||
Marek Rosa
|
r2093 | |||
Jani Honkonen
|
r2131 | void setLabels(const QStringList &labels); | ||
Michal Klocek
|
r2111 | QStringList labels() const { return m_labelsList; } | ||
Michal Klocek
|
r2118 | //this flag indicates that axis is used to show intervals it means labels are in between ticks | ||
bool intervalAxis() const { return m_intervalAxis; } | ||||
Michal Klocek
|
r2111 | |||
Jani Honkonen
|
r2104 | virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; | ||
Michal Klocek
|
r1965 | |||
Michal Klocek
|
r1241 | protected: | ||
Jani Honkonen
|
r2131 | void setGeometry(const QRectF &size) { Q_UNUSED(size);}; | ||
Michal Klocek
|
r1241 | virtual void updateGeometry() = 0; | ||
virtual QVector<qreal> calculateLayout() const = 0; | ||||
Michal Klocek
|
r1965 | |||
Michal Klocek
|
r2111 | QList<QGraphicsItem *> lineItems() { return m_grid->childItems(); }; | ||
QList<QGraphicsItem *> labelItems() { return m_labels->childItems();}; | ||||
QList<QGraphicsItem *> shadeItems() { return m_shades->childItems();}; | ||||
QList<QGraphicsItem *> arrowItems() { return m_arrow->childItems();}; | ||||
QFont font() const { return m_font; } | ||||
qreal min() const {return m_min; } | ||||
qreal max() const {return m_max; } | ||||
QStringList createValueLabels(int ticks) const; | ||||
Jani Honkonen
|
r2131 | QStringList createDateTimeLabels(const QString &format, int ticks) const; | ||
Michal Klocek
|
r504 | |||
sauimone
|
r775 | public Q_SLOTS: | ||
Michal Klocek
|
r1643 | virtual void handleAxisUpdated(); | ||
Michal Klocek
|
r1698 | virtual void handleDomainUpdated(); | ||
Michal Klocek
|
r1965 | |||
Michal Klocek
|
r85 | private: | ||
Michal Klocek
|
r452 | inline bool isEmpty(); | ||
Michal Klocek
|
r223 | void createItems(int count); | ||
Michal Klocek
|
r502 | void deleteItems(int count); | ||
sauimone
|
r745 | void updateLayout(QVector<qreal> &layout); | ||
Michal Klocek
|
r677 | void axisSelected(); | ||
Michal Klocek
|
r497 | |||
Michal Klocek
|
r2111 | private: | ||
Jani Honkonen
|
r2104 | QAbstractAxis *m_chartAxis; | ||
Michal Klocek
|
r176 | int m_labelsAngle; | ||
Michal Klocek
|
r2105 | QRectF m_axisRect; | ||
QRectF m_gridRect; | ||||
Michal Klocek
|
r788 | QScopedPointer<QGraphicsItemGroup> m_grid; | ||
QScopedPointer<QGraphicsItemGroup> m_shades; | ||||
QScopedPointer<QGraphicsItemGroup> m_labels; | ||||
Michal Klocek
|
r1729 | QScopedPointer<QGraphicsItemGroup> m_arrow; | ||
Jani Honkonen
|
r2104 | QGraphicsSimpleTextItem *m_title; | ||
Michal Klocek
|
r291 | QVector<qreal> m_layoutVector; | ||
Michal Klocek
|
r452 | qreal m_min; | ||
qreal m_max; | ||||
Michal Klocek
|
r1241 | AxisAnimation *m_animation; | ||
Michal Klocek
|
r1534 | QFont m_font; | ||
Michal Klocek
|
r1965 | QString m_titleText; | ||
Michal Klocek
|
r2105 | int m_labelPadding; | ||
Michal Klocek
|
r2111 | QStringList m_labelsList; | ||
Michal Klocek
|
r2118 | bool m_intervalAxis; | ||
Michal Klocek
|
r140 | |||
Jani Honkonen
|
r2131 | friend class AxisAnimation; | ||
friend class AxisItem; | ||||
Michal Klocek
|
r677 | |||
}; | ||||
class AxisItem: public QGraphicsLineItem | ||||
{ | ||||
Michal Klocek
|
r967 | public: | ||
Michal Klocek
|
r1006 | explicit AxisItem(ChartAxis *axis, QGraphicsItem *parent = 0) : QGraphicsLineItem(parent), m_axis(axis) {} | ||
Michal Klocek
|
r677 | |||
protected: | ||||
Jani Honkonen
|
r2097 | void mousePressEvent(QGraphicsSceneMouseEvent *event) { | ||
Q_UNUSED(event) | ||||
m_axis->axisSelected(); | ||||
} | ||||
QRectF boundingRect() const { | ||||
return shape().boundingRect(); | ||||
} | ||||
QPainterPath shape() const { | ||||
QPainterPath path = QGraphicsLineItem::shape(); | ||||
QRectF rect = path.boundingRect(); | ||||
Michal Klocek
|
r2111 | path.addRect(rect.adjusted(0, 0, m_axis->orientation() != Qt::Horizontal ? 8 : 0, m_axis->orientation() != Qt::Vertical ? 8 : 0)); | ||
Jani Honkonen
|
r2097 | return path; | ||
} | ||||
Michal Klocek
|
r679 | |||
Michal Klocek
|
r677 | private: | ||
Jani Honkonen
|
r2104 | ChartAxis *m_axis; | ||
Michal Klocek
|
r67 | }; | ||
QTCOMMERCIALCHART_END_NAMESPACE | ||||
Jani Honkonen
|
r1935 | #endif /* CHARTAXI_H */ | ||