Parcourir la source

Export feature added

Rémi Synave il y a 1 an
Parent
commit
62497b9f15
4 fichiers modifiés avec 53 ajouts et 16 suppressions
  1. 24 3
      WorkArea/WorkArea.cpp
  2. 3 1
      WorkArea/WorkArea.hpp
  3. 24 12
      dsl/MainWindow.cpp
  4. 2 0
      dsl/MainWindow.hpp

+ 24 - 3
WorkArea/WorkArea.cpp

@@ -83,12 +83,12 @@ WorkArea::~WorkArea ()
 void
 WorkArea::loadImage (const std::string & filename)
 {
-  QImage opened (QString::fromStdString (filename));
+  original = new QImage (QString::fromStdString (filename));
   img =
-    new QImage (opened. scaled (screenSizeX, screenSizeY - this->geometry ().y (),
+    new QImage (original->scaled (screenSizeX, screenSizeY - this->geometry ().y (),
 		Qt::KeepAspectRatio, Qt::FastTransformation));
   
-  resizeFactor = (img->width()*1.0)/opened.width();
+  resizeFactor = (img->width()*1.0)/original->width();
   liste_points.clear ();
   
   setFixedSize (img->width (), img->height ());
@@ -144,6 +144,27 @@ WorkArea::saveStrengthLine (const std::string & filename)
   this->modificationInProgress = false;
 }
 
+void
+WorkArea::exportPNG (const std::string & filename)
+{
+  QImage tempImg(*original);
+  QPainter painter(&tempImg);
+  for (int i = 0; i < liste_points.length (); i++)
+    {
+      if ((i % 2) == 1)
+	{
+	  painter.setPen (QPen (Qt::red, epaisseurLigne/resizeFactor));
+	  std::pair < QPoint *, QPoint * > endPoints =
+	    StrengthLine (liste_points[i - 1], liste_points[i]).toDraw (&tempImg);
+	  painter.drawLine (*(std::get < 0 > (endPoints))/resizeFactor,
+			    *(std::get < 1 > (endPoints))/resizeFactor);
+	}
+
+    }
+  tempImg.save(QString::fromStdString (filename));
+  
+}
+
 void
 WorkArea::setReadOnly(bool readOnly){
   this->readOnly = readOnly;

+ 3 - 1
WorkArea/WorkArea.hpp

@@ -47,7 +47,8 @@ private:
   unsigned int screenSizeX, screenSizeY;
   bool readOnly;
   bool modificationInProgress;
-  
+
+  QImage *original;
   QImage *img;
   double resizeFactor;
   QList < QPoint * >liste_points;
@@ -73,6 +74,7 @@ public:
   void loadImage (const std::string & filename);
   void loadSL (const std::string & filename);
   void saveStrengthLine (const std::string & filename);
+  void exportPNG (const std::string & filename);
   void setReadOnly(bool readOnly);
   bool getReadOnly();
   void setModificationInProgress(bool mip);

+ 24 - 12
dsl/MainWindow.cpp

@@ -132,6 +132,13 @@ MainWindow::save ()
   wa->saveStrengthLine (toSave.toStdString ());
 }
 
+void
+MainWindow::exportPNG ()
+{
+  QString toSave =  QDir::currentPath ().append("/").append(QFileInfo(filenames->at(openedImage)).baseName().append(*suffix).append(".png"));
+  wa->exportPNG (toSave.toStdString ());
+}
+
 QMessageBox::StandardButton
 MainWindow::checkModificationinProgress()
 {
@@ -143,9 +150,9 @@ MainWindow::checkModificationinProgress()
 void
 MainWindow::firstImage ()
 {
-  if(this->checkModificationinProgress() == QMessageBox::Yes)
-    if(filenames != NULL)
-      if(filenames->size() > 1){
+  if(filenames != NULL)
+    if(filenames->size() > 1)
+      if(this->checkModificationinProgress() == QMessageBox::Yes){
 	openedImage = 0;
 	loadImage();
       }
@@ -154,9 +161,9 @@ MainWindow::firstImage ()
 void
 MainWindow::previousImage ()
 {
-  if(this->checkModificationinProgress() == QMessageBox::Yes)
-    if(filenames != NULL)
-      if(filenames->size() > 1){
+  if(filenames != NULL)
+    if(filenames->size() > 1)
+      if(this->checkModificationinProgress() == QMessageBox::Yes){
 	openedImage = (openedImage-1+filenames->size())%(filenames->size());
 	loadImage();
       }
@@ -165,9 +172,9 @@ MainWindow::previousImage ()
 void
 MainWindow::nextImage ()
 {
-  if(this->checkModificationinProgress() == QMessageBox::Yes)
-    if(filenames != NULL)
-      if(filenames->size() > 1){
+  if(filenames != NULL)
+    if(filenames->size() > 1)
+      if(this->checkModificationinProgress() == QMessageBox::Yes){
 	openedImage = (openedImage+1)%(filenames->size());
 	loadImage();
       }
@@ -176,9 +183,9 @@ MainWindow::nextImage ()
 void
 MainWindow::lastImage ()
 {
-  if(this->checkModificationinProgress() == QMessageBox::Yes)
-    if(filenames != NULL)
-      if(filenames->size() > 1){
+  if(filenames != NULL)
+    if(filenames->size() > 1)
+      if(this->checkModificationinProgress() == QMessageBox::Yes){
 	openedImage = filenames->size()-1;
 	loadImage();
       }
@@ -222,6 +229,10 @@ MainWindow::createActions ()
   saveAct->setShortcuts (QKeySequence::Save);
   connect (saveAct, &QAction::triggered, this, &MainWindow::save);
 
+  exportAct = new QAction (tr ("&Export in PNG"), this);
+  exportAct->setShortcut (QKeySequence(Qt::CTRL | Qt::Key_E));
+  connect (exportAct, &QAction::triggered, this, &MainWindow::exportPNG);
+
   exitAct = new QAction (tr ("E&xit"), this);
   exitAct->setShortcuts (QKeySequence::Quit);
   connect (exitAct, &QAction::triggered, this, &QWidget::close);
@@ -262,6 +273,7 @@ MainWindow::createMenus ()
   fileMenu = menuBar ()->addMenu (tr ("&File"));
   fileMenu->addAction (openAct);
   fileMenu->addAction (saveAct);
+  fileMenu->addAction (exportAct);
 
   fileMenu->addSeparator ();
 

+ 2 - 0
dsl/MainWindow.hpp

@@ -45,6 +45,7 @@ private:
 
   QAction *openAct;
   QAction *saveAct;
+  QAction *exportAct;
   QAction *exitAct;
   QAction *automaticLoadingAct;
   QAction *readOnlyAct;
@@ -73,6 +74,7 @@ private:
 private slots:
   void openFile ();
   void save ();
+  void exportPNG ();
   void firstImage ();
   void previousImage ();
   void nextImage ();