2017-04-27 18:26:05 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2013-04-14 03:44:02 +00:00
|
|
|
/*
|
|
|
|
* maintab.cpp
|
|
|
|
*
|
2022-03-05 16:25:49 +00:00
|
|
|
* "notebook" area of the main window of Subsurface
|
2013-04-14 03:44:02 +00:00
|
|
|
*
|
|
|
|
*/
|
2022-03-05 16:25:49 +00:00
|
|
|
#include "maintab.h"
|
2015-06-01 19:58:23 +00:00
|
|
|
|
2019-04-13 15:43:45 +00:00
|
|
|
#include "TabDiveEquipment.h"
|
2017-04-04 17:21:30 +00:00
|
|
|
#include "TabDiveExtraInfo.h"
|
|
|
|
#include "TabDiveInformation.h"
|
2022-03-05 16:25:49 +00:00
|
|
|
#include "TabDiveNotes.h"
|
2017-04-04 17:21:30 +00:00
|
|
|
#include "TabDivePhotos.h"
|
|
|
|
#include "TabDiveStatistics.h"
|
|
|
|
|
2022-03-05 16:25:49 +00:00
|
|
|
#include "core/selection.h"
|
|
|
|
#include "desktop-widgets/simplewidgets.h" // for isGnome3Session()
|
|
|
|
#include "qt-models/diveplannermodel.h"
|
2013-04-07 22:20:43 +00:00
|
|
|
|
2022-03-05 16:25:49 +00:00
|
|
|
#include <QShortcut>
|
2019-04-13 16:14:50 +00:00
|
|
|
|
2020-11-04 21:09:44 +00:00
|
|
|
static bool paletteIsDark(const QPalette &p)
|
|
|
|
{
|
|
|
|
// we consider a palette dark if the text color is lighter than the windows background
|
|
|
|
return p.window().color().valueF() < p.windowText().color().valueF();
|
|
|
|
}
|
|
|
|
|
2013-04-07 22:20:43 +00:00
|
|
|
MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
|
2018-03-15 21:41:59 +00:00
|
|
|
lastSelectedDive(true),
|
2017-11-30 19:33:43 +00:00
|
|
|
lastTabSelectedDive(0),
|
2022-03-05 16:25:49 +00:00
|
|
|
lastTabSelectedDiveTrip(0)
|
2013-04-07 22:20:43 +00:00
|
|
|
{
|
2022-03-05 16:25:49 +00:00
|
|
|
extraWidgets << new TabDiveNotes(this);
|
2022-03-12 14:15:05 +00:00
|
|
|
addTab(extraWidgets.last(), tr("Notes"));
|
2020-04-13 17:26:29 +00:00
|
|
|
extraWidgets << new TabDiveEquipment(this);
|
2022-03-12 14:15:05 +00:00
|
|
|
addTab(extraWidgets.last(), tr("Equipment"));
|
2020-04-13 17:26:29 +00:00
|
|
|
extraWidgets << new TabDiveInformation(this);
|
2022-03-12 14:15:05 +00:00
|
|
|
addTab(extraWidgets.last(), tr("Information"));
|
2020-04-13 17:26:29 +00:00
|
|
|
extraWidgets << new TabDiveStatistics(this);
|
2022-03-12 14:15:05 +00:00
|
|
|
addTab(extraWidgets.last(), tr("Summary"));
|
2020-04-13 17:26:29 +00:00
|
|
|
extraWidgets << new TabDivePhotos(this);
|
2022-03-12 14:15:05 +00:00
|
|
|
addTab(extraWidgets.last(), tr("Media"));
|
2020-04-13 17:26:29 +00:00
|
|
|
extraWidgets << new TabDiveExtraInfo(this);
|
2022-03-12 14:15:05 +00:00
|
|
|
addTab(extraWidgets.last(), tr("Extra Info"));
|
2017-04-04 17:21:30 +00:00
|
|
|
|
2020-11-04 21:09:44 +00:00
|
|
|
// make sure we know if this is a light or dark mode
|
|
|
|
isDark = paletteIsDark(palette());
|
|
|
|
|
2020-11-02 20:36:29 +00:00
|
|
|
// call colorsChanged() for the initial setup now that the extraWidgets are loaded
|
|
|
|
colorsChanged();
|
|
|
|
|
2020-11-24 11:50:52 +00:00
|
|
|
connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &MainTab::updateDiveInfo);
|
2019-02-24 20:22:33 +00:00
|
|
|
|
2014-06-03 22:29:28 +00:00
|
|
|
QShortcut *closeKey = new QShortcut(QKeySequence(Qt::Key_Escape), this);
|
2022-02-19 11:53:52 +00:00
|
|
|
connect(closeKey, &QShortcut::activated, this, &MainTab::escDetected);
|
2014-06-03 22:29:28 +00:00
|
|
|
|
2013-09-26 20:02:27 +00:00
|
|
|
if (qApp->style()->objectName() == "oxygen")
|
2013-09-26 19:51:11 +00:00
|
|
|
setDocumentMode(true);
|
2013-09-26 20:02:27 +00:00
|
|
|
else
|
|
|
|
setDocumentMode(false);
|
|
|
|
|
2013-09-27 15:52:01 +00:00
|
|
|
// Current display of things on Gnome3 looks like shit, so
|
2019-04-13 15:43:45 +00:00
|
|
|
// let's fix that.
|
2013-09-27 15:52:01 +00:00
|
|
|
if (isGnome3Session()) {
|
2022-03-05 16:25:49 +00:00
|
|
|
// TODO: Either do this for all scroll areas or none
|
|
|
|
//QPalette p;
|
|
|
|
//p.setColor(QPalette::Window, QColor(Qt::white));
|
|
|
|
//ui.scrollArea->viewport()->setPalette(p);
|
2013-12-04 20:24:37 +00:00
|
|
|
|
|
|
|
// GroupBoxes in Gnome3 looks like I'v drawn them...
|
2019-04-01 21:15:23 +00:00
|
|
|
static const QString gnomeCss = QStringLiteral(
|
2013-12-04 20:24:37 +00:00
|
|
|
"QGroupBox {"
|
2019-04-01 21:15:23 +00:00
|
|
|
"background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
|
|
|
|
"stop: 0 #E0E0E0, stop: 1 #FFFFFF);"
|
|
|
|
"border: 2px solid gray;"
|
|
|
|
"border-radius: 5px;"
|
|
|
|
"margin-top: 1ex;"
|
2013-12-04 20:24:37 +00:00
|
|
|
"}"
|
|
|
|
"QGroupBox::title {"
|
2019-04-01 21:15:23 +00:00
|
|
|
"subcontrol-origin: margin;"
|
|
|
|
"subcontrol-position: top center;"
|
|
|
|
"padding: 0 3px;"
|
|
|
|
"background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
|
|
|
|
"stop: 0 #E0E0E0, stop: 1 #FFFFFF);"
|
2013-12-04 20:24:37 +00:00
|
|
|
"}");
|
2022-03-05 16:25:49 +00:00
|
|
|
for (QGroupBox *box: findChildren<QGroupBox *>())
|
2013-12-04 20:24:37 +00:00
|
|
|
box->setStyleSheet(gnomeCss);
|
2013-09-27 15:52:01 +00:00
|
|
|
}
|
2014-12-23 18:16:11 +00:00
|
|
|
// QLineEdit and QLabels should have minimal margin on the left and right but not waste vertical space
|
2015-01-02 20:42:02 +00:00
|
|
|
QMargins margins(3, 2, 1, 0);
|
2022-03-05 16:25:49 +00:00
|
|
|
for (QLabel *label: findChildren<QLabel *>())
|
2014-12-23 18:16:11 +00:00
|
|
|
label->setContentsMargins(margins);
|
2019-02-24 20:22:33 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 06:12:46 +00:00
|
|
|
void MainTab::nextInputField(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
keyPressEvent(event);
|
|
|
|
}
|
|
|
|
|
2019-03-29 17:29:08 +00:00
|
|
|
void MainTab::updateDiveInfo()
|
2013-05-06 16:23:14 +00:00
|
|
|
{
|
2022-02-19 11:53:52 +00:00
|
|
|
// don't execute this while planning a dive
|
|
|
|
if (DivePlannerPointsModel::instance()->isPlanner())
|
2013-11-12 07:33:27 +00:00
|
|
|
return;
|
2019-04-12 18:33:43 +00:00
|
|
|
|
2022-09-18 11:49:29 +00:00
|
|
|
// If there is no current dive, disable all widgets.
|
2019-04-12 18:33:43 +00:00
|
|
|
bool enabled = current_dive != nullptr;
|
2022-09-18 11:49:29 +00:00
|
|
|
for (TabBase *widget: extraWidgets)
|
|
|
|
widget->setEnabled(enabled);
|
2019-04-12 18:33:43 +00:00
|
|
|
|
2019-03-29 17:29:08 +00:00
|
|
|
if (current_dive) {
|
2020-04-13 17:01:36 +00:00
|
|
|
for (TabBase *widget: extraWidgets)
|
|
|
|
widget->updateData();
|
2022-03-05 16:25:49 +00:00
|
|
|
if (single_selected_trip()) {
|
2019-05-04 12:23:46 +00:00
|
|
|
// Remember the tab selected for last dive but only if we're not on the dive site tab
|
2022-09-18 11:49:29 +00:00
|
|
|
if (lastSelectedDive)
|
2022-03-12 14:15:05 +00:00
|
|
|
lastTabSelectedDive = currentIndex();
|
|
|
|
setTabText(0, tr("Trip notes"));
|
2019-05-04 12:23:46 +00:00
|
|
|
// Recover the tab selected for last dive trip but only if we're not on the dive site tab
|
2022-09-18 11:49:29 +00:00
|
|
|
if (lastSelectedDive)
|
2022-03-12 14:15:05 +00:00
|
|
|
setCurrentIndex(lastTabSelectedDiveTrip);
|
2017-11-30 19:33:43 +00:00
|
|
|
lastSelectedDive = false;
|
2013-06-14 16:17:46 +00:00
|
|
|
} else {
|
2019-05-04 12:23:46 +00:00
|
|
|
// Remember the tab selected for last dive trip but only if we're not on the dive site tab
|
2022-09-18 11:49:29 +00:00
|
|
|
if (!lastSelectedDive)
|
2022-03-12 14:15:05 +00:00
|
|
|
lastTabSelectedDiveTrip = currentIndex();
|
|
|
|
setTabText(0, tr("Notes"));
|
2019-05-04 12:23:46 +00:00
|
|
|
// Recover the tab selected for last dive but only if we're not on the dive site tab
|
2022-09-18 11:49:29 +00:00
|
|
|
if (!lastSelectedDive)
|
2022-03-12 14:15:05 +00:00
|
|
|
setCurrentIndex(lastTabSelectedDive);
|
2017-11-30 19:33:43 +00:00
|
|
|
lastSelectedDive = true;
|
2013-06-14 16:17:46 +00:00
|
|
|
}
|
2013-05-08 19:08:00 +00:00
|
|
|
} else {
|
2017-04-04 17:21:30 +00:00
|
|
|
clearTabs();
|
2013-05-08 19:08:00 +00:00
|
|
|
}
|
2013-05-18 23:42:59 +00:00
|
|
|
}
|
2013-05-20 13:25:16 +00:00
|
|
|
|
2019-04-01 19:07:51 +00:00
|
|
|
// Remove focus from any active field to update the corresponding value in the dive.
|
|
|
|
// Do this by setting the focus to ourself
|
|
|
|
void MainTab::stealFocus()
|
|
|
|
{
|
|
|
|
setFocus();
|
|
|
|
}
|
|
|
|
|
2014-06-03 22:29:28 +00:00
|
|
|
void MainTab::escDetected()
|
|
|
|
{
|
2022-02-19 11:53:52 +00:00
|
|
|
stealFocus();
|
2014-06-03 22:29:28 +00:00
|
|
|
}
|
2014-06-27 12:17:33 +00:00
|
|
|
|
2019-02-23 17:31:02 +00:00
|
|
|
void MainTab::clearTabs()
|
|
|
|
{
|
|
|
|
for (auto widget: extraWidgets)
|
2017-04-04 17:21:30 +00:00
|
|
|
widget->clear();
|
2015-10-20 20:36:59 +00:00
|
|
|
}
|
2020-11-02 20:10:33 +00:00
|
|
|
|
2020-11-04 21:09:44 +00:00
|
|
|
void MainTab::changeEvent(QEvent *ev)
|
|
|
|
{
|
|
|
|
if (ev->type() == QEvent::PaletteChange) {
|
|
|
|
// check if this is a light or dark mode
|
|
|
|
bool dark = paletteIsDark(palette());
|
|
|
|
if (dark != isDark) {
|
|
|
|
// things have changed, so setup the colors correctly
|
|
|
|
isDark = dark;
|
|
|
|
colorsChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QTabWidget::changeEvent(ev);
|
|
|
|
}
|
|
|
|
|
2020-11-02 20:36:29 +00:00
|
|
|
// setup the colors of 'header' elements in the tab widget
|
2020-11-02 20:10:33 +00:00
|
|
|
void MainTab::colorsChanged()
|
|
|
|
{
|
2020-11-04 21:09:44 +00:00
|
|
|
QString colorText = isDark ? QStringLiteral("lightblue") : QStringLiteral("mediumblue");
|
2020-11-02 20:36:29 +00:00
|
|
|
QString lastpart = colorText + " ;}";
|
|
|
|
|
|
|
|
// only set the color if the widget is enabled
|
|
|
|
QString CSSLabelcolor = "QLabel:enabled { color: " + lastpart;
|
|
|
|
QString CSSTitlecolor = "QGroupBox::title:enabled { color: " + lastpart ;
|
|
|
|
|
|
|
|
// apply to all the group boxes
|
|
|
|
QList<QGroupBox *>groupBoxes = this->findChildren<QGroupBox *>();
|
|
|
|
for (QGroupBox *gb: groupBoxes)
|
|
|
|
gb->setStyleSheet(QString(CSSTitlecolor));
|
|
|
|
|
|
|
|
// apply to all labels that are marked as headers in the .ui file
|
|
|
|
QList<QLabel *>labels = this->findChildren<QLabel *>();
|
|
|
|
for (QLabel *ql: labels) {
|
|
|
|
if (ql->property("isHeader").toBool())
|
|
|
|
ql->setStyleSheet(QString(CSSLabelcolor));
|
|
|
|
}
|
|
|
|
|
|
|
|
// finally call the individual updateUi() functions so they can overwrite these style sheets
|
2020-11-02 20:10:33 +00:00
|
|
|
for (TabBase *widget: extraWidgets)
|
2020-11-04 21:09:44 +00:00
|
|
|
widget->updateUi(colorText);
|
2020-11-02 20:10:33 +00:00
|
|
|
}
|