/
messagedialog.cpp
114 lines (94 loc) · 3.37 KB
/
messagedialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/** @file messagedialog.cpp Dialog for showing a message.
*
* @authors Copyright (c) 2013 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/MessageDialog"
#include "de/SequentialLayout"
#include "de/DialogContentStylist"
namespace de {
using namespace ui;
DENG_GUI_PIMPL(MessageDialog)
{
LabelWidget *title;
LabelWidget *message;
DialogContentStylist buttonStylist;
Impl(Public *i) : Base(i)
{
ScrollAreaWidget &area = self.area();
// Create widgets.
area.add(title = new LabelWidget);
area.add(message = new LabelWidget);
// Configure style.
title->setFont("title");
title->setTextColor("accent");
title->setSizePolicy(ui::Fixed, ui::Expand);
title->setAlignment(ui::AlignLeft);
title->setTextAlignment(ui::AlignRight);
title->setOverrideImageSize(title->font().ascent().valuei());
title->setImageColor(style().colors().colorf("accent"));
title->setTextGap("gap");
title->setTextLineAlignment(ui::AlignLeft);
message->setSizePolicy(ui::Fixed, ui::Expand);
message->setAlignment(ui::AlignLeft);
message->setTextLineAlignment(ui::AlignLeft);
updateLayout();
}
void updateLayout(LayoutBehavior behavior = ExcludeHidden)
{
ScrollAreaWidget &area = self.area();
// Simple vertical layout.
SequentialLayout layout(area.contentRule().left(),
area.contentRule().top());
layout.setOverrideWidth(rule("dialog.message.width"));
// Put all the widgets into the layout.
foreach (Widget *w, area.childWidgets())
{
// Individual children can be hidden to exclude them from the layout.
if (behavior == IncludeHidden || !w->behavior().testFlag(Widget::Hidden))
{
layout << w->as<GuiWidget>();
}
}
area.setContentSize(layout.width(), layout.height());
}
};
MessageDialog::MessageDialog(String const &name)
: DialogWidget(name)
, d(new Impl(this))
{}
void MessageDialog::useInfoStyle()
{
DialogWidget::useInfoStyle();
title().setTextColor("inverted.accent");
message().setTextColor("inverted.text");
d->buttonStylist.addContainer(buttonsMenu());
d->buttonStylist.addContainer(extraButtonsMenu());
d->buttonStylist.setAdjustMargins(false);
d->buttonStylist.setInfoStyle(true);
}
LabelWidget &MessageDialog::title()
{
return *d->title;
}
LabelWidget &MessageDialog::message()
{
return *d->message;
}
void MessageDialog::updateLayout(LayoutBehavior behavior)
{
d->updateLayout(behavior);
}
} // namespace de