1 | // Part of BNC, a utility for retrieving decoding and
|
---|
2 | // converting GNSS data streams from NTRIP broadcasters.
|
---|
3 | //
|
---|
4 | // Copyright (C) 2007
|
---|
5 | // German Federal Agency for Cartography and Geodesy (BKG)
|
---|
6 | // http://www.bkg.bund.de
|
---|
7 | // Czech Technical University Prague, Department of Geodesy
|
---|
8 | // http://www.fsv.cvut.cz
|
---|
9 | //
|
---|
10 | // Email: euref-ip@bkg.bund.de
|
---|
11 | //
|
---|
12 | // This program is free software; you can redistribute it and/or
|
---|
13 | // modify it under the terms of the GNU General Public License
|
---|
14 | // as published by the Free Software Foundation, version 2.
|
---|
15 | //
|
---|
16 | // This program is distributed in the hope that it will be useful,
|
---|
17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | // GNU General Public License for more details.
|
---|
20 | //
|
---|
21 | // You should have received a copy of the GNU General Public License
|
---|
22 | // along with this program; if not, write to the Free Software
|
---|
23 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
---|
24 |
|
---|
25 | /* -------------------------------------------------------------------------
|
---|
26 | * BKG NTRIP Client
|
---|
27 | * -------------------------------------------------------------------------
|
---|
28 | *
|
---|
29 | * Class: t_graphWin
|
---|
30 | *
|
---|
31 | * Purpose: Window for plots
|
---|
32 | *
|
---|
33 | * Author: L. Mervart
|
---|
34 | *
|
---|
35 | * Created: 23-Jun-2012
|
---|
36 | *
|
---|
37 | * Changes:
|
---|
38 | *
|
---|
39 | * -----------------------------------------------------------------------*/
|
---|
40 |
|
---|
41 | #include "graphwin.h"
|
---|
42 | #include "qwt_scale_widget.h"
|
---|
43 | #include <qwt_scale_engine.h>
|
---|
44 |
|
---|
45 | using namespace std;
|
---|
46 |
|
---|
47 | // Constructor
|
---|
48 | ////////////////////////////////////////////////////////////////////////////
|
---|
49 | t_graphWin::t_graphWin(QWidget* parent, const QString& fileName,
|
---|
50 | const QVector<QWidget*>& plots,
|
---|
51 | const QByteArray& scaleTitle,
|
---|
52 | const QwtInterval scaleInterval) : QDialog(parent) {
|
---|
53 |
|
---|
54 | _fileName = fileName;
|
---|
55 |
|
---|
56 | this->setAttribute(Qt::WA_DeleteOnClose);
|
---|
57 |
|
---|
58 | setWindowTitle(_fileName);
|
---|
59 |
|
---|
60 | int ww = QFontMetrics(font()).width('w');
|
---|
61 | setMinimumSize(plots.size()*40*ww, 40*ww);
|
---|
62 |
|
---|
63 | // Buttons
|
---|
64 | // -------
|
---|
65 | _buttonClose = new QPushButton(tr("Close"), this);
|
---|
66 | _buttonClose->setMaximumWidth(10*ww);
|
---|
67 | connect(_buttonClose, SIGNAL(clicked()), this, SLOT(slotClose()));
|
---|
68 |
|
---|
69 | _buttonPrint = new QPushButton(tr("Print"), this);
|
---|
70 | _buttonPrint->setMaximumWidth(10*ww);
|
---|
71 | connect(_buttonPrint, SIGNAL(clicked()), this, SLOT(slotPrint()));
|
---|
72 |
|
---|
73 | // Color Scale
|
---|
74 | // -----------
|
---|
75 | _colorScale = new QwtScaleWidget( this );
|
---|
76 | _colorScale->setAlignment( QwtScaleDraw::RightScale );
|
---|
77 | _colorScale->setColorBarEnabled( true );
|
---|
78 |
|
---|
79 | QwtText title(scaleTitle);
|
---|
80 | QFont font = _colorScale->font();
|
---|
81 | font.setBold( true );
|
---|
82 | title.setFont( font );
|
---|
83 | _colorScale->setTitle( title );
|
---|
84 |
|
---|
85 | _colorScale->setColorMap(scaleInterval, new t_colorMap());
|
---|
86 |
|
---|
87 | QwtLinearScaleEngine scaleEngine;
|
---|
88 | _colorScale->setScaleDiv(scaleEngine.transformation(),
|
---|
89 | scaleEngine.divideScale(scaleInterval.minValue(),
|
---|
90 | scaleInterval.maxValue(),
|
---|
91 | 8, 5));
|
---|
92 |
|
---|
93 | // Layout
|
---|
94 | // ------
|
---|
95 | _canvas = new QWidget(this);
|
---|
96 | QHBoxLayout* plotLayout = new QHBoxLayout(_canvas);
|
---|
97 | for (int ip = 0; ip < plots.size(); ip++) {
|
---|
98 | plotLayout->addWidget(plots[ip]);
|
---|
99 | }
|
---|
100 | plotLayout->addWidget(_colorScale);
|
---|
101 |
|
---|
102 | QHBoxLayout* buttonLayout = new QHBoxLayout;
|
---|
103 | buttonLayout->addWidget(_buttonClose);
|
---|
104 | buttonLayout->addWidget(_buttonPrint);
|
---|
105 |
|
---|
106 | QVBoxLayout* mainLayout = new QVBoxLayout(this);
|
---|
107 | mainLayout->addWidget(_canvas);
|
---|
108 | mainLayout->addLayout(buttonLayout);
|
---|
109 | }
|
---|
110 |
|
---|
111 | // Destructor
|
---|
112 | ////////////////////////////////////////////////////////////////////////////
|
---|
113 | t_graphWin::~t_graphWin() {
|
---|
114 | }
|
---|
115 |
|
---|
116 | // Accept the Options
|
---|
117 | ////////////////////////////////////////////////////////////////////////////
|
---|
118 | void t_graphWin::slotClose() {
|
---|
119 | done(0);
|
---|
120 | }
|
---|
121 |
|
---|
122 | // Close Dialog gracefully
|
---|
123 | ////////////////////////////////////////////////////////////////////////////
|
---|
124 | void t_graphWin::closeEvent(QCloseEvent* event) {
|
---|
125 | QDialog::closeEvent(event);
|
---|
126 | }
|
---|
127 |
|
---|
128 | // Print the widget
|
---|
129 | ////////////////////////////////////////////////////////////////////////////
|
---|
130 | void t_graphWin::slotPrint() {
|
---|
131 |
|
---|
132 | QPrinter printer;
|
---|
133 | QPrintDialog* dialog = new QPrintDialog(&printer, this);
|
---|
134 | dialog->setWindowTitle(tr("Print Plot"));
|
---|
135 | if (dialog->exec() != QDialog::Accepted) {
|
---|
136 | return;
|
---|
137 | }
|
---|
138 | else {
|
---|
139 | QPainter painter;
|
---|
140 | painter.begin(&printer);
|
---|
141 | double xscale = printer.pageRect().width()/double(_canvas->width());
|
---|
142 | double yscale = printer.pageRect().height()/double(_canvas->height());
|
---|
143 | double scale = qMin(xscale, yscale);
|
---|
144 | painter.translate(printer.paperRect().x() + printer.pageRect().width()/2,
|
---|
145 | printer.paperRect().y() + printer.pageRect().height()/2);
|
---|
146 | painter.scale(scale, scale);
|
---|
147 | painter.translate(-width()/2, -height()/2);
|
---|
148 | _canvas->render(&painter);
|
---|
149 | }
|
---|
150 | }
|
---|
151 |
|
---|
152 | // Save the Widget as PNG Files
|
---|
153 | ////////////////////////////////////////////////////////////////////////////
|
---|
154 | void t_graphWin::savePNG(const QString& dirName, QByteArray ext) {
|
---|
155 | if (dirName.isEmpty()) {
|
---|
156 | return;
|
---|
157 | }
|
---|
158 | QImage image(_canvas->size(), QImage::Format_RGB32);
|
---|
159 | QPainter painter(&image);
|
---|
160 | _canvas->render(&painter);
|
---|
161 | QDir dir(dirName);
|
---|
162 | QFileInfo fileInfo(_fileName);
|
---|
163 | if (ext.isEmpty()) {
|
---|
164 | ext = ".png";
|
---|
165 | }
|
---|
166 | QString fileName = dir.path() + QDir::separator()
|
---|
167 | + fileInfo.completeBaseName() + ext;
|
---|
168 | image.save(fileName,"PNG");
|
---|
169 | }
|
---|