GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/windows/okdialog.cpp Lines: 28 38 73.7 %
Date: 2017-11-29 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-2017  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
2
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
2
                   const int minWidth) :
44
    Window(title, modal, parent, "ok.xml"),
45
    ActionListener(),
46


10
    mTextBox(new TextBox(this))
47
{
48
4
    mTextBox->setEditable(false);
49
4
    mTextBox->setOpaque(Opaque_false);
50
2
    mTextBox->setTextWrapped(msg, minWidth);
51
52
    // TRANSLATORS: ok dialog button
53

8
    Button *const okButton = new Button(this, button, "ok", this);
54
55

2
    int width = getFont()->getWidth(title);
56
4
    if (width < mTextBox->getMinWidth())
57
        width = mTextBox->getMinWidth();
58
4
    if (width < okButton->getWidth())
59
2
        width = okButton->getWidth();
60
61
4
    if (mTextBox->getWidth() > width)
62
        width = mTextBox->getWidth();
63
2
    if (okButton->getWidth() > width)
64
        width = okButton->getWidth();
65
8
    setContentSize(width, mTextBox->getHeight() + okButton->getHeight()
66

8
        + getOption("buttonPadding", 8));
67
4
    mTextBox->setPosition((width - mTextBox->getWidth()) / 2, 0);
68
6
    okButton->setPosition((width - okButton->getWidth()) / 2,
69

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

6
}