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
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