Commit c6fd5163 authored by LE BRETON Come's avatar LE BRETON Come

build and update become touch. disconnect buttons from slider. heavy leak.

parent ff5a309e
......@@ -132,7 +132,7 @@ void setup(dtkApplication *application)
menubar_generator_1.populate(application->window()->menubar());
menubar_generator_2.populate(application->window()->menubar());
application->window()->menubar()->build();
application->window()->menubar()->touch();
}
//
......
......@@ -49,7 +49,7 @@ public:
this->menubar->addMenu(menu_1);
this->menubar->addMenu(menu_2);
this->menubar->addMenu(menu_3);
this->menubar->build();
this->menubar->touch();
};
~dummyWorkspaceA(void) {};
......@@ -191,7 +191,7 @@ dummyWindow::dummyWindow(QWidget *parent) : QFrame(parent)
this->menubar->addMenu(this->menu_1);
this->menubar->addMenu(this->menu_2);
this->menubar->addMenu(this->menu_3);
this->menubar->build();
this->menubar->touch();
QHBoxLayout *l = new QHBoxLayout(this);
l->setContentsMargins(0, 0, 0, 0);
......
......@@ -135,9 +135,9 @@ dtkWidgetsMenu *dtkWidgetsMenu::addMenu(int icon_id, const QString& title)
dtkWidgetsMenuFacade *dtkWidgetsMenu::widget(void)
{
if( d->widget) {
delete d->widget;
}
// if( d->widget) {
// delete d->widget;
// }
d->widget = new dtkWidgetsMenuFacade(this);
......@@ -150,9 +150,9 @@ dtkWidgetsMenuFacade *dtkWidgetsMenu::widget(void)
dtkWidgetsMenuHeaderFacade *dtkWidgetsMenu::header(void)
{
if(!d->header) {
// if(!d->header) {
d->header = new dtkWidgetsMenuHeaderFacade(this);
}
// }
return d->header;
}
......
......@@ -295,30 +295,7 @@ dtkWidgetsMenuBarContainerSlide::dtkWidgetsMenuBarContainerSlide(dtkWidgetsMenuB
int count = menu_bar->size();
for (dtkWidgetsMenu *menu : menu_bar->menus()) {
dtkWidgetsMenuHeaderFacade *header = menu->header();
dtkWidgetsMenuFacade *widget = menu->widget();
layout->addWidget(header);
layout->addWidget(widget);
int i = 0;
int s = -10;
QWidget *l = nullptr;
dtkWidgetsMenuItemFacade *l_item = nullptr;
dtkWidgetsMenuInnerFacade *l_menu = nullptr;
for (QWidget *item : widget->items()) {
// ::dtkWidgetsMenuBarHelper::handle(item, i, s, l, l_item, l_menu, c, mb, menu);
i++;
}
layout->addWidget(new dtkWidgetsMenuItemSpacerFacade(8, 8));
}
this->touch(mb);
}
dtkWidgetsMenuBarContainerSlide::~dtkWidgetsMenuBarContainerSlide(void)
......@@ -327,77 +304,19 @@ dtkWidgetsMenuBarContainerSlide::~dtkWidgetsMenuBarContainerSlide(void)
menu_bar = nullptr;
}
void dtkWidgetsMenuBarContainerSlide::update(dtkWidgetsMenu *menu)
void dtkWidgetsMenuBarContainerSlide::touch(dtkWidgetsMenuBar *mb)
{
for(int i = 0; i < this->layout()->count(); i++) {
if(!menu->widget()->items().contains(this->layout()->itemAt(i)->widget()))
this->layout()->itemAt(i)->widget()->hide();
}
int i = 0;
int s = -10;
QWidget *l = nullptr;
dtkWidgetsMenuItemFacade *l_item = nullptr;
dtkWidgetsMenuInnerFacade *l_menu = nullptr;
for (QWidget *item : menu->widget()->items()) {
bool got = 0;
QLayoutItem *item = nullptr; while ((item = this->layout()->takeAt(0))) delete item->widget();
for(int i = 0; i < this->layout()->count(); i++)
if(this->layout()->itemAt(i)->widget() == item)
got = true;
this->layout()->addWidget(new dtkWidgetsMenuItemSpacerFacade(4, 4));
if(!got)
this->layout()->addWidget(item);
// ::dtkWidgetsMenuBarHelper::handle(item, i, s, l, l_item, l_menu, dynamic_cast<dtkWidgetsMenuBarContainer *>(this->parentWidget()), 0, menu);
i++;
}
}
void dtkWidgetsMenuBarContainerSlide::update(dtkWidgetsMenuBar *bar)
{
// Hide unwanted widgets
// If a one of the formerly displayed widgets is not in the list of wanted menus, hide it.
QList<QWidget *> widgets;
for (dtkWidgetsMenu *menu : bar->menus()) {
widgets << menu->widget();
widgets << menu->header();
}
// Iterates on the formerly displayed widgets (are they all displayed ?)
for(int i = 0; i < this->layout()->count(); i++) {
// Hides the widget if not a wanted menu item (header or widget)
if(!widgets.contains(this->layout()->itemAt(i)->widget()))
this->layout()->itemAt(i)->widget()->hide();
}
// Show new widgets
for (dtkWidgetsMenu *menu : bar->menus()) {
for (dtkWidgetsMenu *menu : mb->menus()) {
dtkWidgetsMenuHeaderFacade *header = menu->header();
dtkWidgetsMenuFacade *widget = menu->widget();
// qDebug() << "Widget" << widget;
bool found = 0;
// What if it was present then hidden then present again ?
for(int i = 0; i < this->layout()->count(); ++i) {
if( this->layout()->itemAt(i)->widget() == widget) {
found = true;
this->layout()->itemAt(i)->widget()->show();
}
}
// If the widget was not yet present, we add it
if(!found) {
this->layout()->addWidget(header);
this->layout()->addWidget(widget);
header->show();
widget->show();
}
this->layout()->addWidget(header);
this->layout()->addWidget(widget);
int i = 0;
int s = -10;
......@@ -408,13 +327,14 @@ void dtkWidgetsMenuBarContainerSlide::update(dtkWidgetsMenuBar *bar)
for (QWidget *item : widget->items()) {
// ::dtkWidgetsMenuBarHelper::handle(item, i, s, l, l_item, l_menu, dynamic_cast<dtkWidgetsMenuBarContainer *>(this->parentWidget()), bar, menu);
// ::dtkWidgetsMenuBarHelper::handle(item, i, s, l, l_item, l_menu, c, mb, menu);
++i;
i++;
}
this->layout()->addWidget(new dtkWidgetsMenuItemSpacerFacade(8, 8));
}
}
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsMenuBarContainer implementation
// ///////////////////////////////////////////////////////////////////
......@@ -523,23 +443,22 @@ void dtkWidgetsMenuBarContainer::switchToNextSlide(dtkWidgetsMenu *m)
::stack << m;
}
void dtkWidgetsMenuBarContainer::build(dtkWidgetsMenuBar *mb)
void dtkWidgetsMenuBarContainer::touch(dtkWidgetsMenuBar *mb)
{
if(!this->master_slide) {
this->master_slide = new dtkWidgetsMenuBarContainerSlide(mb, this);
this->slider->addSlide(fa::cogs, this->master_slide);
} else {
this->master_slide->update(mb); // TODO
}
for (auto m : mb->menus()) {
for (auto mm : m->menus()) {
if(!this->slides.keys().contains(mm))
this->buildChildSlide(mm);
else
this->slides[mm]->update(mm); // TODO
}
}
qDeleteAll(this->slides);
this->slides.clear();
this->master_slide->touch(mb);
for (auto m : mb->menus())
for (auto mm : m->menus())
this->buildChildSlide(mm);
}
void dtkWidgetsMenuBarContainer::buildChildSlide(dtkWidgetsMenu *menu)
......@@ -548,18 +467,17 @@ void dtkWidgetsMenuBarContainer::buildChildSlide(dtkWidgetsMenu *menu)
this->slides.insert(menu, slide);
for (auto m : menu->menus()) {
for (auto m : menu->menus())
this->buildChildSlide(m);
}
}
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsMenuBarPrivate
// ///////////////////////////////////////////////////////////////////
void dtkWidgetsMenuBarPrivate::update(void)
void dtkWidgetsMenuBarPrivate::touch(void)
{
QLayoutItem *child; while ((child = this->layout->takeAt(0)) != 0) delete child;
QLayoutItem *child; while ((child = this->layout->takeAt(0)) != 0) delete child->widget();
for (dtkWidgetsMenu *m : menu_list) {
......@@ -586,21 +504,20 @@ void dtkWidgetsMenuBarPrivate::update(void)
}
}
std::function<void(void)> callback = [=](void) -> void {
this->c->blockSignals(false);
this->c->slider->blockSignals(false);
q->emit clicked(target);
};
// std::function<void(void)> callback = [=](void) -> void {
// this->c->blockSignals(false);
// this->c->slider->blockSignals(false);
// q->emit clicked(target);
// };
if(!this->c->width()) {
this->toggle->collapsed = !this->toggle->collapsed;
this->toggle->touch();
this->c->slider->blockSignals(true);
this->c->blockSignals(true);
this->c->toggle(callback);
// this->c->toggle(callback);
} else {
callback();
// callback();
}
});
......@@ -667,8 +584,6 @@ dtkWidgetsMenuBar::dtkWidgetsMenuBar(QWidget *parent) : QFrame(parent), d(new dt
dtkWidgetsMenuBar::~dtkWidgetsMenuBar(void)
{
this->clear();
delete d;
}
......@@ -738,7 +653,7 @@ void dtkWidgetsMenuBar::removeMenu(const QString &title)
if (m) {
d->menu_list.removeOne(m);
d->update();
d->touch();
}
}
......@@ -865,13 +780,6 @@ void dtkWidgetsMenuBar::setCurrentIndex(int index, std::function<void (void)>& c
callback();
}
void dtkWidgetsMenuBar::clear(void)
{
d->menu_hash.clear();
d->menu_list.clear();
d->update();
}
int dtkWidgetsMenuBar::size(void) const
{
return d->menu_list.size();
......@@ -917,11 +825,11 @@ void dtkWidgetsMenuBar::mouseMoveEvent(QMouseEvent *event)
d->o_pos = d->c_pos;
}
void dtkWidgetsMenuBar::build(void)
void dtkWidgetsMenuBar::touch(void)
{
d->update();
d->touch();
d->c->build(this);
d->c->touch(this);
}
// /////////////////////////////////////////////////////////////////////////////
......
......@@ -99,9 +99,6 @@ public slots:
void setCurrentIndex(int);
void setCurrentIndex(int, std::function<void (void)>&);
public slots:
void clear(void);
public:
int size(void) const;
......@@ -112,7 +109,7 @@ public slots:
void setFixedHeight(int);
public slots:
void build(void);
void touch(void);
protected:
void resizeEvent(QResizeEvent *) override;
......
......@@ -56,7 +56,7 @@ public slots:
public:
void build(const QVector<dtkWidgetsMenu *> &);
void build(dtkWidgetsMenuBar *);
void touch(dtkWidgetsMenuBar *);
void buildChildSlide(dtkWidgetsMenu *);
public:
......@@ -92,8 +92,7 @@ public:
bool isMaster(void) const { return (menu_bar != nullptr); }
public:
void update(dtkWidgetsMenu *);
void update(dtkWidgetsMenuBar *);
void touch(dtkWidgetsMenuBar *);
private:
dtkWidgetsMenu *menu = nullptr;
......@@ -125,7 +124,7 @@ public:
dtkWidgetsMenuBarButtonCollapse *toggle;
public:
void update(void);
void touch(void);
public:
QPoint o_pos;
......
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