Parcourir la source

First version of csl

Rémi Synave il y a 1 an
Parent
commit
d3743d1b68
6 fichiers modifiés avec 195 ajouts et 4 suppressions
  1. 23 1
      WorkArea/WorkArea.cpp
  2. 2 3
      WorkArea/WorkArea.hpp
  3. 100 0
      csl/MainWindow.cpp
  4. 41 0
      csl/MainWindow.hpp
  5. 17 0
      csl/csl.pro
  6. 12 0
      csl/main.cpp

+ 23 - 1
WorkArea/WorkArea.cpp

@@ -47,7 +47,6 @@ WorkArea::WorkArea (int screenSizeX, int screenSizeY, const std::string & imageF
   while (!in.atEnd()) {
     QString line = in.readLine();
     QStringList parts = line.split(" ");
-    qDebug() << parts[0].toInt() << Qt::endl;
     liste_points << new QPoint(parts[0].toInt(), parts[1].toInt());
     liste_points << new QPoint(parts[2].toInt(), parts[3].toInt());
   }
@@ -69,6 +68,24 @@ WorkArea::loadImage (const std::string & filename)
   resize (img->width (), img->height ());
 }
 
+void
+WorkArea::loadSL (const std::string & filename)
+{
+  liste_points.clear();
+  QFile file(QString::fromStdString (filename));
+  if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
+    return;
+  
+  QTextStream in(&file);
+  while (!in.atEnd()) {
+    QString line = in.readLine();
+    QStringList parts = line.split(" ");
+    liste_points << new QPoint(parts[0].toInt(), parts[1].toInt());
+    liste_points << new QPoint(parts[2].toInt(), parts[3].toInt());
+  }
+  file.close();
+}
+
 void
 WorkArea::saveStrengthLine (const std::string & filename)
 {
@@ -84,6 +101,11 @@ WorkArea::saveStrengthLine (const std::string & filename)
   file.close ();
 }
 
+void
+WorkArea::setReadOnly(bool readOnly){
+  this->readOnly = readOnly;
+}
+
 
 void
 WorkArea::paintEvent (QPaintEvent * event)

+ 2 - 3
WorkArea/WorkArea.hpp

@@ -44,10 +44,9 @@ public:
   
   void paint (QPainter & painter);
   void loadImage (const std::string & filename);
+  void loadSL (const std::string & filename);
   void saveStrengthLine (const std::string & filename);
-
-
-
+  void setReadOnly(bool readOnly);
 
 };
 

+ 100 - 0
csl/MainWindow.cpp

@@ -0,0 +1,100 @@
+#include <QGuiApplication>
+#include <QScreen>
+#include <QWidget>
+#include <QMenuBar>
+#include <QFileDialog>
+#include <QHBoxLayout>
+#include <QPushButton>
+
+#include "MainWindow.hpp"
+
+
+MainWindow::MainWindow ()
+{
+  createActions ();
+  createMenus ();
+
+  setWindowTitle (tr ("DSL - Draw Strength Line"));
+
+  QScreen *screen = QGuiApplication::primaryScreen ();
+  QRect screenGeometry = screen->geometry ();
+  screenWidth = screenGeometry.width () - 200;
+  screenHeight = screenGeometry.height () - 200;
+
+  QWidget *central= new QWidget(this);
+  waLeft = new WorkArea ((screenWidth/2)-25, screenHeight, this);
+  waRight = new WorkArea ((screenWidth/2)-25, screenHeight, this);
+  QHBoxLayout *layout = new QHBoxLayout(this);
+  layout->addWidget(waLeft);
+  QPushButton *button = new QPushButton("coucou", this);
+  button->setFixedSize(QSize(50,20));
+  layout->addWidget(button);
+  layout->addWidget(waRight);
+  central->setLayout(layout);
+  
+  setCentralWidget (central);
+
+  setFixedSize (screenWidth, screenHeight);
+}
+
+void
+MainWindow::open ()
+{
+  QString imageFilename = QFileDialog::getOpenFileName (this,
+						   QObject::
+						   tr ("Open image file"),
+						   QDir::currentPath (),
+						   QObject::
+						   tr
+						   ("Images files (*.jpg *.png);;All files (*.*)"));
+  QString SLLeftFilename = QFileDialog::getOpenFileName (this,
+						   QObject::
+						   tr ("Open strength lines file"),
+						   QDir::currentPath (),
+						   QObject::
+						   tr
+						   ("Text files (*.txt);;All files (*.*)"));
+  QString SLRightFilename = QFileDialog::getOpenFileName (this,
+						   QObject::
+						   tr ("Open strength lines file"),
+						   QDir::currentPath (),
+						   QObject::
+						   tr
+						   ("Text files (*.txt);;All files (*.*)"));
+
+  openC(imageFilename, SLLeftFilename, SLRightFilename);
+}
+
+void
+MainWindow::openC (QString image, QString leftSL, QString rightSL){
+  waLeft->loadImage (image.toStdString ());
+  waRight->loadImage (image.toStdString ());
+  waLeft->loadSL(leftSL.toStdString());
+  waRight->loadSL(rightSL.toStdString());
+  waLeft->setReadOnly(true);
+  waRight->setReadOnly(true);
+  setFixedSize (waLeft->geometry().width()*2+50, waLeft->geometry().height()+waLeft->geometry().y());
+}
+
+void
+MainWindow::createActions ()
+{
+  openAct = new QAction (tr ("&Open image"), this);
+  openAct->setShortcuts (QKeySequence::Open);
+  connect (openAct, &QAction::triggered, this, &MainWindow::open);
+
+  exitAct = new QAction (tr ("E&xit"), this);
+  exitAct->setShortcuts (QKeySequence::Quit);
+  connect (exitAct, &QAction::triggered, this, &QWidget::close);
+}
+
+void
+MainWindow::createMenus ()
+{
+  fileMenu = menuBar ()->addMenu (tr ("&File"));
+  fileMenu->addAction (openAct);
+
+  fileMenu->addSeparator ();
+
+  fileMenu->addAction (exitAct);
+}

+ 41 - 0
csl/MainWindow.hpp

@@ -0,0 +1,41 @@
+#ifndef MAINWINDOW_HPP
+#define MAINWINDOW_HPP
+
+#include <QMainWindow>
+#include <QAction>
+#include <QMenu>
+
+#include "WorkArea.hpp"
+
+
+class MainWindow: public QMainWindow
+{
+  Q_OBJECT 
+
+
+private:
+  int screenWidth, screenHeight;
+
+  QMenu *fileMenu;
+
+  QAction *openAct;
+  QAction *exitAct;
+
+  WorkArea *waLeft;
+  WorkArea *waRight;
+
+  void createActions ();
+  void createMenus ();
+
+		     
+private slots:
+  void open ();
+
+  
+public:
+  MainWindow ();
+  void openC (QString image, QString leftSL, QString rightSL);
+  
+};
+
+#endif

+ 17 - 0
csl/csl.pro

@@ -0,0 +1,17 @@
+QT += core gui widgets
+
+INCLUDEPATH = ../StrengthLine/ \
+              ../WorkArea/
+
+HEADERS = ../StrengthLine/StrengthLine.hpp \
+          ../WorkArea/WorkArea.hpp \
+          MainWindow.hpp
+                
+SOURCES = ../StrengthLine/StrengthLine.cpp \
+          ../WorkArea/WorkArea.cpp \
+          MainWindow.cpp \
+          main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/dsl
+INSTALLS += target

+ 12 - 0
csl/main.cpp

@@ -0,0 +1,12 @@
+#include <QApplication>
+
+#include "MainWindow.hpp"
+
+int
+main (int argc, char *argv[])
+{
+  QApplication app (argc, argv);
+  MainWindow window;
+  window.show ();
+  return app.exec ();
+}