chartaxis_p.h
165 lines
| 4.4 KiB
| text/x-c
|
CLexer
|
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$ | ||||
** | ||||
****************************************************************************/ | ||||
|
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. | ||||
|
r1241 | #ifndef CHARTAXIS_H | ||
#define CHARTAXIS_H | ||||
|
r67 | |||
|
r855 | #include "qchartglobal.h" | ||
|
r677 | #include "chart_p.h" | ||
|
r1241 | #include "axisanimation_p.h" | ||
|
r67 | #include <QGraphicsItem> | ||
|
r1534 | #include <QFont> | ||
|
r67 | |||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
|
r1541 | class QAbstractAxis; | ||
|
r530 | class ChartPresenter; | ||
|
r140 | |||
|
r1006 | class ChartAxis : public Chart | ||
|
r67 | { | ||
|
r140 | Q_OBJECT | ||
|
r67 | public: | ||
|
r1241 | enum AxisType{ X_AXIS,Y_AXIS }; | ||
|
r67 | |||
|
r1541 | ChartAxis(QAbstractAxis *axis, ChartPresenter *presenter); | ||
|
r1006 | ~ChartAxis(); | ||
|
r67 | |||
|
r1241 | virtual AxisType axisType() const = 0; | ||
|
r140 | |||
|
r184 | void setAxisOpacity(qreal opacity); | ||
qreal axisOpacity() const; | ||||
|
r176 | void setGridOpacity(qreal opacity); | ||
qreal gridOpacity() const; | ||||
|
r140 | |||
|
r176 | void setLabelsOpacity(qreal opacity); | ||
qreal labelsOpacity() const; | ||||
|
r140 | |||
|
r176 | void setShadesOpacity(qreal opacity); | ||
qreal shadesOpacity() const; | ||||
|
r67 | |||
|
r176 | void setLabelsAngle(int angle); | ||
int labelsAngle()const { return m_labelsAngle; } | ||||
|
r745 | void setShadesBrush(const QBrush &brush); | ||
void setShadesPen(const QPen &pen); | ||||
|
r140 | |||
|
r745 | void setAxisPen(const QPen &pen); | ||
void setGridPen(const QPen &pen); | ||||
|
r176 | |||
|
r745 | void setLabelsPen(const QPen &pen); | ||
void setLabelsBrush(const QBrush &brush); | ||||
void setLabelsFont(const QFont &font); | ||||
|
r176 | |||
|
r1241 | void setLayout(QVector<qreal> &layout); | ||
QVector<qreal> layout() const { return m_layoutVector; } | ||||
void setAnimation(AxisAnimation* animation); | ||||
ChartAnimation* animation() const { return m_animation; }; | ||||
QRectF geometry() const { return m_rect; } | ||||
|
r1534 | qreal minimumWidth(); | ||
qreal minimumHeight(); | ||||
|
r1241 | protected: | ||
virtual void updateGeometry() = 0; | ||||
virtual QVector<qreal> calculateLayout() const = 0; | ||||
|
r1577 | void createNumberLabels(QStringList &labels,qreal min, qreal max,int ticks) const; | ||
void createCategoryLabels(QStringList &labels,qreal min, qreal max,const QStringList &categories) const; | ||||
|
r504 | |||
|
r775 | public Q_SLOTS: | ||
|
r1643 | virtual void handleAxisUpdated(); | ||
|
r502 | void handleAxisCategoriesUpdated(); | ||
|
r531 | void handleRangeChanged(qreal min , qreal max,int tickCount); | ||
|
r745 | void handleGeometryChanged(const QRectF &size); | ||
|
r439 | |||
|
r85 | private: | ||
|
r452 | inline bool isEmpty(); | ||
|
r223 | void createItems(int count); | ||
|
r502 | void deleteItems(int count); | ||
|
r745 | void updateLayout(QVector<qreal> &layout); | ||
|
r677 | void axisSelected(); | ||
|
r497 | |||
|
r1241 | protected: | ||
|
r1541 | QAbstractAxis* m_chartAxis; | ||
|
r140 | QRectF m_rect; | ||
|
r176 | int m_labelsAngle; | ||
|
r788 | QScopedPointer<QGraphicsItemGroup> m_grid; | ||
QScopedPointer<QGraphicsItemGroup> m_shades; | ||||
QScopedPointer<QGraphicsItemGroup> m_labels; | ||||
QScopedPointer<QGraphicsItemGroup> m_axis; | ||||
|
r291 | QVector<qreal> m_layoutVector; | ||
|
r452 | qreal m_min; | ||
qreal m_max; | ||||
|
r502 | int m_ticksCount; | ||
|
r1241 | AxisAnimation *m_animation; | ||
|
r1534 | qreal m_minWidth; | ||
qreal m_minHeight; | ||||
QFont m_font; | ||||
|
r140 | |||
|
r530 | friend class AxisAnimation; | ||
|
r677 | friend class AxisItem; | ||
}; | ||||
class AxisItem: public QGraphicsLineItem | ||||
{ | ||||
|
r967 | public: | ||
|
r1006 | explicit AxisItem(ChartAxis *axis, QGraphicsItem *parent = 0) : QGraphicsLineItem(parent), m_axis(axis) {} | ||
|
r677 | |||
protected: | ||||
void mousePressEvent(QGraphicsSceneMouseEvent *event) | ||||
{ | ||||
Q_UNUSED(event) | ||||
m_axis->axisSelected(); | ||||
} | ||||
QRectF boundingRect() const | ||||
{ | ||||
|
r679 | return shape().boundingRect(); | ||
|
r677 | } | ||
QPainterPath shape() const | ||||
{ | ||||
|
r679 | QPainterPath path = QGraphicsLineItem::shape(); | ||
QRectF rect = path.boundingRect(); | ||||
|
r1006 | path.addRect(rect.adjusted(0,0,m_axis->axisType()!=ChartAxis::X_AXIS?8:0,m_axis->axisType()!=ChartAxis::Y_AXIS?8:0)); | ||
|
r677 | return path; | ||
} | ||||
|
r679 | |||
|
r677 | private: | ||
|
r1006 | ChartAxis* m_axis; | ||
|
r530 | |||
|
r67 | }; | ||
QTCOMMERCIALCHART_END_NAMESPACE | ||||
#endif /* AXISITEM_H_ */ | ||||