~ubuntu-branches/ubuntu/gutsy/kdebase-workspace/gutsy

« back to all changes in this revision

Viewing changes to plasma/applets/clock/clock.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-10-11 14:04:48 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071011140448-v0eb7lxbb24zagca
Tags: 3.94.0-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
    m_theme->setContentType(Plasma::Svg::SingleImage);
62
62
    m_theme->resize(m_pixelSize, m_pixelSize);
63
63
 
 
64
    connectToEngine();
 
65
    setCachePaintMode(NoCacheMode);
 
66
}
 
67
 
 
68
void Clock::connectToEngine()
 
69
{
64
70
    Plasma::DataEngine* timeEngine = dataEngine("time");
65
 
    timeEngine->connectSource(m_timezone, this);
66
 
    timeEngine->setProperty("reportSeconds", m_showSecondHand);
67
 
    updated(m_timezone, timeEngine->query(m_timezone));
68
 
    constraintsUpdated();
 
71
    if (m_showSecondHand) {
 
72
        timeEngine->connectSource(m_timezone, this, 500);
 
73
    } else {
 
74
        timeEngine->connectSource(m_timezone, this, 6000, Plasma::AlignToMinute);
 
75
    }
69
76
}
70
77
 
71
 
QSizeF Clock::contentSize() const
 
78
QSizeF Clock::contentSizeHint() const
72
79
{
73
80
    return m_size;
74
81
}
75
82
 
76
 
void Clock::constraintsUpdated()
 
83
void Clock::constraintsUpdated(Plasma::Constraints constraints)
77
84
{
78
 
    prepareGeometryChange();
79
 
    if (formFactor() == Plasma::Planar ||
80
 
        formFactor() == Plasma::MediaCenter) {
81
 
        m_size = m_theme->size();
82
 
    } else {
83
 
        QFontMetrics fm(QApplication::font());
84
 
        m_size = QSizeF(fm.width("00:00:00") * 1.2, fm.height() * 1.5);
 
85
    if (constraints & Plasma::FormFactorConstraint) {
 
86
        prepareGeometryChange();
 
87
        if (formFactor() == Plasma::Planar ||
 
88
                formFactor() == Plasma::MediaCenter) {
 
89
            m_size = m_theme->size();
 
90
        } else {
 
91
            QFontMetrics fm(QApplication::font());
 
92
            m_size = QSizeF(fm.width("00:00:00") * 1.2, fm.height() * 1.5);
 
93
        }
 
94
        updateGeometry();
85
95
    }
86
96
}
87
97
 
102
112
    if (m_time.minute() == m_lastTimeSeen.minute() &&
103
113
        m_time.second() == m_lastTimeSeen.second()) {
104
114
        // avoid unnecessary repaints
105
 
        //kDebug() << "avoided unnecessary update!";
106
115
        return;
107
116
    }
108
 
 
109
117
    m_lastTimeSeen = m_time;
110
118
    update();
111
119
}
132
140
void Clock::configAccepted()
133
141
{
134
142
    KConfigGroup cg = config();
135
 
    m_showTimeString = ui.showTimeStringCheckBox->checkState() == Qt::Checked;
136
 
    m_showSecondHand = ui.showSecondHandCheckBox->checkState() == Qt::Checked;
 
143
    m_showTimeString = ui.showTimeStringCheckBox->isChecked();
 
144
    m_showSecondHand = ui.showSecondHandCheckBox->isChecked();
 
145
 
137
146
    cg.writeEntry("showTimeString", m_showTimeString);
138
147
    cg.writeEntry("showSecondHand", m_showSecondHand);
139
 
    dataEngine("time")->setProperty("reportSeconds", m_showSecondHand);
140
 
    QGraphicsItem::update();
 
148
    update();
141
149
    cg.writeEntry("size", ui.spinSize->value());
142
150
    m_size = QSize(ui.spinSize->value(), ui.spinSize->value());
143
151
    m_theme->resize(m_size);
144
152
    QStringList tzs = ui.timeZones->selection();
145
 
    /*
 
153
 
146
154
    if (tzs.count() > 0) {
147
155
        //TODO: support multiple timezones
148
156
        QString tz = tzs.at(0);
149
157
        if (tz != m_timezone) {
150
158
            dataEngine("time")->disconnectSource(m_timezone, this);
151
159
            m_timezone = tz;
152
 
            dataEngine("time")->connectSource(m_timezone, this);
153
160
        }
154
161
    } else if (m_timezone != "Local") {
155
162
        dataEngine("time")->disconnectSource(m_timezone, this);
156
163
        m_timezone = "Local";
157
 
        dataEngine("time")->connectSource(m_timezone, this);
158
164
    }
159
 
    */
160
165
 
161
 
    dataEngine("time")->connectSource(m_timezone, this);
162
 
    constraintsUpdated();
 
166
    connectToEngine();
 
167
    constraintsUpdated(Plasma::AllConstraints);
 
168
    cg.config()->sync();
163
169
}
164
170
 
165
171
Clock::~Clock()
229
235
    m_theme->paint(p, tempRect, "HourHand");
230
236
    p->restore();
231
237
 
232
 
//     drawHand(p, hours, "SecondHand", 1);
233
238
    p->save();
234
239
    p->translate(boundSize.width()/2, boundSize.height()/2);
235
240
    p->rotate(minutes);
253
258
        p->restore();
254
259
    }
255
260
 
256
 
 
257
261
    p->save();
258
262
    m_theme->resize(boundSize);
259
263
    elementSize = m_theme->elementSize("HandCenterScrew");