##// END OF EJS Templates
Added copyright headers to *.h/*.cpp files missing them...
Miikka Heikkinen -
r2435:984cff4693b3
parent child
Show More
@@ -1,11 +1,31
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
1 #include <QApplication>
21 #include <QApplication>
2 #include "widget.h"
22 #include "widget.h"
3
23
4 int main(int argc, char *argv[])
24 int main(int argc, char *argv[])
5 {
25 {
6 QApplication a(argc, argv);
26 QApplication a(argc, argv);
7 Widget w;
27 Widget w;
8 w.show();
28 w.show();
9
29
10 return a.exec();
30 return a.exec();
11 }
31 }
@@ -1,62 +1,82
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
1 #include "widget.h"
21 #include "widget.h"
2 #include <QAudioDeviceInfo>
22 #include <QAudioDeviceInfo>
3 #include <QAudioInput>
23 #include <QAudioInput>
4 #include <QChartView>
24 #include <QChartView>
5 #include <QLineSeries>
25 #include <QLineSeries>
6 #include <QChart>
26 #include <QChart>
7 #include <QVBoxLayout>
27 #include <QVBoxLayout>
8 #include <QValueAxis>
28 #include <QValueAxis>
9 #include "xyseriesiodevice.h"
29 #include "xyseriesiodevice.h"
10
30
11 QTCOMMERCIALCHART_USE_NAMESPACE
31 QTCOMMERCIALCHART_USE_NAMESPACE
12
32
13 Widget::Widget(QWidget *parent)
33 Widget::Widget(QWidget *parent)
14 : QWidget(parent),
34 : QWidget(parent),
15 m_device(0),
35 m_device(0),
16 m_chart(0),
36 m_chart(0),
17 m_series(0),
37 m_series(0),
18 m_audioInput(0)
38 m_audioInput(0)
19 {
39 {
20 m_chart = new QChart;
40 m_chart = new QChart;
21 QChartView *chartView = new QChartView(m_chart);
41 QChartView *chartView = new QChartView(m_chart);
22 chartView->setMinimumSize(800, 600);
42 chartView->setMinimumSize(800, 600);
23 m_series = new QLineSeries;
43 m_series = new QLineSeries;
24 m_chart->addSeries(m_series);
44 m_chart->addSeries(m_series);
25 QValueAxis *axisX = new QValueAxis;
45 QValueAxis *axisX = new QValueAxis;
26 axisX->setRange(0, 2000);
46 axisX->setRange(0, 2000);
27 axisX->setLabelFormat("%g");
47 axisX->setLabelFormat("%g");
28 axisX->setTitleText("Samples");
48 axisX->setTitleText("Samples");
29 QValueAxis *axisY = new QValueAxis;
49 QValueAxis *axisY = new QValueAxis;
30 axisY->setRange(-1, 1);
50 axisY->setRange(-1, 1);
31 axisY->setTitleText("Audio level");
51 axisY->setTitleText("Audio level");
32 m_chart->setAxisX(axisX, m_series);
52 m_chart->setAxisX(axisX, m_series);
33 m_chart->setAxisY(axisY, m_series);
53 m_chart->setAxisY(axisY, m_series);
34 m_chart->legend()->hide();
54 m_chart->legend()->hide();
35 m_chart->setTitle("Data from the microphone");
55 m_chart->setTitle("Data from the microphone");
36
56
37 QVBoxLayout *mainLayout = new QVBoxLayout;
57 QVBoxLayout *mainLayout = new QVBoxLayout;
38 mainLayout->addWidget(chartView);
58 mainLayout->addWidget(chartView);
39 setLayout(mainLayout);
59 setLayout(mainLayout);
40
60
41 QAudioFormat formatAudio;
61 QAudioFormat formatAudio;
42 formatAudio.setSampleRate(8000);
62 formatAudio.setSampleRate(8000);
43 formatAudio.setChannelCount(1);
63 formatAudio.setChannelCount(1);
44 formatAudio.setSampleSize(8);
64 formatAudio.setSampleSize(8);
45 formatAudio.setCodec("audio/pcm");
65 formatAudio.setCodec("audio/pcm");
46 formatAudio.setByteOrder(QAudioFormat::LittleEndian);
66 formatAudio.setByteOrder(QAudioFormat::LittleEndian);
47 formatAudio.setSampleType(QAudioFormat::UnSignedInt);
67 formatAudio.setSampleType(QAudioFormat::UnSignedInt);
48
68
49 QAudioDeviceInfo inputDevices = QAudioDeviceInfo::defaultInputDevice();
69 QAudioDeviceInfo inputDevices = QAudioDeviceInfo::defaultInputDevice();
50 m_audioInput = new QAudioInput(inputDevices,formatAudio, this);
70 m_audioInput = new QAudioInput(inputDevices,formatAudio, this);
51
71
52 m_device = new XYSeriesIODevice(m_series, this);
72 m_device = new XYSeriesIODevice(m_series, this);
53 m_device->open(QIODevice::WriteOnly);
73 m_device->open(QIODevice::WriteOnly);
54
74
55 m_audioInput->start(m_device);
75 m_audioInput->start(m_device);
56 }
76 }
57
77
58 Widget::~Widget()
78 Widget::~Widget()
59 {
79 {
60 m_audioInput->stop();
80 m_audioInput->stop();
61 m_device->close();
81 m_device->close();
62 }
82 }
@@ -1,32 +1,52
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
1 #ifndef WIDGET_H
21 #ifndef WIDGET_H
2 #define WIDGET_H
22 #define WIDGET_H
3
23
4 #include <QWidget>
24 #include <QWidget>
5 #include <QChartGlobal>
25 #include <QChartGlobal>
6
26
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 class QLineSeries;
28 class QLineSeries;
9 class QChart;
29 class QChart;
10 QTCOMMERCIALCHART_END_NAMESPACE
30 QTCOMMERCIALCHART_END_NAMESPACE
11
31
12 QTCOMMERCIALCHART_USE_NAMESPACE
32 QTCOMMERCIALCHART_USE_NAMESPACE
13
33
14 class XYSeriesIODevice;
34 class XYSeriesIODevice;
15 class QAudioInput;
35 class QAudioInput;
16
36
17 class Widget : public QWidget
37 class Widget : public QWidget
18 {
38 {
19 Q_OBJECT
39 Q_OBJECT
20
40
21 public:
41 public:
22 Widget(QWidget *parent = 0);
42 Widget(QWidget *parent = 0);
23 ~Widget();
43 ~Widget();
24
44
25 private:
45 private:
26 XYSeriesIODevice *m_device;
46 XYSeriesIODevice *m_device;
27 QChart *m_chart;
47 QChart *m_chart;
28 QLineSeries *m_series;
48 QLineSeries *m_series;
29 QAudioInput *m_audioInput;
49 QAudioInput *m_audioInput;
30 };
50 };
31
51
32 #endif // WIDGET_H
52 #endif // WIDGET_H
@@ -1,37 +1,57
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
1 #include "xyseriesiodevice.h"
21 #include "xyseriesiodevice.h"
2 #include <QXYSeries>
22 #include <QXYSeries>
3
23
4 XYSeriesIODevice::XYSeriesIODevice(QXYSeries * series, QObject *parent) :
24 XYSeriesIODevice::XYSeriesIODevice(QXYSeries * series, QObject *parent) :
5 QIODevice(parent),
25 QIODevice(parent),
6 m_series(series)
26 m_series(series)
7 {
27 {
8 }
28 }
9
29
10 qint64 XYSeriesIODevice::readData(char * data, qint64 maxSize)
30 qint64 XYSeriesIODevice::readData(char * data, qint64 maxSize)
11 {
31 {
12 Q_UNUSED(data)
32 Q_UNUSED(data)
13 Q_UNUSED(maxSize)
33 Q_UNUSED(maxSize)
14 return -1;
34 return -1;
15 }
35 }
16
36
17 qint64 XYSeriesIODevice::writeData(const char * data, qint64 maxSize)
37 qint64 XYSeriesIODevice::writeData(const char * data, qint64 maxSize)
18 {
38 {
19 qint64 range = 2000;
39 qint64 range = 2000;
20 QList<QPointF> oldPoints = m_series->points();
40 QList<QPointF> oldPoints = m_series->points();
21 QList<QPointF> points;
41 QList<QPointF> points;
22 int resolution = 4;
42 int resolution = 4;
23
43
24 if (oldPoints.count() < range) {
44 if (oldPoints.count() < range) {
25 points = m_series->points();
45 points = m_series->points();
26 } else {
46 } else {
27 for (int i = maxSize/resolution; i < oldPoints.count(); i++)
47 for (int i = maxSize/resolution; i < oldPoints.count(); i++)
28 points.append(QPointF(i - maxSize/resolution, oldPoints.at(i).y()));
48 points.append(QPointF(i - maxSize/resolution, oldPoints.at(i).y()));
29 }
49 }
30
50
31 qint64 size = points.count();
51 qint64 size = points.count();
32 for (int k = 0; k < maxSize/resolution; k++)
52 for (int k = 0; k < maxSize/resolution; k++)
33 points.append(QPointF(k + size, ((quint8)data[resolution * k] - 128)/128.0));
53 points.append(QPointF(k + size, ((quint8)data[resolution * k] - 128)/128.0));
34
54
35 m_series->replace(points);
55 m_series->replace(points);
36 return maxSize;
56 return maxSize;
37 }
57 }
@@ -1,27 +1,47
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
1 #ifndef XYSERIESIODEVICE_H
21 #ifndef XYSERIESIODEVICE_H
2 #define XYSERIESIODEVICE_H
22 #define XYSERIESIODEVICE_H
3
23
4 #include <QIODevice>
24 #include <QIODevice>
5 #include <QChartGlobal>
25 #include <QChartGlobal>
6
26
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 class QXYSeries;
28 class QXYSeries;
9 QTCOMMERCIALCHART_END_NAMESPACE
29 QTCOMMERCIALCHART_END_NAMESPACE
10
30
11 QTCOMMERCIALCHART_USE_NAMESPACE
31 QTCOMMERCIALCHART_USE_NAMESPACE
12
32
13 class XYSeriesIODevice : public QIODevice
33 class XYSeriesIODevice : public QIODevice
14 {
34 {
15 Q_OBJECT
35 Q_OBJECT
16 public:
36 public:
17 explicit XYSeriesIODevice(QXYSeries * series, QObject *parent = 0);
37 explicit XYSeriesIODevice(QXYSeries * series, QObject *parent = 0);
18
38
19 protected:
39 protected:
20 qint64 readData(char * data, qint64 maxSize);
40 qint64 readData(char * data, qint64 maxSize);
21 qint64 writeData(const char * data, qint64 maxSize);
41 qint64 writeData(const char * data, qint64 maxSize);
22
42
23 private:
43 private:
24 QXYSeries *m_series;
44 QXYSeries *m_series;
25 };
45 };
26
46
27 #endif // XYSERIESIODEVICE_H
47 #endif // XYSERIESIODEVICE_H
@@ -1,99 +1,119
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
1 #include "callout.h"
21 #include "callout.h"
2 #include <QPainter>
22 #include <QPainter>
3 #include <QFontMetrics>
23 #include <QFontMetrics>
4 #include <QGraphicsSceneMouseEvent>
24 #include <QGraphicsSceneMouseEvent>
5 #include <QMouseEvent>
25 #include <QMouseEvent>
6
26
7 Callout::Callout(QGraphicsItem * parent):
27 Callout::Callout(QGraphicsItem * parent):
8 QGraphicsItem(parent)
28 QGraphicsItem(parent)
9 {
29 {
10 }
30 }
11
31
12 QRectF Callout::boundingRect() const
32 QRectF Callout::boundingRect() const
13 {
33 {
14 QPointF anchor = mapFromParent(m_anchor);
34 QPointF anchor = mapFromParent(m_anchor);
15 QRectF rect;
35 QRectF rect;
16 rect.setLeft(qMin(m_rect.left(), anchor.x()));
36 rect.setLeft(qMin(m_rect.left(), anchor.x()));
17 rect.setRight(qMax(m_rect.right(), anchor.x()));
37 rect.setRight(qMax(m_rect.right(), anchor.x()));
18 rect.setTop(qMin(m_rect.top(), anchor.y()));
38 rect.setTop(qMin(m_rect.top(), anchor.y()));
19 rect.setBottom(qMax(m_rect.bottom(), anchor.y()));
39 rect.setBottom(qMax(m_rect.bottom(), anchor.y()));
20 return rect;
40 return rect;
21 }
41 }
22
42
23 void Callout::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
43 void Callout::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
24 {
44 {
25 Q_UNUSED(option)
45 Q_UNUSED(option)
26 Q_UNUSED(widget)
46 Q_UNUSED(widget)
27 QPainterPath path;
47 QPainterPath path;
28 path.addRoundedRect(m_rect, 5, 5);
48 path.addRoundedRect(m_rect, 5, 5);
29
49
30 QPointF anchor = mapFromParent(m_anchor);
50 QPointF anchor = mapFromParent(m_anchor);
31 if (!m_rect.contains(anchor)) {
51 if (!m_rect.contains(anchor)) {
32 QPointF point1, point2;
52 QPointF point1, point2;
33
53
34 // establish the position of the anchor point in relation to m_rect
54 // establish the position of the anchor point in relation to m_rect
35 bool above = anchor.y() <= m_rect.top();
55 bool above = anchor.y() <= m_rect.top();
36 bool aboveCenter = anchor.y() > m_rect.top() && anchor.y() <= m_rect.center().y();
56 bool aboveCenter = anchor.y() > m_rect.top() && anchor.y() <= m_rect.center().y();
37 bool belowCenter = anchor.y() > m_rect.center().y() && anchor.y() <= m_rect.bottom();
57 bool belowCenter = anchor.y() > m_rect.center().y() && anchor.y() <= m_rect.bottom();
38 bool below = anchor.y() > m_rect.bottom();
58 bool below = anchor.y() > m_rect.bottom();
39
59
40 bool onLeft = anchor.x() <= m_rect.left();
60 bool onLeft = anchor.x() <= m_rect.left();
41 bool leftOfCenter = anchor.x() > m_rect.left() && anchor.x() <= m_rect.center().x();
61 bool leftOfCenter = anchor.x() > m_rect.left() && anchor.x() <= m_rect.center().x();
42 bool rightOfCenter = anchor.x() > m_rect.center().x() && anchor.x() <= m_rect.right();
62 bool rightOfCenter = anchor.x() > m_rect.center().x() && anchor.x() <= m_rect.right();
43 bool onRight = anchor.x() > m_rect.right();
63 bool onRight = anchor.x() > m_rect.right();
44
64
45 // get the nearest m_rect corner.
65 // get the nearest m_rect corner.
46 qreal x = (onRight + rightOfCenter) * m_rect.width();
66 qreal x = (onRight + rightOfCenter) * m_rect.width();
47 qreal y = (below + belowCenter) * m_rect.height();
67 qreal y = (below + belowCenter) * m_rect.height();
48 bool cornerCase = (above && onLeft) || (above && onRight) || (below && onLeft) || (below && onRight);
68 bool cornerCase = (above && onLeft) || (above && onRight) || (below && onLeft) || (below && onRight);
49 bool vertical = qAbs(anchor.x() - x) > qAbs(anchor.y() - y);
69 bool vertical = qAbs(anchor.x() - x) > qAbs(anchor.y() - y);
50
70
51 qreal x1 = x + leftOfCenter * 10 - rightOfCenter * 20 + cornerCase * !vertical * (onLeft * 10 - onRight * 20);
71 qreal x1 = x + leftOfCenter * 10 - rightOfCenter * 20 + cornerCase * !vertical * (onLeft * 10 - onRight * 20);
52 qreal y1 = y + aboveCenter * 10 - belowCenter * 20 + cornerCase * vertical * (above * 10 - below * 20);;
72 qreal y1 = y + aboveCenter * 10 - belowCenter * 20 + cornerCase * vertical * (above * 10 - below * 20);;
53 point1.setX(x1);
73 point1.setX(x1);
54 point1.setY(y1);
74 point1.setY(y1);
55
75
56 qreal x2 = x + leftOfCenter * 20 - rightOfCenter * 10 + cornerCase * !vertical * (onLeft * 20 - onRight * 10);;
76 qreal x2 = x + leftOfCenter * 20 - rightOfCenter * 10 + cornerCase * !vertical * (onLeft * 20 - onRight * 10);;
57 qreal y2 = y + aboveCenter * 20 - belowCenter * 10 + cornerCase * vertical * (above * 20 - below * 10);;
77 qreal y2 = y + aboveCenter * 20 - belowCenter * 10 + cornerCase * vertical * (above * 20 - below * 10);;
58 point2.setX(x2);
78 point2.setX(x2);
59 point2.setY(y2);
79 point2.setY(y2);
60
80
61 path.moveTo(point1);
81 path.moveTo(point1);
62 path.lineTo(mapFromParent(m_anchor));
82 path.lineTo(mapFromParent(m_anchor));
63 path.lineTo(point2);
83 path.lineTo(point2);
64 path = path.simplified();
84 path = path.simplified();
65 }
85 }
66 painter->setBrush(QColor(255, 255, 255));
86 painter->setBrush(QColor(255, 255, 255));
67 painter->drawPath(path);
87 painter->drawPath(path);
68 painter->drawText(m_textRect, m_text);
88 painter->drawText(m_textRect, m_text);
69 }
89 }
70
90
71 void Callout::mousePressEvent(QGraphicsSceneMouseEvent *event)
91 void Callout::mousePressEvent(QGraphicsSceneMouseEvent *event)
72 {
92 {
73 event->setAccepted(true);
93 event->setAccepted(true);
74 }
94 }
75
95
76 void Callout::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
96 void Callout::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
77 {
97 {
78 if (event->buttons() & Qt::LeftButton){
98 if (event->buttons() & Qt::LeftButton){
79 setPos(mapToParent(event->pos() - event->buttonDownPos(Qt::LeftButton)));
99 setPos(mapToParent(event->pos() - event->buttonDownPos(Qt::LeftButton)));
80 event->setAccepted(true);
100 event->setAccepted(true);
81 } else {
101 } else {
82 event->setAccepted(false);
102 event->setAccepted(false);
83 }
103 }
84 }
104 }
85
105
86 void Callout::setText(const QString &text)
106 void Callout::setText(const QString &text)
87 {
107 {
88 m_text = text;
108 m_text = text;
89 QFontMetrics metrics(m_font);
109 QFontMetrics metrics(m_font);
90 m_textRect = metrics.boundingRect(QRect(0, 0, 150, 150), Qt::AlignLeft, m_text);
110 m_textRect = metrics.boundingRect(QRect(0, 0, 150, 150), Qt::AlignLeft, m_text);
91 m_textRect.translate(5, 5);
111 m_textRect.translate(5, 5);
92 prepareGeometryChange();
112 prepareGeometryChange();
93 m_rect = m_textRect.adjusted(-5, -5, 5, 5);
113 m_rect = m_textRect.adjusted(-5, -5, 5, 5);
94 }
114 }
95
115
96 void Callout::setAnchor(QPointF point)
116 void Callout::setAnchor(QPointF point)
97 {
117 {
98 m_anchor = point;
118 m_anchor = point;
99 }
119 }
@@ -1,32 +1,52
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
1 #ifndef CALLOUT_H
21 #ifndef CALLOUT_H
2 #define CALLOUT_H
22 #define CALLOUT_H
3
23
4 #include <QGraphicsItem>
24 #include <QGraphicsItem>
5 #include <QFont>
25 #include <QFont>
6
26
7 class QGraphicsSceneMouseEvent;
27 class QGraphicsSceneMouseEvent;
8
28
9 class Callout : public QGraphicsItem
29 class Callout : public QGraphicsItem
10 {
30 {
11 public:
31 public:
12 Callout(QGraphicsItem * parent = 0);
32 Callout(QGraphicsItem * parent = 0);
13
33
14 void setText(const QString &text);
34 void setText(const QString &text);
15 void setAnchor(QPointF point);
35 void setAnchor(QPointF point);
16
36
17 QRectF boundingRect() const;
37 QRectF boundingRect() const;
18 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget);
38 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget);
19
39
20 protected:
40 protected:
21 void mousePressEvent(QGraphicsSceneMouseEvent *event);
41 void mousePressEvent(QGraphicsSceneMouseEvent *event);
22 void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
42 void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
23
43
24 private:
44 private:
25 QString m_text;
45 QString m_text;
26 QRectF m_textRect;
46 QRectF m_textRect;
27 QRectF m_rect;
47 QRectF m_rect;
28 QPointF m_anchor;
48 QPointF m_anchor;
29 QFont m_font;
49 QFont m_font;
30 };
50 };
31
51
32 #endif // CALLOUT_H
52 #endif // CALLOUT_H
@@ -1,11 +1,31
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
1 #include <QApplication>
21 #include <QApplication>
2 #include "view.h"
22 #include "view.h"
3
23
4 int main(int argc, char *argv[])
24 int main(int argc, char *argv[])
5 {
25 {
6 QApplication a(argc, argv);
26 QApplication a(argc, argv);
7 View w;
27 View w;
8 w.show();
28 w.show();
9
29
10 return a.exec();
30 return a.exec();
11 }
31 }
@@ -1,26 +1,55
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
1 #ifndef CHARTHELPERS_P_H
30 #ifndef CHARTHELPERS_P_H
2 #define CHARTHELPERS_P_H
31 #define CHARTHELPERS_P_H
3
32
4 #include <qnumeric.h>
33 #include <qnumeric.h>
5 #include <QPointF>
34 #include <QPointF>
6
35
7 static inline bool isValidValue(qreal value)
36 static inline bool isValidValue(qreal value)
8 {
37 {
9 if (qIsNaN(value) || qIsInf(value)) {
38 if (qIsNaN(value) || qIsInf(value)) {
10 qWarning("Ignored NaN, Inf, or -Inf value.");
39 qWarning("Ignored NaN, Inf, or -Inf value.");
11 return false;
40 return false;
12 }
41 }
13 return true;
42 return true;
14 }
43 }
15
44
16 static inline bool isValidValue(qreal x, qreal y)
45 static inline bool isValidValue(qreal x, qreal y)
17 {
46 {
18 return (isValidValue(x) && isValidValue(y));
47 return (isValidValue(x) && isValidValue(y));
19 }
48 }
20
49
21 static inline bool isValidValue(const QPointF point)
50 static inline bool isValidValue(const QPointF point)
22 {
51 {
23 return (isValidValue(point.x()) && isValidValue(point.y()));
52 return (isValidValue(point.x()) && isValidValue(point.y()));
24 }
53 }
25
54
26 #endif // CHARTHELPERS_P_H
55 #endif // CHARTHELPERS_P_H
@@ -1,74 +1,83
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
22 // -------------
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
21 #ifndef CHARTLAYOUT_H
30 #ifndef CHARTLAYOUT_H
22 #define CHARTLAYOUT_H
31 #define CHARTLAYOUT_H
23 #include <QGraphicsLayout>
32 #include <QGraphicsLayout>
24 #include <QMargins>
33 #include <QMargins>
25 #include "qchartglobal.h"
34 #include "qchartglobal.h"
26
35
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
37
29 class ChartPresenter;
38 class ChartPresenter;
30 class ChartTitle;
39 class ChartTitle;
31 class QLegend;
40 class QLegend;
32 class ChartAxis;
41 class ChartAxis;
33 class ChartBackground;
42 class ChartBackground;
34
43
35 class ChartLayout : public QGraphicsLayout
44 class ChartLayout : public QGraphicsLayout
36 {
45 {
37 public:
46 public:
38
47
39 ChartLayout(ChartPresenter *presenter);
48 ChartLayout(ChartPresenter *presenter);
40 virtual ~ChartLayout();
49 virtual ~ChartLayout();
41
50
42 void setMargins(const QMargins &margins);
51 void setMargins(const QMargins &margins);
43 QMargins margins() const;
52 QMargins margins() const;
44
53
45 void setGeometry(const QRectF &rect);
54 void setGeometry(const QRectF &rect);
46
55
47 protected:
56 protected:
48 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
57 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
49 int count() const { return 0; }
58 int count() const { return 0; }
50 QGraphicsLayoutItem *itemAt(int) const { return 0; };
59 QGraphicsLayoutItem *itemAt(int) const { return 0; };
51 void removeAt(int) {};
60 void removeAt(int) {};
52
61
53 private:
62 private:
54 QRectF calculateBackgroundGeometry(const QRectF &geometry, ChartBackground *background) const;
63 QRectF calculateBackgroundGeometry(const QRectF &geometry, ChartBackground *background) const;
55 QRectF calculateContentGeometry(const QRectF &geometry) const;
64 QRectF calculateContentGeometry(const QRectF &geometry) const;
56 QRectF calculateTitleGeometry(const QRectF &geometry, ChartTitle *title) const;
65 QRectF calculateTitleGeometry(const QRectF &geometry, ChartTitle *title) const;
57 QRectF calculateLegendGeometry(const QRectF &geometry, QLegend *legend) const;
66 QRectF calculateLegendGeometry(const QRectF &geometry, QLegend *legend) const;
58 QRectF calculateAxisGeometry(const QRectF &geometry, const QList<ChartAxis *>& axes) const;
67 QRectF calculateAxisGeometry(const QRectF &geometry, const QList<ChartAxis *>& axes) const;
59 QRectF calculateBackgroundMinimum(const QRectF &minimum) const;
68 QRectF calculateBackgroundMinimum(const QRectF &minimum) const;
60 QRectF calculateContentMinimum(const QRectF &minimum) const;
69 QRectF calculateContentMinimum(const QRectF &minimum) const;
61 QRectF calculateTitleMinimum(const QRectF &minimum, ChartTitle *title) const;
70 QRectF calculateTitleMinimum(const QRectF &minimum, ChartTitle *title) const;
62 QRectF calculateAxisMinimum(const QRectF &minimum, const QList<ChartAxis *>& axes) const;
71 QRectF calculateAxisMinimum(const QRectF &minimum, const QList<ChartAxis *>& axes) const;
63 QRectF calculateLegendMinimum(const QRectF &minimum, QLegend *legend) const;
72 QRectF calculateLegendMinimum(const QRectF &minimum, QLegend *legend) const;
64
73
65 private:
74 private:
66 ChartPresenter *m_presenter;
75 ChartPresenter *m_presenter;
67 QMargins m_margins;
76 QMargins m_margins;
68 QRectF m_minChartRect;
77 QRectF m_minChartRect;
69 QRectF m_minAxisRect;
78 QRectF m_minAxisRect;
70 };
79 };
71
80
72 QTCOMMERCIALCHART_END_NAMESPACE
81 QTCOMMERCIALCHART_END_NAMESPACE
73
82
74 #endif
83 #endif
@@ -1,67 +1,76
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
22 // -------------
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
21 #ifndef LEGENDLAYOUT_H
30 #ifndef LEGENDLAYOUT_H
22 #define LEGENDLAYOUT_H
31 #define LEGENDLAYOUT_H
23 #include <QGraphicsLayout>
32 #include <QGraphicsLayout>
24 #include "qchartglobal.h"
33 #include "qchartglobal.h"
25
34
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
36
28 class QLegend;
37 class QLegend;
29
38
30 class LegendLayout : public QGraphicsLayout
39 class LegendLayout : public QGraphicsLayout
31 {
40 {
32 public:
41 public:
33
42
34 LegendLayout(QLegend *legend);
43 LegendLayout(QLegend *legend);
35 virtual ~LegendLayout();
44 virtual ~LegendLayout();
36
45
37 void setGeometry(const QRectF &rect);
46 void setGeometry(const QRectF &rect);
38
47
39 void setOffset(qreal x, qreal y);
48 void setOffset(qreal x, qreal y);
40 QPointF offset() const;
49 QPointF offset() const;
41
50
42 void invalidate();
51 void invalidate();
43 protected:
52 protected:
44 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
53 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
45 int count() const { return 0; }
54 int count() const { return 0; }
46 QGraphicsLayoutItem *itemAt(int) const { return 0; };
55 QGraphicsLayoutItem *itemAt(int) const { return 0; };
47 void removeAt(int) {};
56 void removeAt(int) {};
48
57
49 private:
58 private:
50 void setAttachedGeometry(const QRectF &rect);
59 void setAttachedGeometry(const QRectF &rect);
51 void setDettachedGeometry(const QRectF &rect);
60 void setDettachedGeometry(const QRectF &rect);
52
61
53 private:
62 private:
54 QLegend *m_legend;
63 QLegend *m_legend;
55 qreal m_offsetX;
64 qreal m_offsetX;
56 qreal m_offsetY;
65 qreal m_offsetY;
57 qreal m_minOffsetX;
66 qreal m_minOffsetX;
58 qreal m_minOffsetY;
67 qreal m_minOffsetY;
59 qreal m_maxOffsetX;
68 qreal m_maxOffsetX;
60 qreal m_maxOffsetY;
69 qreal m_maxOffsetY;
61 qreal m_width;
70 qreal m_width;
62 qreal m_height;
71 qreal m_height;
63 };
72 };
64
73
65 QTCOMMERCIALCHART_END_NAMESPACE
74 QTCOMMERCIALCHART_END_NAMESPACE
66
75
67 #endif
76 #endif
General Comments 0
You need to be logged in to leave comments. Login now