#include "CMerchandizeSelector.h"
CMerchandizeSelector
::CMerchandizeSelector(QWidget* pParent
){
Q_CHECK_PTR(pScene); // checks object creation
setSceneRect(minX, minY, maxX, maxY);
setScene(pScene);
setWindowTitle(trUtf8("Merchandize selector"));
// TODO: sets scene widget flags so it cannot be closed
/*
m_pIconList=new QStringList; // creates new string list for storing icon names
Q_CHECK_PTR(m_pIconList); // checks creation
*/
m_cPixmap.fill(Qt::black);
//QPainter p(this); // painter
p.translate(rCenterX, rCenterY); // translated coordinate system to centre of widget
p.
setWindow(QRect(minX, minY, maxX, maxY
));
p.
setViewport(QRect(minX, minY, maxX, maxY
));
// only for test purposes, images must be read from database
m_cImageList.
append(QImage(":/images/apple_cake.png"));
m_cImageList.
append(QImage(":/images/bigmac.png"));
m_cImageList.
append(QImage(":/images/applejuice.png"));
m_cImageList.
append(QImage(":/images/cafe_cool"));
m_cImageList.
append(QImage(":/images/chesseburger.png"));
m_cImageList.
append(QImage(":/images/coke.png"));
// computes positions for images
for (m_iCounter=0; m_iCounter<iLoadTreshold; m_iCounter++)
{
QPointF tmpPoint
=computePoint
(0,
0, rCircleRadius, m_iCounter
*rAngle
*Pi
/180);
m_cImagePointList.append(tmpPoint);
qDebug() << "(" << tmpPoint.rx() << ", " << tmpPoint.ry() << "); ";
}
// draws an image at computed coords
for (m_iCounter=0; m_iCounter<m_cImageList.count(); m_iCounter++)
{
p.drawImage(m_cImagePointList.at(m_iCounter), m_cImageList.at(m_iCounter));
//p.drawImage(QPointF(80*m_iCounter, 0), m_cImageList.at(m_iCounter));
}
}
CMerchandizeSelector::~CMerchandizeSelector()
{
}
// computes cartesian coordinates for given circle and its angle
QPointF CMerchandizeSelector
::computePoint(qreal rOriginX, qreal rOriginY, qreal rRadius, qreal rAngle
) {
p.setX(rOriginX+rRadius*cos(rAngle*Pi/180)); // computes x
p.setY(rOriginX+rRadius*sin(rAngle*Pi/180)); // computes y
//p.setX(rOriginX+rRadius*cos(rAngle)); // computes x
//p.setY(rOriginX+rRadius*sin(rAngle)); // computes y
return p; // returns p
}
// painter event
/*
void CMerchandizeSelector::paintEvent(QPaintEvent *e)
{
QPainter p(this);
p.setClipRect(e->rect());
p.drawTiledPixmap(rect(), m_cPixmap);
for (m_iCounter=0; m_iCounter<m_cImageList.count(); m_iCounter++)
{
//p.drawImage(m_cImagePointList.at(m_iCounter), m_cImageList.at(m_iCounter));
p.drawImage(QPointF(80*m_iCounter, 0), m_cImageList.at(m_iCounter));
}
}
*/
#include "CMerchandizeSelector.h"
CMerchandizeSelector::CMerchandizeSelector(QWidget* pParent)
{
QGraphicsScene* pScene=new QGraphicsScene(this); // creates new scene
Q_CHECK_PTR(pScene); // checks object creation
pScene->setItemIndexMethod(QGraphicsScene::NoIndex);
setSceneRect(minX, minY, maxX, maxY);
setScene(pScene);
setWindowTitle(trUtf8("Merchandize selector"));
// TODO: sets scene widget flags so it cannot be closed
/*
m_pIconList=new QStringList; // creates new string list for storing icon names
Q_CHECK_PTR(m_pIconList); // checks creation
*/
m_cPixmap=QPixmap(100, 100);
m_cPixmap.fill(Qt::black);
QPainter p(&m_cPixmap); // painter
//QPainter p(this); // painter
p.translate(rCenterX, rCenterY); // translated coordinate system to centre of widget
p.setWindow(QRect(minX, minY, maxX, maxY));
p.setViewport(QRect(minX, minY, maxX, maxY));
// only for test purposes, images must be read from database
m_cImageList.append(QImage(":/images/apple_cake.png"));
m_cImageList.append(QImage(":/images/bigmac.png"));
m_cImageList.append(QImage(":/images/applejuice.png"));
m_cImageList.append(QImage(":/images/cafe_cool"));
m_cImageList.append(QImage(":/images/chesseburger.png"));
m_cImageList.append(QImage(":/images/coke.png"));
// computes positions for images
for (m_iCounter=0; m_iCounter<iLoadTreshold; m_iCounter++)
{
QPointF tmpPoint=computePoint(0, 0, rCircleRadius, m_iCounter*rAngle*Pi/180);
m_cImagePointList.append(tmpPoint);
qDebug() << "(" << tmpPoint.rx() << ", " << tmpPoint.ry() << "); ";
}
// draws an image at computed coords
for (m_iCounter=0; m_iCounter<m_cImageList.count(); m_iCounter++)
{
p.drawImage(m_cImagePointList.at(m_iCounter), m_cImageList.at(m_iCounter));
//p.drawImage(QPointF(80*m_iCounter, 0), m_cImageList.at(m_iCounter));
}
}
CMerchandizeSelector::~CMerchandizeSelector()
{
}
// computes cartesian coordinates for given circle and its angle
QPointF CMerchandizeSelector::computePoint(qreal rOriginX, qreal rOriginY, qreal rRadius, qreal rAngle)
{
QPointF p; // point
p.setX(rOriginX+rRadius*cos(rAngle*Pi/180)); // computes x
p.setY(rOriginX+rRadius*sin(rAngle*Pi/180)); // computes y
//p.setX(rOriginX+rRadius*cos(rAngle)); // computes x
//p.setY(rOriginX+rRadius*sin(rAngle)); // computes y
return p; // returns p
}
// painter event
/*
void CMerchandizeSelector::paintEvent(QPaintEvent *e)
{
QPainter p(this);
p.setClipRect(e->rect());
p.drawTiledPixmap(rect(), m_cPixmap);
for (m_iCounter=0; m_iCounter<m_cImageList.count(); m_iCounter++)
{
//p.drawImage(m_cImagePointList.at(m_iCounter), m_cImageList.at(m_iCounter));
p.drawImage(QPointF(80*m_iCounter, 0), m_cImageList.at(m_iCounter));
}
}
*/
To copy to clipboard, switch view to plain text mode
Here is header file:
#ifndef CMERCHANDIZESELECTOR_H_
#define CMERCHANDIZESELECTOR_H_
// qt includes
#include <QtGui/QGraphicsView>
//#include <QtGui/QGraphicsScene>
//#include <QtGui/QGraphicsItem>
#include <QtGui/QImage>
//#include <QtCore/QPointer>
//#include <QtCore/QStringList>
#include <QtCore/QPointF>
#include <QtCore/QRect>
//#include <QtCore/QRectF>
#include <QtGui/QPainter>
#include <QtGui/QPixmap>
#include <QtGui/QPaintEvent>
#include <QtDebug>
// math support includes
#include <cmath>
// custom includes
#include "globals.h"
{
Q_OBJECT
public:
CMerchandizeSelector
(QWidget* pParent
=0);
virtual ~CMerchandizeSelector();
private:
QList<QImage> m_cImageList; // list of icon filenames on 3d graphics browse
QList<QPointF> m_cImagePointList; // list of coordinates for icons
quint16 m_iCounter; // protected loop counter
//QPointer <CLens> m_pLens; // lens for zoming selected merchandize
//QStringList m_pIconList; // list of icon filenames on 3d graphics browse
/*
void keyPressEvent(QKeyEvent *event);
void timerEvent(QTimerEvent *event);
void wheelEvent(QWheelEvent *event);
void drawBackground(QPainter *painter, const QRectF &rect);
*/
//void paintEvent(QPaintEvent *e); // painter event
QPointF computePoint
(qreal rOriginX, qreal rOriginY, qreal rRadius, qreal rAngle
);
};
#endif /*CMERCHANDIZESELECTOR_H_*/
#ifndef CMERCHANDIZESELECTOR_H_
#define CMERCHANDIZESELECTOR_H_
// qt includes
#include <QtGui/QGraphicsView>
//#include <QtGui/QGraphicsScene>
//#include <QtGui/QGraphicsItem>
#include <QtGui/QImage>
//#include <QtCore/QPointer>
//#include <QtCore/QStringList>
#include <QtCore/QPointF>
#include <QtCore/QRect>
//#include <QtCore/QRectF>
#include <QtGui/QPainter>
#include <QtGui/QPixmap>
#include <QtGui/QPaintEvent>
#include <QtDebug>
// math support includes
#include <cmath>
// custom includes
#include "globals.h"
class CMerchandizeSelector : public QGraphicsView
{
Q_OBJECT
public:
CMerchandizeSelector(QWidget* pParent=0);
virtual ~CMerchandizeSelector();
private:
QList<QImage> m_cImageList; // list of icon filenames on 3d graphics browse
QList<QPointF> m_cImagePointList; // list of coordinates for icons
quint16 m_iCounter; // protected loop counter
QPixmap m_cPixmap; // pixmap
//QPointer <CLens> m_pLens; // lens for zoming selected merchandize
//QStringList m_pIconList; // list of icon filenames on 3d graphics browse
/*
void keyPressEvent(QKeyEvent *event);
void timerEvent(QTimerEvent *event);
void wheelEvent(QWheelEvent *event);
void drawBackground(QPainter *painter, const QRectF &rect);
*/
//void paintEvent(QPaintEvent *e); // painter event
QPointF computePoint(qreal rOriginX, qreal rOriginY, qreal rRadius, qreal rAngle);
};
#endif /*CMERCHANDIZESELECTOR_H_*/
To copy to clipboard, switch view to plain text mode
And here are constants, used in app (file globals.h):
// globals.h
#ifndef GLOBALS_H
#define GLOBALS_H
// qt includes
#include <QtGlobal>
// scene rect coords
static const qint16 minX=0;
static const qint16 minY=0;
static const qint16 maxX=600; // scene width
static const qint16 maxY=600; // scene height
//static const qreal rCenterX=(maxX+minX)/2; // scente centre x
static const qreal rCenterX=(maxX-minX)/2; // scente centre x
//static const qreal rCenterY=(maxY+minY)/2; // scente centre x
static const qreal rCenterY=(maxY-minY)/2; // scente centre x
static const qreal rCirleMargin=20.0; // circle margin
static const qreal rCircleRadius=maxX-rCenterX-rCirleMargin; // radius of circle
// geometric constants
static const qreal pi=3.14159265358979323846264338327950288419716939937510; // pi constant
static const qreal Pi=pi; // alias for pi
static const quint8 iLoadTreshold=10; // icon load treshold
static const qreal rEmtpyCircle=0; // emtpy circle
static const qreal rFullCircle=360; // full circle has 360 degrees
static const qreal rAngle=rFullCircle/iLoadTreshold; // merchandize icon appears every rAngle degrees on rotary
// merchandize selector
#endif
// globals.h
#ifndef GLOBALS_H
#define GLOBALS_H
// qt includes
#include <QtGlobal>
// scene rect coords
static const qint16 minX=0;
static const qint16 minY=0;
static const qint16 maxX=600; // scene width
static const qint16 maxY=600; // scene height
//static const qreal rCenterX=(maxX+minX)/2; // scente centre x
static const qreal rCenterX=(maxX-minX)/2; // scente centre x
//static const qreal rCenterY=(maxY+minY)/2; // scente centre x
static const qreal rCenterY=(maxY-minY)/2; // scente centre x
static const qreal rCirleMargin=20.0; // circle margin
static const qreal rCircleRadius=maxX-rCenterX-rCirleMargin; // radius of circle
// geometric constants
static const qreal pi=3.14159265358979323846264338327950288419716939937510; // pi constant
static const qreal Pi=pi; // alias for pi
static const quint8 iLoadTreshold=10; // icon load treshold
static const qreal rEmtpyCircle=0; // emtpy circle
static const qreal rFullCircle=360; // full circle has 360 degrees
static const qreal rAngle=rFullCircle/iLoadTreshold; // merchandize icon appears every rAngle degrees on rotary
// merchandize selector
#endif
To copy to clipboard, switch view to plain text mode
Can anyone help me please why pictures are not shown?! I read the docs about qt's coordinate system, but I simply do not get it how it works!!!!
Bookmarks