1 // Copyright (c) 2008  GeometryFactory Sarl (France).
2 // All rights reserved.
3 //
4 // This file is part of CGAL (www.cgal.org).
5 //
6 // $URL: https://github.com/CGAL/cgal/blob/v5.3/GraphicsView/include/CGAL/Qt/DemosMainWindow.h $
7 // $Id: DemosMainWindow.h b80daff 2021-02-19T11:29:38+01:00 Maxime Gimeno
8 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial
9 //
10 //
11 // Author(s)     : Andreas Fabri <Andreas.Fabri@geometryfactory.com>
12 //                 Laurent Rineau <Laurent.Rineau@geometryfactory.com>
13 
14 #ifndef CGAL_QT_DEMOS_MAIN_WINDOW_H
15 #define CGAL_QT_DEMOS_MAIN_WINDOW_H
16 
17 #include <CGAL/license/GraphicsView.h>
18 
19 
20 #include <iostream>
21 #include <QVector>
22 #include <QMainWindow>
23 #include <QDragEnterEvent>
24 #include <QDropEvent>
25 
26 #include <CGAL/auto_link/Qt.h>
27 #include <CGAL/export/Qt.h>
28 #include <CGAL/Qt/resources.h>
29 #include <QSettings>
30 
31 // forward declaration
32 class QLabel;
33 class QGraphicsView;
34 class QAction;
35 class QMenu;
36 
37 namespace CGAL {
38 namespace Qt {
39 
40 // forward declaration
41 class GraphicsViewNavigation;
42 
43 class CGAL_QT_EXPORT DemosMainWindow : public QMainWindow
44 {
45   Q_OBJECT
46 
47 public:
48   enum Option { NoOption = 0x0,
49                 Size     = 0x1,
50                 Position = 0x2,
51                 State    = 0x4};
52 
53   Q_DECLARE_FLAGS(Options, Option)
54 
55   virtual void dragEnterEvent(QDragEnterEvent *event);
56   virtual void dropEvent(QDropEvent *event);
57 
open(QString)58   virtual void open(QString)
59   {
60     std::cerr << "You should implement open(QString);" << std::endl;
61   }
62 
63 public:
64   unsigned int maxNumberOfRecentFiles() const ;
65 
66 public Q_SLOTS:
67   void setMaxNumberOfRecentFiles(const unsigned int);
68 
69 private:
70   QMenu* getMenu(QString objectName, QString title);
71   void popupAboutBox(QString title, QString html_resource_name);
72   QMenu* getHelpMenu();
73 
74 protected:
75   DemosMainWindow (QWidget * parent = nullptr, ::Qt::WindowFlags flags = ::Qt::WindowType(0) );
76   ~DemosMainWindow();
77   void setupStatusBar();
78   void addNavigation(QGraphicsView*);
79   void setupOptionsMenu(QMenu* menu  = nullptr);
80   void addAboutCGAL(QMenu* menu  = nullptr);
81   void addAboutDemo(QString htmlResourceName, QMenu* menu  = nullptr);
82   void setupExportSVG(QAction*, QGraphicsView*);
83 
84   void addRecentFiles(QMenu* menu, QAction* insertBefore = nullptr);
85 
86   void writeState(QString groupname = "MainWindow");
87   void readState(QString groupname = "MainWindow",
88                  Options what_to_save = Options(Size|State));
89 
90 protected Q_SLOTS:
91   void setUseAntialiasing(bool checked);
92   void setUseOpenGL(bool checked);
93   void popupAboutCGAL();
94   void popupAboutDemo();
95 
96   void exportSVG();
97 
98   void openRecentFile_aux();
99   void addToRecentFiles(QString fileName);
100   void updateRecentFileActions();
101 
102 Q_SIGNALS:
103   void openRecentFile(QString filename);
104 
105 protected:
106   QGraphicsView* view;
107   GraphicsViewNavigation* navigation;
108   QLabel* xycoord ;
109 
110   QAction *actionUse_OpenGL;
111   QAction *actionUse_Antialiasing;
112   QAction *actionAbout;
113   QAction *actionAboutCGAL;
114 
115   QString aboutHtmlResource;
116 
117   QAction* recentFilesSeparator;
118   unsigned int maxNumRecentFiles;
119   QVector<QAction*> recentFileActs;
120   QSettings settings;
121 }; // end class DemosMainWindow
122 
123 } // namespace Qt
124 } // namespace CGAL
125 
126 Q_DECLARE_OPERATORS_FOR_FLAGS(CGAL::Qt::DemosMainWindow::Options)
127 
128 #ifdef CGAL_HEADER_ONLY
129 #include <CGAL/Qt/DemosMainWindow_impl.h>
130 #endif // CGAL_HEADER_ONLY
131 
132 #endif // CGAL_QT_DEMOS_MAIN_WINDOW_H
133 
134