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

Last change on this file since 8127 was 8127, checked in by stoecker, 16 months ago

update qwt and qwtpolar, many QT5 fixes (unfinished)

File size: 6.0 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 "graphwin.h"
45#include "bncsettings.h"
46
47using namespace std;
48
49// Constructor
50////////////////////////////////////////////////////////////////////////////
51t_graphWin::t_graphWin(QWidget* parent, const QString& fileName, 
52                       const QVector<QWidget*>& plots,
53                       const QByteArray* scaleTitle,
54                       const QwtInterval* scaleInterval) :  QDialog(parent) {
55
56  _fileName = fileName;
57
58  this->setAttribute(Qt::WA_DeleteOnClose);
59
60  setWindowTitle(_fileName);
61
62  int ww = QFontMetrics(font()).width('w');
63  setMinimumSize(plots.size()*40*ww, 40*ww);
64
65  // Buttons
66  // -------
67  _buttonClose = new QPushButton(tr("Close"), this);
68  _buttonClose->setMaximumWidth(10*ww);
69  connect(_buttonClose, SIGNAL(clicked()), this, SLOT(slotClose()));
70
71  _buttonPrint = new QPushButton(tr("Print"), this);
72  _buttonPrint->setMaximumWidth(10*ww);
73  connect(_buttonPrint, SIGNAL(clicked()), this, SLOT(slotPrint()));
74
75  // Color Scale
76  // -----------
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->setTransformation(scaleEngine.transformation());
92     _colorScale->setScaleDiv(scaleEngine.divideScale(scaleInterval->minValue(),
93                                                      scaleInterval->maxValue(),
94                                                      8, 5));
95  }
96  else {
97    _colorScale = 0;
98  }
99
100  // Layout
101  // ------
102  _canvas = new QWidget(this);
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    }
111  }
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);
119  }
120
121  QHBoxLayout* buttonLayout = new QHBoxLayout;
122  buttonLayout->addWidget(_buttonClose);
123  buttonLayout->addWidget(_buttonPrint);
124
125  QVBoxLayout* mainLayout = new QVBoxLayout(this);
126  mainLayout->addWidget(_canvas);
127  mainLayout->addLayout(buttonLayout);
128}
129
130// Destructor
131////////////////////////////////////////////////////////////////////////////
132t_graphWin::~t_graphWin() {
133}
134
135// Accept the Options
136////////////////////////////////////////////////////////////////////////////
137void t_graphWin::slotClose() {
138  done(0);
139}
140
141// Close Dialog gracefully
142////////////////////////////////////////////////////////////////////////////
143void t_graphWin::closeEvent(QCloseEvent* event) {
144  QDialog::closeEvent(event);
145}
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);
160    double xscale = printer.pageRect().width()/double(_canvas->width());
161    double yscale = printer.pageRect().height()/double(_canvas->height());
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);
167    _canvas->render(&painter);
168  }
169}
170
171// Save the Widget as PNG Files
172////////////////////////////////////////////////////////////////////////////
173void t_graphWin::savePNG(const QString& dirName, QByteArray ext) {
174
175  if (dirName.isEmpty()) {
176    return;
177  }
178
179  QDir dir(dirName);
180  QFileInfo fileInfo(_fileName);
181  if (ext.isEmpty()) {
182    ext = ".png";
183  }
184  QString fileName = dir.path() + QDir::separator()
185                   + fileInfo.completeBaseName() + ext;
186
187  QPalette palette = _canvas->palette();
188  QColor oldColor = palette.color(QPalette::Window);
189  palette.setColor(QPalette::Window, Qt::white);
190  _canvas->setPalette(palette);
191
192  QImage image(_canvas->size(), QImage::Format_RGB32);
193  QPainter painter(&image);
194  _canvas->render(&painter);
195  image.save(fileName,"PNG");
196
197  palette.setColor(QPalette::Window, oldColor);
198  _canvas->setPalette(palette);
199}
Note: See TracBrowser for help on using the repository browser.