~ubuntu-branches/ubuntu/maverick/kdebase-workspace/maverick-proposed

« back to all changes in this revision

Viewing changes to kdm/kfrontend/kdmclock.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-07-08 01:11:52 UTC
  • mfrom: (1.1.43 upstream)
  • Revision ID: james.westby@ubuntu.com-20100708011152-z0h26httnjr91mmy
Tags: 4:4.4.92-0ubuntu1
* New upstream rc release:
  - Bump kde-sc-dev-latest to 4.4.92
  - Refresh patches
  - Update symbols
  - plasma-widgets-workspace replaces/conflicts plasma-widget-logout

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include <QTime>
29
29
#include <QTimer>
30
30
 
31
 
KdmClock::KdmClock( QWidget *parent )
32
 
        : inherited( parent )
 
31
KdmClock::KdmClock(QWidget *parent)
 
32
    : inherited(parent)
33
33
{
34
 
        QTimer *timer = new QTimer( this );
35
 
        connect( timer, SIGNAL(timeout()), SLOT(timeout()) );
36
 
        timer->start( 1000 );
 
34
    QTimer *timer = new QTimer(this);
 
35
    connect(timer, SIGNAL(timeout()), SLOT(timeout()));
 
36
    timer->start(1000);
37
37
 
38
38
#ifdef MORE
39
 
        mDate = false;//config->readEntry( "date", false );
40
 
        mSecond = true;//config->readEntry( "second", true );
41
 
        mDigital = false;//config->readEntry( "digital", false );
42
 
        mBorder = true;//config->readEntry( "border", false );
43
 
 
44
 
        //config->setGroup( "Font" );
45
 
        mFont.setFamily( QString::fromLatin1("Utopia")/*config->readEntry( "Family", "Utopia" )*/ );
46
 
        mFont.setPointSize( 51/*config->readEntry( "Point Size", 51 )*/ );
47
 
        mFont.setWeight( 75/*config->readEntry( "Weight", 75 )*/ );
48
 
        mFont.setItalic( true/*config->readEntry( "Italic", true )*/ );
49
 
        mFont.setBold( true/*config->readEntry( "Bold", false )*/ );
50
 
 
51
 
        if (mBorder)
52
 
                setFrameStyle( WinPanel|Sunken );
 
39
    mDate = false;//config->readEntry("date", false);
 
40
    mSecond = true;//config->readEntry("second", true);
 
41
    mDigital = false;//config->readEntry("digital", false);
 
42
    mBorder = true;//config->readEntry("border", false);
 
43
 
 
44
    //config->setGroup("Font");
 
45
    mFont.setFamily(QString::fromLatin1("Utopia")/*config->readEntry("Family", "Utopia")*/);
 
46
    mFont.setPointSize(51/*config->readEntry("Point Size", 51)*/);
 
47
    mFont.setWeight(75/*config->readEntry("Weight", 75)*/);
 
48
    mFont.setItalic(true/*config->readEntry("Italic", true)*/);
 
49
    mFont.setBold(true/*config->readEntry("Bold", false)*/);
 
50
 
 
51
    if (mBorder)
 
52
        setFrameStyle(WinPanel | Sunken);
53
53
#endif
54
54
 
55
 
        setFixedSize( 100, 100 );
 
55
    setFixedSize(100, 100);
56
56
 
57
 
        repaint();
 
57
    repaint();
58
58
}
59
59
 
60
60
 
61
 
void KdmClock::showEvent( QShowEvent * )
 
61
void KdmClock::showEvent(QShowEvent *)
62
62
{
63
 
        repaint();
 
63
    repaint();
64
64
}
65
65
 
66
66
 
67
67
void KdmClock::timeout()
68
68
{
69
 
        repaint();
 
69
    repaint();
70
70
}
71
71
 
72
 
void KdmClock::paintEvent( QPaintEvent * )
 
72
void KdmClock::paintEvent(QPaintEvent *)
73
73
{
74
 
        QPainter p( this );
75
 
#ifdef MORE
76
 
        drawFrame( &p );
77
 
#endif
78
 
 
79
 
        p.setPen( palette().foreground().color() );
80
 
        p.setBrush( palette().foreground() );
81
 
 
82
 
        QTime time = QTime::currentTime();
83
 
 
84
 
#ifdef MORE
85
 
        if (mDigital) {
86
 
                QString buf;
87
 
                if (mSecond)
88
 
                        buf.sprintf( "%02d:%02d:%02d", time.hour(), time.minute(),
89
 
                                     time.second() );
90
 
                else
91
 
                        buf.sprintf( "%02d:%02d", time.hour(), time.minute() );
92
 
                mFont.setPointSize( qMin( (int)(width() / buf.length() * 1.5), height() ) );
93
 
                p.setFont( mFont );
94
 
                p.drawText( contentsRect(), Qt::AlignCenter, buf );
95
 
        } else
96
 
#endif
97
 
        {
98
 
                QTransform matrix;
99
 
                QPoint cp = contentsRect().center();
100
 
                matrix.translate( cp.x(), cp.y() );
101
 
                int d = qMin( contentsRect().width() - 15, contentsRect().height() - 15 );
102
 
                matrix.scale( d/1000.0F, d/1000.0F );
103
 
 
104
 
                QPolygon pts;
105
 
 
106
 
                // Hour
107
 
                float h_angle = 30*(time.hour()%12-3) + time.minute()/2;
108
 
                matrix.rotate( h_angle );
109
 
                p.setWorldTransform( matrix );
110
 
                pts.setPoints( 4, -20,0, 0,-20, 300,0, 0,20 );
111
 
                p.drawPolygon( pts );
112
 
                matrix.rotate( -h_angle );
113
 
 
114
 
                // Minute
115
 
                float m_angle = (time.minute()-15)*6;
116
 
                matrix.rotate( m_angle );
117
 
                p.setWorldTransform( matrix );
118
 
                pts.setPoints( 4, -10,0, 0,-10, 400,0, 0,10 );
119
 
                p.drawPolygon( pts );
120
 
                matrix.rotate( -m_angle );
121
 
 
122
 
                // Second
123
 
#ifdef MORE
124
 
                if (mSecond)
125
 
#endif
126
 
                {
127
 
                        float s_angle = (time.second()-15)*6;
128
 
                        matrix.rotate( s_angle );
129
 
                        p.setWorldTransform( matrix );
130
 
                        pts.setPoints( 4,0,0,0,0,400,0,0,0 );
131
 
                        p.drawPolygon( pts );
132
 
                        matrix.rotate( -s_angle );
133
 
                }
134
 
 
135
 
                // quadrante
136
 
                for (int i = 0; i < 60; i++) {
137
 
                        p.setWorldTransform( matrix );
138
 
                        if ((i % 5) == 0)
139
 
                                p.drawLine( 450,0, 500,0 ); // draw hour lines
140
 
                        else
141
 
                                p.drawPoint( 480,0 ); // draw second lines
142
 
                        matrix.rotate( 6 );
143
 
                }
144
 
 
145
 
        } // if (mDigital)
 
74
    QPainter p(this);
 
75
#ifdef MORE
 
76
    drawFrame(&p);
 
77
#endif
 
78
 
 
79
    p.setPen(palette().foreground().color());
 
80
    p.setBrush(palette().foreground());
 
81
 
 
82
    QTime time = QTime::currentTime();
 
83
 
 
84
#ifdef MORE
 
85
    if (mDigital) {
 
86
        QString buf;
 
87
        if (mSecond)
 
88
            buf.sprintf("%02d:%02d:%02d", time.hour(), time.minute(),
 
89
                        time.second());
 
90
        else
 
91
            buf.sprintf("%02d:%02d", time.hour(), time.minute());
 
92
        mFont.setPointSize(qMin((int)(width() / buf.length() * 1.5), height()));
 
93
        p.setFont(mFont);
 
94
        p.drawText(contentsRect(), Qt::AlignCenter, buf);
 
95
    } else
 
96
#endif
 
97
    {
 
98
        QTransform matrix;
 
99
        QPoint cp = contentsRect().center();
 
100
        matrix.translate(cp.x(), cp.y());
 
101
        int d = qMin(contentsRect().width() - 15, contentsRect().height() - 15);
 
102
        matrix.scale(d / 1000.0F, d / 1000.0F);
 
103
 
 
104
        QPolygon pts;
 
105
 
 
106
        // Hour
 
107
        float h_angle = 30 * (time.hour() % 12 - 3) + time.minute() / 2;
 
108
        matrix.rotate(h_angle);
 
109
        p.setWorldTransform(matrix);
 
110
        pts.setPoints(4, -20, 0, 0, -20, 300, 0, 0, 20);
 
111
        p.drawPolygon(pts);
 
112
        matrix.rotate(-h_angle);
 
113
 
 
114
        // Minute
 
115
        float m_angle = (time.minute() - 15) * 6;
 
116
        matrix.rotate(m_angle);
 
117
        p.setWorldTransform(matrix);
 
118
        pts.setPoints(4, -10, 0, 0, -10, 400, 0, 0, 10);
 
119
        p.drawPolygon(pts);
 
120
        matrix.rotate(-m_angle);
 
121
 
 
122
        // Second
 
123
#ifdef MORE
 
124
        if (mSecond)
 
125
#endif
 
126
        {
 
127
            float s_angle = (time.second() - 15) * 6;
 
128
            matrix.rotate(s_angle);
 
129
            p.setWorldTransform(matrix);
 
130
            pts.setPoints(4, 0, 0, 0, 0, 400, 0, 0, 0);
 
131
            p.drawPolygon(pts);
 
132
            matrix.rotate(-s_angle);
 
133
        }
 
134
 
 
135
        // quadrante
 
136
        for (int i = 0; i < 60; i++) {
 
137
            p.setWorldTransform(matrix);
 
138
            if ((i % 5) == 0)
 
139
                p.drawLine(450, 0, 500, 0); // draw hour lines
 
140
            else
 
141
                p.drawPoint(480, 0); // draw second lines
 
142
            matrix.rotate(6);
 
143
        }
 
144
 
 
145
    } // if (mDigital)
146
146
}
147
147
 
148
148
#include "kdmclock.moc"