#include "mainwindow.h" //#include "ui_mainwindow.h" #include "stdio.h" #include #include #include #define DELIMITER "|" #include MainWindow::MainWindow(QString tmp, QWidget *parent) : QMainWindow(parent) { current=0; signalmap = new QSignalMapper(this); maxcolumn=4; maxrow=3;//unused and unimplemented // QSetting walk-throught QCoreApplication::setOrganizationName("FwF"); QCoreApplication::setOrganizationDomain("nothing2do.eu"); QCoreApplication::setApplicationName("sondagE"); conf.setValue("hmpi", 0); fenetre.setLayout(&layoutGrid); setCentralWidget(&fenetre); addQuestion(tmp); connect(signalmap, SIGNAL(mapped(const QString &)),this, SLOT(react(const QString &))); } MainWindow::~MainWindow() { //delete ui; } int MainWindow::setCurrent(int tmp){ current=tmp; return fillGrid(); } int MainWindow::fillGrid(){ int hm=question.at(current).count(DELIMITER)+1; for(int bcl=0; bcl<=hm; bcl++){ addButtons(question.at(current), *&layoutGrid); } return 1; } int MainWindow::addButtons(QString tmp, QGridLayout & layout){ int hm=question.at(current).count(DELIMITER)+1; int row, column; qWarning() << "hm=" << hm; qWarning() << "maxcolumn=" << maxcolumn; int bcl; for (bcl=0; bcl<=hm; bcl++){ qWarning() << "bcl=" << hm; row=bcl/maxcolumn; qWarning() << "row=" << row; column=bcl%maxcolumn; qWarning() << "column=" << column; /*add when screen is full of qpushbutton*/ buttons.insert(question.at(current).split(DELIMITER).at(bcl), new QPushButton(question.at(current).split(DELIMITER).at(bcl), this)); layout.addWidget(buttons.value(question.at(current).split(DELIMITER).at(bcl)), row, column); connect(buttons.value(question.at(current).split(DELIMITER).at(bcl)), SIGNAL(clicked()), signalmap, SLOT(map())); signalmap->setMapping(buttons.value(question.at(current).split(DELIMITER).at(bcl)), question.at(current).split(DELIMITER).at(bcl)); } return buttons.size(); } int MainWindow::addQuestion(QString tmp){ question.append(tmp); return question.size(); } void MainWindow::react(const QString &tmp){ /*tmp is the clicked button */ if(tmp=="quit")end(); if(tmp=="+")admin(); next(); } void MainWindow::admin(){ /*QLabel * resLabel=new QLabel("resultat : ", this); layoutGrid.addWidget(resLabel,0,0); QLabel * res=new QLabel(result.at(current), this); layoutGrid.addWidget(res,0,1); QPushButton * retour=new QPushButton("retour", this); layoutGrid.addWidget(retour, 2,0,-1,-1); connect(retour, SIGNAL(clicked()), this, SLOT(backadmin())); */ qApp->aboutQt(); qApp->quit(); } void MainWindow::backadmin(){ screenStacked.setCurrentIndex(layoutpage); } void MainWindow::next(){ current++; if(question.size()<=current)admin(); flushGrid(layoutGrid); fillGrid(); } void MainWindow::end(){ hmpi++; qApp->quit(); } void MainWindow::flushGrid(QGridLayout& tmp){ for(int bcl=0; bcl<=tmp.count(); bcl++){ } } void MainWindow::setOrientation(ScreenOrientation orientation) { #if defined(Q_OS_SYMBIAN) // If the version of Qt on the device is < 4.7.2, that attribute won't work if (orientation != ScreenOrientationAuto) { const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.')); if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) { qWarning("Screen orientation locking only supported with Qt 4.7.2 and above"); return; } } #endif // Q_OS_SYMBIAN Qt::WidgetAttribute attribute; switch (orientation) {//max* was added by nothing2do.eu #if QT_VERSION < 0x040702 // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes case ScreenOrientationLockPortrait: maxcolumn=2; maxrow=6; fillGrid(); attribute = static_cast(128); break; case ScreenOrientationLockLandscape: maxcolumn=6; maxrow=2; fillGrid(); attribute = static_cast(129); break; default: case ScreenOrientationAuto: maxcolumn=4; maxrow=4; fillGrid(); attribute = static_cast(130); break; #else // QT_VERSION > 0x040702 (note : it was "QT_VERSION < 0x040702") case ScreenOrientationLockPortrait: maxcolumn=2; maxrow=6; fillGrid(); attribute = Qt::WA_LockPortraitOrientation; break; case ScreenOrientationLockLandscape: maxcolumn=6; maxrow=2; fillGrid(); attribute = Qt::WA_LockLandscapeOrientation; break; default: case ScreenOrientationAuto: maxcolumn=4; maxrow=4; fillGrid(); attribute = Qt::WA_AutoOrientation; break; #endif // QT_VERSION < 0x040702 }; setAttribute(attribute, true); } void MainWindow::showExpanded() { #if defined(Q_OS_SYMBIAN) || defined(Q_WS_SIMULATOR) showFullScreen(); #elif defined(Q_WS_MAEMO_5) showMaximized(); #else show(); #endif fillGrid(); }