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

Last change on this file since 8252 was 8252, checked in by stoecker, 6 years ago

see #105 - reenable Qt4 build options, drop generic version dependend includes, replace by direct requirements, remaining QtCore lines should also be replaced

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