Просмотр исходного кода

read only and automatic json fill loading feature added

Rémi Synave 2 лет назад
Родитель
Сommit
ff60a89cb3
4 измененных файлов с 59 добавлено и 7 удалено
  1. 5 0
      WorkArea/WorkArea.cpp
  2. 1 0
      WorkArea/WorkArea.hpp
  3. 47 7
      dsl/MainWindow.cpp
  4. 6 0
      dsl/MainWindow.hpp

+ 5 - 0
WorkArea/WorkArea.cpp

@@ -120,6 +120,11 @@ WorkArea::setReadOnly(bool readOnly){
   this->readOnly = readOnly;
 }
 
+bool
+WorkArea::getReadOnly(){
+  return this->readOnly;
+}
+
 
 void
 WorkArea::paintEvent (QPaintEvent * event)

+ 1 - 0
WorkArea/WorkArea.hpp

@@ -50,6 +50,7 @@ public:
   void loadSL (const std::string & filename);
   void saveStrengthLine (const std::string & filename);
   void setReadOnly(bool readOnly);
+  bool getReadOnly();
 
 };
 

+ 47 - 7
dsl/MainWindow.cpp

@@ -26,6 +26,7 @@ MainWindow::MainWindow ()
   directoryname = NULL;
   suffix = NULL;
   filenames = NULL;
+  autoLoad = false;
 
   setWindowTitle (tr ("DSL - Draw Strength Line"));
 
@@ -35,7 +36,7 @@ MainWindow::MainWindow ()
   int screenHeight = screenGeometry.height () - 200;
   
   wa = new WorkArea (screenWidth, screenHeight, this);
-  
+  wa->setReadOnly(false);
   setCentralWidget (wa);
 
   setFixedSize (screenWidth, screenHeight);
@@ -76,13 +77,26 @@ MainWindow::openFile ()
 	  }
 
 	QDir::setCurrent(*directoryname);
-	wa->loadImage (filenames->at(openedImage).toStdString ());
-	wa->repaint();
-	setFixedSize (wa->geometry().width(), wa->geometry().height()+wa->geometry().y());
+	loadImage();
       }
   }
 }
 
+void
+MainWindow::loadImage()
+{
+  wa->loadImage (filenames->at(openedImage).toStdString ());
+  if(autoLoad)
+    {
+      QString jsonFile(QDir::currentPath ().append("/").append(QFileInfo(filenames->at(openedImage)).baseName().append(*suffix).append(".json")));
+      if(QFile(jsonFile).exists()){
+	wa->loadSL(QDir::currentPath ().append("/").append(QFileInfo(filenames->at(openedImage)).baseName().append(*suffix).append(".json")).toStdString());
+      }
+    }
+  wa->repaint();
+  setFixedSize (wa->geometry().width(), wa->geometry().height()+wa->geometry().y());
+}
+
 void
 MainWindow::save ()
 {
@@ -127,11 +141,24 @@ MainWindow::lastImage ()
 }
 
 void
-MainWindow::loadImage()
+MainWindow::automaticLoading ()
 {
-  wa->loadImage (filenames->at(openedImage).toStdString ());
+  autoLoad = !autoLoad;
+  automaticLoadingAct->setChecked(!autoLoad);
+}
+
+
+void
+MainWindow::readOnly ()
+{
+  if(wa->getReadOnly()){
+    wa->setReadOnly(false);
+    readOnlyAct->setText(tr ("W&ritable"));
+  }else{
+    wa->setReadOnly(true);
+    readOnlyAct->setText(tr ("&Read Only"));
+  }
   wa->repaint();
-  setFixedSize (wa->geometry().width(), wa->geometry().height()+wa->geometry().y());
 }
 
 
@@ -150,6 +177,15 @@ MainWindow::createActions ()
   exitAct->setShortcuts (QKeySequence::Quit);
   connect (exitAct, &QAction::triggered, this, &QWidget::close);
 
+  automaticLoadingAct = new QAction (tr ("Automatic &Loading Line json file"), this);
+  automaticLoadingAct->setShortcut (QKeySequence(Qt::CTRL | Qt::Key_L));
+  automaticLoadingAct->setCheckable(true);
+  connect (automaticLoadingAct, &QAction::triggered, this, &MainWindow::automaticLoading);
+
+  readOnlyAct = new QAction (tr ("&Read Only"), this);
+  readOnlyAct->setShortcut (QKeySequence(Qt::CTRL | Qt::Key_R));
+  connect (readOnlyAct, &QAction::triggered, this, &MainWindow::readOnly);
+
   firstImageAct = new QAction (tr ("First"), this);
   firstImageAct->setShortcuts (QKeySequence::MoveToPreviousLine);
   connect (firstImageAct, &QAction::triggered, this, &MainWindow::firstImage);
@@ -178,6 +214,10 @@ MainWindow::createMenus ()
 
   fileMenu->addAction (exitAct);
 
+  editMenu = menuBar()->addMenu(tr("&Edit"));
+  editMenu->addAction (automaticLoadingAct);
+  editMenu->addAction (readOnlyAct);
+
   imageMenu = menuBar ()->addMenu (tr ("&Image"));
   imageMenu->addAction (firstImageAct);
   imageMenu->addAction (previousImageAct);

+ 6 - 0
dsl/MainWindow.hpp

@@ -16,11 +16,14 @@ class MainWindow: public QMainWindow
 
 private:
   QMenu *fileMenu;
+  QMenu *editMenu;
   QMenu *imageMenu;
 
   QAction *openAct;
   QAction *saveAct;
   QAction *exitAct;
+  QAction *automaticLoadingAct;
+  QAction *readOnlyAct;
   QAction *firstImageAct;
   QAction *previousImageAct;
   QAction *nextImageAct;
@@ -32,6 +35,7 @@ private:
   int openedImage;
   QString *directoryname;
   QString *suffix;
+  bool autoLoad;
 
   void createActions ();
   void createMenus ();
@@ -47,6 +51,8 @@ private slots:
   void previousImage ();
   void nextImage ();
   void lastImage ();
+  void automaticLoading ();
+  void readOnly ();
 
   
 public: