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