axisitem_p.h
124 lines
| 2.8 KiB
| text/x-c
|
CLexer
Michal Klocek
|
r67 | #ifndef AXISITEM_H_ | ||
#define AXISITEM_H_ | ||||
Michal Klocek
|
r140 | #include "domain_p.h" | ||
Michal Klocek
|
r677 | #include "chart_p.h" | ||
Michal Klocek
|
r67 | #include <QGraphicsItem> | ||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
Michal Klocek
|
r140 | class QChartAxis; | ||
Michal Klocek
|
r530 | class ChartPresenter; | ||
Michal Klocek
|
r140 | |||
Michal Klocek
|
r677 | class Axis : public Chart | ||
Michal Klocek
|
r67 | { | ||
Michal Klocek
|
r140 | Q_OBJECT | ||
Michal Klocek
|
r67 | public: | ||
enum AxisType{X_AXIS,Y_AXIS}; | ||||
Michal Klocek
|
r677 | Axis(QChartAxis* axis,ChartPresenter* presenter,AxisType type = X_AXIS); | ||
~Axis(); | ||||
Michal Klocek
|
r67 | |||
Michal Klocek
|
r176 | AxisType axisType() const {return m_type;}; | ||
Michal Klocek
|
r140 | |||
Michal Klocek
|
r184 | void setAxisOpacity(qreal opacity); | ||
qreal axisOpacity() const; | ||||
Michal Klocek
|
r176 | void setGridOpacity(qreal opacity); | ||
qreal gridOpacity() const; | ||||
Michal Klocek
|
r140 | |||
Michal Klocek
|
r176 | void setLabelsOpacity(qreal opacity); | ||
qreal labelsOpacity() const; | ||||
Michal Klocek
|
r140 | |||
Michal Klocek
|
r176 | void setShadesOpacity(qreal opacity); | ||
qreal shadesOpacity() const; | ||||
Michal Klocek
|
r67 | |||
Michal Klocek
|
r176 | void setLabelsAngle(int angle); | ||
int labelsAngle()const { return m_labelsAngle; } | ||||
void setShadesBrush(const QBrush& brush); | ||||
void setShadesPen(const QPen& pen); | ||||
Michal Klocek
|
r140 | |||
Michal Klocek
|
r184 | void setAxisPen(const QPen& pen); | ||
Michal Klocek
|
r176 | void setGridPen(const QPen& pen); | ||
void setLabelsPen(const QPen& pen); | ||||
void setLabelsBrush(const QBrush& brush); | ||||
void setLabelsFont(const QFont& font); | ||||
Michal Klocek
|
r513 | inline QRectF geometry() const { return m_rect; } | ||
Michal Klocek
|
r530 | inline QVector<qreal> layout() { return m_layoutVector;}; | ||
Michal Klocek
|
r504 | |||
Michal Klocek
|
r176 | public slots: | ||
Michal Klocek
|
r502 | void handleAxisUpdated(); | ||
void handleAxisCategoriesUpdated(); | ||||
Michal Klocek
|
r531 | void handleRangeChanged(qreal min , qreal max,int tickCount); | ||
Michal Klocek
|
r502 | void handleGeometryChanged(const QRectF& size); | ||
Michal Klocek
|
r439 | |||
Michal Klocek
|
r393 | |||
Michal Klocek
|
r85 | private: | ||
Michal Klocek
|
r452 | inline bool isEmpty(); | ||
Michal Klocek
|
r223 | void createItems(int count); | ||
Michal Klocek
|
r502 | void deleteItems(int count); | ||
Michal Klocek
|
r530 | |||
Michal Klocek
|
r502 | QVector<qreal> calculateLayout() const; | ||
Michal Klocek
|
r530 | void updateLayout(QVector<qreal>& layout); | ||
void setLayout(QVector<qreal>& layout); | ||||
Michal Klocek
|
r502 | QStringList createLabels(int ticks, qreal min, qreal max) const; | ||
Michal Klocek
|
r677 | void axisSelected(); | ||
Michal Klocek
|
r497 | |||
Michal Klocek
|
r67 | private: | ||
Michal Klocek
|
r439 | QChartAxis* m_chartAxis; | ||
Michal Klocek
|
r140 | AxisType m_type; | ||
QRectF m_rect; | ||||
Michal Klocek
|
r176 | int m_labelsAngle; | ||
QGraphicsItemGroup m_grid; | ||||
QGraphicsItemGroup m_shades; | ||||
QGraphicsItemGroup m_labels; | ||||
Michal Klocek
|
r272 | QGraphicsItemGroup m_axis; | ||
Michal Klocek
|
r291 | QVector<qreal> m_layoutVector; | ||
Michal Klocek
|
r452 | qreal m_min; | ||
qreal m_max; | ||||
Michal Klocek
|
r502 | int m_ticksCount; | ||
Michal Klocek
|
r513 | qreal m_zoomFactor; | ||
Michal Klocek
|
r140 | |||
Michal Klocek
|
r530 | friend class AxisAnimation; | ||
Michal Klocek
|
r677 | friend class AxisItem; | ||
}; | ||||
class AxisItem: public QGraphicsLineItem | ||||
{ | ||||
public: | ||||
AxisItem(Axis* axis,QGraphicsItem* parent=0):QGraphicsLineItem(parent),m_axis(axis){}; | ||||
protected: | ||||
void mousePressEvent(QGraphicsSceneMouseEvent *event) | ||||
{ | ||||
Q_UNUSED(event) | ||||
m_axis->axisSelected(); | ||||
} | ||||
QRectF boundingRect() const | ||||
{ | ||||
Michal Klocek
|
r679 | return shape().boundingRect(); | ||
Michal Klocek
|
r677 | } | ||
QPainterPath shape() const | ||||
{ | ||||
Michal Klocek
|
r679 | QPainterPath path = QGraphicsLineItem::shape(); | ||
QRectF rect = path.boundingRect(); | ||||
path.addRect(rect.adjusted(0,0,m_axis->axisType()!=Axis::X_AXIS?8:0,m_axis->axisType()!=Axis::Y_AXIS?8:0)); | ||||
Michal Klocek
|
r677 | return path; | ||
} | ||||
Michal Klocek
|
r679 | |||
Michal Klocek
|
r677 | private: | ||
Axis* m_axis; | ||||
Michal Klocek
|
r530 | |||
Michal Klocek
|
r67 | }; | ||
QTCOMMERCIALCHART_END_NAMESPACE | ||||
#endif /* AXISITEM_H_ */ | ||||