22 #include <tqpainter.h>
28 #include "kgameprogress.h"
30 #include <tdeapplication.h>
33 : TQFrame(parent, name),
34 TQRangeControl(0, 100, 1, 10, 0),
35 orient(TQt::Horizontal)
41 : TQFrame(parent, name),
42 TQRangeControl(0, 100, 1, 10, 0),
49 TQt::Orientation orientation, TQWidget *parent,
const char *name)
50 : TQFrame(parent, name),
51 TQRangeControl(minValue, maxValue, 1, 10, value),
67 void KGameProgress::initialize()
70 use_supplied_bar_color =
false;
74 setBackgroundMode( PaletteBackground );
75 connect(kapp, TQ_SIGNAL(appearanceChanged()),
this, TQ_SLOT(paletteChange()));
79 void KGameProgress::paletteChange()
81 TQPalette p = kapp->palette();
82 const TQColorGroup &colorGroup = p.active();
83 if (!use_supplied_bar_color)
84 bar_color = colorGroup.highlight();
85 bar_text_color = colorGroup.highlightedText();
86 text_color = colorGroup.text();
100 bar_pixmap =
new TQPixmap(pixmap);
106 use_supplied_bar_color =
true;
115 if (bar_style != style) {
131 TQRangeControl::setValue(
value);
136 text_enabled = enable;
154 TQSize KGameProgress::sizeHint()
const
167 TQSize KGameProgress::minimumSizeHint()
const
172 TQSizePolicy KGameProgress::sizePolicy()
const
175 return TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Expanding );
177 return TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed );
190 int KGameProgress::recalcValue(
int range)
192 int abs_value =
value() - minValue();
193 int abs_range = maxValue() - minValue();
194 return abs_range ? range * abs_value / abs_range : 0;
197 void KGameProgress::valueChange()
199 repaint(contentsRect(),
false);
203 void KGameProgress::rangeChange()
205 repaint(contentsRect(),
false);
209 void KGameProgress::styleChange(TQStyle&)
214 void KGameProgress::adjustStyle()
216 switch (style().styleHint(TQStyle::SH_GUIStyle)) {
218 setFrameStyle(TQFrame::WinPanel | TQFrame::Sunken);
222 setFrameStyle(TQFrame::Panel | TQFrame::Sunken);
229 void KGameProgress::paletteChange(
const TQPalette &p )
233 TQFrame::paletteChange(p);
236 void KGameProgress::drawText(TQPainter *p)
238 TQRect r(contentsRect());
245 s.replace(TQRegExp(TQString::fromLatin1(
"%p")), TQString::number(recalcValue(100)));
246 s.replace(TQRegExp(TQString::fromLatin1(
"%v")), TQString::number(
value()));
247 s.replace(TQRegExp(TQString::fromLatin1(
"%m")), TQString::number(maxValue()));
249 p->setPen(text_color);
250 TQFont font = p->font();
254 p->drawText(r, AlignCenter, s);
255 p->setClipRegion( fr );
256 p->setPen(bar_text_color);
257 p->drawText(r, AlignCenter, s);
260 void KGameProgress::drawContents(TQPainter *p)
262 TQRect cr = contentsRect(), er = cr;
264 TQBrush fb(bar_color), eb(backgroundColor());
267 fb.setPixmap(*bar_pixmap);
269 if (backgroundPixmap())
270 eb.setPixmap(*backgroundPixmap());
274 if (orient ==TQt::Horizontal) {
275 fr.setWidth(recalcValue(cr.width()));
276 er.setLeft(fr.right() + 1);
278 fr.setTop(cr.bottom() - recalcValue(cr.height()));
279 er.setBottom(fr.top() - 1);
282 p->setBrushOrigin(cr.topLeft());
290 const int margin = 2;
291 int max, num, dx, dy;
292 if (orient ==TQt::Horizontal) {
293 fr.setHeight(cr.height() - 2 * margin);
294 fr.setWidth((
int)(0.67 * fr.height()));
295 fr.moveTopLeft(TQPoint(cr.left() + margin, cr.top() + margin));
296 dx = fr.width() + margin;
298 max = (cr.width() - margin) / (fr.width() + margin) + 1;
299 num = recalcValue(max);
301 fr.setWidth(cr.width() - 2 * margin);
302 fr.setHeight((
int)(0.67 * fr.width()));
303 fr.moveBottomLeft(TQPoint(cr.left() + margin, cr.bottom() - margin));
305 dy = - (fr.height() + margin);
306 max = (cr.height() - margin) / (fr.height() + margin) + 1;
307 num = recalcValue(max);
309 p->setClipRect(cr.x() + margin, cr.y() + margin,
310 cr.width() - margin, cr.height() - margin);
311 for (
int i = 0; i < num; i++) {
312 p->setBrushOrigin(fr.topLeft());
318 if (orient ==TQt::Horizontal)
319 er.setLeft(fr.right() + 1);
321 er.setBottom(fr.bottom() + 1);
323 p->setBrushOrigin(cr.topLeft());
331 if (text_enabled && bar_style != Blocked)
345 #include "kgameprogress.moc"
void setBarStyle(BarStyle style)
Set the progress bar style.
const TQPixmap * barPixmap() const
Retrieve the bar pixmap.
~KGameProgress()
Destruct the progress bar.
void percentageChanged(int)
Emitted when the state of the progress bar changes.
const TQColor & barColor() const
Retrieve the bar color.
void advance(int prog)
Advance the progress bar by prog.
void setValue(int value)
Set the current value of the progress bar to value.
BarStyle
Possible values for bar style.
void setTextEnabled(bool)
If this is set to true, the progress text will be displayed.
TQString format() const
Retrieve the current format for printing status text.
void setBarColor(const TQColor &)
Set the color of the progress bar.
int value() const
Retrive the current status.
KGameProgress(TQWidget *parent=0, const char *name=0)
Construct a horizontal progress bar.
BarStyle barStyle() const
Retrieve the bar style.
void setBarPixmap(const TQPixmap &)
Set a pixmap to be shown in the progress bar.
Orientation orientation() const
Retrive the orientation of the progress bar.
void setOrientation(Orientation)
Set the orientation of the progress bar.
bool textEnabled() const
Returns true if progress text will be displayed, false otherwise.
void setFormat(const TQString &format)
Set the format of the text to use to display status.