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>
This commit is contained in:
Tomaz Canabrava 2014-08-22 22:26:07 -03:00 committed by Dirk Hohndel
parent fe9e67bfaf
commit 9acf1caca3
4 changed files with 235 additions and 484 deletions

View file

@ -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);
}

View file

@ -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<QAction*> profileToolbarActions;
};
#endif // MAINWINDOW_H

View file

@ -109,444 +109,9 @@
<property name="spacing">
<number>0</number>
</property>
<item row="17" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0">
<widget class="QToolButton" name="profPhe">
<property name="toolTip">
<string>Toggle pHe graph</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../subsurface.qrc">
<normaloff>:/icon_he</normaloff>:/icon_he</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QToolButton" name="profCalcAllTissues">
<property name="toolTip">
<string>Toggle calculating all tissues</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../subsurface.qrc">
<normaloff>:/icon_ceiling_alltissues</normaloff>:/icon_ceiling_alltissues</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QToolButton" name="profDcCeiling">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>Toggle DC reported ceiling</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../subsurface.qrc">
<normaloff>:/icon_ceiling_dc</normaloff>:/icon_ceiling_dc</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QToolButton" name="profCalcCeiling">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>Toggle calculated ceiling</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../subsurface.qrc">
<normaloff>:/icon_ceiling_calculated</normaloff>:/icon_ceiling_calculated</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item row="10" column="0">
<widget class="QToolButton" name="profNdl_tts">
<property name="toolTip">
<string>Toggle NDL, TTS</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../subsurface.qrc">
<normaloff>:/icon_NDLTTS</normaloff>:/icon_NDLTTS</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QToolButton" name="profIncrement3m">
<property name="toolTip">
<string>Toggle calculated ceiling with 3m increments</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../subsurface.qrc">
<normaloff>:/icon_ceiling_3m</normaloff>:/icon_ceiling_3m</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QToolButton" name="profHR">
<property name="toolTip">
<string>Toggle heart rate</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../subsurface.qrc">
<normaloff>:/icon_HR</normaloff>:/icon_HR</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QToolButton" name="profMod">
<property name="toolTip">
<string>Toggle MOD</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../subsurface.qrc">
<normaloff>:/icon_mod</normaloff>:/icon_mod</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QToolButton" name="profEad">
<property name="toolTip">
<string>Toggle EAD, END, EADD</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../subsurface.qrc">
<normaloff>:/icon_ead</normaloff>:/icon_ead</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item row="11" column="0">
<widget class="QToolButton" name="profSAC">
<property name="toolTip">
<string>Toggle SAC rate</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../subsurface.qrc">
<normaloff>:/icon_lung</normaloff>:/icon_lung</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item row="13" column="0">
<widget class="QToolButton" name="profScaled">
<property name="toolTip">
<string>Rescale depth axis</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../subsurface.qrc">
<normaloff>:/scale</normaloff>:/scale</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item row="12" column="0">
<widget class="QToolButton" name="profRuler">
<property name="toolTip">
<string>Toggle ruler</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../subsurface.qrc">
<normaloff>:/units</normaloff>:/units</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1" rowspan="19">
<item row="0" column="0" rowspan="3">
<widget class="ProfileWidget2" name="newProfile"/>
</item>
<item row="0" column="0">
<widget class="QToolButton" name="profPO2">
<property name="toolTip">
<string>Toggle pO₂ Graph</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../subsurface.qrc">
<normaloff>:/icon_o2</normaloff>:/icon_o2</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QToolButton" name="profPn2">
<property name="toolTip">
<string>Toggle pN₂ Graph</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../subsurface.qrc">
<normaloff>:/icon_n2</normaloff>:/icon_n2</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item row="15" column="0">
<widget class="QToolButton" name="profTankbar">
<property name="toolTip">
<string>Toggle Cylinder Bar</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../subsurface.qrc">
<normaloff>:/gaschange</normaloff>:/gaschange</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item row="14" column="0">
<widget class="QToolButton" name="profTogglePicture">
<property name="toolTip">
<string>Toggle viewing picture thumbnails</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../subsurface.qrc">
<normaloff>:/pictures</normaloff>:/pictures</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
@ -690,7 +255,7 @@ p, li { white-space: pre-wrap; }
<x>0</x>
<y>0</y>
<width>1682</width>
<height>19</height>
<height>25</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
@ -1072,12 +637,204 @@ p, li { white-space: pre-wrap; }
</action>
<action name="actionConfigure_Dive_Computer">
<property name="text">
<string>Configure Dive Computer</string>
<string>Configure &amp;Dive Computer</string>
</property>
</action>
<action name="actionReplanDive">
<property name="text">
<string>Re-plan dive</string>
<string>Re-plan &amp;dive</string>
</property>
</action>
<action name="profPO2">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../subsurface.qrc">
<normaloff>:/icon_o2</normaloff>:/icon_o2</iconset>
</property>
<property name="text">
<string>Show PO2</string>
</property>
</action>
<action name="profPn2">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../subsurface.qrc">
<normaloff>:/icon_n2</normaloff>:/icon_n2</iconset>
</property>
<property name="text">
<string>Show Pn2</string>
</property>
</action>
<action name="profPhe">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../subsurface.qrc">
<normaloff>:/icon_he</normaloff>:/icon_he</iconset>
</property>
<property name="text">
<string>Show Ph2</string>
</property>
</action>
<action name="profDcCeiling">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../subsurface.qrc">
<normaloff>:/icon_ceiling_dc</normaloff>:/icon_ceiling_dc</iconset>
</property>
<property name="text">
<string>Show Dc Ceiling</string>
</property>
</action>
<action name="profCalcCeiling">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../subsurface.qrc">
<normaloff>:/icon_ceiling_calculated</normaloff>:/icon_ceiling_calculated</iconset>
</property>
<property name="text">
<string>Calculate Ceiling</string>
</property>
</action>
<action name="profCalcAllTissues">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../subsurface.qrc">
<normaloff>:/icon_ceiling_alltissues</normaloff>:/icon_ceiling_alltissues</iconset>
</property>
<property name="text">
<string>Calculate All Tissues</string>
</property>
</action>
<action name="profIncrement3m">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../subsurface.qrc">
<normaloff>:/icon_ceiling_3m</normaloff>:/icon_ceiling_3m</iconset>
</property>
<property name="text">
<string>3m Increments</string>
</property>
</action>
<action name="profHR">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../subsurface.qrc">
<normaloff>:/icon_HR</normaloff>:/icon_HR</iconset>
</property>
<property name="text">
<string>Heart Rate</string>
</property>
</action>
<action name="profMod">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../subsurface.qrc">
<normaloff>:/icon_mod</normaloff>:/icon_mod</iconset>
</property>
<property name="text">
<string>Show Mod</string>
</property>
</action>
<action name="profEad">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../subsurface.qrc">
<normaloff>:/icon_ead</normaloff>:/icon_ead</iconset>
</property>
<property name="text">
<string>Show EAD</string>
</property>
</action>
<action name="profNdl_tts">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../subsurface.qrc">
<normaloff>:/icon_NDLTTS</normaloff>:/icon_NDLTTS</iconset>
</property>
<property name="text">
<string>Show NTL TTS</string>
</property>
</action>
<action name="profSAC">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../subsurface.qrc">
<normaloff>:/icon_lung</normaloff>:/icon_lung</iconset>
</property>
<property name="text">
<string>Show SAC</string>
</property>
</action>
<action name="profRuler">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../subsurface.qrc">
<normaloff>:/ruler</normaloff>:/ruler</iconset>
</property>
<property name="text">
<string>Show Ruler</string>
</property>
</action>
<action name="profScaled">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../subsurface.qrc">
<normaloff>:/scale</normaloff>:/scale</iconset>
</property>
<property name="text">
<string>Scale Graph</string>
</property>
</action>
<action name="profTogglePicture">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../subsurface.qrc">
<normaloff>:/pictures</normaloff>:/pictures</iconset>
</property>
<property name="text">
<string>Toggle Pictures</string>
</property>
</action>
<action name="profTankbar">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../subsurface.qrc">
<normaloff>:/gaschange</normaloff>:/gaschange</iconset>
</property>
<property name="text">
<string>Show Tank Bar</string>
</property>
</action>
</widget>

View file

@ -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));