• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • libtdegames
 

libtdegames

  • libtdegames
kgamelcd.cpp
1/*
2 This file is part of the TDE games library
3 Copyright (C) 2001,2002,2003 Nicolas Hadacek (hadacek@kde.org)
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License version 2 as published by the Free Software Foundation.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#include "kgamelcd.h"
21#include "kgamelcd.moc"
22
23#include <tqlayout.h>
24#include <tqlabel.h>
25#include <tqtimer.h>
26
27#include <tdeglobal.h>
28
29
30//-----------------------------------------------------------------------------
31KGameLCD::KGameLCD(uint nbDigits, TQWidget *parent, const char *name)
32 : TQLCDNumber(nbDigits, parent, name), _htime(800)
33{
34 const TQPalette &p = palette();
35 _fgColor = p.color(TQPalette::Active, TQColorGroup::Foreground);
36 _hlColor = p.color(TQPalette::Active, TQColorGroup::HighlightedText);
37
38 _timer = new TQTimer(this);
39 connect(_timer, TQ_SIGNAL(timeout()), TQ_SLOT(timeout()));
40
41 setFrameStyle(Panel | Plain);
42 setSegmentStyle(Flat);
43
44 displayInt(0);
45}
46
47KGameLCD::~KGameLCD()
48{}
49
50void KGameLCD::setDefaultBackgroundColor(const TQColor &color)
51{
52 TQPalette p = palette();
53 p.setColor(TQColorGroup::Background, color);
54 setPalette(p);
55}
56
57void KGameLCD::setDefaultColor(const TQColor &color)
58{
59 _fgColor = color;
60 TQPalette p = palette();
61 p.setColor(TQColorGroup::Foreground, color);
62 setPalette(p);
63}
64
65void KGameLCD::setHighlightColor(const TQColor &color)
66{
67 _hlColor = color;
68}
69
70void KGameLCD::setLeadingString(const TQString &s)
71{
72 _lead = s;
73 displayInt(0);
74}
75
76void KGameLCD::setHighlightTime(uint time)
77{
78 _htime = time;
79}
80
81void KGameLCD::resetColor()
82{
83 setColor(TQColor());
84}
85
86void KGameLCD::setColor(const TQColor &color)
87{
88 const TQColor &c = (color.isValid() ? color : _fgColor);
89 TQPalette p = palette();
90 p.setColor(TQColorGroup::Foreground, c);
91 setPalette(p);
92}
93
94void KGameLCD::displayInt(int v)
95{
96 int n = numDigits() - _lead.length();
97 display(_lead + TQString::number(v).rightJustify(n));
98}
99
100void KGameLCD::highlight()
101{
102 highlight(true);
103 _timer->start(_htime, true);
104}
105
106void KGameLCD::highlight(bool light)
107{
108 if (light) setColor(_hlColor);
109 else resetColor();
110}
111
112//-----------------------------------------------------------------------------
113KGameLCDClock::KGameLCDClock(TQWidget *parent, const char *name)
114: KGameLCD(5, parent, name)
115{
116 _timerClock = new TQTimer(this);
117 connect(_timerClock, TQ_SIGNAL(timeout()), TQ_SLOT(timeoutClock()));
118}
119
120KGameLCDClock::~KGameLCDClock()
121{}
122
123void KGameLCDClock::timeoutClock()
124{
125 // waiting an hour does not restart timer
126 if ( _min==59 && _sec==59 ) return;
127 _sec++;
128 if (_sec==60) {
129 _min++;
130 _sec = 0;
131 }
132 showTime();
133}
134
135TQString KGameLCDClock::pretty() const
136{
137 TQString sec = TQString::number(_sec).rightJustify(2, '0', true);
138 TQString min = TQString::number(_min).rightJustify(2, '0', true);
139 return min + ':' + sec;
140}
141
142void KGameLCDClock::showTime()
143{
144 display(pretty());
145}
146
147void KGameLCDClock::reset()
148{
149 _timerClock->stop();
150 _sec = 0;
151 _min = 0;
152 showTime();
153}
154
155void KGameLCDClock::start()
156{
157 _timerClock->start(1000); // 1 second
158}
159
160void KGameLCDClock::stop()
161{
162 _timerClock->stop();
163}
164
165uint KGameLCDClock::seconds() const
166{
167 return _min*60 + _sec;
168}
169
170void KGameLCDClock::setTime(uint sec)
171{
172 Q_ASSERT( sec<3600 );
173 _sec = sec % 60;
174 _min = sec / 60;
175 showTime();
176}
177
178void KGameLCDClock::setTime(const TQString &s)
179{
180 Q_ASSERT( s.length()==5 && s[2]==':' );
181 uint min = kMin(s.section(':', 0, 0).toUInt(), uint(59));
182 uint sec = kMin(s.section(':', 1, 1).toUInt(), uint(59));
183 setTime(sec + min*60);
184}
185
186
187//-----------------------------------------------------------------------------
188class KGameLCDList::KGameLCDListPrivate
189{
190public:
191 TQValueVector<TQLabel *> _leadings;
192};
193
194KGameLCDList::KGameLCDList(const TQString &title, TQWidget *parent,
195 const char *name)
196 : TQWidget(parent, name)
197{
198 init(title);
199}
200
201KGameLCDList::KGameLCDList(TQWidget *parent, const char *name)
202 : TQWidget(parent, name)
203{
204 init(TQString());
205}
206
207KGameLCDList::~KGameLCDList()
208{
209 delete d;
210}
211
212void KGameLCDList::init(const TQString &title)
213{
214 d = new KGameLCDListPrivate;
215
216 TQGridLayout *top = new TQGridLayout(this, 1, 2, 5);
217 top->setColStretch(1, 1);
218
219 _title = new TQLabel(title, this);
220 _title->setAlignment(AlignCenter);
221 top->addMultiCellWidget(_title, 0, 0, 0, 1, AlignCenter);
222}
223
224void KGameLCDList::append(TQLCDNumber *lcd)
225{
226 append(TQString(), lcd);
227}
228
229void KGameLCDList::append(const TQString &leading, TQLCDNumber *lcd)
230{
231 uint i = size();
232 TQLabel *label = 0;
233 if ( !leading.isEmpty() ) {
234 label = new TQLabel(leading, this);
235 static_cast<TQGridLayout *>(layout())->addWidget(label, i+1, 0);
236 }
237 d->_leadings.push_back(label);
238 _lcds.push_back(lcd);
239 static_cast<TQGridLayout *>(layout())->addWidget(lcd, i+1, 1);
240}
241
242void KGameLCDList::clear()
243{
244 for (uint i=0; i<_lcds.size(); i++) {
245 delete d->_leadings[i];
246 delete _lcds[i];
247 }
248 d->_leadings.clear();
249 _lcds.clear();
250}
KGameLCDClock::seconds
uint seconds() const
Definition: kgamelcd.cpp:165
KGameLCDClock::setTime
void setTime(uint seconds)
Set the time.
Definition: kgamelcd.cpp:170
KGameLCDClock::stop
virtual void stop()
Stop the clock but do not reset it to zero.
Definition: kgamelcd.cpp:160
KGameLCDClock::start
virtual void start()
Start the clock from the current time.
Definition: kgamelcd.cpp:155
KGameLCDClock::pretty
TQString pretty() const
Definition: kgamelcd.cpp:135
KGameLCDClock::reset
virtual void reset()
Stop the clock and reset it to zero.
Definition: kgamelcd.cpp:147
KGameLCDList::size
uint size() const
Definition: kgamelcd.h:240
KGameLCDList::KGameLCDList
KGameLCDList(const TQString &title, TQWidget *parent=0, const char *name=0)
Constructor.
Definition: kgamelcd.cpp:194
KGameLCDList::lcd
TQLCDNumber * lcd(uint i) const
Definition: kgamelcd.h:235
KGameLCDList::clear
void clear()
Delete all TQLCDNumber and clear the list.
Definition: kgamelcd.cpp:242
KGameLCDList::append
void append(TQLCDNumber *lcd)
Append a TQLCDNumber at the bottom of the list.
Definition: kgamelcd.cpp:224
KGameLCDList::title
TQLabel * title() const
Definition: kgamelcd.h:230
KGameLCD
This class is a visually enhanced TQLCDNumber:
Definition: kgamelcd.h:43
KGameLCD::setHighlightTime
void setHighlightTime(uint time)
Set the highlight duration in milliseconds.
Definition: kgamelcd.cpp:76
KGameLCD::setDefaultBackgroundColor
void setDefaultBackgroundColor(const TQColor &color)
Set the default background color.
Definition: kgamelcd.cpp:50
KGameLCD::setColor
void setColor(const TQColor &color)
Set the foreground color.
Definition: kgamelcd.cpp:86
KGameLCD::setDefaultColor
void setDefaultColor(const TQColor &color)
Set the default foreground color.
Definition: kgamelcd.cpp:57
KGameLCD::setLeadingString
void setLeadingString(const TQString &s)
Set the string that will be displayed before the integer number to be displayed.
Definition: kgamelcd.cpp:70
KGameLCD::resetColor
void resetColor()
Reset the foreground color to the default one.
Definition: kgamelcd.cpp:81
KGameLCD::highlight
void highlight()
Highlight the LCD with the TQColorGourp::HighlightedText color for a small time (setHighlightTime).
Definition: kgamelcd.cpp:100
KGameLCD::displayInt
void displayInt(int value)
Display the given integer with the (optionnal) leading string.
Definition: kgamelcd.cpp:94
KGameLCD::setHighlightColor
void setHighlightColor(const TQColor &color)
Set highlight color.
Definition: kgamelcd.cpp:65

libtdegames

Skip menu "libtdegames"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

libtdegames

Skip menu "libtdegames"
  • libtdegames
Generated for libtdegames by doxygen 1.9.4
This website is maintained by Timothy Pearson.