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