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

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