GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/windows/okdialog.cpp Lines: 28 38 73.7 %
Date: 2018-07-14 Branches: 31 68 45.6 %

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-2018  The ManaPlus Developers
6
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
#include "gui/windows/okdialog.h"
24
25
#include "soundmanager.h"
26
27
#include "const/sound.h"
28
29
#include "gui/widgets/button.h"
30
#include "gui/widgets/textbox.h"
31
32
#include "gui/fonts/font.h"
33
34
#include "debug.h"
35
36
1
OkDialog::OkDialog(const std::string &restrict title,
37
                   const std::string &restrict msg,
38
                   const std::string &restrict button,
39
                   const DialogTypeT soundEvent,
40
                   const Modal modal,
41
                   const ShowCenter showCenter,
42
                   Window *const parent,
43
1
                   const int minWidth) :
44
    Window(title, modal, parent, "ok.xml"),
45
    ActionListener(),
46

5
    mTextBox(new TextBox(this))
47
{
48
1
    mTextBox->setEditable(false);
49
2
    mTextBox->setOpaque(Opaque_false);
50
1
    mTextBox->setTextWrapped(msg, minWidth);
51
52
    // TRANSLATORS: ok dialog button
53
    Button *const okButton = new Button(this,
54
        button,
55
        "ok",
56
        BUTTON_SKIN,
57

3
        this);
58
59

1
    int width = getFont()->getWidth(title);
60
2
    if (width < mTextBox->getMinWidth())
61
        width = mTextBox->getMinWidth();
62
2
    if (width < okButton->getWidth())
63
1
        width = okButton->getWidth();
64
65
2
    if (mTextBox->getWidth() > width)
66
        width = mTextBox->getWidth();
67
1
    if (okButton->getWidth() > width)
68
        width = okButton->getWidth();
69
4
    setContentSize(width, mTextBox->getHeight() + okButton->getHeight()
70

4
        + getOption("buttonPadding", 8));
71
2
    mTextBox->setPosition((width - mTextBox->getWidth()) / 2, 0);
72
2
    okButton->setPosition((width - okButton->getWidth()) / 2,
73

5
        mTextBox->getHeight() + getOption("buttonPadding", 8));
74
75
    // +++ virtual method call
76
1
    add(mTextBox);
77
1
    add(okButton);
78
79
1
    if (showCenter == ShowCenter_true)
80
1
        center();
81
    else
82
        centerHorisontally();
83
    // +++ virtual method call
84
1
    setVisible(Visible_true);
85
1
    okButton->requestFocus();
86
87
1
    if (soundEvent == DialogType::OK)
88
        soundManager.playGuiSound(SOUND_INFO);
89
1
    else if (soundEvent == DialogType::ERROR)
90
        soundManager.playGuiSound(SOUND_ERROR);
91
1
}
92
93
void OkDialog::action(const ActionEvent &event)
94
{
95
    setActionEventId(event.getId());
96
    distributeActionEvent();
97
    scheduleDelete();
98

3
}