source: ntrip/trunk/BNC/src/rinex/graphwin.cpp@ 9366

Last change on this file since 9366 was 8566, checked in by mervart, 5 years ago
File size: 6.5 KB
Line 
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 <qwt_scale_widget.h>
42#include <qwt_scale_engine.h>
43
44#include <QDir>
45#include <QFileInfo>
46#include <QHBoxLayout>
47#include <QVBoxLayout>
48#include <QPushButton>
49
50#include "graphwin.h"
51#include "bncsettings.h"
52
53using namespace std;
54
55// Constructor
56////////////////////////////////////////////////////////////////////////////
57t_graphWin::t_graphWin(QWidget* parent, const QString& fileName, const QVector<QWidget*>& plots,
58 bool specialLayout, const QByteArray* scaleTitle,
59 const QwtInterval* scaleInterval,
60 const QVector<int>* rows) : QDialog(parent) {
61
62 _fileName = fileName;
63
64 this->setAttribute(Qt::WA_DeleteOnClose);
65
66 setWindowTitle(_fileName);
67
68 int ww = QFontMetrics(font()).width('w');
69
70 // Buttons
71 // -------
72 _buttonClose = new QPushButton(tr("Close"), this);
73 _buttonClose->setMaximumWidth(10*ww);
74 connect(_buttonClose, SIGNAL(clicked()), this, SLOT(slotClose()));
75
76 _buttonPrint = new QPushButton(tr("Print"), this);
77 _buttonPrint->setMaximumWidth(10*ww);
78 connect(_buttonPrint, SIGNAL(clicked()), this, SLOT(slotPrint()));
79
80 // Color Scale
81 // -----------
82 if (scaleTitle && scaleInterval) {
83 _colorScale = new QwtScaleWidget( this );
84 _colorScale->setAlignment( QwtScaleDraw::RightScale );
85 _colorScale->setColorBarEnabled( true );
86
87 QwtText title(*scaleTitle);
88 QFont font = _colorScale->font();
89 font.setBold( true );
90 title.setFont( font );
91 _colorScale->setTitle( title );
92
93 _colorScale->setColorMap(*scaleInterval, new t_colorMap());
94
95 QwtLinearScaleEngine scaleEngine;
96 _colorScale->setTransformation(scaleEngine.transformation());
97 _colorScale->setScaleDiv(scaleEngine.divideScale(scaleInterval->minValue(),
98 scaleInterval->maxValue(),
99 8, 5));
100 }
101 else {
102 _colorScale = 0;
103 }
104
105 // Layout
106 // ------
107 _canvas = new QWidget(this);
108 if (specialLayout) {
109 QHBoxLayout* plotLayout = new QHBoxLayout(_canvas);
110 plotLayout->addWidget(plots[0]);
111 QVBoxLayout* hlpLayout = new QVBoxLayout;
112 hlpLayout->addWidget(plots[1]);
113 hlpLayout->addWidget(plots[2]);
114 plotLayout->addLayout(hlpLayout);
115 }
116 else {
117 int iRow = -1;
118 QVBoxLayout* plotLayout = new QVBoxLayout(_canvas);
119 QHBoxLayout* rowLayout = new QHBoxLayout();
120 for (int ip = 0; ip < plots.size(); ip++) {
121 if (rows) {
122 if (iRow != -1 && iRow != rows->at(ip)) {
123 plotLayout->addLayout(rowLayout);
124 rowLayout = new QHBoxLayout();
125 }
126 iRow = rows->at(ip);
127 }
128 plots[ip]->setMinimumSize(30*ww, 30*ww);
129 rowLayout->addWidget(plots[ip]);
130 }
131 if (_colorScale) {
132 rowLayout->addWidget(_colorScale);
133 }
134 plotLayout->addLayout(rowLayout);
135 }
136
137 QHBoxLayout* buttonLayout = new QHBoxLayout;
138 buttonLayout->addWidget(_buttonClose);
139 buttonLayout->addWidget(_buttonPrint);
140
141 QVBoxLayout* mainLayout = new QVBoxLayout(this);
142 mainLayout->addWidget(_canvas);
143 mainLayout->addLayout(buttonLayout);
144}
145
146// Destructor
147////////////////////////////////////////////////////////////////////////////
148t_graphWin::~t_graphWin() {
149}
150
151// Accept the Options
152////////////////////////////////////////////////////////////////////////////
153void t_graphWin::slotClose() {
154 done(0);
155}
156
157// Close Dialog gracefully
158////////////////////////////////////////////////////////////////////////////
159void t_graphWin::closeEvent(QCloseEvent* event) {
160 QDialog::closeEvent(event);
161}
162
163// Print the widget
164////////////////////////////////////////////////////////////////////////////
165void t_graphWin::slotPrint() {
166
167 QPrinter printer;
168 QPrintDialog* dialog = new QPrintDialog(&printer, this);
169 dialog->setWindowTitle(tr("Print Plot"));
170 if (dialog->exec() != QDialog::Accepted) {
171 return;
172 }
173 else {
174 QPainter painter;
175 painter.begin(&printer);
176 double xscale = printer.pageRect().width()/double(_canvas->width());
177 double yscale = printer.pageRect().height()/double(_canvas->height());
178 double scale = qMin(xscale, yscale);
179 painter.translate(printer.paperRect().x() + printer.pageRect().width()/2,
180 printer.paperRect().y() + printer.pageRect().height()/2);
181 painter.scale(scale, scale);
182 painter.translate(-width()/2, -height()/2);
183 _canvas->render(&painter);
184 }
185}
186
187// Save the Widget as PNG Files
188////////////////////////////////////////////////////////////////////////////
189void t_graphWin::savePNG(const QString& dirName, QByteArray ext) {
190
191 if (dirName.isEmpty()) {
192 return;
193 }
194
195 QDir dir(dirName);
196 QFileInfo fileInfo(_fileName);
197 if (ext.isEmpty()) {
198 ext = ".png";
199 }
200 QString fileName = dir.path() + QDir::separator()
201 + fileInfo.completeBaseName() + ext;
202
203 QPalette palette = _canvas->palette();
204 QColor oldColor = palette.color(QPalette::Window);
205 palette.setColor(QPalette::Window, Qt::white);
206 _canvas->setPalette(palette);
207
208 QImage image(_canvas->size(), QImage::Format_RGB32);
209 QPainter painter(&image);
210 _canvas->render(&painter);
211 image.save(fileName,"PNG");
212
213 palette.setColor(QPalette::Window, oldColor);
214 _canvas->setPalette(palette);
215}
Note: See TracBrowser for help on using the repository browser.