From 8999b217c156daafdb7582efa432f7811b1208df Mon Sep 17 00:00:00 2001 From: Norbert Moutarde Date: Sun, 5 Jan 2014 16:01:03 +0100 Subject: [PATCH] button style-sheet is now stored in config ! --- mainwindow.cpp | 60 +++++++++++++++++++++++++++----------------------- mainwindow.h | 4 ++-- 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 2ad9653..4563b79 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -123,12 +123,8 @@ CLabel* MainWindow::addWidget(const QString &key, const CLabel *a){ int maxl=conf->value(QString("maxline")).toInt(); grid->addWidget(a, grid->count()/maxc, grid->count()%maxc, 1, 1, Qt::AlignVCenter | Qt::AlignHCenter); //QObject::connect(a, SIGNAL(pressed()), signalmap, SLOT(map())); - qDebug()<<"connect2 : "<setMapping(a, key); - /*if(grid->count()==maxc*maxl){ - grid->addWidget(new CLabel(QString("next")), maxc, maxl, 1, 1, Qt::AlignVCenter | Qt::AlignHCenter); - return NULL; - };*/ return a; } void MainWindow::action(const QString &a){ @@ -145,7 +141,7 @@ void MainWindow::action(const QString &a){ } else if(a.split(QString(" "))[0]=="new"){ QString b=""; - for(int c=1;caddAction(trUtf8("&Start..."), this, SLOT(start()),QKeySequence(trUtf8("Ctrl+S", "Start"))); FileMenu->addAction(trUtf8("&Back"), this, SLOT(back()),QKeySequence(trUtf8("Ctrl+B", "Back"))); - FileMenu->addAction(trUtf8("&Update"), this, SLOT(updateUi()),QKeySequence(trUtf8("Ctrl+U", "Update"))); - FileMenu->addAction(trUtf8("Up&load"), this, SLOT(sendUi()),QKeySequence(trUtf8("Ctrl+L", "Update"))); + FileMenu->addAction(trUtf8("&Download"), this, SLOT(updateUi()),QKeySequence(trUtf8("Ctrl+D", "Downlad"))); + FileMenu->addAction(trUtf8("Up&load"), this, SLOT(sendUi()),QKeySequence(trUtf8("Ctrl+L", "Upload"))); FileMenu->addAction(trUtf8("&Quit..."), this, SLOT(quit()),QKeySequence(trUtf8("Ctrl+Q", "Quit"))); menuBar()->addMenu(FileMenu); EditMenu=new QMenu(QString("&Edit")); @@ -198,6 +194,7 @@ void MainWindow::flush(){ } CLabel::CLabel( const QString& text, const QString & style, QWidget * parent ) : QLabel(parent) { + m_style=style; setText(text); setWordWrap(true); setLineWidth(5); @@ -208,16 +205,16 @@ CLabel::CLabel( const QString& text, const QString & style, QWidget * parent ) : CLabel::~CLabel() { } -void CLabel::mousePressEvent ( QMouseEvent * event ) +void CLabel::mousePressEvent (QMouseEvent * event ) { switch(event->button()){ - case Qt::LeftButton:setStyleSheet("background-color: red;border-style: inset;border-width: 7px;border-radius: 10px;border-color: beige;font: bold 15px;padding: 6px;");emit pressed();break; + case Qt::LeftButton:setStyleSheet(m_style.replace(QString("border-style: outset"), QString("border-style: inset")));emit pressed();break; } } void CLabel::mouseReleaseEvent( QMouseEvent * event ) { switch(event->button()){ - case Qt::LeftButton:setStyleSheet("background-color: red;border-style: outset;border-width: 7px;border-radius: 10px;border-color: beige;font: bold 15px;padding: 6px;");emit released();break; + case Qt::LeftButton:setStyleSheet(m_style);emit released();break; } } @@ -271,7 +268,6 @@ QString &MainWindow::get(int row, int column){ } int MainWindow::exec(const QList & a){ qDebug()<<"exec("<prepare(a[0]); for (int j=1; jbindValue(j-1, a[j]); @@ -281,7 +277,7 @@ int MainWindow::exec(const QList & a){ QSqlError b=q->lastError(); db.commit(); - if (b.isValid())qDebug()<<"SQL error->exec() :"<isSelect())return q->size(); else return 0; } @@ -320,6 +316,11 @@ void MainWindow::addButtonDB(){ QString a, c, b=QInputDialog::getText(this, QString("label"), QString("Entrez son label"),QLineEdit::Normal, QString(), &ok); if ((b=="")||(ok==0))return; cmd.append(b); + for(int i=0;i tmp({"select label,action from ui where keyword like :word;"});; - label->setText(QString::number(way.size())); - //label->setText(a); - tmp.append(b); + QList tmp({"select label,action from ui where keyword like ?;", b}); + //label->setText(QString::number(way.size())); + label->setText(a); + //tmp.append(b); exec(tmp); int labCol = 0;//r.indexOf("label"); int actCol = 1;//r.indexOf("action"); - QMutexLocker locker(&sql); + //QMutexLocker locker(&sql); int i=0; while(q->next()){ - addWidget(q->value(actCol).toString(), new CLabel(q->value(labCol).toString())); + addWidget(q->value(actCol).toString(), new CLabel(q->value(labCol).toString(), conf->value(QString("button")).toString())); i++; }; qDebug()<<"end getButtons : "<value(QString("download")).toString(); QUrl update(conf->value(QString("download")).toString()); m = new FileDownloader(update, this); @@ -373,15 +378,14 @@ void MainWindow::sendUi(){ qDebug()<<"sendUi() : "<value(QString("upload")).toString(); QUrl upload(conf->value(QString("upload")).toString()); net=new QNetworkAccessManager(this); - net->put(QNetworkRequest(upload),data); + qDebug()<<"net->put : "<put(QNetworkRequest(upload),data); } void MainWindow::back(){ - bool ok; - int a=QInputDialog::getInt(this, QString("back()"), QString("Quel page ?"), way.size()-2, 0, way.size()-1, 1, &ok); - if(ok){ - getButtons(way[a]); - qDebug()<<"retour : "<downloadedData().size()<<" byte"; - QMutexLocker locker(&sql); + qDebug()<<"writeUpdate()->sql.trylock:"<downloadedData().count('\n'); qDebug()<<"first line : "<downloadedData().split('\n').at(0); @@ -451,6 +455,8 @@ void MainWindow::writeUpdate(){ }; db.commit(); data=m->downloadedData(); + updatelocker.unlock(); + qDebug()<<"updatlocker unlocked"; getButtons(conf->value(QString("start"), QVariant("begin")).toString()); } diff --git a/mainwindow.h b/mainwindow.h index 44b9d62..683d216 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -60,7 +60,7 @@ private: class CLabel : public QLabel { Q_OBJECT - + QString m_style; public: explicit CLabel(const QString& text ="default", const QString &style="background-color: red;border-style: outset;border-width: 7px;border-radius: 10px;border-color: beige;font: bold 15px;padding: 6px;", QWidget * parent = 0 ); @@ -122,7 +122,7 @@ public slots: signals: private: - QMutex sql,update; + QMutex sql,updatelocker; QWidget *screen; QGridLayout *grid; QLabel *label; -- 2.45.1