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

Last change on this file since 11205 was 11158, checked in by stuerze, 4 weeks ago

deprecated functions exchanged libs updated

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