#ifndef FRAME_H
#define FRAME_H
#include <QGraphicsItem>
#include <QtGui>
#include "umbrella.h"
class umbrella;
class QParallelAnimationGroup;
class frame : public umbrella
{
public:
QPainterPath shape
() const;
[B
] /**<-- did add this line here*/[/B
] void setFramePosMiddle(qreal x,qreal y);
void setFrameRotation(qreal frameRotation);
protected:
qreal x,y,frameRotation;
};
#endif // FRAME_H
#ifndef FRAME_H
#define FRAME_H
#include <QGraphicsItem>
#include <QtGui>
#include "umbrella.h"
class umbrella;
class QGraphicsSceneMouseEvent;
class QParallelAnimationGroup;
class frame : public umbrella
{
public:
frame(QGraphicsItem *parent = 0);
QRectF boundingRect() const;
QPainterPath shape() const; [B] /**<-- did add this line here*/[/B]
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
void setFramePosMiddle(qreal x,qreal y);
void setFrameRotation(qreal frameRotation);
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
qreal x,y,frameRotation;
};
#endif // FRAME_H
To copy to clipboard, switch view to plain text mode
frame.cpp file
#include "frame.h"
: umbrella(parent)
{
this->frameRotation=0;
}
QRectF frame
::boundingRect() const {
}
{
framePolygon.
append(QPoint(2,
27));
framePolygon.
append(QPoint(30,
1));
framePolygon.
append(QPoint(65,
8));
framePolygon.
append(QPoint(100,
1));
framePolygon.
append(QPoint(127,
28));
framePolygon.
append(QPoint(119,
64));
framePolygon.
append(QPoint(122,
96));
framePolygon.
append(QPoint(99,
126));
framePolygon.
append(QPoint(64,
119));
framePolygon.
append(QPoint(29,
125));
framePolygon.
append(QPoint(5,
96));
framePolygon.
append(QPoint(9,
62));
path.addPolygon(framePolygon);
return path;
}
{
Q_UNUSED(option);
Q_UNUSED(widget);
painter->drawRect(boundingRect());
myframePen.setWidth(4);
myframePen.setColor(Qt::black);
myframePen.setJoinStyle(Qt::RoundJoin);
myframecolor
=(QColor(0,
0,
255,
70));
myframeBrush.setColor(myframecolor);
myframeBrush.setStyle(Qt::SolidPattern);
myframePolygon.
append(QPoint(2,
27));
myframePolygon.
append(QPoint(30,
1));
myframePolygon.
append(QPoint(65,
8));
myframePolygon.
append(QPoint(100,
1));
myframePolygon.
append(QPoint(127,
28));
myframePolygon.
append(QPoint(119,
64));
myframePolygon.
append(QPoint(122,
96));
myframePolygon.
append(QPoint(99,
126));
myframePolygon.
append(QPoint(64,
119));
myframePolygon.
append(QPoint(29,
125));
myframePolygon.
append(QPoint(5,
96));
myframePolygon.
append(QPoint(9,
62));
myframePainterPath.addPolygon(myframePolygon);
int frameWide =128;
int frameHigh =128;
int xc = 0 + frameWide/2;
int yc = 0 + frameHigh/2;
painter->translate(+xc,+yc);
painter->rotate(frameRotation);
painter->translate(-xc,-yc);
painter->setPen(myframePen);
painter->drawPolygon(myframePolygon);
painter->fillPath(myframePainterPath,myframeBrush);
}
if(event->button() == Qt::RightButton){
qDebug() << "click with the right mouse button";
}
else if(event->button() == Qt::LeftButton){
qDebug() << "click with the left mouse button";
}
else{
qDebug() << "click with the whell button";
}
}
void frame::setFramePosMiddle(qreal x, qreal y)
{
this->setPos(x-128/2,y-128/2);
}
void frame::setFrameRotation(qreal frameRotation)
{
this->frameRotation=frameRotation;
update();
}
#include "frame.h"
frame::frame(QGraphicsItem *parent)
: umbrella(parent)
{
this->frameRotation=0;
}
QRectF frame::boundingRect() const
{
return QRectF(0,0,128,128);
}
QPainterPath frame::shape() const
{
QPolygon framePolygon;
framePolygon.append(QPoint(2,27));
framePolygon.append(QPoint(30,1));
framePolygon.append(QPoint(65,8));
framePolygon.append(QPoint(100,1));
framePolygon.append(QPoint(127,28));
framePolygon.append(QPoint(119,64));
framePolygon.append(QPoint(122,96));
framePolygon.append(QPoint(99,126));
framePolygon.append(QPoint(64,119));
framePolygon.append(QPoint(29,125));
framePolygon.append(QPoint(5,96));
framePolygon.append(QPoint(9,62));
QPainterPath path;
path.addPolygon(framePolygon);
return path;
}
void frame::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
QPolygon myframePolygon;
QColor myframecolor;
QBrush myframeBrush;
QPainterPath myframePainterPath;
QPen myframePen;
painter->drawRect(boundingRect());
myframePen.setWidth(4);
myframePen.setColor(Qt::black);
myframePen.setJoinStyle(Qt::RoundJoin);
myframecolor=(QColor(0,0,255,70));
myframeBrush.setColor(myframecolor);
myframeBrush.setStyle(Qt::SolidPattern);
myframePolygon.append(QPoint(2,27));
myframePolygon.append(QPoint(30,1));
myframePolygon.append(QPoint(65,8));
myframePolygon.append(QPoint(100,1));
myframePolygon.append(QPoint(127,28));
myframePolygon.append(QPoint(119,64));
myframePolygon.append(QPoint(122,96));
myframePolygon.append(QPoint(99,126));
myframePolygon.append(QPoint(64,119));
myframePolygon.append(QPoint(29,125));
myframePolygon.append(QPoint(5,96));
myframePolygon.append(QPoint(9,62));
myframePainterPath.addPolygon(myframePolygon);
int frameWide =128;
int frameHigh =128;
int xc = 0 + frameWide/2;
int yc = 0 + frameHigh/2;
painter->translate(+xc,+yc);
painter->rotate(frameRotation);
painter->translate(-xc,-yc);
painter->setPen(myframePen);
painter->drawPolygon(myframePolygon);
painter->fillPath(myframePainterPath,myframeBrush);
}
void frame::mousePressEvent(QGraphicsSceneMouseEvent *event){
if(event->button() == Qt::RightButton){
qDebug() << "click with the right mouse button";
}
else if(event->button() == Qt::LeftButton){
qDebug() << "click with the left mouse button";
}
else{
qDebug() << "click with the whell button";
}
QGraphicsItem::mousePressEvent(event);
}
void frame::setFramePosMiddle(qreal x, qreal y)
{
this->setPos(x-128/2,y-128/2);
}
void frame::setFrameRotation(qreal frameRotation)
{
this->frameRotation=frameRotation;
update();
}
To copy to clipboard, switch view to plain text mode
Bookmarks