]> git.nothing2do.fr Git - diary-mobile.git/commitdiff
try longpress() but fail, and action("new") don't mess up with next/prev
authorNorbert Moutarde <norbert.moutarde@nothing2do.eu>
Mon, 7 Aug 2017 16:09:18 +0000 (18:09 +0200)
committerNorbert Moutarde <norbert.moutarde@nothing2do.eu>
Mon, 7 Aug 2017 16:09:18 +0000 (18:09 +0200)
mainwindow.cpp
mainwindow.h

index c113c1d1bbc4a500c07f71e77ee2fc90deed411f..535fe1823fca0ff1dead2dc827cf595e5ddf697d 100644 (file)
@@ -65,6 +65,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
     valeur=new QMap<QString, QString>;
     qDebug()<<"1' connect : "<<connect(signalmap, SIGNAL(mapped(const QString &)), this, SLOT(action(const QString &)));
     qDebug()<<"2' connect : "<<connect(this, SIGNAL(datafilled()), this, SLOT(start()));
+    //qDebug()<<"3' connect : "<<connect(CLabel, SIGNAL(longpress()), MainWindow, SLOT(action(QString("edit "+id))););
     //a desperated attempt to get the output of my cmd, i've try Qprocess (but don't get it)
     //qDebug()<<"3' connect : "<<connect(shell, SIGNAL(readyReadStandardOutput()), this, SLOT(shellReady()));
     label=new QLabel;
@@ -565,22 +566,25 @@ void MainWindow::flush(){
     }
     //widget.clear();
 }
-CLabel::CLabel( const QString& text, const QSettings & set, QWidget * parent ) : QLabel(parent)
+CLabel::CLabel( const QString& text, const QSettings & set, int tmpid, QWidget * parent ) : QLabel(parent)
 {
     QString a=set.value(QString("currenttype")).toString();
     m_style=set.value(a).toString();
     setText(text);
     setWordWrap(true);
     setLineWidth(5);
+    id=tmpid;
     setStyleSheet(m_style);
     setScaledContents(true);
     settings=&set;
+    parents=parent;
 }
 CLabel::~CLabel()
 {
 }
 void CLabel::mousePressEvent (QMouseEvent * event )
 {
+    t.start();
     QString a=settings->value(QString("currenttype")).toString();
     QString bb=settings->value(a+QString("before")).toString();
     QString ba=settings->value(a+QString("after")).toString();
@@ -591,11 +595,17 @@ void CLabel::mousePressEvent (QMouseEvent * event )
 }
 void CLabel::mouseReleaseEvent( QMouseEvent * event )
 {
+    int c=t.elapsed();
     QString a=settings->value(QString("currenttype")).toString();
     QString bb=settings->value(a+QString("before")).toString();
     QString ba=settings->value(a+QString("after")).toString();
+    QString tmp("edit "+id);
     switch(event->button()){
-        case Qt::LeftButton:setStyleSheet(m_style.replace(ba, bb));emit released();break;
+        case Qt::LeftButton:
+            setStyleSheet(m_style.replace(ba, bb));
+            if(c>2000)emit longpress();
+            else emit released();
+        break;
         //case Qt::LeftButton:setStyleSheet(m_style.replace(setting->value(setting->value(QString("currenttype")).toString()+"after").toString(), setting->value(QString("currenttype")).toString()+"before"));emit released();break;
 
     }
@@ -658,7 +668,7 @@ void MainWindow::firstrun(){
     conf->setValue(QString("choosebuttons"), QVariant("select id,label from buttons where keyword like ? order by label;"));
     conf->setValue(QString("addbuttons"), QVariant("insert into buttons (keyword, label, action) values (:keyword, :label, :action)"));
     conf->setValue(QString("addraw"), QVariant("INSERT INTO raw (date, texte) VALUES (:date, :txt);"));
-    conf->setValue(QString("getbuttons"), QVariant("select label,action from buttons where keyword like ? order by label;"));
+    conf->setValue(QString("getbuttons"), QVariant("select label,action,id from buttons where keyword like ? order by label;"));
     conf->setValue(QString("editbuttons"), QVariant("select id,keyword,label,action from buttons where id=?;"));
     conf->setValue(QString("updatebuttons"), QVariant("update buttons set keyword=?, label=?, action=? where id=?;"));
     conf->setValue(QString("deletebuttons"), QVariant("delete from buttons where id=?"));
@@ -703,7 +713,7 @@ int MainWindow::exec(const QList<QString> & a){
     return -1;
 }
 int MainWindow::exec2(const QList<QString> & a){
-    qDebug()<<"exec("<<a[0]<<") size="<<a.size();
+    qDebug()<<"exec("<<a[0]<<") size="<<a.size()<<", q->prepare: "<<qq->prepare(a[0]);
     qq->prepare(a[0]);
     for (int j=1; j<a.size(); j++){
         qq->bindValue(j-1, a[j]);
@@ -741,7 +751,7 @@ void MainWindow::entry(const QString &a){
     if(a=="")c=context+" : "+entry;
     else c=context+", "+a+" : "+entry;
     QList<QString> d({conf->value(QString("addraw")).toString(), time, c});
-    if(!exec(d))qDebug()<<"exec don't works (entry(QString))";
+    if(!exec2(d))qDebug()<<"exec don't works (entry(QString))";
     QSqlError b=q->lastError();
     if (b.isValid())qDebug()<<"q->lastError():"<<b.text();
 }
@@ -764,7 +774,9 @@ void MainWindow::addDB(const QString & tmp, const QString & cur){
         tmpfile=QFileDialog::getOpenFileName();
         a.replace(QString("!file!"),tmpfile);
     };
-
+    /*if(a.contains(QString("!label"))){
+        a.replace(QString("!label!"), label->text());
+    };*/
     insert(tmp, b, c, a);
     return;
 }
@@ -787,6 +799,7 @@ void MainWindow::get(const QString & d, const QString &b){
     //while(q->next()){
          printItem(*q);
     //}
+    showExpanded();
 }
 void MainWindow::chooseDB(){
     QString b;
@@ -1279,6 +1292,7 @@ void MainWindow::reset(){
 bool MainWindow::printItem(const QSqlQuery & a){
     int labCol = 0;//r.indexOf("label");
     int actCol = 1;//r.indexOf("action");
+    int idcol = 2;//r.indexOf("id");
     int i=0;
     qDebug()<<"printItem()";
     if(page){
@@ -1287,7 +1301,7 @@ bool MainWindow::printItem(const QSqlQuery & a){
     };
     do{
         int tmp=0;
-        if(a.isValid())tmp=addWidget(a.value(actCol).toString(), new CLabel(a.value(labCol).toString(), *conf));
+        if(a.isValid())tmp=addWidget(a.value(actCol).toString(), new CLabel(a.value(labCol).toString(), *conf, a.value(idcol).toInt()));
         if(tmp==1){
             addWidget(QString("nextpage"), new CLabel(trUtf8("Next"), *conf));
             return 1;
@@ -1295,7 +1309,7 @@ bool MainWindow::printItem(const QSqlQuery & a){
         i++;
     }while(a.next());
     qDebug()<<"end printItem : "<<i<<" button(s) way.size()"<<way.size()<<" page : "<<page;
-    showExpanded();
+    //showExpanded();
     return 0;
 }
 void MainWindow::get2(const QString & d, const QString &b){
index d5ab20f2f29b87b7930cd2b7db55fb577e350086..f5dc9d5b3ecb5e51b252a445ec57a32e94bd1e9e 100644 (file)
@@ -86,8 +86,11 @@ class CLabel : public QLabel
 Q_OBJECT
     QString m_style;
     QSettings * settings;
+    QTime t;
+    int id;
+    QWidget * parents;
 public:
-    explicit CLabel(const QString&, const QSettings &, QWidget * parent = 0 );
+    explicit CLabel(const QString&, const QSettings &, int=0, QWidget * parent = 0 );
     ~CLabel();
     void SetTextToLabel(const QString &);
     QSettings * getSettings();
@@ -95,6 +98,7 @@ signals:
     void clicked();
     void pressed();
     void released();
+    void longpress();
 private slots:
 protected:
     void mousePressEvent ( QMouseEvent * event ) ;