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

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