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

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