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