summaryrefslogtreecommitdiffstats
path: root/qt-ui/mainwindow.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2014-08-22 22:26:07 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-08-23 08:09:11 -0700
commit9acf1caca3370f3e7eaf53c88e5419a62c07e4cb (patch)
treee7a4635c1ee338e97854b86aa5bd73ea8aecb1ae /qt-ui/mainwindow.cpp
parentfe9e67bfaf250aecc17de437668fddfecd7e9b23 (diff)
downloadsubsurface-9acf1caca3370f3e7eaf53c88e5419a62c07e4cb.tar.gz
A much better Toolbar for the profile.
Using QToolBar I was able to remove much of the dead code from the mainwindow.ui xml file by transforming the QToolButtons into actions and loading them dynamically in the .cpp code. I couldn't use the designer for this ( as I wanted ) because Qt has no notion of ToolBars outside of the areas where the MainWindow should have one, and we use it in a very different area. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/mainwindow.cpp')
-rw-r--r--qt-ui/mainwindow.cpp47
1 files changed, 20 insertions, 27 deletions
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 17c554777..4c70f5ca3 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -20,6 +20,7 @@
#include <QStringList>
#include <QSettings>
#include <QShortcut>
+#include <QToolBar>
#include <fcntl.h>
#include "divelistview.h"
#include "starwidget.h"
@@ -69,6 +70,10 @@ MainWindow::MainWindow() : QMainWindow(),
Q_ASSERT_X(m_Instance == NULL, "MainWindow", "MainWindow recreated!");
m_Instance = this;
ui.setupUi(this);
+ profileToolbarActions << ui.profCalcAllTissues << ui.profCalcCeiling << ui.profDcCeiling << ui.profEad <<
+ ui.profHR << ui.profIncrement3m << ui.profMod << ui.profNdl_tts << ui.profNdl_tts <<
+ ui.profPhe << ui.profPn2 << ui.profPO2 << ui.profRuler << ui.profSAC << ui.profScaled <<
+ ui.profTogglePicture << ui.profTankbar;
setWindowIcon(QIcon(":subsurface-icon"));
if (!QIcon::hasThemeIcon("window-close")) {
QIcon::setThemeName("subsurface");
@@ -117,6 +122,19 @@ MainWindow::MainWindow() : QMainWindow(),
#endif
memset(&copyPasteDive, 0, sizeof(copyPasteDive));
memset(&what, 0, sizeof(what));
+
+ QToolBar *toolBar = new QToolBar();
+ Q_FOREACH(QAction *a, profileToolbarActions)
+ toolBar->addAction(a);
+ toolBar->setOrientation(Qt::Vertical);
+
+ // since I'm adding the toolBar by hand, because designer
+ // has no concept of "toolbar" for a non-mainwindow widget (...)
+ // I need to take the current item that's in the toolbar Position
+ // and reposition it alongside the grid layout.
+ QLayoutItem *p = ui.gridLayout->takeAt(0);
+ ui.gridLayout->addWidget(toolBar,0,0);
+ ui.gridLayout->addItem(p, 0, 1);
}
MainWindow::~MainWindow()
@@ -228,26 +246,6 @@ void MainWindow::cleanUpEmpty()
disableDcShortcuts();
}
-void MainWindow::setToolButtonsEnabled(bool enabled)
-{
- ui.profPO2->setEnabled(enabled);
- ui.profPn2->setEnabled(enabled);
- ui.profPhe->setEnabled(enabled);
- ui.profDcCeiling->setEnabled(enabled);
- ui.profCalcCeiling->setEnabled(enabled);
- ui.profCalcAllTissues->setEnabled(enabled);
- ui.profIncrement3m->setEnabled(enabled);
- ui.profMod->setEnabled(enabled);
- ui.profEad->setEnabled(enabled);
- ui.profNdl_tts->setEnabled(enabled);
- ui.profSAC->setEnabled(enabled);
- ui.profRuler->setEnabled(enabled);
- ui.profScaled->setEnabled(enabled);
- ui.profHR->setEnabled(enabled);
- ui.profTogglePicture->setEnabled(enabled);
- ui.profTankbar->setEnabled(enabled);
-}
-
bool MainWindow::okToClose(QString message)
{
if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING ||
@@ -1291,7 +1289,7 @@ void MainWindow::editCurrentDive()
PreferencesDialog::instance()->emitSettingsChanged();
#define TOOLBOX_PREF_PROFILE(METHOD, INTERNAL_PREFS, QT_PREFS) \
-void MainWindow::on_ ## METHOD ##_clicked(bool triggered) \
+void MainWindow::on_ ## METHOD ##_triggered(bool triggered) \
{ \
prefs. INTERNAL_PREFS = triggered;\
PREF_PROFILE(QT_PREFS); \
@@ -1338,12 +1336,7 @@ void MainWindow::on_actionConfigure_Dive_Computer_triggered()
void MainWindow::setEnabledToolbar(bool arg1)
{
- QList<QToolButton*> toolBar;
- toolBar << ui.profCalcAllTissues << ui.profCalcCeiling << ui.profDcCeiling << ui.profEad <<
- ui.profHR << ui.profIncrement3m << ui.profMod << ui.profNdl_tts << ui.profNdl_tts <<
- ui.profPhe << ui.profPn2 << ui.profPO2 << ui.profRuler << ui.profSAC << ui.profScaled <<
- ui.profTogglePicture << ui.profTankbar;
- Q_FOREACH(QToolButton *b, toolBar)
+ Q_FOREACH(QAction *b, profileToolbarActions)
b->setEnabled(arg1);
}