Skip to content

Commit

Permalink
libgui|PersistentCanvasWindow: Saving and restore state during runtime
Browse files Browse the repository at this point in the history
The window can now remember or restore its state at any point without
touching the Config.
  • Loading branch information
skyjake committed Nov 30, 2014
1 parent 8cfdc6a commit 695e167
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
11 changes: 11 additions & 0 deletions doomsday/libgui/include/de/gui/persistentcanvaswindow.h
Expand Up @@ -144,6 +144,17 @@ class LIBGUI_PUBLIC PersistentCanvasWindow : public CanvasWindow
*/
void restoreFromConfig();

/**
* Saves the current state in memory (not persistently). The saved state can
* later be restored with a call to restoreState().
*/
void saveState();

/**
* Restores the attribuets of the window from previously saved state.
*/
void restoreState();

static PersistentCanvasWindow &main();

// Events.
Expand Down
23 changes: 17 additions & 6 deletions doomsday/libgui/src/persistentcanvaswindow.cpp
Expand Up @@ -432,8 +432,7 @@ DENG2_PIMPL(PersistentCanvasWindow)

struct Task
{
enum Type
{
enum Type {
ShowNormal,
ShowFullscreen,
ShowMaximized,
Expand All @@ -457,16 +456,18 @@ DENG2_PIMPL(PersistentCanvasWindow)

// Logical state.
State state;
State savedState; // used by saveState(), restoreState()
bool neverShown;

typedef QList<Task> Tasks;
Tasks queue;

Instance(Public *i, String const &windowId)
: Base(i),
id(windowId),
state(windowId),
neverShown(true)
: Base(i)
, id(windowId)
, state(windowId)
, savedState(windowId)
, neverShown(true)
{
// Keep a global pointer to the main window.
if(id == MAIN_WINDOW_ID)
Expand Down Expand Up @@ -818,6 +819,16 @@ void PersistentCanvasWindow::restoreFromConfig()
d->applyToWidget(d->state);
}

void PersistentCanvasWindow::saveState()
{
d->savedState = d->widgetState();
}

void PersistentCanvasWindow::restoreState()
{
d->applyToWidget(d->savedState);
}

bool PersistentCanvasWindow::isCentered() const
{
return d->state.isCentered();
Expand Down

0 comments on commit 695e167

Please sign in to comment.