Skip to content

Commit

Permalink
Refactor|UI|Client: Added SidebarWidget: base class for sidebars
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Jan 1, 2016
1 parent 4f8f2c6 commit 58be4ad
Show file tree
Hide file tree
Showing 6 changed files with 245 additions and 114 deletions.
Expand Up @@ -19,8 +19,8 @@
#ifndef DENG_CLIENT_RENDERERAPPEARANCEEDITOR_H
#define DENG_CLIENT_RENDERERAPPEARANCEEDITOR_H

#include <de/PanelWidget>
#include <de/IPersistent>
#include "ui/widgets/sidebarwidget.h"

/**
* Editor for modifying the settings for the renderer's visual appearance.
Expand All @@ -29,8 +29,8 @@
*
* @see ClientApp::rendererAppearanceSettings()
*/
class RendererAppearanceEditor : public de::PanelWidget,
public de::IPersistent
class RendererAppearanceEditor : public SidebarWidget
, public de::IPersistent
{
Q_OBJECT

Expand All @@ -40,10 +40,6 @@ class RendererAppearanceEditor : public de::PanelWidget,
void operator >> (de::PersistentState &toState) const;
void operator << (de::PersistentState const &fromState);

protected:
void preparePanelForOpening();
void panelDismissed();

private:
DENG2_PRIVATE(d)
};
Expand Down
7 changes: 4 additions & 3 deletions doomsday/apps/client/include/ui/editors/variablegroupeditor.h
Expand Up @@ -53,10 +53,7 @@ class VariableGroupEditor : public de::FoldPanelWidget

IOwner &owner();
de::ButtonWidget &resetButton();

de::Rule const &firstColumnWidth() const;
void preparePanelForOpening();
void panelClosing();

void addSpace();
void addLabel(de::String const &text);
Expand All @@ -76,6 +73,10 @@ class VariableGroupEditor : public de::FoldPanelWidget

void fetch();

// PanelWidget.
void preparePanelForOpening();
void panelClosing();

public slots:
virtual void resetToDefaults();
virtual void foldAll();
Expand Down
52 changes: 52 additions & 0 deletions doomsday/apps/client/include/ui/widgets/sidebarwidget.h
@@ -0,0 +1,52 @@
/** @file sidebarwidget.h Base class for sidebar widgets.
*
* @authors Copyright (c) 2015-2016 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>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 the
* Free Software Foundation; either version 2 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 General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#ifndef DENG_CLIENT_UI_SIDEBARWIDGET_H
#define DENG_CLIENT_UI_SIDEBARWIDGET_H

#include <de/PanelWidget>
#include <de/ScrollAreaWidget>
#include <de/SequentialLayout>

/**
* Editor for changing model asset parameters.
*/
class SidebarWidget : public de::PanelWidget
{
Q_OBJECT

public:
SidebarWidget(de::String const &title, de::String const &name = "");

de::SequentialLayout &layout();
de::ScrollAreaWidget &containerWidget();
de::IndirectRule &firstColumnWidth();
de::Rule const &maximumOfAllGroupFirstColumns() const;

protected:
void updateSidebarLayout(de::Rule const &minWidth);

void preparePanelForOpening();
void panelDismissed();

private:
DENG2_PRIVATE(d)
};


#endif // DENG_CLIENT_UI_SIDEBARWIDGET_H
Expand Up @@ -80,6 +80,6 @@ coloradjustment {
rule slider { constant $= slider.width.constant * 1.36 }
}

rendererappearance {
sidebar {
rule width { constant $= UNIT * 100 }
}
134 changes: 31 additions & 103 deletions doomsday/apps/client/src/ui/editors/rendererappearanceeditor.cpp
Expand Up @@ -45,10 +45,6 @@ public VariableGroupEditor::IOwner
using Group = VariableGroupEditor;

SettingsRegister &settings;
DialogContentStylist stylist;
ScrollAreaWidget *container;
IndirectRule *firstColumnWidth; ///< Shared by all groups.
ButtonWidget *close;
ProfilePickerWidget *profile;

Group *skyGroup;
Expand All @@ -66,26 +62,16 @@ public VariableGroupEditor::IOwner
Instance(Public *i)
: Base(i)
, settings(ClientApp::renderSystem().appearanceSettings())
, firstColumnWidth(new IndirectRule)
{
// The editor will close automatically when going to Ring Zero.
App::app().audienceForGameChange() += this;

settings.audienceForProfileChange += this;

// The contents of the editor will scroll.
container = new ScrollAreaWidget;
container->enableIndicatorDraw(true);
stylist.setContainer(*container);
GuiWidget *container = &self.containerWidget();

container->add(close = new ButtonWidget);
// The contents of the editor will scroll.
container->add(profile = new ProfilePickerWidget(settings, tr("appearance")));

close->setImage(style().images().image("close.ringless"));
close->setImageColor(style().colors().colorf("altaccent"));
close->setOverrideImageSize(style().fonts().font("title").height().valuei());
close->setAction(new SignalAction(thisPublic, SLOT(close())));

// Sky settings.
skyGroup = new Group(this, "sky", tr("Sky"));

Expand Down Expand Up @@ -384,31 +370,27 @@ public VariableGroupEditor::IOwner
partGroup->addSlider("rend-particle-visible-near", Ranged(0, 1000), 1, 0)->setMinLabel(tr("None"));

partGroup->commit();

// Now we can define the first column width.
firstColumnWidth->setSource(maximumOfAllGroupFirstColumns());
}

~Instance()
{
App::app().audienceForGameChange() -= this;
settings.audienceForProfileChange -= this;
releaseRef(firstColumnWidth);
}

void resetToDefaults(String const &settingName)
Rule const &firstColumnWidthRule() const
{
settings.resetSettingToDefaults(settingName);
return self.firstColumnWidth();
}

Rule const &firstColumnWidthRule() const
ScrollAreaWidget &containerWidget()
{
return *firstColumnWidth;
return self.containerWidget();
}

ScrollAreaWidget &containerWidget()
void resetToDefaults(String const &settingName)
{
return *container;
settings.resetSettingToDefaults(settingName);
}

void currentGameChanged(game::Game const &newGame)
Expand All @@ -426,24 +408,11 @@ public VariableGroupEditor::IOwner
fetch();
}

Rule const &maximumOfAllGroupFirstColumns()
{
Rule const *max = 0;
foreach(Widget *child, container->childWidgets())
{
if(Group *g = child->maybeAs<Group>())
{
changeRef(max, OperatorRule::maximum(g->firstColumnWidth(), max));
}
}
return *refless(max);
}

void fetch()
{
bool const isReadOnly = settings.isReadOnlyProfile(settings.currentProfile());

foreach(Widget *child, container->childWidgets())
foreach(Widget *child, self.containerWidget().childWidgets())
{
if(Group *g = child->maybeAs<Group>())
{
Expand All @@ -465,11 +434,12 @@ public VariableGroupEditor::IOwner

void saveFoldState(PersistentState &toState)
{
foreach(Widget *child, container->childWidgets())
foreach(Widget *child, self.containerWidget().childWidgets())
{
if(Group *g = child->maybeAs<Group>())
{
toState.objectNamespace().set(self.name() + "." + g->name() + ".open", g->isOpen());
toState.objectNamespace().set(self.name() + "." + g->name() + ".open",
g->isOpen());
}
}
}
Expand All @@ -478,7 +448,7 @@ public VariableGroupEditor::IOwner
{
bool gotState = false;

foreach(Widget *child, container->childWidgets())
foreach(Widget *child, self.containerWidget().childWidgets())
{
if(Group *g = child->maybeAs<Group>())
{
Expand All @@ -503,66 +473,36 @@ public VariableGroupEditor::IOwner
};

RendererAppearanceEditor::RendererAppearanceEditor()
: PanelWidget("rendererappearanceeditor")
: SidebarWidget(tr("Renderer Appearance"), "rendererappearanceeditor")
, d(new Instance(this))
{
setSizePolicy(Fixed);
setOpeningDirection(Left);
set(Background(style().colors().colorf("background")).withSolidFillOpacity(1));

d->profile->setOpeningDirection(Down);

// Set up the editor UI.
LabelWidget *title = LabelWidget::newWithText("Renderer Appearance", d->container);
title->setFont("title");
title->setTextColor("accent");

LabelWidget *profLabel = LabelWidget::newWithText(tr("Profile:"), d->container);
LabelWidget *profLabel = LabelWidget::newWithText(tr("Profile:"), &containerWidget());

// Layout.
RuleRectangle const &area = d->container->contentRule();
title->rule()
.setInput(Rule::Top, area.top())
.setInput(Rule::Left, area.left());
d->close->rule()
.setInput(Rule::Right, area.right())
.setInput(Rule::Bottom, title->rule().bottom());

SequentialLayout layout(area.left(), title->rule().bottom(), Down);

layout.append(*profLabel, SequentialLayout::IgnoreMinorAxis);
layout().append(*profLabel, SequentialLayout::IgnoreMinorAxis);
d->profile->rule()
.setInput(Rule::Left, profLabel->rule().right())
.setInput(Rule::Top, profLabel->rule().top());

layout << d->lightGroup->title() << *d->lightGroup
<< d->volLightGroup->title() << *d->volLightGroup
<< d->glowGroup->title() << *d->glowGroup
<< d->shadowGroup->title() << *d->shadowGroup
<< d->lensGroup->title() << *d->lensGroup
<< d->matGroup->title() << *d->matGroup
<< d->objectGroup->title() << *d->objectGroup
<< d->modelGroup->title() << *d->modelGroup
<< d->spriteGroup->title() << *d->spriteGroup
<< d->partGroup->title() << *d->partGroup
<< d->skyGroup->title() << *d->skyGroup;

// Update container size.
d->container->setContentSize(OperatorRule::maximum(layout.width(),
profLabel->rule().width() +
d->profile->rule().width() +
d->profile->button().rule().width(),
style().rules().rule("rendererappearance.width")),
title->rule().height() + layout.height());
d->container->rule().setSize(d->container->contentRule().width() +
d->container->margins().width(),
rule().height());
setContent(d->container);
layout() << d->lightGroup->title() << *d->lightGroup
<< d->volLightGroup->title() << *d->volLightGroup
<< d->glowGroup->title() << *d->glowGroup
<< d->shadowGroup->title() << *d->shadowGroup
<< d->lensGroup->title() << *d->lensGroup
<< d->matGroup->title() << *d->matGroup
<< d->objectGroup->title() << *d->objectGroup
<< d->modelGroup->title() << *d->modelGroup
<< d->spriteGroup->title() << *d->spriteGroup
<< d->partGroup->title() << *d->partGroup
<< d->skyGroup->title() << *d->skyGroup;

updateSidebarLayout(profLabel->rule().width() +
d->profile->rule().width() +
d->profile->button().rule().width());

d->fetch();

// Install the editor.
ClientWindow::main().setSidebar(ClientWindow::RightEdge, this);
}

void RendererAppearanceEditor::operator >> (PersistentState &toState) const
Expand All @@ -574,15 +514,3 @@ void RendererAppearanceEditor::operator << (PersistentState const &fromState)
{
d->restoreFoldState(fromState);
}

void RendererAppearanceEditor::preparePanelForOpening()
{
PanelWidget::preparePanelForOpening();
}

void RendererAppearanceEditor::panelDismissed()
{
PanelWidget::panelDismissed();

ClientWindow::main().unsetSidebar(ClientWindow::RightEdge);
}

0 comments on commit 58be4ad

Please sign in to comment.