PDA

View Full Version : Drawing graphics, used example from KAsteroids



serjts
20th May 2011, 18:24
Hi all,

I have to develop a GUI which will be deployed in an embedded system. But first i would like to develop a "simulator". The screen of the embedded system will have the GUI, and the simulator on the pc will have the GUI inserted in the system's "picture" on which the user clicks to interact.

Since performance was a issue I chose the KASterioids example and developed from that using pixmaps whenever possible (like sprites or gifs if you want). I got the embedded GUI components and rendering fine, and now i want to insert it in the simulator. But the main problem is that I can't get the GUI to render in the transparent window of the simulator's image.... any help will be much appreciated.

Here is the some code to understand:

Here i try to setup the two scenes:

TopLevel::TopLevel( QWidget *parent, const char *name )
: Q3MainWindow( parent, name, 0 )
{

LCDArea = new LCDRender(this);
LCDArea->setAttribute(Qt::WA_ContentsPropagated);

KIOSKArea = new KIOSKRender(LCDArea);
KIOSKArea->setAttribute(Qt::WA_ContentsPropagated);


/* QWidget *mainWin = new QWidget(LCDArea);
mainWin->setFixedSize(681, 541);
QImage backgnd(QCoreApplication::applicationDirPath()+"/../mc_home_charge/resources/aux/bg.png");
// QPalette p(palette());
// p.setBrush(mainWin->backgroundRole(), QBrush(backgnd));
// mainWin->setPalette(p);
QPixmap pm( QCoreApplication::applicationDirPath()+"/../mc_home_charge/resources/aux/bg.png");
mainWin->setBackgroundPixmap(pm);
mainWin->setAutoFillBackground(true); */

//setBackgroundColor(Qt::black);
//setBackgroundMode(Qt::NoBackground);
LCDArea->setAutoFillBackground(true);
setCentralWidget(LCDArea);
}

here is the KIOSK or "physical unit"

KIOSKRender::KIOSKRender( QWidget *parent, const char *name )
: QWidget( parent, name ),
field(0, 0, LCD_XOFFSET0+WIDTH, LCD_YOFFSET0+HEIGHT),//field(0, 0, LCD_XOFFSET0+320, LCD_YOFFSET0+240),
view(&field,this)
{
int fontID(-1);
bool fontWarningShown(false);

// Include custom font
QFile res(QCoreApplication::applicationDirPath()+"/../mc_home_charge/"+customFont);
// qDebug() << QCoreApplication::applicationDirPath()+"/../mc_home_charge/"+customFont;
if (res.open(QIODevice::ReadOnly) == false) {
if (fontWarningShown == false) {
qDebug() << "Error opening custom font1";
fontWarningShown = true;
}
} else {
fontID = QFontDatabase::addApplicationFontFromData(res.read All());
if (fontID == -1 && fontWarningShown == false) {
qDebug() << "Error opening custom font2";
fontWarningShown = true;
}
}

view.setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
view.setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
view.setCacheMode(QGraphicsView::CacheBackground);
view.setViewportUpdateMode(QGraphicsView::Bounding RectViewportUpdate);
view.setOptimizationFlags(QGraphicsView::DontClipP ainter
| QGraphicsView::DontSavePainterState
| QGraphicsView::DontAdjustForAntialiasing);
view.viewport()->setFocusProxy( this );


//QPixmap pm( IMG_BACKGROUND );
//field.setBackgroundBrush( pm );
//field.setBackgroundBrush(QBrush(Qt::black));
//setBackgroundMode(Qt::NoBackground);

refreshRate = REFRESH_RATE;

initialized = readSprites();
if ( !initialized ) {
qDebug() << "Error reading sprites";
}

bg->on();

QTimer *refresher = new QTimer(this);
connect(refresher, SIGNAL(timeout()), this, SLOT(refresh()));
refresher->start(1000/refreshRate);
}

Thanks

wysota
21st May 2011, 00:16
What do you want to render where? What does KAsteroids have to do with your code? And why are you using Qt3 classes (Q3MainWindow)?

serjts
23rd May 2011, 09:42
Thank you wysota.

Since I am not yet profficient with Qt I used KAsteroids code as a base to my own code, and hence the Qt3 classes which I plan to substitute once I'm sure everything is working.

So I basically have two classes each with their own QGraphicsScene and QGraphicsView. What I want to do is design two objects, one with a central console or GUI, and another with the simulator or physical UI, which will have the graphical characteristic of being like a photoframe i.e, with transparency near the center. But the problem it that i can't get the GUI to show through the UI's transparency.

Cheers