GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
Line | Branch | Exec | Source |
1 |
/* |
||
2 |
* The ManaPlus Client |
||
3 |
* Copyright (C) 2004-2009 The Mana World Development Team |
||
4 |
* Copyright (C) 2009-2010 The Mana Developers |
||
5 |
* Copyright (C) 2011-2019 The ManaPlus Developers |
||
6 |
* Copyright (C) 2019-2021 Andrei Karas |
||
7 |
* |
||
8 |
* This file is part of The ManaPlus Client. |
||
9 |
* |
||
10 |
* This program is free software; you can redistribute it and/or modify |
||
11 |
* it under the terms of the GNU General Public License as published by |
||
12 |
* the Free Software Foundation; either version 2 of the License, or |
||
13 |
* any later version. |
||
14 |
* |
||
15 |
* This program is distributed in the hope that it will be useful, |
||
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
18 |
* GNU General Public License for more details. |
||
19 |
* |
||
20 |
* You should have received a copy of the GNU General Public License |
||
21 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
22 |
*/ |
||
23 |
|||
24 |
#include "gui/windows/okdialog.h" |
||
25 |
|||
26 |
#include "soundmanager.h" |
||
27 |
|||
28 |
#include "const/sound.h" |
||
29 |
|||
30 |
#include "gui/widgets/button.h" |
||
31 |
#include "gui/widgets/textbox.h" |
||
32 |
|||
33 |
#include "gui/fonts/font.h" |
||
34 |
|||
35 |
#include "debug.h" |
||
36 |
|||
37 |
1 |
OkDialog::OkDialog(const std::string &restrict title, |
|
38 |
const std::string &restrict msg, |
||
39 |
const std::string &restrict button, |
||
40 |
const DialogTypeT soundEvent, |
||
41 |
const Modal modal, |
||
42 |
const ShowCenter showCenter, |
||
43 |
Window *const parent, |
||
44 |
1 |
const int minWidth) : |
|
45 |
Window(title, modal, parent, "ok.xml"), |
||
46 |
ActionListener(), |
||
47 |
✓✗✓✗ ✓✗ |
5 |
mTextBox(new TextBox(this)) |
48 |
{ |
||
49 |
✓✗ | 1 |
mTextBox->setEditable(false); |
50 |
2 |
mTextBox->setOpaque(Opaque_false); |
|
51 |
✓✗ | 1 |
mTextBox->setTextWrapped(msg, minWidth); |
52 |
|||
53 |
// TRANSLATORS: ok dialog button |
||
54 |
Button *const okButton = new Button(this, |
||
55 |
button, |
||
56 |
"ok", |
||
57 |
BUTTON_SKIN, |
||
58 |
✓✗✓✗ ✓✗ |
3 |
this); |
59 |
|||
60 |
✓✗✓✗ |
1 |
int width = getFont()->getWidth(title); |
61 |
✗✓ | 2 |
if (width < mTextBox->getMinWidth()) |
62 |
width = mTextBox->getMinWidth(); |
||
63 |
✓✗ | 2 |
if (width < okButton->getWidth()) |
64 |
1 |
width = okButton->getWidth(); |
|
65 |
|||
66 |
✗✓ | 2 |
if (mTextBox->getWidth() > width) |
67 |
width = mTextBox->getWidth(); |
||
68 |
✗✓ | 1 |
if (okButton->getWidth() > width) |
69 |
width = okButton->getWidth(); |
||
70 |
4 |
setContentSize(width, mTextBox->getHeight() + okButton->getHeight() |
|
71 |
✓✗✓✗ ✓✗ |
4 |
+ getOption("buttonPadding", 8)); |
72 |
✓✗ | 2 |
mTextBox->setPosition((width - mTextBox->getWidth()) / 2, 0); |
73 |
2 |
okButton->setPosition((width - okButton->getWidth()) / 2, |
|
74 |
✓✗✓✗ ✓✗ |
5 |
mTextBox->getHeight() + getOption("buttonPadding", 8)); |
75 |
|||
76 |
// +++ virtual method call |
||
77 |
✓✗ | 1 |
add(mTextBox); |
78 |
✓✗ | 1 |
add(okButton); |
79 |
|||
80 |
✓✗ | 1 |
if (showCenter == ShowCenter_true) |
81 |
✓✗ | 1 |
center(); |
82 |
else |
||
83 |
centerHorisontally(); |
||
84 |
// +++ virtual method call |
||
85 |
✓✗ | 1 |
setVisible(Visible_true); |
86 |
✓✗ | 1 |
okButton->requestFocus(); |
87 |
|||
88 |
✗✓ | 1 |
if (soundEvent == DialogType::OK) |
89 |
soundManager.playGuiSound(SOUND_INFO); |
||
90 |
✗✓ | 1 |
else if (soundEvent == DialogType::ERROR) |
91 |
soundManager.playGuiSound(SOUND_ERROR); |
||
92 |
1 |
} |
|
93 |
|||
94 |
void OkDialog::action(const ActionEvent &event) |
||
95 |
{ |
||
96 |
setActionEventId(event.getId()); |
||
97 |
distributeActionEvent(); |
||
98 |
scheduleDelete(); |
||
99 |
✓✗✓✗ |
3 |
} |
Generated by: GCOVR (Version 3.3) |