|
@@ -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 ();
|