Go nuts with Qt
[ipdf/code.git] / src / controlpanel.h
1 /**
2  * Declarations for Qt4 based control panel
3  */
4 #ifndef _CONTROLPANEL_H
5 #define _CONTROLPANEL_H
6
7 //#define CONTROLPANEL_DISABLED // To turn off the control panel
8
9 #ifndef CONTROLPANEL_DISABLED
10
11
12 #include <QPushButton>
13 #include <QMainWindow>
14 #include <QWidget>
15 #include <QAction>
16 #include <QMenu>
17 #include <QMenuBar>
18 #include <QApplication>
19 #include <QTextEdit>
20 #include <QInputDialog>
21 #include <QFileDialog>
22
23
24 namespace IPDF
25 {
26         class View;
27         class Document;
28         class Screen;
29
30         /**
31          * Class to manage Qt control panel
32          * Should be a singleton from the point of view of View, Document, Screen
33          *  - Just call "Update"
34          */
35         class ControlPanel : public QMainWindow
36         {       
37                 Q_OBJECT // Having this causes shit about undefined vtables
38                                 // Not having it means things break
39                                 // Apparently you need "qmake" to build qt applications
40                                 // Or some bullshit -_-
41                 public:
42                         struct RunArgs
43                         {
44                                 int argc;
45                                 char ** argv;
46                                 View & view;
47                                 Document & doc;
48                                 Screen & screen;
49                         };
50                         
51                         static int Run(void * args);
52                         static void Update() {if (g_panel != NULL) g_panel->UpdateAll();}                       
53         
54                 private:
55                         typedef enum {
56                                 ABOUT,
57                                 INSERT_TEXT,
58                                 PARSE_SVG
59                         } State;
60                         
61                 private slots:
62                         void SetGPURendering();
63                         void SetCPURendering();
64                         void ToggleScreenDebugFont();
65                         void SetViewBounds();
66                         void LoadSVGIntoDocument();
67                         void SetDocumentFont();
68                         void StateInsertText() {ChangeState(INSERT_TEXT);}
69                         void StateAbout() {ChangeState(ABOUT);}
70                         void StateParseSVG() {ChangeState(PARSE_SVG);}
71                         void PressOK() {if (m_on_ok != NULL) (this->*m_on_ok)();}
72
73                 private:
74                         static ControlPanel * g_panel;
75                         void paintEvent(QPaintEvent * e);
76                         ControlPanel(RunArgs & a, QWidget * p = NULL);
77                         virtual ~ControlPanel() {}
78                         void UpdateAll();
79                         void ChangeState(State next_state);
80                         View & m_view;
81                         Document & m_doc;
82                         Screen & m_screen;
83                         
84                         int m_width;
85                         int m_height;
86                         
87                         
88                         State m_state;
89                         
90                         QMenu * CreateMainMenu();
91                         QMenu * CreateViewMenu();
92                         QMenu * CreateDocumentMenu();
93                         QMenu * CreateScreenMenu();
94                         void CreateLayout();
95                         
96                         void InsertTextIntoDocument();
97                         void InsertSVGIntoDocument();
98                         
99                         QAction * m_screen_gpu_rendering;
100                         QAction * m_screen_cpu_rendering;
101                         QAction * m_screen_show_debug;
102                         
103                         QAction * m_document_set_font;
104                         QAction * m_document_insert_text;
105                         QAction * m_document_parse_svg;
106                         QAction * m_document_load_svg;
107                         QAction * m_view_set_bounds;
108                         
109                 
110                         QTextEdit * m_text_edit;
111                         QPushButton * m_ok_button;
112                         
113                         void (ControlPanel::* m_on_ok)();
114
115
116         };
117
118 }
119
120 #endif //CONTROLPANEL_DISABLED
121
122 #endif //_CONTROLPANEL_H

UCC git Repository :: git.ucc.asn.au