Commit 5d709be6 authored by NICLAUSSE Nicolas's avatar NICLAUSSE Nicolas
Browse files

Merge branch...

Merge branch '61-advanced-parameters-display-triggered-by-switch-in-dtkwidgetsmenubar' into 'develop'

Resolve "Advanced parameters display triggered by switch in dtkWidgetsMenuBar"

Closes #61

See merge request !63
parents 8848fe19 bc7a2818
Pipeline #139460 passed with stage
in 0 seconds
......@@ -104,7 +104,7 @@
"parameter": {
"widget": "dtkWidgetsParameterLongLongSpinBox",
"uid": "spin_long",
"advanced": false,
"advanced": true,
"widget_read_only": false
}
},
......
......@@ -22,6 +22,7 @@
#include <dtkThemes/dtkThemesEngine>
#include <dtkFonts/dtkFontAwesome>
#include <dtkCore/dtkCoreParameter>
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsMainWindowPrivate
......@@ -29,15 +30,85 @@
class dtkWidgetsMainWindowPrivate
{
public:
dtkWidgetsMenu *populateAdvancedMenu(void);
dtkWidgetsMenu *populateThemesMenu(dtkWidgetsMenu *);
dtkWidgetsMenu *populateAboutMenu(dtkWidgetsMenu *);
QObject *populateAdvancedParametersSwitch(dtkWidgetsMenu *);
public:
dtkWidgetsMenuBar *menubar = nullptr;
public:
dtkWidgetsMenu *menu_files = nullptr;
dtkWidgetsMenu *menu_themes = nullptr;
dtkWidgetsMenu *menu_about = nullptr;
dtkWidgetsMenu *menu_config = nullptr;
};
dtkWidgetsMenu *dtkWidgetsMainWindowPrivate::populateAdvancedMenu(void)
{
if(!this->menu_config) {
this->menu_config = this->menubar->addMenu(fa::question, "Configuration");
this->populateThemesMenu(this->menu_config);
this->populateAdvancedParametersSwitch(this->menu_config);
// this->populateAboutMenu(this->menu_advanced);
}
return this->menu_config;
}
dtkWidgetsMenu *dtkWidgetsMainWindowPrivate::populateThemesMenu(dtkWidgetsMenu *menu)
{
dtkWidgetsMenu *menu_themes = menu->menu("Themes");
if(!menu_themes) {
menu_themes = menu->addMenu(fa::paintbrush, "Choose Themes");
for (const QString theme : dtkThemesEngine::instance()->themes()) {
dtkWidgetsMenuItem * item = menu_themes->addItem(new dtkWidgetsMenuItemTheme(theme));
QObject::connect(item, &dtkWidgetsMenuItem::clicked, [=] () {
dtkThemesEngine::instance()->apply(theme);
});
}
}
return menu_themes;
}
dtkWidgetsMenu *dtkWidgetsMainWindowPrivate::populateAboutMenu(dtkWidgetsMenu *menu)
{
dtkWidgetsMenu *menu_about = menu->menu("About");
if(!menu_about) {
menu_about = menu->addMenu(fa::question, "About");
menu_about->addMenu(fa::question, "dtk")->addItem(0, "todo");
}
return menu_about;
}
QObject *dtkWidgetsMainWindowPrivate::populateAdvancedParametersSwitch(dtkWidgetsMenu *menu)
{
QObject *switch_widget = menu->object("Switch");
if(!switch_widget) {
dtk::d_bool *switch_parameter = new dtk::d_bool("Advanced Parameters", false, false, true, "Shows / Hide the advanced parameters in the menu");
switch_parameter->setUid("menu_bar/switch_advanced_parameters");
switch_parameter->connect([=](QVariant v) {
if(!menubar) {
return;
}
menubar->advancedParametersDisplayed(v.value<dtk::d_bool>());
});
switch_widget = menu->addParameter("Toggle Advanced Parameters", switch_parameter, "dtkWidgetsParameterBoolCheckBox", true);
QObject::connect(switch_widget, &QWidget::destroyed, [=] () {
delete switch_parameter;
});
}
return switch_widget;
}
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsMainWindow
// ///////////////////////////////////////////////////////////////////
......@@ -64,57 +135,10 @@ dtkWidgetsMenuBar *dtkWidgetsMainWindow::menubar(void)
}
void dtkWidgetsMainWindow::populate(void)
{
// Q_UNUSED(this->populateFileMenu());
Q_UNUSED(this->populateThemesMenu());
// Q_UNUSED(this->populateAboutMenu());
}
dtkWidgetsMenu *dtkWidgetsMainWindow::populateFileMenu(void)
{
Q_UNUSED(this->menubar());
if(!d->menu_files) {
d->menu_files = d->menubar->insertMenu(0, fa::file, "Files");
d->menu_files->addItem(0, "Open");
d->menu_files->addItem(0, "Open Recent");
d->menu_files->addItem(0, "Save");
d->menu_files->addItem(0, "Save As");
}
return d->menu_files;
}
dtkWidgetsMenu *dtkWidgetsMainWindow::populateThemesMenu(void)
{
Q_UNUSED(this->menubar());
if(!d->menu_themes) {
d->menu_themes = d->menubar->addMenu(fa::paintbrush, "Themes");
auto *inner_menu_theme = d->menu_themes->addMenu(fa::paintbrush, "Choose Theme");
for (const QString theme : dtkThemesEngine::instance()->themes()) {
dtkWidgetsMenuItem * item = inner_menu_theme->addItem(new dtkWidgetsMenuItemTheme(theme));
connect(item, &dtkWidgetsMenuItem::clicked, [=] () {
dtkThemesEngine::instance()->apply(theme);
});
}
}
return d->menu_themes;
}
dtkWidgetsMenu *dtkWidgetsMainWindow::populateAboutMenu(void)
{
Q_UNUSED(this->menubar());
if(!d->menu_about) {
d->menu_about = d->menubar->addMenu(fa::question, "About");
d->menu_about->addMenu(fa::question, "dtk")->addItem(0, "prout");
d->menu_about->addMenu(fa::question, "dtk environment (conda)")->addItem(0, "Pour Come");
}
return d->menu_about;
Q_UNUSED(d->populateAdvancedMenu());
}
void dtkWidgetsMainWindow::resizeEvent(QResizeEvent *event)
......
......@@ -35,9 +35,6 @@ public:
public:
void populate(void);
dtkWidgetsMenu *populateFileMenu(void);
dtkWidgetsMenu *populateThemesMenu(void);
dtkWidgetsMenu *populateAboutMenu(void);
protected:
void resizeEvent(QResizeEvent *event);
......
......@@ -12,10 +12,14 @@
// Code:
#include "dtkWidgetsMainWindow.h"
#include "dtkWidgetsParameter.h" // TODO: Rename to dtkWidgetsParameterBase.h
#include "dtkWidgetsMenu+ux.h"
#include "dtkWidgetsParameter.h"
#include "dtkWidgetsMenuItem+custom.h"
#include "dtkWidgetsMenuBar.h"
#include <dtkApplication.h>
#include <dtkFonts/dtkFontAwesome>
......@@ -236,17 +240,10 @@ dtkWidgetsMenuItemParameterFacade::dtkWidgetsMenuItemParameterFacade(dtkWidgetsM
layout->setRowWrapPolicy(QFormLayout::WrapAllRows);
layout->addRow(source->title(), source->widget());
if (source->widget()->advanced()) {
if (source->widget()->advanced() && !dtkApp->window()->menubar()->isAdvancedParametersDisplayed()) {
this->hide();
}
this->param_connect = connect(source->widget(), &dtkWidgetsParameter::advancedChanged, [this] (bool advanced) {
if (advanced)
this->hide();
else
this->show();
});
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
}
......
......@@ -1142,6 +1142,19 @@ QWidget *dtkWidgetsMenuBar::container(void)
return d->c;
}
void dtkWidgetsMenuBar::advancedParametersDisplayed(bool display)
{
if(display != d->advanced_parameters_displayed) {
d->advanced_parameters_displayed = display;
this->touch();
}
}
bool dtkWidgetsMenuBar::isAdvancedParametersDisplayed(void)
{
return d->advanced_parameters_displayed;
}
// /////////////////////////////////////////////////////////////////////////////
#include "dtkWidgetsMenuBar.moc"
......
......@@ -59,6 +59,11 @@ public:
public:
QWidget *container(void);
#pragma mark - Handling of advanced parameters
void advancedParametersDisplayed(bool);
bool isAdvancedParametersDisplayed(void);
// /////////////////////////////////////////////////////////////////////////////
#pragma mark - Convenience builders
// /////////////////////////////////////////////////////////////////////////////
......
......@@ -162,6 +162,9 @@ public:
public:
bool interactive = true;
public:
bool advanced_parameters_displayed = false;
};
//
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment