Root/timelayer.cpp

1/*
2 * Copyright 2010 Niels Kummerfeldt <niels.kummerfeldt@tu-harburg.de>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program 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
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA
18 */
19
20#include "timelayer.h"
21
22#include "mapwidget.h"
23
24#include <QtCore/QTime>
25
26TimeLayer::TimeLayer(MapWidget *map) :
27    AbstractLayer(map),
28    m_updateTimer(new QTimer(this))
29{
30    m_updateTimer->setInterval(60 * 1000);
31    connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(repaint()));
32    int time = (60 - QTime::currentTime().second()) * 1000;
33    QTimer::singleShot(time, this, SLOT(repaint()));
34    QTimer::singleShot(time, m_updateTimer, SLOT(start()));
35}
36
37void TimeLayer::keyPressed(QKeyEvent *event)
38{
39    if (event->modifiers() == Qt::NoModifier &&
40        event->key() == Qt::Key_T) {
41        toggleVisibility();
42    }
43}
44
45void TimeLayer::paint(QPainter *painter)
46{
47    int w = map()->width();
48
49    painter->setBrush(QBrush(QColor(255, 255, 255, 210)));
50    painter->drawRoundedRect(w - 82, 1, 80, 16, 5, 5);
51    painter->drawText(w - 77, 3, 70, 14, Qt::AlignCenter,
52                      QTime::currentTime().toString("h:mm"));
53}
54
55void TimeLayer::repaint()
56{
57    if (isVisible()) {
58        map()->update();
59    }
60}
61
62

Archive Download this file

Branches:
master



interactive