Improve feedback by writing progress to status bar for various operations
[tecorrec.git] / tcMainWindow.cpp
blob4f4f21d20be83c19d2298adc907e99521814b628
1 /***************************************************************************
2 * This file is part of Tecorrec. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
4 * *
5 * Tecorrec is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * Tecorrec is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with Tecorrec. If not, write to the Free Software Foundation, *
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
20 /**
21 * @file tcMainWindow.h
22 * @brief Main application window.
25 #include "tcMainWindow.h"
26 #include "tcViewportWidget.h"
27 #include "tcColourMapWidget.h"
28 #include <tcGlobe.h>
29 #include <tcSrtmCache.h>
30 #include <tcGeoImageData.h>
31 #include <tcChannelManager.h>
32 #include <tcChannel.h>
33 #include <tcChannelConfigWidget.h>
35 #include <QHBoxLayout>
36 #include <QWidget>
37 #include <QMenuBar>
38 #include <QMenu>
39 #include <QStatusBar>
40 #include <QDockWidget>
41 #include <QComboBox>
42 #include <QRadioButton>
43 #include <QSlider>
44 #include <QPushButton>
47 * Constructors + destructor
50 /// Default constructor.
51 tcMainWindow::tcMainWindow()
52 : QMainWindow()
53 , m_viewport(new tcViewportWidget(this))
54 , m_colourMap(new tcColourMapWidget(QStringList()
55 << tr("Red") << tr("Green") << tr("Blue"), this))
56 , m_globe(new tcGlobe(6378.137e3))
58 m_viewport->setGlobe(m_globe);
59 setCentralWidget(m_viewport);
62 // Menu bar
63 QMenuBar* menus = menuBar();
65 QMenu* menuView = menus->addMenu(tr("View", "The menu"));
67 QMenu* menuViewQuality = menuView->addMenu(tr("Elevation Quality", "The menu"));
69 QAction* menuViewQualityAdaptive = menuViewQuality->addAction(tr("Adaptive Resolution"),
70 m_viewport, SLOT(setQualityAdaptive()));
71 QAction* menuViewQualityFull = menuViewQuality->addAction(tr("Full Resolution"),
72 m_viewport, SLOT(setQualityFull()));
74 QMenu* menuViewRender = menuView->addMenu(tr("Render Options", "The menu"));
76 QAction* menuViewRenderNormal = menuViewRender->addAction(tr("Normal", "Polygon mode"),
77 m_viewport, SLOT(setPolygonModeNormal()));
78 QAction* menuViewRenderWireframe = menuViewRender->addAction(tr("Wireframe", "Polygon mode"),
79 m_viewport, SLOT(setPolygonModeWireframe()));
81 QMenu* menuViewRenderColour = menuView->addMenu(tr("Colour Coding", "The menu"));
83 QAction* menuViewRenderColourNone = menuViewRenderColour->addAction(tr("No colour coding"),
84 m_viewport, SLOT(setColourCodingNone()));
85 QAction* menuViewRenderColourElevationSampleAlignment = menuViewRenderColour->addAction(tr("Alignment of elevation samples"),
86 m_viewport, SLOT(setColourCodingElevationSampleAlignment()));
93 // Status bar
94 QStatusBar* statusBar = new QStatusBar(this);
95 connect(m_viewport, SIGNAL(mouseGeoTextChanged(const QString&)),
96 statusBar, SLOT(showMessage(const QString&)));
97 connect(m_globe->imagery()->channelManager(), SIGNAL(progressing(const QString&)),
98 statusBar, SLOT(showMessage(const QString&)));
99 connect(m_globe->dem(), SIGNAL(progressing(const QString&)),
100 statusBar, SLOT(showMessage(const QString&)));
101 setStatusBar(statusBar);
104 QDockWidget* dockElevation;
106 // Docker for elevation data settings
107 QDockWidget* docker = new QDockWidget(tr("Elevation Data"), this);
108 dockElevation = docker;
109 QWidget* dockerWidget = new QWidget(docker);
110 QVBoxLayout* layout = new QVBoxLayout(dockerWidget);
111 docker->setWidget(dockerWidget);
112 addDockWidget(Qt::LeftDockWidgetArea, docker);
114 // Combo box to select data set
115 QComboBox* elevDataSet = new QComboBox(dockerWidget);
116 layout->addWidget(elevDataSet);
117 QStringList elevDataSets = tcSrtmCache::dataSets();
118 foreach (QString dataSet, elevDataSets)
120 elevDataSet->addItem(dataSet);
122 connect(elevDataSet, SIGNAL(currentIndexChanged(const QString&)), m_viewport, SLOT(setElevationDataSet(const QString&)));
123 if (-1 != elevDataSet->currentIndex())
125 m_viewport->setElevationDataSet(elevDataSet->currentText());
128 // Radio buttons
129 QRadioButton* elevFlat = new QRadioButton(tr("Don't Show Elevation (Flat)"), dockerWidget);
130 layout->addWidget(elevFlat);
131 connect(elevFlat, SIGNAL(pressed()), m_viewport, SLOT(setElevationFlat()));
132 QRadioButton* elevRaw = new QRadioButton(tr("Raw SRTM Elevation Data"), dockerWidget);
133 layout->addWidget(elevRaw);
134 connect(elevRaw, SIGNAL(pressed()), m_viewport, SLOT(setElevationRaw()));
135 QRadioButton* elevCorrected = new QRadioButton(tr("Corrected SRTM Elevation Data"), dockerWidget);
136 layout->addWidget(elevCorrected);
137 elevCorrected->setChecked(true);
138 connect(elevCorrected, SIGNAL(pressed()), m_viewport, SLOT(setElevationCorrected()));
139 QSlider* elevCorrectionLevel = new QSlider(Qt::Horizontal, dockerWidget);
140 layout->addWidget(elevCorrectionLevel);
141 elevCorrectionLevel->setRange(0,100);
142 connect(elevCorrectionLevel, SIGNAL(valueChanged(int)), m_viewport, SLOT(setElevationCorrection(int)));
144 // Spacer
145 layout->addStretch();
149 // Docker for satellite imagery
150 QDockWidget* docker = new QDockWidget(tr("Imagery Data"), this);
151 QWidget* dockerWidget = new QWidget(docker);
152 QVBoxLayout* layout = new QVBoxLayout(dockerWidget);
153 docker->setWidget(dockerWidget);
154 tabifyDockWidget(dockElevation, docker);
156 // Button to go to sun view
157 QPushButton* btnSunView = new QPushButton(tr("Sun View"), this);
158 layout->addWidget(btnSunView);
159 connect(btnSunView, SIGNAL(clicked(bool)), m_viewport, SLOT(sunView()));
161 // Grid of colours
162 layout->addWidget(m_colourMap);
163 const tcChannelManager* manager = m_globe->imagery()->channelManager();
164 int numChannels = manager->numChannels();
165 for (int i = 0; i < numChannels; ++i)
167 tcChannel* channel = manager->channel(i);
168 m_colourMap->addInputBand(channel->name(), channel->description());
170 for (int i = 0; i < 3; ++i)
172 m_colourMap->setInputBand(i, 2-i);
174 connect(m_colourMap, SIGNAL(inputBandClicked(int)), this, SLOT(configureChannel(int)));
175 connect(m_colourMap, SIGNAL(inputBandChanged(int, int)), m_viewport, SLOT(setColourMapping(int,int)));
179 // Docker for processing
180 QDockWidget* docker = new QDockWidget(tr("Processing"), this);
181 QWidget* dockerWidget = new QWidget(docker);
182 QVBoxLayout* layout = new QVBoxLayout(dockerWidget);
183 docker->setWidget(dockerWidget);
184 tabifyDockWidget(dockElevation, docker);
186 // Spacer
187 layout->addStretch();
191 /// Destructor.
192 tcMainWindow::~tcMainWindow()
194 delete m_globe;
198 * Private slots
201 /// Show configuration for a channel.
202 void tcMainWindow::configureChannel(int channel)
204 tcChannelManager* manager = m_globe->imagery()->channelManager();
205 tcChannelConfigWidget* configWidget = manager->channel(channel)->configWidget();
206 if (0 != configWidget)
208 connect(configWidget, SIGNAL(updated()),
209 m_viewport, SLOT(updateGL()));
210 connect(configWidget, SIGNAL(texturePointRequested(QObject*, const char*)),
211 m_viewport, SLOT(texturePointMode(QObject*, const char*)));
212 configWidget->setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
213 configWidget->show();