Skip to content

Commit

Permalink
Widgets|UI: Improvements for directory array widget
Browse files Browse the repository at this point in the history
DirectoryArrayWidget can be used to specify whether each directory is recursed or not. These selections are saved persistently to Config.
  • Loading branch information
skyjake committed Oct 28, 2018
1 parent 68a3196 commit c7ea58a
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The Doomsday Engine Project -- Doomsday Base Library
#
# Copyright (c) 2013-2017 Jaakko Keränen <jaakko.keranen@iki.fi>
# Copyright (c) 2013-2018 Jaakko Keränen <jaakko.keranen@iki.fi>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -20,6 +20,12 @@ def setDefaults(d)
record d.resource()
iwadFolder = ''
packageFolder = ''

# Dictionary of folders that should be fully recursed. Affects the
# folders listed in resource.packageFolder (native path -> bool).
recursedFolders = {}

# Online package repositories.
repositories = {
'idgames archive (gamers.org)': 'http://www.gamers.org/pub/idgames/',
'idgames mirror (Idaho, USA)': 'http://mirrors.syringanetworks.net/idgames/',
Expand Down
2 changes: 2 additions & 0 deletions doomsday/sdk/libappfw/include/de/dialogs/messagedialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class LIBAPPFW_PUBLIC MessageDialog : public DialogWidget
LabelWidget &title();
LabelWidget &message();

void setLayoutWidth(const Rule &);

enum LayoutBehavior { ExcludeHidden, IncludeHidden };

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class LIBAPPFW_PUBLIC DirectoryArrayWidget : public VariableArrayWidget

protected:
String labelForElement(Value const &value) const override;
void elementCreated(LabelWidget &, const ui::Item &) override;

private:
DENG2_PRIVATE(d)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class LIBAPPFW_PUBLIC VariableArrayWidget : public GuiWidget

protected:
virtual String labelForElement(Value const &value) const;
virtual void elementCreated(LabelWidget &, const ui::Item &);

public slots:
void updateFromVariable();
Expand Down
15 changes: 9 additions & 6 deletions doomsday/sdk/libappfw/src/dialogs/directorylistdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "de/DirectoryListDialog"
#include "de/DirectoryArrayWidget"

#include <de/SignalAction>
#include <de/CallbackAction>

namespace de {

Expand Down Expand Up @@ -71,8 +71,8 @@ DENG2_PIMPL(DirectoryListDialog)
group->array.set(new ArrayValue);
group->list = new DirectoryArrayWidget(group->array);
group->list->margins().setZero();
//self().add(group->list->detachAddButton(self().area().rule().width()));
//group->list->addButton().hide();
self().add(group->list->detachAddButton(self().area().rule().width()));
group->list->addButton().hide();
self().area().add(group->list);

QObject::connect(group->list, SIGNAL(arrayChanged()),
Expand All @@ -87,11 +87,14 @@ DirectoryListDialog::DirectoryListDialog(String const &name)
: MessageDialog(name)
, d(new Impl(this))
{
area().enableIndicatorDraw(true);
buttons() << new DialogButtonItem(Default | Accept)
<< new DialogButtonItem(Reject);
/*<< new DialogButtonItem(Action, style().images().image("create"),
<< new DialogButtonItem(Reject)
<< new DialogButtonItem(Action, style().images().image("create"),
tr("Add Folder"),
new SignalAction(&d->list->addButton(), SLOT(trigger())));*/
new CallbackAction([this]() {
(*d->groups.begin())->list->addButton().trigger();
}));
}

Id DirectoryListDialog::addGroup(String const &title, String const &description)
Expand Down
10 changes: 9 additions & 1 deletion doomsday/sdk/libappfw/src/dialogs/messagedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ DENG_GUI_PIMPL(MessageDialog)
LabelWidget * title;
LabelWidget * message;
DialogContentStylist buttonStylist;
const Rule * layoutWidth = nullptr;

Impl(Public *i) : Base(i)
{
Expand All @@ -52,6 +53,8 @@ DENG_GUI_PIMPL(MessageDialog)
message->setAlignment(ui::AlignLeft);
message->setTextLineAlignment(ui::AlignLeft);

layoutWidth = holdRef(rule("dialog.message.width"));

updateLayout();
}

Expand All @@ -62,7 +65,7 @@ DENG_GUI_PIMPL(MessageDialog)
// Simple vertical layout.
SequentialLayout layout(area.contentRule().left(),
area.contentRule().top());
layout.setOverrideWidth(rule("dialog.message.width"));
layout.setOverrideWidth(*layoutWidth);

// Put all the widgets into the layout.
foreach (GuiWidget *w, area.childWidgets())
Expand Down Expand Up @@ -106,6 +109,11 @@ LabelWidget &MessageDialog::message()
return *d->message;
}

void MessageDialog::setLayoutWidth(const Rule &layoutWidth)
{
changeRef(d->layoutWidth, layoutWidth);
}

void MessageDialog::updateLayout(LayoutBehavior behavior)
{
d->updateLayout(behavior);
Expand Down
95 changes: 95 additions & 0 deletions doomsday/sdk/libappfw/src/widgets/directoryarraywidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
#include "de/BaseWindow"

#include <de/Config>
#include <de/Garbage>
#include <de/NativePath>
#include <de/TextValue>
#include <de/ToggleWidget>
#include <QFileDialog>

namespace de {
Expand Down Expand Up @@ -67,4 +69,97 @@ String DirectoryArrayWidget::labelForElement(Value const &value) const
return NativePath(value.asText()).pretty();
}

static const String RECURSE_TOGGLE_NAME("recurse-toggle");

/**
* Controller that syncs state between Config.resource.recurseFolders and the toggles
* in the DirectoryArrayWidget items. Destroys itself after the item widget is deleted.
*/
struct RecurseToggler
: DENG2_OBSERVES(ToggleWidget, Toggle)
, DENG2_OBSERVES(Widget, Deletion)
, DENG2_OBSERVES(ui::Item, Change)
, DENG2_OBSERVES(ChildWidgetOrganizer, WidgetUpdate)
{
DirectoryArrayWidget *owner;
ToggleWidget * tog;
const ui::Item * item;

RecurseToggler(DirectoryArrayWidget *owner, LabelWidget &element, const ui::Item &item)
: owner(owner)
, item(&item)
{
tog = &element.guiFind(RECURSE_TOGGLE_NAME)->as<ToggleWidget>();
item.audienceForChange() += this;
element.audienceForDeletion() += this;
tog->audienceForToggle() += this;
owner->elementsMenu().organizer().audienceForWidgetUpdate() += this;
}

static Variable &recursed()
{
return Config::get("resource.recursedFolders");
}

TextValue key() const
{
return {item->label()};
}

void fetch()
{
if (recursed().value().contains(key()))
{
tog->setActive(recursed().value().element(key()).isTrue());
}
}

void toggleStateChanged(ToggleWidget &toggle) override
{
recursed().value().setElement(key(), new NumberValue(toggle.isActive()));
}

void widgetBeingDeleted(Widget &) override
{
item->audienceForChange() -= this;
// tog is already gone
trash(this);
}

void itemChanged(const ui::Item &) override
{
fetch();
}

void widgetUpdatedForItem(GuiWidget &, const ui::Item &) override
{
fetch();
}
};

void DirectoryArrayWidget::elementCreated(LabelWidget &element, const ui::Item &item)
{
element.setSizePolicy(ui::Fixed, ui::Expand);
element.setAlignment(ui::AlignLeft);
element.setTextLineAlignment(ui::AlignLeft);
element.setMaximumTextWidth(rule().width());
element.rule().setInput(Rule::Width, rule().width() - margins().width());

// Add a toggle for configuration recurse mode.
auto *tog = new ToggleWidget(ToggleWidget::DefaultFlags, RECURSE_TOGGLE_NAME);
element.add(tog);
tog->setText("Subdirs");
tog->setActive(true); // recurse is on by default
tog->set(Background());
tog->setFont("small");
tog->margins().setLeft("unit").setRight("gap").setTop("unit").setBottom("unit");
tog->setSizePolicy(ui::Expand, ui::Expand);
tog->rule()
.setInput(Rule::Right, element.rule().right() - rule("gap"))
.setMidAnchorY(element.rule().midY());
element.margins().setRight(tog->rule().width() + rule("gap"));

new RecurseToggler(this, element, item); // deletes itself
}

} // namespace de
20 changes: 15 additions & 5 deletions doomsday/sdk/libappfw/src/widgets/variablearraywidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ DENG_GUI_PIMPL(VariableArrayWidget)
menu->organizer().audienceForWidgetCreation() += this;
menu->organizer().audienceForWidgetUpdate() += this;
menu->setGridSize(1, ui::Expand, 0, ui::Expand);
menu->layout().setRowPadding(2 * rule("unit"));

updateFromVariable();
var.audienceForDeletion() += this;
var.audienceForChange() += this;
}

~Impl()
~Impl() override
{
releaseRef(maxWidth);
}
Expand All @@ -80,13 +81,16 @@ DENG_GUI_PIMPL(VariableArrayWidget)
deleteButton->rule().setMidAnchorY(widget.rule().midY());
}

void widgetCreatedForItem(GuiWidget &widget, ui::Item const &) override
void widgetCreatedForItem(GuiWidget &widget, ui::Item const &item) override
{
auto &label = widget.as<LabelWidget>();
label.setSizePolicy(ui::Expand, ui::Expand);
label.setMaximumTextWidth(*maxWidth);
widget.margins().setLeftRight("").setTopBottom(RuleBank::UNIT);
widget.margins().setRight("").setTopBottom("");
widget.margins().setLeft("");//deleteButton->rule().width());
widget.addEventHandler(new HoverHandler(self()));

self().elementCreated(label, item);
}

void widgetUpdatedForItem(GuiWidget &widget, ui::Item const &item) override
Expand Down Expand Up @@ -173,8 +177,9 @@ VariableArrayWidget::VariableArrayWidget(Variable &variable, String const &name)
d->menu->enableScrolling(false);
d->menu->enablePageKeys(false);
d->menu->rule()
.setLeftTop(margins().left() + rule().left(),
margins().top() + rule().top());
.setLeftTop(/*margins().left() + */rule().left(),
margins().top() + rule().top())
.setInput(Rule::Right, rule().right() - 2 * rule("gap"));

d->addButton->setFont("small");
d->addButton->setStyleImage("create", d->addButton->fontId());
Expand Down Expand Up @@ -221,6 +226,11 @@ String VariableArrayWidget::labelForElement(Value const &value) const
return value.asText();
}

void VariableArrayWidget::elementCreated(LabelWidget &, const ui::Item &)
{
// Derived class may customize the label.
}

ButtonWidget &VariableArrayWidget::addButton()
{
return *d->addButton;
Expand Down

0 comments on commit c7ea58a

Please sign in to comment.