Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Refactor|UI|Client: Ownership of notification widgets
Now using the UniqueWidgetPtr template.
  • Loading branch information
skyjake committed Nov 2, 2014
1 parent edcaf6e commit 82a0a53
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 50 deletions.
1 change: 1 addition & 0 deletions doomsday/client/src/clientapp.cpp
Expand Up @@ -208,6 +208,7 @@ DENG2_PIMPL(ClientApp)
Sys_Shutdown();
DD_Shutdown();

updater.reset();
delete worldSys;
//delete infineSys;
delete winSys;
Expand Down
7 changes: 3 additions & 4 deletions doomsday/client/src/ui/clientwindow.cpp
Expand Up @@ -92,7 +92,7 @@ DENG2_PIMPL(ClientWindow)
bool cursorHasBeenHidden;

// FPS notifications.
LabelWidget *fpsCounter;
UniqueWidgetPtr<LabelWidget> fpsCounter;
float oldFps;

/// @todo Switch dynamically between VR and plain.
Expand Down Expand Up @@ -120,7 +120,6 @@ DENG2_PIMPL(ClientWindow)
, cursorX(new ConstantRule(0))
, cursorY(new ConstantRule(0))
, cursorHasBeenHidden(false)
, fpsCounter(0)
, oldFps(0)
, contentXf(*i)
{
Expand Down Expand Up @@ -218,7 +217,7 @@ DENG2_PIMPL(ClientWindow)
root.add(alerts);

// FPS counter for the notification area.
fpsCounter = new LabelWidget;
fpsCounter.reset(new LabelWidget);
fpsCounter->setSizePolicy(ui::Expand, ui::Expand);
fpsCounter->setAlignment(ui::AlignRight);

Expand Down Expand Up @@ -474,7 +473,7 @@ DENG2_PIMPL(ClientWindow)

void updateFpsNotification(float fps)
{
notifications->showOrHide(fpsCounter, self.isFPSCounterVisible());
notifications->showOrHide(*fpsCounter, self.isFPSCounterVisible());

if(!fequal(oldFps, fps))
{
Expand Down
11 changes: 3 additions & 8 deletions doomsday/client/src/ui/dialogs/alertdialog.cpp
Expand Up @@ -83,7 +83,7 @@ DENG_GUI_PIMPL(AlertDialog)
}
};

ButtonWidget *notification;
UniqueWidgetPtr<ButtonWidget> notification;
MenuWidget *alerts;
bool clearOnDismiss;
TextStyling styling;
Expand All @@ -100,7 +100,7 @@ DENG_GUI_PIMPL(AlertDialog)
, clearOnDismiss(false)
, maxCount(100)
{
notification = new ButtonWidget;
notification.reset(new ButtonWidget);
notification->setSizePolicy(ui::Expand, ui::Expand);
notification->setImage(style().images().image("alert"));
notification->setOverrideImageSize(style().fonts().font("default").height().value());
Expand Down Expand Up @@ -129,11 +129,6 @@ DENG_GUI_PIMPL(AlertDialog)

~Instance()
{
if(!notification->parentWidget())
{
GuiWidget::destroy(notification);
}

App::config(VAR_AUTOHIDE).audienceForChange() -= this;
}

Expand Down Expand Up @@ -251,7 +246,7 @@ DENG_GUI_PIMPL(AlertDialog)
// Change color to indicate new alerts.
notification->setImageColor(style().colors().colorf("accent"));

notifs().showOrHide(notification, true);
notifs().showOrHide(*notification, true);

// Restart the autohiding timer.
if(autoHideAfterSeconds() > 0)
Expand Down
15 changes: 5 additions & 10 deletions doomsday/client/src/ui/widgets/tutorialwidget.cpp
Expand Up @@ -48,32 +48,27 @@ DENG_GUI_PIMPL(TutorialWidget)
};

Step current;
MessageDialog *dlg;
MessageDialog *dlg = nullptr;
LabelWidget *highlight;
NotificationAreaWidget *notifs; ///< Fake notifications just for an example.
LabelWidget *exampleAlert;
NotificationAreaWidget *notifs = nullptr; ///< Fake notifications just for an example.
UniqueWidgetPtr<LabelWidget> exampleAlert;
QTimer flashing;
bool taskBarInitiallyOpen;
Untrapper untrapper;

Instance(Public *i)
: Base(i)
, current(Welcome)
, dlg(0)
, notifs(0)
, exampleAlert(0)
, taskBarInitiallyOpen(ClientWindow::main().taskBar().isOpen())
, untrapper(ClientWindow::main())
{
// Create an example alert (lookalike).
/// @todo There could be a class for an alert notification widget. -jk
exampleAlert = new LabelWidget;
exampleAlert.reset(new LabelWidget);
exampleAlert->setSizePolicy(ui::Expand, ui::Expand);
exampleAlert->setImage(style().images().image("alert"));
exampleAlert->setOverrideImageSize(style().fonts().font("default").height().value());
exampleAlert->setImageColor(style().colors().colorf("accent"));
exampleAlert->hide();
self.add(exampleAlert);

// Highlight rectangle.
self.add(highlight = new LabelWidget);
Expand Down Expand Up @@ -203,7 +198,7 @@ DENG_GUI_PIMPL(TutorialWidget)
notifs = new NotificationAreaWidget("tutorial-notifications");
notifs->useDefaultPlacement(ClientWindow::main().game().rule());
root().addOnTop(notifs);
notifs->showChild(exampleAlert);
notifs->showChild(*exampleAlert);

dlg->title().setText(tr("Notifications"));
dlg->message().setText(tr("The notification area shows the current notifications. "
Expand Down
38 changes: 10 additions & 28 deletions doomsday/client/src/updater/updater.cpp
Expand Up @@ -153,28 +153,22 @@ class UpdaterStatusWidget : public ProgressWidget
ButtonWidget *_clickable;
};

DENG2_PIMPL(Updater),
DENG2_OBSERVES(App, StartupComplete)
DENG2_PIMPL(Updater)
, DENG2_OBSERVES(App, StartupComplete)
{
QNetworkAccessManager *network;
DownloadDialog *download;
UpdaterStatusWidget *status;
QNetworkAccessManager *network = nullptr;
DownloadDialog *download = nullptr; // not owned (in the widget tree, if exists)
UniqueWidgetPtr<UpdaterStatusWidget> status;
UpdateAvailableDialog *availableDlg = nullptr; ///< If currently open (not owned).
bool alwaysShowNotification;
UpdateAvailableDialog *availableDlg; ///< If currently open (not owned).
bool savingSuggested;
bool savingSuggested = false;

VersionInfo latestVersion;
QString latestPackageUri;
QString latestPackageUri2; // fallback location
QString latestLogUri;

Instance(Public *up)
: Base(up),
network(0),
download(0),
status(0),
availableDlg(0),
savingSuggested(false)
Instance(Public *i) : Base(i)
{
network = new QNetworkAccessManager(thisPublic);

Expand All @@ -196,18 +190,6 @@ DENG2_OBSERVES(App, StartupComplete)
st.setPathToDeleteAtStartup("");
}

~Instance()
{
//if(settingsDlg) delete settingsDlg;
if(!status->parentWidget())
{
GuiWidget::destroy(status);
}

// Delete the ongoing download.
if(download) delete download;
}

void setupUI()
{
status = new UpdaterStatusWidget;
Expand Down Expand Up @@ -286,7 +268,7 @@ DENG2_OBSERVES(App, StartupComplete)

void showNotification(bool show)
{
ClientWindow::main().notifications().showOrHide(status, show);
ClientWindow::main().notifications().showOrHide(*status, show);
}

void showCheckingNotification()
Expand Down Expand Up @@ -426,7 +408,7 @@ DENG2_OBSERVES(App, StartupComplete)

void startDownload()
{
DENG2_ASSERT(download == 0);
DENG2_ASSERT(!download);

// The notification provides access to the download dialog.
showDownloadNotification();
Expand Down

0 comments on commit 82a0a53

Please sign in to comment.