Experiment.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. #include <QGuiApplication>
  2. #include <QScreen>
  3. #include <QWidget>
  4. #include <QMenuBar>
  5. #include <QFileDialog>
  6. #include <QVBoxLayout>
  7. #include <QHBoxLayout>
  8. #include <QPushButton>
  9. #include <QDebug>
  10. #include "Experiment.hpp"
  11. Experiment::Experiment ():QMainWindow()
  12. {
  13. createActions ();
  14. createMenus ();
  15. setWindowTitle (tr ("DSL - Draw Strength Line"));
  16. QScreen *screen = QGuiApplication::primaryScreen ();
  17. QRect screenGeometry = screen->geometry ();
  18. screenWidth = screenGeometry.width () - 200;
  19. screenHeight = screenGeometry.height () - 200;
  20. QWidget *central= new QWidget(this);
  21. setCentralWidget (central);
  22. setContentsMargins(0, 0, 0, 0);
  23. QVBoxLayout *layoutV = new QVBoxLayout(central);
  24. layoutV->setSpacing(0);
  25. layoutV->setContentsMargins(0, 0, 0, 0);
  26. central->setLayout(layoutV);
  27. // First line of the interface
  28. QHBoxLayout *layoutH1 = new QHBoxLayout(central);
  29. layoutH1->setSpacing(0);
  30. layoutH1->setContentsMargins(0, 0, 0, 0);
  31. layoutV->addLayout(layoutH1);
  32. waLeft = new WorkArea (((screenWidth-spaceInBetween)/2), screenHeight, central);
  33. waLeft->setContentsMargins(0, 0, 0, 0);
  34. layoutH1->addWidget(waLeft);
  35. QWidget *w1SpaceInBetween = new QWidget(central);
  36. w1SpaceInBetween->setContentsMargins(0, 0, 0, 0);
  37. w1SpaceInBetween->setFixedSize(spaceInBetween,0);
  38. layoutH1->addWidget(w1SpaceInBetween);
  39. waRight = new WorkArea (((screenWidth-spaceInBetween)/2), screenHeight, central);
  40. waRight->setContentsMargins(0, 0, 0, 0);
  41. layoutH1->addWidget(waRight);
  42. // second line of interface
  43. QWidget *hSpaceInBetween = new QWidget(central);
  44. hSpaceInBetween->setContentsMargins(0, 0, 0, 0);
  45. hSpaceInBetween->setFixedSize(0, spaceInBetween);
  46. layoutV->addWidget(hSpaceInBetween);
  47. // third line of interface
  48. QHBoxLayout *layoutH2 = new QHBoxLayout(central);
  49. layoutH2->setSpacing(0);
  50. layoutH2->setContentsMargins(0, 0, 0, 0);
  51. layoutV->addLayout(layoutH2);
  52. leftButton = new QPushButton("Image de gauche", central);
  53. leftButton->setFixedHeight(30);
  54. connect(leftButton, SIGNAL(clicked(bool)), this, SLOT(leftImage()));
  55. layoutH2->addWidget(leftButton);
  56. QWidget *w2SpaceInBetween = new QWidget();
  57. w2SpaceInBetween->setContentsMargins(0, 0, 0, 0);
  58. w2SpaceInBetween->setFixedSize(spaceInBetween,0);
  59. layoutH2->addWidget(w2SpaceInBetween);
  60. rightButton = new QPushButton("Image de droite", central);
  61. rightButton->setFixedHeight(30);
  62. connect(rightButton, SIGNAL(clicked(bool)), this, SLOT(rightImage()));
  63. layoutH2->addWidget(rightButton);
  64. // Fourth line of the interface
  65. progressBar = new QProgressBar(central);
  66. progressBar->setFixedHeight(20);
  67. progressBar->setRange(0, maxProgressBar);
  68. progressBar->setValue(0);
  69. connect(progressBar, SIGNAL(valueChanged(int)), this, SLOT(progressBarValueChanged(int)));
  70. layoutV->addWidget(progressBar);
  71. timer = new QTimer(central);
  72. timer->setSingleShot(false);
  73. timer->setInterval(time);
  74. connect(timer, SIGNAL(timeout()), this, SLOT(ticTimer()));
  75. setFixedSize (screenWidth, screenHeight);
  76. /*POUR TEST*/
  77. QString img_a_ouvrir("/home/remi/images/screenshot.png");
  78. QString sl1_a_ouvrir("/home/remi/images/fzerfrezf.json");
  79. QString sl2_a_ouvrir("/home/remi/images/screenshotb.txt");
  80. openC( img_a_ouvrir, sl1_a_ouvrir, sl2_a_ouvrir);
  81. timer->start();
  82. }
  83. void
  84. Experiment::open ()
  85. {
  86. QString imageFilename = QFileDialog::getOpenFileName (this,
  87. QObject::
  88. tr ("Open image file"),
  89. QDir::currentPath (),
  90. QObject::
  91. tr
  92. ("Images files (*.jpg *.png);;All files (*.*)"));
  93. QString SLLeftFilename = QFileDialog::getOpenFileName (this,
  94. QObject::
  95. tr ("Open strength lines file"),
  96. QDir::currentPath (),
  97. QObject::
  98. tr
  99. ("Text files (*.txt);;All files (*.*)"));
  100. QString SLRightFilename = QFileDialog::getOpenFileName (this,
  101. QObject::
  102. tr ("Open strength lines file"),
  103. QDir::currentPath (),
  104. QObject::
  105. tr
  106. ("Text files (*.txt);;All files (*.*)"));
  107. openC(imageFilename, SLLeftFilename, SLRightFilename);
  108. }
  109. void Experiment::leftImage(){
  110. qDebug() << "Clic sur image gauche" << Qt::endl;
  111. progressBar->setValue(0);
  112. }
  113. void Experiment::rightImage(){
  114. qDebug() << "Clic sur image droite" << Qt::endl;
  115. progressBar->setValue(0);
  116. }
  117. void Experiment::progressBarValueChanged(int value){
  118. if(value == maxProgressBar ){
  119. QApplication::quit();
  120. }
  121. }
  122. void Experiment::ticTimer(){
  123. progressBar->setValue(progressBar->value()+time);
  124. }
  125. void
  126. Experiment::openC (QString image, QString leftSL, QString rightSL){
  127. waLeft->loadImage (image.toStdString ());
  128. waRight->loadImage (image.toStdString ());
  129. waLeft->loadSL(leftSL.toStdString());
  130. waRight->loadSL(rightSL.toStdString());
  131. waLeft->setReadOnly(true);
  132. waRight->setReadOnly(true);
  133. setFixedSize (waLeft->geometry().width()*2+spaceInBetween, waLeft->geometry().height()+waLeft->geometry().y()+spaceInBetween+leftButton->geometry().height()+22); // +22 ??!!
  134. }
  135. void
  136. Experiment::createActions ()
  137. {
  138. openAct = new QAction (tr ("&Open image"), this);
  139. openAct->setShortcuts (QKeySequence::Open);
  140. connect (openAct, &QAction::triggered, this, &Experiment::open);
  141. exitAct = new QAction (tr ("E&xit"), this);
  142. exitAct->setShortcuts (QKeySequence::Quit);
  143. connect (exitAct, &QAction::triggered, this, &QWidget::close);
  144. }
  145. void
  146. Experiment::createMenus ()
  147. {
  148. fileMenu = menuBar ()->addMenu (tr ("&File"));
  149. fileMenu->addAction (openAct);
  150. fileMenu->addSeparator ();
  151. fileMenu->addAction (exitAct);
  152. }