#include <QGraphicsScene>
#include <QGraphicsWidget>
-#include <QGraphicsLinearLayout>
#include <QGraphicsView>
-#include <QGraphicsProxyWidget>
#include <QtGui/QVBoxLayout>
#include <QStateMachine>
#include "listviewscreen.h"
ListViewScreen::ListViewScreen(QWidget *parent)
: QWidget(parent)
{
+ PersonalInfoTab *infoTab = new PersonalInfoTab(QPixmap(":/resources/dummy_personal_infotab_background.png")); //200x300 pix
+ QGraphicsScene *scene= new QGraphicsScene(0,0,800,400);
+ scene->setBackgroundBrush(Qt::white);
+ scene->addItem(infoTab);
- PersonalInfoTab *myTab = new PersonalInfoTab();
- QGraphicsScene *scene= new QGraphicsScene();
- QGraphicsWidget *widget = new QGraphicsWidget();
- QGraphicsLinearLayout *linearLayout = new QGraphicsLinearLayout(widget);
- linearLayout->setOrientation(Qt::Vertical);
- linearLayout->addItem(myTab);
- widget->setLayout(linearLayout);
- scene->addItem(widget);
+ QGraphicsView *view = new QGraphicsView(scene);
+ view->setFrameStyle(0);
+ view->setAlignment(Qt::AlignLeft | Qt::AlignTop);
+ view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- //States and animations
+ QStateMachine *machine = new QStateMachine;
+ machine->setGlobalRestorePolicy(QStateMachine::RestoreProperties);
- QStateMachine machine;
- QState *state1 = new QState(&machine);
- QState *state2 = new QState(&machine);
- machine.setInitialState(state1);
+ QState *state1 = new QState(machine);
+ QState *state2 = new QState(machine);
+ machine->setInitialState(state1);
- state1->assignProperty(widget, "pos", QPointF(-140, 0));
- state2->assignProperty(widget, "pos", QPointF(0, 0));
+ state1->assignProperty(infoTab,"pos", QPointF(-180,50));
- QAbstractTransition *t1 = state1->addTransition(myTab, SIGNAL(clicked()), state2);
- t1->addAnimation(new QPropertyAnimation(widget, "pos"));
+ state2->assignProperty(infoTab,"pos", QPoint(0,50));
- QAbstractTransition *t2 = state2->addTransition(myTab, SIGNAL(clicked()), state1);
- t2->addAnimation(new QPropertyAnimation(widget, "pos"));
+ QAbstractTransition *trans1 = state1->addTransition(infoTab,SIGNAL(clicked()),state2);
+ trans1->addAnimation(new QPropertyAnimation(infoTab,"pos"));
- machine.start();
+ QAbstractTransition *trans2 = state2->addTransition(infoTab,SIGNAL(clicked()),state1);
+ trans2->addAnimation(new QPropertyAnimation(infoTab,"pos"));
+ machine->start();
- QGraphicsView *view = new QGraphicsView(scene);
QVBoxLayout *vbox = new QVBoxLayout(this);
vbox->addWidget(view);
-
}
*/
#include "personalinfotab.h"
-#include <QtGui/QPushButton>
-#include <QtGui/QVBoxLayout>
-#include <QGraphicsProxyWidget>
-#include <QGraphicsLinearLayout>
+#include <QDebug>
-
-PersonalInfoTab::PersonalInfoTab(QGraphicsItem *parent)
- : QGraphicsWidget(parent)
+PersonalInfoTab::PersonalInfoTab(const QPixmap &picture)
+ : QGraphicsObject(), p(picture)
{
- QWidget *infoTab = new QWidget();
- QPushButton *reloadButton = new QPushButton("Testing");
- QVBoxLayout *vbox = new QVBoxLayout(infoTab);
- vbox->addWidget(reloadButton);
-
- // Need to use QGraphicsProxyWidget to enable embedding QWidgets like QPushButton etc.
- QGraphicsProxyWidget *infoTabProxy = new QGraphicsProxyWidget();
- infoTabProxy->setWidget(infoTab);
- QGraphicsLinearLayout *linearVbox = new QGraphicsLinearLayout(this);
- linearVbox->addItem(infoTabProxy);
-
}
void PersonalInfoTab::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
emit clicked();
+ qDebug() << __PRETTY_FUNCTION__;
+}
+
+void PersonalInfoTab::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+{
+ painter->drawPixmap(QPointF(), p);
+}
+
+QRectF PersonalInfoTab::boundingRect() const
+{
+ return QRectF( QPointF(0, 0), p.size());
}
#ifndef PERSONALINFOTAB_H
#define PERSONALINFOTAB_H
-#include <QGraphicsWidget>
+#include <QtCore>
+#include <QtGui>
-class PersonalInfoTab : public QGraphicsWidget
+class PersonalInfoTab : public QGraphicsObject
{
Q_OBJECT
public:
*
* @param parent Parent
*/
- PersonalInfoTab(QGraphicsItem *parent = 0);
+ PersonalInfoTab(const QPixmap &);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
-
-Q_SIGNALS:
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *);
+ QRectF boundingRect() const;
+signals:
void clicked();
+private:
+ QPixmap p;
};
#endif // PERSONALINFOTAB_H