summaryrefslogtreecommitdiffstats
path: root/examples/widgets/shapedclock
diff options
context:
space:
mode:
authoraxis <qt-info@nokia.com>2009-04-24 13:34:15 +0200
committeraxis <qt-info@nokia.com>2009-04-24 13:34:15 +0200
commit8f427b2b914d5b575a4a7c0ed65d2fb8f45acc76 (patch)
treea17e1a767a89542ab59907462206d7dcf2e504b2 /examples/widgets/shapedclock
Long live Qt for S60!
Diffstat (limited to 'examples/widgets/shapedclock')
-rw-r--r--examples/widgets/shapedclock/main.cpp52
-rw-r--r--examples/widgets/shapedclock/shapedclock.cpp159
-rw-r--r--examples/widgets/shapedclock/shapedclock.h67
-rw-r--r--examples/widgets/shapedclock/shapedclock.pro13
4 files changed, 291 insertions, 0 deletions
diff --git a/examples/widgets/shapedclock/main.cpp b/examples/widgets/shapedclock/main.cpp
new file mode 100644
index 0000000000..889aac1f2f
--- /dev/null
+++ b/examples/widgets/shapedclock/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "shapedclock.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ ShapedClock clock;
+ clock.show();
+ return app.exec();
+}
diff --git a/examples/widgets/shapedclock/shapedclock.cpp b/examples/widgets/shapedclock/shapedclock.cpp
new file mode 100644
index 0000000000..9b8a282bb6
--- /dev/null
+++ b/examples/widgets/shapedclock/shapedclock.cpp
@@ -0,0 +1,159 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "shapedclock.h"
+
+//! [0]
+ShapedClock::ShapedClock(QWidget *parent)
+ : QWidget(parent, Qt::FramelessWindowHint | Qt::WindowSystemMenuHint)
+{
+ QTimer *timer = new QTimer(this);
+ connect(timer, SIGNAL(timeout()), this, SLOT(update()));
+ timer->start(1000);
+
+ QAction *quitAction = new QAction(tr("E&xit"), this);
+ quitAction->setShortcut(tr("Ctrl+Q"));
+ connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+ addAction(quitAction);
+
+ setContextMenuPolicy(Qt::ActionsContextMenu);
+ setToolTip(tr("Drag the clock with the left mouse button.\n"
+ "Use the right mouse button to open a context menu."));
+ setWindowTitle(tr("Shaped Analog Clock"));
+}
+//! [0]
+
+//! [1]
+void ShapedClock::mousePressEvent(QMouseEvent *event)
+{
+ if (event->button() == Qt::LeftButton) {
+ dragPosition = event->globalPos() - frameGeometry().topLeft();
+ event->accept();
+ }
+}
+//! [1]
+
+//! [2]
+void ShapedClock::mouseMoveEvent(QMouseEvent *event)
+{
+ if (event->buttons() & Qt::LeftButton) {
+ move(event->globalPos() - dragPosition);
+ event->accept();
+ }
+}
+//! [2]
+
+//! [3]
+void ShapedClock::paintEvent(QPaintEvent *)
+{
+ static const QPoint hourHand[3] = {
+ QPoint(7, 8),
+ QPoint(-7, 8),
+ QPoint(0, -40)
+ };
+ static const QPoint minuteHand[3] = {
+ QPoint(7, 8),
+ QPoint(-7, 8),
+ QPoint(0, -70)
+ };
+
+ QColor hourColor(127, 0, 127);
+ QColor minuteColor(0, 127, 127, 191);
+
+ int side = qMin(width(), height());
+ QTime time = QTime::currentTime();
+
+ QPainter painter(this);
+ painter.setRenderHint(QPainter::Antialiasing);
+ painter.translate(width() / 2, height() / 2);
+ painter.scale(side / 200.0, side / 200.0);
+
+ painter.setPen(Qt::NoPen);
+ painter.setBrush(hourColor);
+
+ painter.save();
+ painter.rotate(30.0 * ((time.hour() + time.minute() / 60.0)));
+ painter.drawConvexPolygon(hourHand, 3);
+ painter.restore();
+
+ painter.setPen(hourColor);
+
+ for (int i = 0; i < 12; ++i) {
+ painter.drawLine(88, 0, 96, 0);
+ painter.rotate(30.0);
+ }
+
+ painter.setPen(Qt::NoPen);
+ painter.setBrush(minuteColor);
+
+ painter.save();
+ painter.rotate(6.0 * (time.minute() + time.second() / 60.0));
+ painter.drawConvexPolygon(minuteHand, 3);
+ painter.restore();
+
+ painter.setPen(minuteColor);
+
+ for (int j = 0; j < 60; ++j) {
+ if ((j % 5) != 0)
+ painter.drawLine(92, 0, 96, 0);
+ painter.rotate(6.0);
+ }
+}
+//! [3]
+
+//! [4]
+void ShapedClock::resizeEvent(QResizeEvent * /* event */)
+{
+ int side = qMin(width(), height());
+ QRegion maskedRegion(width() / 2 - side / 2, height() / 2 - side / 2, side,
+ side, QRegion::Ellipse);
+ setMask(maskedRegion);
+}
+//! [4]
+
+//! [5]
+QSize ShapedClock::sizeHint() const
+{
+ return QSize(100, 100);
+}
+//! [5]
diff --git a/examples/widgets/shapedclock/shapedclock.h b/examples/widgets/shapedclock/shapedclock.h
new file mode 100644
index 0000000000..1de52e78e6
--- /dev/null
+++ b/examples/widgets/shapedclock/shapedclock.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SHAPEDCLOCK_H
+#define SHAPEDCLOCK_H
+
+#include <QWidget>
+
+//! [0]
+class ShapedClock : public QWidget
+{
+ Q_OBJECT
+
+public:
+ ShapedClock(QWidget *parent = 0);
+ QSize sizeHint() const;
+
+protected:
+ void mouseMoveEvent(QMouseEvent *event);
+ void mousePressEvent(QMouseEvent *event);
+ void paintEvent(QPaintEvent *event);
+ void resizeEvent(QResizeEvent *event);
+
+private:
+ QPoint dragPosition;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/shapedclock/shapedclock.pro b/examples/widgets/shapedclock/shapedclock.pro
new file mode 100644
index 0000000000..c4d48f6d84
--- /dev/null
+++ b/examples/widgets/shapedclock/shapedclock.pro
@@ -0,0 +1,13 @@
+HEADERS = shapedclock.h
+SOURCES = shapedclock.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/widgets/shapedclock
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS shapedclock.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/shapedclock
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+symbian:TARGET.UID3 = 0xA000C605 \ No newline at end of file