Commit 7605e8d4 authored by LE BRETON Come's avatar LE BRETON Come

Adds int slider and bool push button.

parent cb47e2e1
......@@ -228,7 +228,7 @@ bool dummyEventFilter::eventFilter(QObject *object, QEvent *event)
qDebug() << "Ate key mouse event for" << object;
return true;
} else {
return QObject::eventFilter(object, event);
......@@ -303,11 +303,11 @@ dummy::dummy(void) : QMainWindow(0)
QString placeholder = "SubSub";
dtkWidgetsMenu *m = this->menu_22->addMenu(fa::home, QString("%1Level3").arg(placeholder));
for(int i = 0; i < 10; i++) {
placeholder += "Sub";
m->addItem(fa::home, QString("%1Level1").arg(placeholder));
dtkWidgetsMenu *menu = m->addMenu(fa::home, QString("%1Level2").arg(placeholder));
m->addItem(fa::home, QString("%1Level3").arg(placeholder));
......@@ -316,13 +316,13 @@ dummy::dummy(void) : QMainWindow(0)
m = menu;
}
this->menubar->addMenu(this->menu_1);
this->menubar->addMenu(this->menu_2);
this->menubar->addMenu(this->menu_3);
for(int i = 0; i < 15; i++) {
dtkWidgetsMenu *menu = this->menubar->addMenu(fa::circlethin, QString("Dummy %1").arg(i));
for(int j = 0; j < 5; j++)
......@@ -333,7 +333,7 @@ dummy::dummy(void) : QMainWindow(0)
for(int j = 0; j < 5; j++)
menu->addItem(fa::circleo, QString("DummyItem %1").arg(j + 5));
}
this->menubar->build();
this->setStyleSheet(m_style);
......
......@@ -69,10 +69,14 @@ set(${PROJECT_NAME}_HEADERS
dtkWidgetsParameter.h
dtkWidgetsParameterBoolCheckBox
dtkWidgetsParameterBoolCheckBox.h
dtkWidgetsParameterBoolPushButton
dtkWidgetsParameterBoolPushButton.h
dtkWidgetsParameterDoubleSpinBox
dtkWidgetsParameterDoubleSpinBox.h
dtkWidgetsParameterFactory
dtkWidgetsParameterFactory.h
dtkWidgetsParameterIntSlider
dtkWidgetsParameterIntSlider.h
dtkWidgetsParameterIntSpinBox
dtkWidgetsParameterIntSpinBox.h
dtkWidgetsParameterMenuBarGenerator
......@@ -112,7 +116,9 @@ set(${PROJECT_NAME}_SOURCES
dtkWidgetsOverlayRope.cpp
dtkWidgetsParameter.cpp
dtkWidgetsParameterBoolCheckBox.cpp
dtkWidgetsParameterBoolPushButton.cpp
dtkWidgetsParameterDoubleSpinBox.cpp
dtkWidgetsParameterIntSlider.cpp
dtkWidgetsParameterIntSpinBox.cpp
dtkWidgetsParameterFactory.cpp
dtkWidgetsParameterMenuBarGenerator.cpp
......
......@@ -21,7 +21,9 @@
#include "dtkWidgetsSettings.h"
#include "dtkWidgetsParameterBoolCheckBox.h"
#include "dtkWidgetsParameterBoolPushButton.h"
#include "dtkWidgetsParameterDoubleSpinBox.h"
#include "dtkWidgetsParameterIntSlider.h"
#include "dtkWidgetsParameterIntSpinBox.h"
#include "dtkWidgetsParameterStringBrowseFile.h"
#include "dtkWidgetsParameterStringListComboBox.h"
......@@ -64,7 +66,9 @@ namespace dtk {
// Initializes default plugins
// ///////////////////////////////////////////////////////////////////
dtk::widgets::parameters::pluginFactory().record("dtkWidgetsParameterBoolCheckBox", dtkWidgetsParameterBoolCheckBoxCreator);
dtk::widgets::parameters::pluginFactory().record("dtkWidgetsParameterBoolPushButton", dtkWidgetsParameterBoolPushButtonCreator);
dtk::widgets::parameters::pluginFactory().record("dtkWidgetsParameterDoubleSpinBox", dtkWidgetsParameterDoubleSpinBoxCreator);
dtk::widgets::parameters::pluginFactory().record("dtkWidgetsParameterIntSlider", dtkWidgetsParameterIntSliderCreator);
dtk::widgets::parameters::pluginFactory().record("dtkWidgetsParameterIntSpinBox", dtkWidgetsParameterIntSpinBoxCreator);
dtk::widgets::parameters::pluginFactory().record("dtkWidgetsParameterStringBrowseFile", dtkWidgetsParameterStringBrowseFileCreator);
dtk::widgets::parameters::pluginFactory().record("dtkWidgetsParameterStringListComboBox", dtkWidgetsParameterStringListComboBoxCreator);
......
#include "dtkWidgetsParameterBoolPushButton.h"
\ No newline at end of file
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkWidgetsParameterBoolPushButton.h"
#include <dtkLog>
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsParameterBoolPushButtonPrivate declaration
// ///////////////////////////////////////////////////////////////////
class dtkWidgetsParameterBoolPushButtonPrivate
{
public:
QPushButton *push_button = nullptr;
bool running = false;
};
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsParameterBoolPushButton implementation
// ///////////////////////////////////////////////////////////////////
dtkWidgetsParameterBoolPushButton::dtkWidgetsParameterBoolPushButton(QWidget* parent) : dtkWidgetsParameterBase<dtk::d_bool>(parent), d(new dtkWidgetsParameterBoolPushButtonPrivate)
{
d->push_button = new QPushButton;
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(d->push_button);
this->setLayout(layout);
}
dtkWidgetsParameterBoolPushButton::~dtkWidgetsParameterBoolPushButton(void)
{
delete d;
}
bool dtkWidgetsParameterBoolPushButton::connect(dtkCoreAbstractParameter *p)
{
if (!p) {
qWarning() << Q_FUNC_INFO << "The input parameter is null. Nothing is done.";
return false;
}
m_parameter = dynamic_cast<dtk::d_bool *>(p);
if(!m_parameter) {
qWarning() << Q_FUNC_INFO << "The type of the parameter is not compatible with the widget dtkWidgetsParameterBoolPushButton.";
return false;
}
d->push_button->setToolTip(m_parameter->documentation());
d->running = p->variant().value<dtk::d_bool>().value();
if(d->running) {
qWarning() << Q_FUNC_INFO << "It is not advised to set d_bool parameter to on before connecting";
}
auto setAppearance = [this] (bool state) {
if (state) {
this->d->push_button->setStyleSheet("background-color: red");
this->d->push_button->setText("Running...");
} else {
this->d->push_button->setStyleSheet("");
this->d->push_button->setText("Run");
}
};
setAppearance(d->running);
m_parameter->connect([=] (QVariant v)
{
bool state = v.value<dtk::d_bool>().value();
d->push_button->blockSignals(true);
setAppearance(state);
d->push_button->blockSignals(false);
});
QObject::connect(d->push_button, &QPushButton::clicked, [=] ()
{
if(d->running) {
d->running = false;
} else {
d->running = true;
}
m_parameter->setValue(d->running);
});
return true;
}
//
// dtkWidgetsParameterBoolPushButtonWidget.cpp ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <dtkWidgetsExport>
#include "dtkWidgetsParameter.h"
#include <dtkCore/dtkCoreParameter>
#include <QtWidgets>
class DTKWIDGETS_EXPORT dtkWidgetsParameterBoolPushButton : public dtkWidgetsParameterBase<dtk::d_bool>
{
Q_OBJECT
public:
dtkWidgetsParameterBoolPushButton(QWidget* parent = 0);
~dtkWidgetsParameterBoolPushButton(void);
public:
bool connect(dtkCoreAbstractParameter *) override;
private:
using dtkWidgetsParameterBase<dtk::d_bool>::m_parameter;
class dtkWidgetsParameterBoolPushButtonPrivate *d;
};
// ///////////////////////////////////////////////////////////////////
inline dtkWidgetsParameter *dtkWidgetsParameterBoolPushButtonCreator(void)
{
return new dtkWidgetsParameterBoolPushButton();
}
//
// dtkWidgetsParameterBoolPushButton.h ends here
#include "dtkWidgetsParameterIntSlider.h"
\ No newline at end of file
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkWidgetsParameterIntSlider.h"
#include <dtkLog>
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsParameterIntSliderPrivate declaration
// ///////////////////////////////////////////////////////////////////
class dtkWidgetsParameterIntSliderPrivate
{
public:
QSlider *slider = nullptr;
};
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsParameterIntSlider implementation
// ///////////////////////////////////////////////////////////////////
dtkWidgetsParameterIntSlider::dtkWidgetsParameterIntSlider(QWidget* parent) : dtkWidgetsParameterBase<dtk::d_int>(parent), d(new dtkWidgetsParameterIntSliderPrivate)
{
d->slider = new QSlider;
d->slider->setOrientation(Qt::Horizontal);
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(d->slider);
this->setLayout(layout);
}
dtkWidgetsParameterIntSlider::~dtkWidgetsParameterIntSlider(void)
{
delete d;
}
bool dtkWidgetsParameterIntSlider::connect(dtkCoreAbstractParameter *p)
{
if (!p) {
qWarning() << Q_FUNC_INFO << "The input parameter is null. Nothing is done.";
return false;
}
m_parameter = dynamic_cast<dtk::d_int *>(p);
if(!m_parameter) {
qWarning() << Q_FUNC_INFO << "The type of the parameter is not compatible with the widget dtkWidgetsParameterIntSlider.";
return false;
}
d->slider->setMinimum(m_parameter->min());
qDebug() << "min" << m_parameter->min();
qDebug() << "max" << m_parameter->max();
d->slider->setMaximum(m_parameter->max());
d->slider->setToolTip(m_parameter->documentation());
d->slider->setValue(m_parameter->value());
m_parameter->connect([=] (QVariant v)
{
int value = v.value<dtk::d_int>().value();
d->slider->blockSignals(true);
d->slider->setValue(value);
d->slider->blockSignals(false);
});
QObject::connect(d->slider, QOverload<int>::of(&QSlider::valueChanged), [=] (int v)
{
m_parameter->block(true);
m_parameter->setValue(v);
m_parameter->block(false);
});
return true;
}
//
// dtkWidgetsParameterIntSliderWidget.cpp ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <dtkWidgetsExport>
#include "dtkWidgetsParameter.h"
#include <dtkCore/dtkCoreParameter>
#include <QtWidgets>
class DTKWIDGETS_EXPORT dtkWidgetsParameterIntSlider : public dtkWidgetsParameterBase<dtk::d_int>
{
Q_OBJECT
public:
dtkWidgetsParameterIntSlider(QWidget* parent = 0);
~dtkWidgetsParameterIntSlider(void);
public:
bool connect(dtkCoreAbstractParameter *) override;
private:
using dtkWidgetsParameterBase<dtk::d_int>::m_parameter;
class dtkWidgetsParameterIntSliderPrivate *d;
};
// ///////////////////////////////////////////////////////////////////
inline dtkWidgetsParameter *dtkWidgetsParameterIntSliderCreator(void)
{
return new dtkWidgetsParameterIntSlider();
}
//
// dtkWidgetsParameterIntSlider.h ends here
......@@ -69,7 +69,7 @@ bool dtkWidgetsParameterStringBrowseFile::connect(dtkCoreAbstractParameter *p)
QObject::connect(d->push_button, &QPushButton::clicked, [=] ()
{
QString path = "/tmp/";
m_parameter->setValue(QFileDialog::getOpenFileName(this, "Input Video", path, tr("Video File (*.mp4 *.avi *.ogg)")));
m_parameter->setValue(QFileDialog::getOpenFileName(this, "Input", path, tr("File (*)")));
});
return true;
......
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