qlegend.h
171 lines
| 4.1 KiB
| text/x-c
|
CLexer
/ src / qlegend.h
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$ | ||||
** | ||||
****************************************************************************/ | ||||
sauimone
|
r524 | #ifndef QLEGEND_H | ||
#define QLEGEND_H | ||||
Michal Klocek
|
r790 | #include <QChartGlobal> | ||
#include <QGraphicsWidget> | ||||
sauimone
|
r762 | #include <QPen> | ||
#include <QBrush> | ||||
Michal Klocek
|
r860 | #include "private/scroller_p.h" //TODO fixme | ||
sauimone
|
r524 | |||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
class Domain; | ||||
sauimone
|
r529 | class LegendMarker; | ||
sauimone
|
r565 | class QPieSlice; | ||
class QXYSeries; | ||||
class QBarSet; | ||||
class QBarSeries; | ||||
class QPieSeries; | ||||
sauimone
|
r792 | class QAreaSeries; | ||
sauimone
|
r716 | class LegendScrollButton; | ||
sauimone
|
r762 | class QSeries; | ||
Michal Klocek
|
r790 | class QChart; | ||
sauimone
|
r524 | |||
Michal Klocek
|
r790 | class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget | ||
sauimone
|
r524 | { | ||
Q_OBJECT | ||||
public: | ||||
sauimone
|
r766 | // We only support these alignments (for now) | ||
sauimone
|
r799 | enum Alignment { | ||
AlignmentTop = Qt::AlignTop, | ||||
AlignmentBottom = Qt::AlignBottom, | ||||
AlignmentLeft = Qt::AlignLeft, | ||||
AlignmentRight = Qt::AlignRight | ||||
sauimone
|
r616 | }; | ||
sauimone
|
r803 | |||
Q_DECLARE_FLAGS(Alignments, Alignment) | ||||
Michal Klocek
|
r790 | private: | ||
explicit QLegend(QChart *chart); | ||||
sauimone
|
r616 | |||
Michal Klocek
|
r790 | public: | ||
sauimone
|
r524 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); | ||
QRectF boundingRect() const; | ||||
Tero Ahola
|
r737 | void setBrush(const QBrush &brush); | ||
Michal Klocek
|
r645 | QBrush brush() const; | ||
Tero Ahola
|
r737 | void setPen(const QPen &pen); | ||
Michal Klocek
|
r645 | QPen pen() const; | ||
sauimone
|
r540 | |||
sauimone
|
r803 | void setAlignmnent(QLegend::Alignments alignment); | ||
QLegend::Alignments alignment() const; | ||||
sauimone
|
r616 | |||
Michal Klocek
|
r790 | |||
sauimone
|
r799 | void detachFromChart(); | ||
void attachToChart(); | ||||
Michal Klocek
|
r855 | bool isAttachedToChart(); | ||
qreal minWidht() const { return m_minWidth;} | ||||
qreal minHeight() const { return m_minHeight;} | ||||
sauimone
|
r799 | |||
Michal Klocek
|
r855 | void setBackgroundVisible(bool visible); | ||
bool isBackgroundVisible() const; | ||||
void setOffset(const QPointF& point); | ||||
QPointF offset() const; | ||||
protected: | ||||
void resizeEvent(QGraphicsSceneResizeEvent *event); | ||||
void hideEvent(QHideEvent *event); | ||||
void showEvent(QShowEvent *event); | ||||
sauimone
|
r547 | |||
sauimone
|
r775 | public Q_SLOTS: | ||
sauimone
|
r724 | // PIMPL ---> | ||
Tero Ahola
|
r737 | void handleSeriesAdded(QSeries *series, Domain *domain); | ||
void handleSeriesRemoved(QSeries *series); | ||||
void handleAdded(QList<QPieSlice *> slices); | ||||
void handleRemoved(QList<QPieSlice *> slices); | ||||
sauimone
|
r724 | // PIMPL <--- | ||
sauimone
|
r524 | |||
private: | ||||
sauimone
|
r565 | // PIMPL ---> | ||
sauimone
|
r792 | void appendMarkers(QAreaSeries *series); | ||
void appendMarkers(QXYSeries *series); | ||||
Tero Ahola
|
r737 | void appendMarkers(QBarSeries *series); | ||
void appendMarkers(QPieSeries *series); | ||||
void deleteMarkers(QSeries *series); | ||||
sauimone
|
r724 | void updateLayout(); | ||
sauimone
|
r565 | |||
Michal Klocek
|
r855 | private: | ||
sauimone
|
r783 | qreal m_margin; | ||
sauimone
|
r626 | |||
Michal Klocek
|
r855 | QRectF m_rect; | ||
qreal m_offsetX; | ||||
qreal m_offsetY; | ||||
//QList<LegendMarker *> m_markers; | ||||
sauimone
|
r540 | |||
Michal Klocek
|
r645 | QBrush m_brush; | ||
QPen m_pen; | ||||
sauimone
|
r803 | QLegend::Alignments m_alignment; | ||
Michal Klocek
|
r855 | QGraphicsItemGroup* m_markers; | ||
sauimone
|
r716 | |||
sauimone
|
r799 | bool m_attachedToChart; | ||
sauimone
|
r803 | QChart *m_chart; | ||
Michal Klocek
|
r855 | qreal m_minWidth; | ||
qreal m_minHeight; | ||||
qreal m_width; | ||||
qreal m_height; | ||||
bool m_visible; | ||||
Michal Klocek
|
r859 | friend class ScrolledQLegend; | ||
sauimone
|
r716 | // <--- PIMPL | ||
sauimone
|
r524 | }; | ||
Michal Klocek
|
r859 | class ScrolledQLegend: public QLegend, public Scroller | ||
{ | ||||
public: | ||||
ScrolledQLegend(QChart *chart):QLegend(chart) | ||||
{ | ||||
} | ||||
void setOffset(const QPointF& point) | ||||
{ | ||||
QLegend::setOffset(point); | ||||
} | ||||
QPointF offset() const | ||||
{ | ||||
return QLegend::offset(); | ||||
} | ||||
void mousePressEvent(QGraphicsSceneMouseEvent* event){ | ||||
Scroller::mousePressEvent(event); | ||||
//QLegend::mousePressEvent(event); | ||||
} | ||||
void mouseMoveEvent(QGraphicsSceneMouseEvent* event){ | ||||
Scroller::mouseMoveEvent(event); | ||||
//QLegend::mouseMoveEvent(event); | ||||
} | ||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent* event){ | ||||
Scroller::mouseReleaseEvent(event); | ||||
//QLegend::mouseReleaseEvent(event); | ||||
} | ||||
}; | ||||
sauimone
|
r524 | QTCOMMERCIALCHART_END_NAMESPACE | ||
#endif // QLEGEND_H | ||||