summaryrefslogtreecommitdiffstats
path: root/kpacman/kpacmanview.cpp
blob: b1931ecc71af620a43d86ee3d3b9f5159d5f7ac1 (plain)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/***************************************************************************
                          kpacmanview.cpp  -  description
                             -------------------
    begin                : Sam Jan 19 13:37:57 CET 2002
    copyright            : (C) 1998-2003 by Jörg Thönnissen
    email                : joe@dsite.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

// include files for TQt
#include <ntqmessagebox.h>

// include files for KDE
#include <kapp.h>
#include <kconfig.h>
#include <kstddirs.h>

// application specific includes
#include "kpacmanview.h"
#include "bitfont.h"
#include "score.h"
#include "referee.h"
#include "status.h"

KpacmanView::KpacmanView( TQWidget *parent, const char *name) : TQWidget( parent, name )
{
    bitfont = NULL;
    fontName = "";

    scheme = mode = -1;
    confScheme();

    score = new Score(this, name, scheme, mode, bitfont);
    referee = new Referee( this, name, scheme, mode, bitfont);
    status = new Status(this, name, scheme, mode);

    setFixedSize(referee->width(), bitfont->height()*3 + referee->height() + status->height());
}

KpacmanView::~KpacmanView()
{
}

void KpacmanView::confMisc(bool defGroup)
{
    KStandardDirs *dirs = KGlobal::dirs();
    TQString findPath;

    if (defGroup || kapp->config()->hasKey("Font")) {
        fontName = kapp->config()->readEntry("Font");

        if (fontName.left(1) != "/" && fontName.left(1) != "~")
            fontName.insert(0, "fonts/");
        if (fontName.right(1) == "/")
            fontName.append("font.xbm");

        findPath = dirs->findResource("appdata", fontName);
        if (!findPath.isEmpty())
            fontName = findPath;

        bitfontFirstChar = kapp->config()->readNumEntry("FontFirstChar", 0x0e);
        bitfontLastChar = kapp->config()->readNumEntry("FontLastChar", 0x5f);
    }
}

void KpacmanView::confScheme()
{
    TQString lastFontName = fontName;
    TQString oldgroup = kapp->config()->group();
    TQString newgroup;

    // if not set, read mode and scheme from the configfile
    if (mode == -1 && scheme == -1) {           
        scheme = kapp->config()->readNumEntry("Scheme", -1);
        mode = kapp->config()->readNumEntry("Mode", -1);
        
        // if mode is not set in the defGroup-group, lookup the scheme group
        if (scheme != -1 || mode == -1) {
            newgroup.sprintf("Scheme %d", scheme);
            kapp->config()->setGroup(newgroup);

            mode = kapp->config()->readNumEntry("Mode", -1);
            kapp->config()->setGroup(oldgroup);
        }
    }

    confMisc();

    if (mode != -1) {
        newgroup.sprintf("Mode %d", mode);
        kapp->config()->setGroup(newgroup);     

        confMisc(FALSE);
    }

    if (scheme != -1) {
        newgroup.sprintf("Scheme %d", scheme);
        kapp->config()->setGroup(newgroup);

        confMisc(FALSE);
    }

    if (lastFontName != fontName) {

        if (bitfont != 0)
            delete bitfont;

        bitfont = new Bitfont(fontName, bitfontFirstChar, bitfontLastChar);
        if (bitfont->width() == 0 || bitfont->height() == 0) {
            TQString msg = i18n("The bitfont could not be contructed.\n\n"
                               "The file '@FONTNAME@' does not exist,\n"
                               "or is of an unknown format.");
            msg.replace(TQRegExp("@FONTNAME@"), fontName);
            // TQMessageBox::critical(this, i18n("Initialization Error"), msg);
            printf("%s\n", msg.data());
        }
    }

    kapp->config()->setGroup(oldgroup);
}

void KpacmanView::setScheme(int Scheme, int Mode)
{
    mode = Mode;
    scheme = Scheme;

    confScheme();

    score->setScheme(Scheme, Mode, bitfont);
    referee->setScheme(Scheme, Mode, bitfont);
    status->setScheme(Scheme, Mode);

    setFixedSize(referee->width(),
                 bitfont->height()*3 + referee->height() + status->height());
    updateGeometry();

    score->repaint(FALSE);
    referee->repaint(FALSE);
    status->repaint(FALSE);
}

void KpacmanView::resizeEvent( TQResizeEvent * )
{
    referee->setGeometry(0, bitfont->height()*3, referee->width(), referee->height());
    referee->setBackgroundColor(BLACK);

    status->setGeometry(0, bitfont->height()*3+referee->height(), referee->width(),
                        status->height());
    status->setBackgroundColor(BLACK);

    score->setGeometry(0, 0, referee->width(), bitfont->height()*3+referee->height()+status->height());
    score->setBackgroundColor(BLACK);
}