Bladeren bron

Ajout de fonctionnalité pour le défilement d'images avec les flèches

Rémi Synave 2 jaren geleden
bovenliggende
commit
5482c01901
4 gewijzigde bestanden met toevoegingen van 69 en 17 verwijderingen
  1. 1 1
      WorkArea/WorkArea.cpp
  2. 58 10
      dsl/MainWindow.cpp
  3. 9 5
      dsl/MainWindow.hpp
  4. 1 1
      dsl/dsl.pro

+ 1 - 1
WorkArea/WorkArea.cpp

@@ -78,7 +78,7 @@ WorkArea::loadSL (const std::string & filename)
   QJsonParseError parseError;
   QJsonDocument doc2 = QJsonDocument::fromJson(ba2, &parseError);
   QJsonArray lines = doc2["lines"].toArray();
-  for(unsigned int i=0; i<lines.size(); i++){
+  for(int i=0; i<lines.size(); i++){
     QJsonArray line = lines[i].toArray();
     QJsonArray point1 = line[0].toArray();
     QJsonArray point2 = line[1].toArray();

+ 58 - 10
dsl/MainWindow.cpp

@@ -5,9 +5,14 @@
 #include <QFileDialog>
 #include <QUrl>
 #include <QFileInfo>
+#include <QInputDialog>
+#include <QDirIterator>
 
 #include <QDebug>
 
+#include <iostream>
+#include <filesystem>
+
 #include "MainWindow.hpp"
 
 
@@ -16,6 +21,12 @@ MainWindow::MainWindow ()
   createActions ();
   createMenus ();
 
+  filename = NULL;
+  directoryname = NULL;
+  prefix = NULL;
+  filenames = new QList< QString* >();
+  filenames->clear();
+
   setWindowTitle (tr ("DSL - Draw Strength Line"));
 
   QScreen *screen = QGuiApplication::primaryScreen ();
@@ -33,15 +44,47 @@ MainWindow::MainWindow ()
 void
 MainWindow::openFile ()
 {
-  filename = QFileDialog::getOpenFileName (this,
-						   QObject::
-						   tr ("Open image file"),
-						   QDir::currentPath (),
-						   QObject::tr("Images files (*.jpg *.png);;All files (*.*)"));
-  QDir::setCurrent(QString(filename).remove(QUrl(filename).fileName()));
-  wa->loadImage (filename.toStdString ());
-  wa->repaint();
-  setFixedSize (wa->geometry().width(), wa->geometry().height()+wa->geometry().y());
+  filename = new QString(QFileDialog::getOpenFileName (this,
+						       QObject::tr ("Open image file"),
+						       QDir::currentPath (),
+						       QObject::tr("Images files (*.jpg *.png);;All files (*.*)")));
+
+  if(!filename->isEmpty()) {
+    QDir::setCurrent(QString(*filename).remove(QUrl(*filename).fileName()));
+    wa->loadImage (filename->toStdString ());
+    wa->repaint();
+    setFixedSize (wa->geometry().width(), wa->geometry().height()+wa->geometry().y());
+  }
+}
+
+void
+MainWindow::openDir ()
+{
+  directoryname = new QString(QFileDialog::getExistingDirectory (this,
+								 QObject::tr ("Open directory"),
+								 QDir::currentPath (),
+								 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks));
+  
+  qDebug() << "Chemin du répertoire : " << *directoryname << Qt::endl;
+
+  if(!directoryname->isEmpty()) {
+    bool ok;
+    QString prefix = QInputDialog::getText(this, tr("Prefix for your json files"),
+					   tr("Prefix to use :"), QLineEdit::Normal,
+					   QDir::home().dirName()+"_", &ok);
+    qDebug() << "Prefix received : " << prefix << Qt::endl;
+
+    filenames->clear();
+    
+    QDirIterator it(*directoryname);
+    while (it.hasNext()) {
+      filenames->append( new QString(it.next()) );
+    }
+
+    for (int i=0 ; i<filenames->size() ; i++)
+      qDebug() << *(filenames->at(i)) << Qt::endl;
+  }
+
 }
 
 void
@@ -49,7 +92,7 @@ MainWindow::save ()
 {
   QString fileToSave = QFileDialog::getSaveFileName (this,
 						   QObject::tr ("Save file"),
-						   QDir::currentPath ().append("/").append(QFileInfo(filename).baseName()).append(".json"),
+						   QDir::currentPath ().append("/").append(QFileInfo(*filename).baseName()).append(".json"),
 						   QObject::tr("JSON file (*.json);;All files (*.*)"));
   if(!fileToSave.endsWith(".json"))
     fileToSave.append(".json");
@@ -88,6 +131,10 @@ MainWindow::createActions ()
   openFileAct->setShortcuts (QKeySequence::Open);
   connect (openFileAct, &QAction::triggered, this, &MainWindow::openFile);
 
+  openDirAct = new QAction (tr ("&Open directory"), this);
+  openDirAct->setShortcut (QKeySequence(Qt::CTRL, Qt::Key_Alt, Qt::Key_O));
+  connect (openDirAct, &QAction::triggered, this, &MainWindow::openDir);
+
   saveAct = new QAction (tr ("&Save"), this);
   saveAct->setShortcuts (QKeySequence::Save);
   connect (saveAct, &QAction::triggered, this, &MainWindow::save);
@@ -118,6 +165,7 @@ MainWindow::createMenus ()
 {
   fileMenu = menuBar ()->addMenu (tr ("&File"));
   fileMenu->addAction (openFileAct);
+  fileMenu->addAction (openDirAct);
   fileMenu->addAction (saveAct);
 
   fileMenu->addSeparator ();

+ 9 - 5
dsl/MainWindow.hpp

@@ -29,7 +29,10 @@ private:
 
   WorkArea *wa;
 
-  QString filename;
+  QString *filename;
+  QString *directoryname;
+  QString *prefix;
+  QList< QString* > *filenames;
 
   void createActions ();
   void createMenus ();
@@ -37,11 +40,12 @@ private:
 		     
 private slots:
   void openFile ();
+  void openDir ();
   void save ();
-  void firstImage();
-  void previousImage();
-  void nextImage();
-  void lastImage();
+  void firstImage ();
+  void previousImage ();
+  void nextImage ();
+  void lastImage ();
 
   
 public:

+ 1 - 1
dsl/dsl.pro

@@ -11,7 +11,7 @@ SOURCES = ../StrengthLine/StrengthLine.cpp \
           ../WorkArea/WorkArea.cpp \
           MainWindow.cpp \
           main.cpp
-
+                    
 # install
 target.path = $$[QT_INSTALL_EXAMPLES]/dsl
 INSTALLS += target