Commit cc00ff72 authored by WINTZ Julien's avatar WINTZ Julien

Extending menu framework

parent 827e097d
......@@ -249,6 +249,19 @@ void dtkWidgetsMenuBarButton::leaveEvent(QEvent *)
//
// /////////////////////////////////////////////////////////////////////////////
dtkWidgetsMenuBarContainerSlide::dtkWidgetsMenuBarContainerSlide(dtkWidgetsMenuBarContainer *parent) : QFrame(parent)
{
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->setAlignment(Qt::AlignTop);
this->setAttribute(Qt::WA_NoSystemBackground);
this->setAttribute(Qt::WA_TranslucentBackground);
}
dtkWidgetsMenuBarContainerSlide::dtkWidgetsMenuBarContainerSlide(dtkWidgetsMenu *m, dtkWidgetsMenuBarContainer *c) : QFrame(c), menu(m)
{
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
......@@ -320,6 +333,27 @@ void dtkWidgetsMenuBarContainerSlide::touch(dtkWidgetsMenuBar *mb, dtkWidgetsMen
static_cast<QBoxLayout *>(this->layout())->addStretch();
}
void dtkWidgetsMenuBarContainerSlide::touch(const QVector<dtkWidgetsMenu *>& menus, dtkWidgetsMenuBarContainer *c)
{
QLayoutItem *item = nullptr; while ((item = this->layout()->takeAt(0))) delete item->widget();
for (dtkWidgetsMenu *m : menus) {
dtkWidgetsMenuHeaderFacade *header = new dtkWidgetsMenuHeaderFacade(m);
dtkWidgetsMenuFacade *widget = new dtkWidgetsMenuFacade(m);
this->layout()->addWidget(header);
this->layout()->addWidget(widget);
::dtkWidgetsMenuBarHelper::handle(widget->items(), c);
}
this->layout()->addWidget(new dtkWidgetsMenuItemSpacerFacade(::margin/2, ::margin/2, this));
static_cast<QBoxLayout *>(this->layout())->addStretch();
}
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsMenuBarContainer implementation
// ///////////////////////////////////////////////////////////////////
......@@ -338,7 +372,8 @@ dtkWidgetsMenuBarContainer::dtkWidgetsMenuBarContainer(QWidget *parent) : dtkWid
this->addWidget(this->navigator);
this->addWidget(this->slider);
connect(navigator, &dtkWidgetsMenuNavigationFacade::clicked, [=](void) -> void {
connect(navigator, &dtkWidgetsMenuNavigationFacade::clicked, [=] (void) -> void
{
dtkWidgetsMenu *menu = nullptr;
if (::stack.count())
......@@ -358,8 +393,8 @@ void dtkWidgetsMenuBarContainer::setCurrentIndex(int index, std::function<void (
this->slider->enableSpying(false);
this->slider->blockSignals(true);
static std::function<void (void)> ca = [=] (void) -> void {
static std::function<void (void)> ca = [=] (void) -> void
{
this->slider->blockSignals(false);
this->slider->enableSpying(true);
callback();
......@@ -383,8 +418,8 @@ void dtkWidgetsMenuBarContainer::switchToRoot(std::function<void(void)> &callbac
this->slider->enableSpying(false);
this->slider->blockSignals(true);
static std::function<void(void)> cb = [=](void) -> void {
static std::function<void(void)> cb = [=](void) -> void
{
while (!::stack.isEmpty())
this->slider->remSlide(this->slides[::stack.takeLast()]);
......@@ -406,8 +441,8 @@ void dtkWidgetsMenuBarContainer::switchToPrevSlide(dtkWidgetsMenu *m)
else
this->navigator->setMenu(0);
std::function<void()> callback = [=] (void) -> void {
std::function<void()> callback = [=] (void) -> void
{
this->slider->remSlide(this->slides[m]);
};
......@@ -457,6 +492,16 @@ void dtkWidgetsMenuBarContainer::touch(dtkWidgetsMenuBar *mb)
this->buildChildSlide(mm);
}
void dtkWidgetsMenuBarContainer::build(const QVector<dtkWidgetsMenu *>& menus)
{
if(!this->master_slide) {
this->master_slide = new dtkWidgetsMenuBarContainerSlide(this);
this->slider->addSlide(fa::cogs, this->master_slide);
}
this->master_slide->touch(menus, this);
}
void dtkWidgetsMenuBarContainer::buildChildSlide(dtkWidgetsMenu *menu)
{
dtkWidgetsMenuBarContainerSlide *slide = new dtkWidgetsMenuBarContainerSlide(menu, this);
......
......@@ -55,9 +55,9 @@ public slots:
void switchToNextSlide(dtkWidgetsMenu *);
public:
void build(const QVector<dtkWidgetsMenu *> &);
void touch(dtkWidgetsMenuBar *);
void build(const QVector<dtkWidgetsMenu *>&);
void buildChildSlide(dtkWidgetsMenu *);
void touch(dtkWidgetsMenuBar *);
public:
dtkWidgetsMenuBar *q = nullptr;
......@@ -88,16 +88,23 @@ public:
dtkWidgetsMenuBarContainerSlide(dtkWidgetsMenuBar *, dtkWidgetsMenuBarContainer * = nullptr);
~dtkWidgetsMenuBarContainerSlide(void);
protected:
dtkWidgetsMenuBarContainerSlide(dtkWidgetsMenuBarContainer *);
public:
bool isMaster(void) const { return (menu_bar != nullptr); }
public:
void touch(dtkWidgetsMenuBar *, dtkWidgetsMenuBarContainer *);
void touch(dtkWidgetsMenu *, dtkWidgetsMenuBarContainer *);
void touch(const QVector<dtkWidgetsMenu *>&, dtkWidgetsMenuBarContainer *);
private:
dtkWidgetsMenu *menu = nullptr;
dtkWidgetsMenuBar *menu_bar = nullptr;
private:
friend class dtkWidgetsMenuBarContainer;
};
// ///////////////////////////////////////////////////////////////////
......
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