Skip to content

Commit

Permalink
Widgets|libappfw: Dialog for managing a list of directories
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Jun 21, 2016
1 parent d7f4e2a commit 449e392
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 13 deletions.
1 change: 1 addition & 0 deletions doomsday/sdk/libappfw/include/de/DirectoryListDialog
@@ -0,0 +1 @@
#include "dialogs/directorylistdialog.h"
53 changes: 53 additions & 0 deletions doomsday/sdk/libappfw/include/de/dialogs/directorylistdialog.h
@@ -0,0 +1,53 @@
/** @file directorylistdialog.h Dialog for editing a list of directories.
*
* @authors Copyright (c) 2016 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* LGPL: http://www.gnu.org/licenses/lgpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#ifndef LIBAPPFW_DIRECTORYLISTDIALOG_H
#define LIBAPPFW_DIRECTORYLISTDIALOG_H

#include "../MessageDialog"
#include "../DirectoryArrayWidget"

namespace de {

/**
* Dialog for editing a list of directories.
*/
class LIBAPPFW_PUBLIC DirectoryListDialog : public MessageDialog
{
public:
DirectoryListDialog(String const &name = String());

/**
* Sets the list elements.
* @param elements Array of text strings, or a single TextValue.
*/
void setValue(Value const &elements);

/**
* Returns the contents of the directory list.
* Array of text strings, or a single TextValue.
*/
Value const &value() const;

private:
DENG2_PRIVATE(d)
};

} // namespace de

#endif // LIBAPPFW_DIRECTORYLISTDIALOG_H
11 changes: 6 additions & 5 deletions doomsday/sdk/libappfw/include/de/widgets/buttonwidget.h
Expand Up @@ -110,17 +110,18 @@ class LIBAPPFW_PUBLIC ButtonWidget : public LabelWidget

Action const *action() const;

/**
* Triggers the action of the button.
*/
void trigger();

State state() const;

// Events.
void update();
bool handleEvent(Event const &event);

public slots:
/**
* Triggers the action of the button.
*/
void trigger();

signals:
void pressed();

Expand Down
@@ -1,4 +1,4 @@
/** @file nativefolderarraywidget.h Array of native directories.
/** @file directoryarraywidget.h Widget for an array of native directories.
*
* @authors Copyright (c) 2016 Jaakko Keränen <jaakko.keranen@iki.fi>
*
Expand Down
13 changes: 13 additions & 0 deletions doomsday/sdk/libappfw/include/de/widgets/variablearraywidget.h
Expand Up @@ -30,6 +30,8 @@ class ButtonWidget;
/**
* Widget for editing Variables with array values.
*
* Uses an expanding sizing policy.
*
* @ingroup guiWidgets
*/
class LIBAPPFW_PUBLIC VariableArrayWidget : public GuiWidget
Expand All @@ -47,6 +49,17 @@ class LIBAPPFW_PUBLIC VariableArrayWidget : public GuiWidget
MenuWidget &elementsMenu();
ButtonWidget &addButton();

/**
* Changes the layout of the widget so that the add button can be freely
* positioned outside the widget's area. By default the add button is attached
* under the array values.
*
* @param contentWidth The widget contents use this as the width.
*
* @return Pointer to the add button, whose ownership is given to the caller.
*/
ButtonWidget *detachAddButton(Rule const &contentWidth);

ui::Item *makeItem(Value const &value);

protected:
Expand Down
65 changes: 65 additions & 0 deletions doomsday/sdk/libappfw/src/dialogs/directorylistdialog.cpp
@@ -0,0 +1,65 @@
/** @file directorylistdialog.cpp Dialog for editing a list of directories.
*
* @authors Copyright (c) 2016 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* LGPL: http://www.gnu.org/licenses/lgpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#include "de/DirectoryListDialog"
#include "de/DirectoryArrayWidget"

#include <de/SignalAction>

namespace de {

DENG2_PIMPL(DirectoryListDialog)
{
Variable array;
DirectoryArrayWidget *list;

Instance(Public *i) : Base(i)
{
array.set(new ArrayValue);
list = new DirectoryArrayWidget(array);
self.add(list->detachAddButton(self.area().rule().width()));
list->addButton().hide();
}
};

DirectoryListDialog::DirectoryListDialog(String const &name)
: MessageDialog(name)
, d(new Instance(this))
{
area().add(d->list);

buttons() << new DialogButtonItem(Default | Accept)
<< new DialogButtonItem(Reject)
<< new DialogButtonItem(Action, style().images().image("create"),
tr("Add Folder"),
new SignalAction(&d->list->addButton(), SLOT(trigger())));

updateLayout();
}

void DirectoryListDialog::setValue(Value const &elements)
{
d->array.set(elements);
}

Value const &DirectoryListDialog::value() const
{
return d->array.value();
}

} // namespace de
5 changes: 2 additions & 3 deletions doomsday/sdk/libappfw/src/dialogs/inputdialog.cpp
Expand Up @@ -33,9 +33,8 @@ InputDialog::InputDialog(String const &name)
d->editor->setSignalOnEnter(true);
connect(d->editor, SIGNAL(enterPressed(QString)), this, SLOT(accept()));

buttons()
<< new DialogButtonItem(Default | Accept)
<< new DialogButtonItem(Reject);
buttons() << new DialogButtonItem(Default | Accept)
<< new DialogButtonItem(Reject);

updateLayout();
}
Expand Down
5 changes: 1 addition & 4 deletions doomsday/sdk/libappfw/src/widgets/directoryarraywidget.cpp
@@ -1,4 +1,4 @@
/** @file directoryarraywidget.cpp
/** @file directoryarraywidget.cpp Widget for an array of native directories.
*
* @authors Copyright (c) 2016 Jaakko Keränen <jaakko.keranen@iki.fi>
*
Expand Down Expand Up @@ -49,9 +49,6 @@ DirectoryArrayWidget::DirectoryArrayWidget(Variable &variable, String const &nam
dlg.setLabelText(QFileDialog::Accept, tr("Select"));
if (dlg.exec())
{
//App::config().set("resource.iwadFolder", dlg.selectedFiles().at(0));
//reload = true;

elementsMenu().items() << makeItem(TextValue(dlg.selectedFiles().at(0)));
setVariableFromWidget();
}
Expand Down
14 changes: 14 additions & 0 deletions doomsday/sdk/libappfw/src/widgets/variablearraywidget.cpp
Expand Up @@ -218,6 +218,20 @@ ButtonWidget &VariableArrayWidget::addButton()
return *d->addButton;
}

ButtonWidget *VariableArrayWidget::detachAddButton(Rule const &contentWidth)
{
d->addButton->setSizePolicy(ui::Expand, ui::Expand);
d->addButton->orphan();

d->maxWidth->setSource(contentWidth - margins().width());
d->menu->setGridSize(1, ui::Fixed, 0, ui::Expand);
d->menu->rule().setInput(Rule::Width, contentWidth - margins().width());
rule().setSize(contentWidth,
d->menu->rule().height() + margins().height());

return d->addButton;
}

ui::Item *VariableArrayWidget::makeItem(Value const &value)
{
auto *item = new ui::Item(ui::Item::ShownAsLabel, labelForElement(value));
Expand Down

0 comments on commit 449e392

Please sign in to comment.