mainwindow.cpp 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. #include "mainwindow.h"
  2. #include "selectsettingwindow.h"
  3. #include <QMenu>
  4. #include <QMenuBar>
  5. #include <QMessageBox>
  6. #include <QAction>
  7. #include <QtGui>
  8. #include "svgview.h"
  9. /* map:
  10. * constructors
  11. * copie makers
  12. * herited fonctions
  13. * fonctions
  14. * getter/setters
  15. * events
  16. * destruction!!!
  17. */
  18. MainWindow::MainWindow()
  19. : QMainWindow()
  20. , m_view(new SvgView)
  21. {
  22. this->setAttribute(Qt::WA_AcceptTouchEvents);
  23. //les menus:
  24. //fichier (ui status ok)
  25. //logic status:
  26. //should opensettingsof each sorts (machine/cut/app)
  27. //already loading 30% svgs
  28. //should be able to rasterize jpg and png
  29. QMenu *fileMenu = new QMenu(tr("&File"), this);
  30. QMenu *openMenu = new QMenu(tr("&Open"), this);
  31. QAction *openAction = openMenu->addAction(tr("&Default file"));
  32. openAction->setShortcut(QKeySequence("Ctrl+D"));
  33. QAction *opentestfileAction = openMenu->addAction(tr("&Test file"));
  34. openAction->setShortcut(QKeySequence("Ctrl+T"));
  35. QAction *openfileDialogAction = openMenu->addAction(tr("&Any file..."));
  36. openAction->setShortcut(QKeySequence("Ctrl+A"));
  37. fileMenu->addMenu(openMenu);
  38. QAction *quitAction = fileMenu->addAction(tr("E&xit"));
  39. quitAction->setShortcuts(QKeySequence::Quit);
  40. menuBar()->addMenu(fileMenu);
  41. //to do setting menu
  42. //(wip:ui)
  43. //(todo:logic)
  44. QMenu *settingsMenu = new QMenu(tr("&Settings"), this);
  45. //popup the machine parameter window
  46. QAction *setmachineAction = settingsMenu->addAction(tr("&Machine Settings"));
  47. openAction->setShortcut(QKeySequence(tr("Ctrl+M")));
  48. //popup the engrave/cut parameter window
  49. QAction *setparametersAction = settingsMenu->addAction(tr("&Cut/Engrave Settings"));
  50. openAction->setShortcut(QKeySequence(tr("Ctrl+G")));
  51. //popup the engrave/cut parameter window
  52. QAction *setapplicationsAction = settingsMenu->addAction(tr("&Application Settings"));
  53. openAction->setShortcut(QKeySequence(tr("Ctrl+A")));
  54. menuBar()->addMenu(settingsMenu);
  55. //vue
  56. QMenu *viewMenu = new QMenu(tr("&View"), this);
  57. m_backgroundAction = viewMenu->addAction(tr("&Background"));
  58. m_backgroundAction->setEnabled(false);
  59. m_backgroundAction->setCheckable(true);
  60. m_backgroundAction->setChecked(false);
  61. connect(m_backgroundAction, SIGNAL(toggled(bool)), m_view, SLOT(setViewBackground(bool)));
  62. m_outlineAction = viewMenu->addAction(tr("Ou&tline"));
  63. m_outlineAction->setEnabled(false);
  64. m_outlineAction->setCheckable(true);
  65. m_outlineAction->setChecked(true);
  66. connect(m_outlineAction, SIGNAL(toggled(bool)), m_view, SLOT(setViewOutline(bool)));
  67. menuBar()->addMenu(viewMenu);
  68. //render menu
  69. QMenu *rendererMenu = new QMenu(tr("&Renderer"), this);
  70. m_nativeAction = rendererMenu->addAction(tr("&Native"));
  71. m_nativeAction->setCheckable(true);
  72. m_nativeAction->setChecked(true);
  73. #ifndef QT_NO_OPENGL
  74. m_glAction = rendererMenu->addAction(tr("Open&GL"));
  75. m_glAction->setCheckable(true);
  76. #endif
  77. m_imageAction = rendererMenu->addAction(tr("&Image"));
  78. m_imageAction->setCheckable(true);
  79. #ifndef QT_NO_OPENGL
  80. rendererMenu->addSeparator();
  81. m_highQualityAntialiasingAction = rendererMenu->addAction(tr("&High Quality Antialiasing"));
  82. m_highQualityAntialiasingAction->setEnabled(false);
  83. m_highQualityAntialiasingAction->setCheckable(true);
  84. m_highQualityAntialiasingAction->setChecked(false);
  85. connect(m_highQualityAntialiasingAction, SIGNAL(toggled(bool)), m_view, SLOT(setHighQualityAntialiasing(bool)));
  86. #endif
  87. QActionGroup *rendererGroup = new QActionGroup(this);
  88. rendererGroup->addAction(m_nativeAction);
  89. #ifndef QT_NO_OPENGL
  90. rendererGroup->addAction(m_glAction);
  91. #endif
  92. rendererGroup->addAction(m_imageAction);
  93. menuBar()->addMenu(rendererMenu);
  94. connect(openAction, SIGNAL(triggered()), this, SLOT(openexampleFile()));
  95. connect(opentestfileAction, SIGNAL(triggered()), this, SLOT(opentestFile()));
  96. connect(openfileDialogAction, SIGNAL(triggered()), this, SLOT(openfile_Dialog()));
  97. connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
  98. connect(rendererGroup, SIGNAL(triggered(QAction*)),
  99. this, SLOT(setRenderer(QAction*)));
  100. this->setMouseTracking (true);
  101. setCentralWidget(m_view);
  102. setWindowTitle(tr("SVG Viewer"));
  103. selectsettingwindow *truc=new selectsettingwindow();
  104. //truc->show();
  105. addDockWidget(Qt::RightDockWidgetArea,truc->r_dock);
  106. addDockWidget(Qt::LeftDockWidgetArea,truc->l_dock);
  107. QDockWidget *trac=new QDockWidget();
  108. trac->setWidget(truc->get_centralwidget());
  109. addDockWidget(Qt::BottomDockWidgetArea,trac);
  110. }
  111. //load a default file containing all colors/parameters for create the first machine's settings
  112. //default file should contains at least 16 grayscale rects, to be rasterised,
  113. //and 16 rgb rects to be cutted.
  114. void MainWindow::openexampleFile(const QString &path)
  115. {
  116. QString fileName;
  117. if (path.isNull())
  118. {fileName=":/files/matricereglagelaser.svg";
  119. /* fileName = QFileDialog::getOpenFileName(this, tr("Open SVG File"),
  120. m_currentPath, "SVG files (*.svg *.svgz *.svg.gz)");*/}
  121. else
  122. fileName = path;
  123. if (!fileName.isEmpty()) {
  124. QFile file(fileName);
  125. if (!file.exists()) {
  126. QMessageBox::critical(this, tr("Open SVG File"),
  127. QString("Could not open file '%1'.").arg(fileName));
  128. m_outlineAction->setEnabled(false);
  129. m_backgroundAction->setEnabled(false);
  130. return;
  131. }
  132. m_view->openFile(file);
  133. if (!fileName.startsWith(":/")) {
  134. m_currentPath = fileName;
  135. setWindowTitle(tr("%1 - SVGViewer").arg(m_currentPath));
  136. }
  137. m_outlineAction->setEnabled(true);
  138. m_backgroundAction->setEnabled(true);
  139. //resize(m_view->sizeHint() + QSize(80, 80 + menuBar()->height()));
  140. }
  141. }
  142. //load a svg file full of path, to test its rendering
  143. // (for now: fails cause svg path are not entirely implemented)
  144. //but thats what why its made for.
  145. void MainWindow::opentestFile(const QString &path)
  146. {
  147. QString fileName;
  148. if (path.isNull())
  149. {
  150. // fileName="/home/tuxun/Bureau/cheshire-catvinyle1.svg";
  151. fileName=":/files/cheshire-cat.svg";
  152. //fileName="/home/tuxun/Bureau/carre.svg";
  153. /* fileName = QFileDialog::getOpenFileName(this, tr("Open SVG File"),
  154. m_currentPath, "SVG files (*.svg *.svgz *.svg.gz)");*/}
  155. else
  156. fileName = path;
  157. if (!fileName.isEmpty()) {
  158. QFile file(fileName);
  159. if (!file.exists()) {
  160. QMessageBox::critical(this, tr("Open SVG File"),
  161. QString("Could not open file '%1'.").arg(fileName));
  162. m_outlineAction->setEnabled(false);
  163. m_backgroundAction->setEnabled(false);
  164. return;
  165. }
  166. m_view->openFile(file);
  167. if (!fileName.startsWith(":/")) {
  168. m_currentPath = fileName;
  169. setWindowTitle(tr("%1 - SVGViewer").arg(m_currentPath));
  170. }
  171. m_outlineAction->setEnabled(true);
  172. m_backgroundAction->setEnabled(true);
  173. //resize(m_view->sizeHint() + QSize(80, 80 + menuBar()->height()));
  174. }
  175. }
  176. //load a svg file full of path, to test its rendering
  177. // (for now: fails cause svg path are not entirely implemented)
  178. //but thats what why its made for.
  179. void MainWindow::openfile_Dialog(QString fileName)
  180. {
  181. // QMessageBox::critical(this, tr("Open SVG File"),QString("Could not open file '%1'.").arg(fileName));
  182. //QString fileName;
  183. if (fileName.isEmpty()) {
  184. fileName = QFileDialog::getOpenFileName(this, tr("Open SVG File"),
  185. m_currentPath, "SVG files (*.svg *.svgz *.svg.gz)");
  186. }
  187. if (!fileName.isEmpty()) {
  188. QFile file(fileName);
  189. if (!file.exists()) {
  190. QMessageBox::critical(this, tr("Open SVG File"),
  191. QString("Could not open file '%1'.").arg(fileName));
  192. return;
  193. }
  194. m_view->openFile(file);
  195. if (!fileName.startsWith(":/")) {
  196. m_currentPath = fileName;
  197. setWindowTitle(tr("%1 - SVGViewer").arg(m_currentPath));
  198. }
  199. m_outlineAction->setEnabled(true);
  200. m_backgroundAction->setEnabled(true);
  201. //resize(m_view->sizeHint() + QSize(80, 80 + menuBar()->height()));
  202. }
  203. }
  204. void MainWindow::setRenderer(QAction *action)
  205. {
  206. #ifndef QT_NO_OPENGL
  207. m_highQualityAntialiasingAction->setEnabled(false);
  208. #endif
  209. if (action == m_nativeAction)
  210. m_view->setRenderer(SvgView::Native);
  211. #ifndef QT_NO_OPENGL
  212. else if (action == m_glAction) {
  213. m_highQualityAntialiasingAction->setEnabled(true);
  214. m_view->setRenderer(SvgView::OpenGL);
  215. }
  216. #endif
  217. else if (action == m_imageAction) {
  218. m_view->setRenderer(SvgView::Image);
  219. }
  220. }