summaryrefslogtreecommitdiffstats
path: root/noatun/modules/winskin/waDigit.cpp
blob: f19266b1d3f37f1b2b4f0885d26c181a55151278 (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
/*
  The digit for the time
  Copyright (C) 1999  Martin Vogt
  Copyright (C) 2002  Ryan Cumming

  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.

  For more information look at the file COPYRIGHT in this package

 */


#include "waDigit.h"
#include "waSkinModel.h"

#include <kconfig.h>
#include <kglobal.h>

WaDigit::WaDigit() : WaWidget(_WA_MAPPING_DIGITS)
{
    KConfig *config = TDEGlobal::config();
    config->setGroup("Winskin");

    reverse_time = config->readNumEntry("timeReversed", false);
}


WaDigit::~WaDigit()
{
    KConfig *config = TDEGlobal::config();
    config->setGroup("Winskin");
    config->writeEntry("timeReversed", reverse_time);
}

void WaDigit::paintEvent(TQPaintEvent *)
{
    paintBackground();

    const char *time = timeString.latin1();
    int len = strlen(time);
    if (len == 0) 
	return;

    // Declare all these variables after we check for zero-length
    WaSkinModel *waSkinModel = WaSkinModel::instance();

    int x = waSkinModel->getMapGeometry(mapping).x();
    int y = waSkinModel->getMapGeometry(mapping).y();

    TQRect mapRect;

    // We expect strings either in the form "xx:yy", or "-xx:yy"
    // If the string length is 6, we have it in the form of "-xx:yy"
    // Remove the -, move the string forward one character, and 
    // continue parsing
    mapRect = waSkinModel->getMapGeometry(_WA_MAPPING_MINUS);
    if (len == 6) {
        waSkinModel->getDigit('-', TQT_TQPAINTDEVICE(this), mapRect.x() - x, mapRect.y() - y);
        time++;
    }
    else {
        waSkinModel->getDigit(' ', TQT_TQPAINTDEVICE(this), mapRect.x() - x, mapRect.y() - y);
    }

    mapRect = waSkinModel->getMapGeometry(_WA_MAPPING_DIGIT_1);
    waSkinModel->getDigit(time[0], TQT_TQPAINTDEVICE(this), mapRect.x() - x, mapRect.y() - y);

    mapRect = waSkinModel->getMapGeometry(_WA_MAPPING_DIGIT_2);
    waSkinModel->getDigit(time[1], TQT_TQPAINTDEVICE(this), mapRect.x() - x, mapRect.y() - y);

    mapRect = waSkinModel->getMapGeometry(_WA_MAPPING_DIGIT_3);
    waSkinModel->getDigit(time[3], TQT_TQPAINTDEVICE(this), mapRect.x() - x, mapRect.y() - y);

    mapRect = waSkinModel->getMapGeometry(_WA_MAPPING_DIGIT_4);
    waSkinModel->getDigit(time[4], TQT_TQPAINTDEVICE(this), mapRect.x() - x, mapRect.y() - y);
}

void WaDigit::mousePressEvent(TQMouseEvent* e) {
    if (e->button() == Qt::LeftButton) {
        reverse_time = !reverse_time;
        emit digitsClicked();
    }
    else
        WaWidget::mousePressEvent(e);
}

#include "waDigit.moc"