Started with some initial animation on the Touchscreen-interface

This commit is contained in:
Micke Prag 2009-03-11 18:27:22 +00:00
parent bc623ef529
commit 11e57c3bdc
7 changed files with 187 additions and 3 deletions

View file

@ -7,6 +7,11 @@ TARGET = TouchInterface
TEMPLATE = lib
CONFIG += plugin
DESTDIR = ../../TelldusCenter/plugins
SOURCES += touchplugin.cpp
HEADERS += touchplugin.h
SOURCES += touchplugin.cpp \
panel.cpp \
button.cpp
HEADERS += touchplugin.h \
panel.h \
button.h
RESOURCES += TouchInterface.qrc
contains(QT_CONFIG, opengl):QT += opengl

View file

@ -0,0 +1,23 @@
#include "button.h"
#include <QPainter>
#include <QDebug>
Button::Button(const QRectF &rect, const QBrush &brush, QObject *parent)
: QObject(parent),
QGraphicsRectItem(rect)
{
}
void Button::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) {
painter->setPen(Qt::NoPen);
painter->setBrush(QColor(0, 0, 0, 64));
painter->drawRoundRect(rect().translated(2, 2));
painter->setBrush(Qt::black);
painter->setPen(Qt::black);
painter->drawText( rect().adjusted( 10, 10, -10, -10 ), "Hej");
}
void Button::mousePressEvent(QGraphicsSceneMouseEvent * ) {
emit clicked();
}

View file

@ -0,0 +1,20 @@
#ifndef BUTTON_H
#define BUTTON_H
#include <QGraphicsRectItem>
class Button : public QObject, public QGraphicsRectItem
{
Q_OBJECT
public:
Button(const QRectF &rect, const QBrush &brush, QObject *parent = 0);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *);
virtual void mousePressEvent(QGraphicsSceneMouseEvent * );
signals:
void clicked();
};
#endif // BUTTON_H

View file

@ -0,0 +1,98 @@
#include "panel.h"
#include "button.h"
#ifndef QT_NO_OPENGL
#include <QtOpenGL/QtOpenGL>
#endif
#include <QTimeLine>
#include <QVector>
#include <QDebug>
class PanelPrivate {
public:
QVector<Button*> buttons;
Button *animatedButton;
QRectF from, to;
QTimeLine *timer;
};
Panel::Panel(QWidget *parent)
:QGraphicsView(parent),
d( new PanelPrivate )
{
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setFrameStyle(0);
setBackgroundBrush( Qt::blue );
#ifndef QT_NO_OPENGL
setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
#endif
QRectF bounds(0, 0, 200, 200);
setScene(new QGraphicsScene(bounds, this));
Button *button = new Button(QRectF(-25, -25, 50, 50), Qt::red);
button->setPos(50, 150);
scene()->addItem(button);
connect(button, SIGNAL(clicked()), this, SLOT(click()));
d->buttons.append(button);
button = new Button(QRectF(-25, -25, 50, 50), Qt::red);
button->setPos(125, 150);
scene()->addItem(button);
connect(button, SIGNAL(clicked()), this, SLOT(click()));
d->buttons.append(button);
d->timer = new QTimeLine(400, this);
d->timer->setFrameRange(0, 100);
connect(d->timer, SIGNAL(frameChanged(int)), this, SLOT(tick(int)));
}
Panel::~Panel() {
delete d;
}
void Panel::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) {
painter->setPen(Qt::NoPen);
painter->setBrush(QColor(0, 0, 0, 64));
painter->drawRoundRect(rect().translated(2, 2));
}
void Panel::resizeEvent(QResizeEvent *event)
{
QGraphicsView::resizeEvent(event);
fitInView(scene()->sceneRect(), Qt::KeepAspectRatio);
}
void Panel::tick( int frame) {
if (!d->animatedButton) {
d->timer->stop();
return;
}
float percent = (frame/100.0);
QPointF from = d->from.topLeft(), to = d->to.topLeft();
QPointF rect = from - percent * (from - to);
d->animatedButton->setPos( rect );
QTransform trans;
trans = trans.rotate(180 * percent, Qt::YAxis);
trans = trans.scale(percent * d->to.width() / d->animatedButton->rect().width() + 1, percent * d->to.height() / d->animatedButton->rect().height() + 1);
d->animatedButton->setTransform( trans );
}
void Panel::click() {
d->animatedButton = qobject_cast<Button *>(sender());
if (d->animatedButton) {
QPointF pos = d->animatedButton->pos();
QRectF rect = d->animatedButton->rect();
d->from = QRectF(pos, rect.size());
d->to = QRectF(100, 100, 125, 125);
d->timer->start();
}
}

View file

@ -0,0 +1,28 @@
#ifndef PANEL_H
#define PANEL_H
#include <QGraphicsView>
class PanelPrivate;
class Panel : public QGraphicsView
{
Q_OBJECT
public:
Panel(QWidget *parent = 0);
~Panel();
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *);
protected:
void resizeEvent(QResizeEvent *event);
private slots:
void tick(int frame);
void click();
private:
PanelPrivate *d;
};
#endif // PANEL_H

View file

@ -1,17 +1,23 @@
#include <QtCore>
#include <QLabel>
#include "touchplugin.h"
#include "panel.h"
QIcon TouchPlugin::iconForPage( const QString &page ) const {
Q_UNUSED(page);
return QIcon(":/images/touchinterface.png");
}
void TouchPlugin::init() {
}
QString TouchPlugin::pluginName() const {
return "TouchInterface";
}
QWidget *TouchPlugin::widget( const QString &page, QWidget *parent ) const {
return new QLabel("Hello world", parent);
Q_UNUSED(page)
return new Panel(parent);
}
QStringList TouchPlugin::widgets() const {

View file

@ -11,11 +11,15 @@ class TouchPlugin : public QObject, public TelldusCenterPlugin
Q_INTERFACES(TelldusCenterPlugin)
public:
virtual QIcon iconForPage( const QString &page ) const;
virtual void init();
virtual QString pluginName() const;
virtual QWidget *widget( const QString &page, QWidget *parent ) const;
virtual QStringList widgets() const;
signals:
void hej();
};
#endif // TOUCHPLUGIN_H