Commit 1aa42527 authored by LE BRETON Come's avatar LE BRETON Come

Instanciate all the facades at each touch, outside the menus.

parent c6fd5163
......@@ -28,6 +28,45 @@ static QColor fg_color = QColor("#88ffffff");
static int padding = 5;
static int margin = 10;
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsMenuHelper
// ///////////////////////////////////////////////////////////////////
namespace dtkWidgetsMenuHelper {
static int margin = 16/2;
QWidget *build(QObject *source)
{
if(dtkWidgetsMenu *menu = dynamic_cast<dtkWidgetsMenu *>(source)) {
return new dtkWidgetsMenuInnerFacade(menu);
} else if(dtkWidgetsMenuItem *item = dynamic_cast<dtkWidgetsMenuItem *>(source)) {
if (item->isParameter()) {
return new dtkWidgetsMenuItemParameterFacade(static_cast<dtkWidgetsMenuItemParameter *>(item));
} else if (item->isCustom()) {
return new dtkWidgetsMenuItemCustomFacade(static_cast<dtkWidgetsMenuItemCustom *>(item));
} else if (item->isSeparator()) {
return new dtkWidgetsMenuItemSpacerFacade(margin, margin);
} else {
return new dtkWidgetsMenuItemFacade(item);
}
}
return nullptr;
}
}
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsMenuNavigationFacade
// ///////////////////////////////////////////////////////////////////
......@@ -232,6 +271,10 @@ dtkWidgetsMenuFacade::dtkWidgetsMenuFacade(dtkWidgetsMenu *m, QWidget *parent) :
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(1);
layout->setAlignment(Qt::AlignTop);
for (QObject *object : m->objects()) {
this->addWidget(dtkWidgetsMenuHelper::build(object));
}
}
dtkWidgetsMenuFacade::~dtkWidgetsMenuFacade(void)
......
......@@ -18,57 +18,6 @@
#include <dtkFonts>
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsMenuHelper
// ///////////////////////////////////////////////////////////////////
namespace dtkWidgetsMenuHelper {
static int margin = 16/2;
QWidget *build(QObject *source)
{
// qDebug() << Q_FUNC_INFO << 0;
if(dtkWidgetsMenu *menu = dynamic_cast<dtkWidgetsMenu *>(source)) {
return new dtkWidgetsMenuInnerFacade(menu);
} else if(dtkWidgetsMenuItem *item = dynamic_cast<dtkWidgetsMenuItem *>(source)) {
// qDebug() << Q_FUNC_INFO << 1 << item->title();
if (item->isParameter()) {
// qDebug() << Q_FUNC_INFO << 2;
return new dtkWidgetsMenuItemParameterFacade(static_cast<dtkWidgetsMenuItemParameter *>(item));
} else if (item->isCustom()) {
// qDebug() << Q_FUNC_INFO << 3;
return new dtkWidgetsMenuItemCustomFacade(static_cast<dtkWidgetsMenuItemCustom *>(item));
} else if (item->isSeparator()) {
// qDebug() << Q_FUNC_INFO << 4;
return new dtkWidgetsMenuItemSpacerFacade(margin, margin);
} else {
// qDebug() << Q_FUNC_INFO << 5;
return new dtkWidgetsMenuItemFacade(item);
}
}
return nullptr;
}
}
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsMenuPrivate
// ///////////////////////////////////////////////////////////////////
......@@ -85,10 +34,6 @@ public:
public:
int icon_id;
public:
dtkWidgetsMenuFacade *widget = nullptr;
dtkWidgetsMenuHeaderFacade *header = nullptr;
};
// ///////////////////////////////////////////////////////////////////
......@@ -99,6 +44,7 @@ dtkWidgetsMenu::dtkWidgetsMenu(int icon_id, const QString& title, QObject *paren
{
d->title = title;
d->icon_id = icon_id;
}
dtkWidgetsMenu::~dtkWidgetsMenu(void)
......@@ -133,30 +79,6 @@ dtkWidgetsMenu *dtkWidgetsMenu::addMenu(int icon_id, const QString& title)
return m;
}
dtkWidgetsMenuFacade *dtkWidgetsMenu::widget(void)
{
// if( d->widget) {
// delete d->widget;
// }
d->widget = new dtkWidgetsMenuFacade(this);
for (QObject *object : d->object_list) {
d->widget->addWidget(dtkWidgetsMenuHelper::build(object));
}
return d->widget;
}
dtkWidgetsMenuHeaderFacade *dtkWidgetsMenu::header(void)
{
// if(!d->header) {
d->header = new dtkWidgetsMenuHeaderFacade(this);
// }
return d->header;
}
void dtkWidgetsMenu::clear(void)
{
d->object_hash.clear();
......@@ -239,6 +161,11 @@ QObject *dtkWidgetsMenu::object(const QString& id)
return d->object_hash[id];
}
QVector<QObject *> dtkWidgetsMenu::objects(void) const
{
return d->object_list;
}
int dtkWidgetsMenu::icon(void) const
{
return d->icon_id;
......
......@@ -60,12 +60,6 @@ public:
dtkWidgetsMenuItem *addParameter(dtkWidgetsMenuItem *item);
dtkWidgetsMenuItem *addParameter(const QString&, dtkCoreParameter *, const QString& representation);
#pragma mark - UI inference
public slots:
dtkWidgetsMenuFacade *widget(void);
dtkWidgetsMenuHeaderFacade *header(void);
#pragma mark -
public slots:
......@@ -78,6 +72,8 @@ public:
QObject *object(const QString&);
QVector<QObject *> objects(void) const;
public:
int icon(void) const;
......
This diff is collapsed.
......@@ -93,6 +93,7 @@ public:
public:
void touch(dtkWidgetsMenuBar *);
void touch(dtkWidgetsMenu *);
private:
dtkWidgetsMenu *menu = nullptr;
......
......@@ -40,9 +40,6 @@ public:
public:
QVBoxLayout *layout;
public:
QPropertyAnimation *animation;
};
// /////////////////////////////////////////////////////////////////////////////
......@@ -54,10 +51,6 @@ dtkWidgetsOverlayPane::dtkWidgetsOverlayPane(QWidget *parent) : QFrame(parent)
d = new dtkWidgetsOverlayPanePrivate;
d->width = 0;
d->animation = new QPropertyAnimation(this, "width");
d->animation->setDuration(::duration);
d->animation->setEasingCurve(QEasingCurve::OutQuad);
d->layout = new QVBoxLayout;
d->layout->setAlignment(Qt::AlignTop);
d->layout->setContentsMargins(0, 0, 0, 0);
......@@ -111,14 +104,13 @@ void dtkWidgetsOverlayPane::toggle(void)
qlonglong stt = d->on ? d->bound : 0;
qlonglong end = d->on ? 0 : d->bound;
if (d->animation->state() == QAbstractAnimation::Running) {
d->animation->stop();
stt = d->animation->currentValue().toInt();
}
QPropertyAnimation *animation = new QPropertyAnimation(this, "width");
animation->setDuration(::duration);
animation->setEasingCurve(QEasingCurve::OutQuad);
d->animation->setStartValue(stt);
d->animation->setEndValue(end);
d->animation->start();
animation->setStartValue(stt);
animation->setEndValue(end);
animation->start(QAbstractAnimation::DeleteWhenStopped);
d->on = !d->on;
}
......@@ -131,19 +123,16 @@ void dtkWidgetsOverlayPane::toggle(std::function<void (void)>& callback)
qlonglong stt = d->on ? d->bound : 0;
qlonglong end = d->on ? 0 : d->bound;
if (d->animation->state() == QAbstractAnimation::Running) {
d->animation->stop();
stt = d->animation->currentValue().toInt();
}
QPropertyAnimation *animation = new QPropertyAnimation(this, "width");
animation->setDuration(::duration);
animation->setEasingCurve(QEasingCurve::OutQuad);
d->animation->setStartValue(stt);
d->animation->setEndValue(end);
d->animation->start();
connect(animation, &QAbstractAnimation::finished, callback);
d->animation->disconnect();
animation->setStartValue(stt);
animation->setEndValue(end);
animation->start(QAbstractAnimation::DeleteWhenStopped);
connect(d->animation, &QAbstractAnimation::finished, callback);
d->on = !d->on;
}
......
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