~ubuntu-branches/ubuntu/karmic/ggz-kde-games/karmic

« back to all changes in this revision

Viewing changes to fyrdman/levelselector.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Stephen Zander
  • Date: 2004-02-18 20:14:39 UTC
  • Revision ID: james.westby@ubuntu.com-20040218201439-nobnsh8tx4kaw6q0
Tags: upstream-0.0.7
ImportĀ upstreamĀ versionĀ 0.0.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "levelselector.h"
 
2
#include "level.h"
 
3
 
 
4
#include <klocale.h>
 
5
 
 
6
#include <qcombobox.h>
 
7
#include <qtextedit.h>
 
8
#include <qlayout.h>
 
9
#include <qpushbutton.h>
 
10
 
 
11
LevelSelector::LevelSelector(bool ro, QWidget *parent, const char *name)
 
12
: QDialog(parent, name, true)
 
13
{
 
14
        QVBoxLayout *lay;
 
15
        QHBoxLayout *lay2;
 
16
        QPushButton *ok, *cancel;
 
17
 
 
18
        combo = new QComboBox(this);
 
19
        //if(ro) combo->setReadOnly(true);
 
20
 
 
21
        desc = new QTextEdit(this);
 
22
        desc->setReadOnly(true);
 
23
 
 
24
        if(!ro) ok = new QPushButton(i18n("Play"), this);
 
25
        else ok = new QPushButton(i18n("Close"), this);
 
26
        if(!ro) cancel = new QPushButton(i18n("Cancel"), this);
 
27
        else cancel = NULL;
 
28
 
 
29
        lay = new QVBoxLayout(this, 5);
 
30
        lay->add(combo);
 
31
        lay->add(desc);
 
32
        lay2 = new QHBoxLayout(lay, 5);
 
33
        lay2->add(ok);
 
34
        if(!ro) lay2->add(cancel);
 
35
 
 
36
        if(!ro) connect(ok, SIGNAL(clicked()), SLOT(accept()));
 
37
        else connect(ok, SIGNAL(clicked()), SLOT(close()));
 
38
        if(!ro) connect(cancel, SIGNAL(clicked()), SLOT(reject()));
 
39
        connect(combo, SIGNAL(activated(int)), SLOT(slotActivated(int)));
 
40
 
 
41
        if(!ro) setCaption(i18n("Select a level"));
 
42
        else setCaption(i18n("Level information"));
 
43
}
 
44
 
 
45
LevelSelector::~LevelSelector()
 
46
{
 
47
}
 
48
 
 
49
void LevelSelector::accept()
 
50
{
 
51
        // ...
 
52
        QDialog::accept();
 
53
}
 
54
 
 
55
void LevelSelector::slotActivated(int id)
 
56
{
 
57
        QString level, author, version;
 
58
        int width, height, players;
 
59
        QString text;
 
60
 
 
61
        level = combo->currentText();
 
62
        author = "unknown";
 
63
        version = "unknown";
 
64
        width = 0;
 
65
        height = 0;
 
66
        players = 0;
 
67
 
 
68
        for(Level *l = m_levels.first(); l; l = m_levels.next())
 
69
                if(l->title() == level)
 
70
                {
 
71
                        author = l->author();
 
72
                        version = l->version();
 
73
                        width = l->width();
 
74
                        height = l->height();
 
75
                        players = l->players();
 
76
                }
 
77
 
 
78
        text = i18n("Level: <i>%1</i><br>Author: <i>%2</i><br>Version: <i>%3</i><br>").arg(level).arg(author).arg(version);
 
79
        text += i18n("Width: <i>%1</i><br>Height: <i>%2</i><br>Players: <i>%3</i>").arg(width).arg(height).arg(players);
 
80
 
 
81
        desc->setText(text);
 
82
}
 
83
 
 
84
void LevelSelector::addLevel(Level *level)
 
85
{
 
86
        combo->insertItem(level->title());
 
87
        m_levels.append(level);
 
88
 
 
89
        slotActivated(0);
 
90
}
 
91
 
 
92
QString LevelSelector::level()
 
93
{
 
94
        return combo->currentText();
 
95
}
 
96