From 9acf1caca3370f3e7eaf53c88e5419a62c07e4cb Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 22 Aug 2014 22:26:07 -0300 Subject: 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 Signed-off-by: Dirk Hohndel --- qt-ui/mainwindow.cpp | 47 ++- qt-ui/mainwindow.h | 33 +- qt-ui/mainwindow.ui | 635 ++++++++++++--------------------------- qt-ui/profile/profilewidget2.cpp | 4 +- 4 files changed, 235 insertions(+), 484 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 #include #include +#include #include #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(©PasteDive, 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 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); } diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index 1340d9076..100eac6cb 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -127,22 +127,22 @@ slots: void on_actionImportDiveLog_triggered(); /* TODO: Move those slots below to it's own class */ - void on_profCalcAllTissues_clicked(bool triggered); - void on_profCalcCeiling_clicked(bool triggered); - void on_profDcCeiling_clicked(bool triggered); - void on_profEad_clicked(bool triggered); - void on_profIncrement3m_clicked(bool triggered); - void on_profMod_clicked(bool triggered); - void on_profNdl_tts_clicked(bool triggered); - void on_profPO2_clicked(bool triggered); - void on_profPhe_clicked(bool triggered); - void on_profPn2_clicked(bool triggered); - void on_profHR_clicked(bool triggered); - void on_profRuler_clicked(bool triggered); - void on_profSAC_clicked(bool triggered); - void on_profScaled_clicked(bool triggered); - void on_profTogglePicture_clicked(bool triggered); - void on_profTankbar_clicked(bool triggered); + void on_profCalcAllTissues_triggered(bool triggered); + void on_profCalcCeiling_triggered(bool triggered); + void on_profDcCeiling_triggered(bool triggered); + void on_profEad_triggered(bool triggered); + void on_profIncrement3m_triggered(bool triggered); + void on_profMod_triggered(bool triggered); + void on_profNdl_tts_triggered(bool triggered); + void on_profPO2_triggered(bool triggered); + void on_profPhe_triggered(bool triggered); + void on_profPn2_triggered(bool triggered); + void on_profHR_triggered(bool triggered); + void on_profRuler_triggered(bool triggered); + void on_profSAC_triggered(bool triggered); + void on_profScaled_triggered(bool triggered); + void on_profTogglePicture_triggered(bool triggered); + void on_profTankbar_triggered(bool triggered); void on_actionExport_triggered(); void on_copy_triggered(); void on_paste_triggered(); @@ -192,6 +192,7 @@ private: QDialog *survey; struct dive copyPasteDive; struct dive_components what; + QList profileToolbarActions; }; #endif // MAINWINDOW_H diff --git a/qt-ui/mainwindow.ui b/qt-ui/mainwindow.ui index 52314d596..2dceac69d 100644 --- a/qt-ui/mainwindow.ui +++ b/qt-ui/mainwindow.ui @@ -109,444 +109,9 @@ 0 - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Toggle pHe graph - - - ... - - - - :/icon_he:/icon_he - - - - 24 - 24 - - - - true - - - true - - - - - - - Toggle calculating all tissues - - - ... - - - - :/icon_ceiling_alltissues:/icon_ceiling_alltissues - - - - 24 - 24 - - - - true - - - true - - - - - - - true - - - Toggle DC reported ceiling - - - ... - - - - :/icon_ceiling_dc:/icon_ceiling_dc - - - - 24 - 24 - - - - true - - - true - - - - - - - true - - - Toggle calculated ceiling - - - ... - - - - :/icon_ceiling_calculated:/icon_ceiling_calculated - - - - 24 - 24 - - - - true - - - true - - - - - - - Toggle NDL, TTS - - - ... - - - - :/icon_NDLTTS:/icon_NDLTTS - - - - 24 - 24 - - - - true - - - true - - - - - - - Toggle calculated ceiling with 3m increments - - - ... - - - - :/icon_ceiling_3m:/icon_ceiling_3m - - - - 24 - 24 - - - - true - - - true - - - - - - - Toggle heart rate - - - ... - - - - :/icon_HR:/icon_HR - - - - 24 - 24 - - - - true - - - true - - - - - - - Toggle MOD - - - ... - - - - :/icon_mod:/icon_mod - - - - 24 - 24 - - - - true - - - true - - - - - - - Toggle EAD, END, EADD - - - ... - - - - :/icon_ead:/icon_ead - - - - 24 - 24 - - - - true - - - true - - - - - - - Toggle SAC rate - - - ... - - - - :/icon_lung:/icon_lung - - - - 24 - 24 - - - - true - - - true - - - - - - - Rescale depth axis - - - ... - - - - :/scale:/scale - - - - 24 - 24 - - - - true - - - true - - - - - - - Toggle ruler - - - ... - - - - :/units:/units - - - - 24 - 24 - - - - true - - - true - - - - + - - - - Toggle pO₂ Graph - - - ... - - - - :/icon_o2:/icon_o2 - - - - 24 - 24 - - - - true - - - true - - - - - - - Toggle pN₂ Graph - - - ... - - - - :/icon_n2:/icon_n2 - - - - 24 - 24 - - - - true - - - true - - - - - - - Toggle Cylinder Bar - - - ... - - - - :/gaschange:/gaschange - - - - 24 - 24 - - - - true - - - true - - - - - - - Toggle viewing picture thumbnails - - - ... - - - - :/pictures:/pictures - - - - 24 - 24 - - - - true - - - true - - - @@ -690,7 +255,7 @@ p, li { white-space: pre-wrap; } 0 0 1682 - 19 + 25 @@ -1072,12 +637,204 @@ p, li { white-space: pre-wrap; } - Configure Dive Computer + Configure &Dive Computer - Re-plan dive + Re-plan &dive + + + + + true + + + + :/icon_o2:/icon_o2 + + + Show PO2 + + + + + true + + + + :/icon_n2:/icon_n2 + + + Show Pn2 + + + + + true + + + + :/icon_he:/icon_he + + + Show Ph2 + + + + + true + + + + :/icon_ceiling_dc:/icon_ceiling_dc + + + Show Dc Ceiling + + + + + true + + + + :/icon_ceiling_calculated:/icon_ceiling_calculated + + + Calculate Ceiling + + + + + true + + + + :/icon_ceiling_alltissues:/icon_ceiling_alltissues + + + Calculate All Tissues + + + + + true + + + + :/icon_ceiling_3m:/icon_ceiling_3m + + + 3m Increments + + + + + true + + + + :/icon_HR:/icon_HR + + + Heart Rate + + + + + true + + + + :/icon_mod:/icon_mod + + + Show Mod + + + + + true + + + + :/icon_ead:/icon_ead + + + Show EAD + + + + + true + + + + :/icon_NDLTTS:/icon_NDLTTS + + + Show NTL TTS + + + + + true + + + + :/icon_lung:/icon_lung + + + Show SAC + + + + + true + + + + :/ruler:/ruler + + + Show Ruler + + + + + true + + + + :/scale:/scale + + + Scale Graph + + + + + true + + + + :/pictures:/pictures + + + Toggle Pictures + + + + + true + + + + :/gaschange:/gaschange + + + Show Tank Bar diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index bd51b3310..fcad3197f 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -740,7 +740,7 @@ void ProfileWidget2::setEmptyState() setBackgroundBrush(getColor(::BACKGROUND, isGrayscale)); dataModel->clear(); currentState = EMPTY; - MainWindow::instance()->setToolButtonsEnabled(false); + MainWindow::instance()->setEnabledToolbar(false); fixBackgroundPos(); background->setVisible(true); @@ -788,7 +788,7 @@ void ProfileWidget2::setProfileState() MainWindow::instance()->enableDcShortcuts(); currentState = PROFILE; - MainWindow::instance()->setToolButtonsEnabled(true); + MainWindow::instance()->setEnabledToolbar(true); toolTipItem->readPos(); setBackgroundBrush(getColor(::BACKGROUND, isGrayscale)); -- cgit v1.2.3-70-g09d2