#ifndef DISPLAYCLASS_H
#define DISPLAYCLASS_H
#include <QtGui/QWidget>
#include <QMainWindow>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsSvgItem>
#include <QGraphicsItem>
#include <QSvgRenderer>
#include <QTimer>
#include <QDebug>
//#include <qdesignerexportwidget.h>
#include <QLabel>
class
/*QDESIGNER_WIDGET_EXPORT*/ displayclass
: public QWidget{
Q_OBJECT
public:
void UpdateAll(double rotation, int save_angle);
void DisplaySquare(double rotation);
void DisplayArrow();
void DisplayLabel(double rotation);
public slots:
void Input(int rotation);
private slots:
void Timer();
};
#endif
#ifndef DISPLAYCLASS_H
#define DISPLAYCLASS_H
#include <QtGui/QWidget>
#include <QMainWindow>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsSvgItem>
#include <QGraphicsItem>
#include <QSvgRenderer>
#include <QTimer>
#include <QDebug>
//#include <qdesignerexportwidget.h>
#include <QLabel>
class /*QDESIGNER_WIDGET_EXPORT*/ displayclass : public QWidget
{
Q_OBJECT
public:
displayclass(QWidget *parent = 0);
QSvgRenderer *svgRend;
QGraphicsScene *scene;
QGraphicsView *view;
QLabel *label;
QGraphicsRectItem *rectangle;
QGraphicsSvgItem *arrow;
QTimer *timer;
void UpdateAll(double rotation, int save_angle);
void DisplaySquare(double rotation);
void DisplayArrow();
void DisplayLabel(double rotation);
public slots:
void Input(int rotation);
private slots:
void Timer();
};
#endif
To copy to clipboard, switch view to plain text mode
#include "displayclass.h"
displayclass
::displayclass(QWidget *parent
) :{
//Definitions
connect(timer, SIGNAL(timeout()), this, SLOT(Timer()));
timer->start(30);
scene->setSceneRect(0,0,300,300);
view
->setGeometry
(QRect(0,
0,
350,
350));
view->setScene(scene);
view->show();
UpdateAll(0,0);
}
void displayclass::UpdateAll(double rotation, int save_angle)
{
static double rot=0;
if(save_angle==1)
{
rot=rotation;
}
else
{
DisplaySquare(rot);
DisplayArrow();
DisplayLabel(rot);
}
}
void displayclass::DisplaySquare(double rotation)
{
static int rectangle_activated=0;
if(rectangle_activated==0)
{
rectangle->setBrush( Qt::red );
rectangle->setPos(0,0);
qDebug()<<rectangle->pos();
rectangle_activated=1;
scene->addItem(rectangle);
}
rectangle->setRotation(rotation);
}
void displayclass::DisplayArrow()
{
static int arrow_activated=0;
if(arrow_activated==0)
{
arrow->setParentItem(rectangle);
arrow->setSharedRenderer(svgRend);
arrow->setPos(0,0);
}
}
void displayclass::DisplayLabel(double rotation)
{
static bool label_activated=0;
if(label_activated==0)
{
label->setParent(this);
label->setGeometry((scene->width()/2)-25,(scene->height()/2)-(label->height()/2),50,25);
label->setAlignment(Qt::AlignCenter | Qt::AlignHCenter);
label->setAutoFillBackground(1);
label->setStyleSheet("QLabel { border-width: 2px; border-radius: 4px; border-style: solid; border-color: darkGray; background-color: white;}");
label_activated=1;
}
label
->setText
(QString::number(rotation
));
}
void displayclass::Timer()
{
UpdateAll(0,0);
}
void displayclass::Input(int rotation)
{
UpdateAll(rotation,1);
}
#include "displayclass.h"
displayclass::displayclass(QWidget *parent) :
QWidget(parent)
{
//Definitions
scene = new QGraphicsScene(QRect(0, 0, 300, 300),this);
svgRend = new QSvgRenderer(QLatin1String(":/arrow.svg"),this);
view = new QGraphicsView(this);
arrow = new QGraphicsSvgItem();
rectangle = new QGraphicsRectItem(0,0,100,100);
label = new QLabel(this);
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(Timer()));
timer->start(30);
scene->setSceneRect(0,0,300,300);
view->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
view->setGeometry(QRect(0, 0, 350, 350));
view->setScene(scene);
view->show();
UpdateAll(0,0);
}
void displayclass::UpdateAll(double rotation, int save_angle)
{
static double rot=0;
if(save_angle==1)
{
rot=rotation;
}
else
{
DisplaySquare(rot);
DisplayArrow();
DisplayLabel(rot);
}
}
void displayclass::DisplaySquare(double rotation)
{
static int rectangle_activated=0;
if(rectangle_activated==0)
{
rectangle->setBrush( Qt::red );
rectangle->setPos(0,0);
qDebug()<<rectangle->pos();
rectangle_activated=1;
scene->addItem(rectangle);
}
rectangle->setRotation(rotation);
}
void displayclass::DisplayArrow()
{
static int arrow_activated=0;
if(arrow_activated==0)
{
arrow->setParentItem(rectangle);
arrow->setSharedRenderer(svgRend);
arrow->setPos(0,0);
}
}
void displayclass::DisplayLabel(double rotation)
{
static bool label_activated=0;
if(label_activated==0)
{
label->setParent(this);
label->setGeometry((scene->width()/2)-25,(scene->height()/2)-(label->height()/2),50,25);
label->setAlignment(Qt::AlignCenter | Qt::AlignHCenter);
label->setAutoFillBackground(1);
label->setStyleSheet("QLabel { border-width: 2px; border-radius: 4px; border-style: solid; border-color: darkGray; background-color: white;}");
label_activated=1;
}
label->setText(QString::number(rotation));
}
void displayclass::Timer()
{
UpdateAll(0,0);
}
void displayclass::Input(int rotation)
{
UpdateAll(rotation,1);
}
To copy to clipboard, switch view to plain text mode
displayclass1 = new displayclass(centralWidget);
displayclass1
->setObjectName
(QString::fromUtf8("displayclass1"));
displayclass1
->setGeometry
(QRect(40,
60,
211,
231));
displayclass2 = new displayclass(centralWidget);
displayclass2
->setObjectName
(QString::fromUtf8("displayclass2"));
displayclass2
->setGeometry
(QRect(350,
60,
201,
231));
displayclass1 = new displayclass(centralWidget);
displayclass1->setObjectName(QString::fromUtf8("displayclass1"));
displayclass1->setGeometry(QRect(40, 60, 211, 231));
displayclass2 = new displayclass(centralWidget);
displayclass2->setObjectName(QString::fromUtf8("displayclass2"));
displayclass2->setGeometry(QRect(350, 60, 201, 231));
To copy to clipboard, switch view to plain text mode
Hmm, anything else I should specify if it could be helpful?
Bookmarks