Terrible hacky SolveCubic.
[ipdf/code.git] / src / controlpanel.cpp
1 /**
2  * Definitions for Qt4 based control panel
3  */
4
5 #include "controlpanel.h"
6 #include "view.h"
7 #include "screen.h"
8 #include "document.h"
9
10 #ifndef CONTROLPANEL_DISABLED
11
12 namespace IPDF
13 {
14         
15         
16 ControlPanel::ControlPanel(RunArgs & args, QWidget * p) : QMainWindow(p), 
17         m_view(args.view), m_doc(args.doc), m_screen(args.screen)
18 {
19         // Size
20         resize(300,300);
21         // Title
22         setWindowTitle("IPDF Control Panel");
23         // Tooltip
24         setToolTip("This is the IPDF Control Panel.\nDo you feel in control?");
25         
26         // Main menues
27         CreateMainMenu();
28         CreateViewMenu();
29         CreateDocumentMenu();
30         CreateScreenMenu();
31         
32         UpdateAll();
33
34 }
35
36 QMenu * ControlPanel::CreateMainMenu()
37 {
38         QMenu * main = menuBar()->addMenu("&Main");
39         
40         // Quit entry
41         QAction * quit = new QAction("&Quit", this);
42         main->addAction(quit);
43         connect(quit, SIGNAL(triggered()), qApp, SLOT(quit()));
44         return main;
45 }
46
47 QMenu * ControlPanel::CreateDocumentMenu()
48 {
49         QMenu * document = menuBar()->addMenu("&Document");
50         return document;
51 }
52
53 QMenu * ControlPanel::CreateViewMenu()
54 {
55         QMenu * view = menuBar()->addMenu("&View");
56         
57
58         
59         return view;
60 }
61
62
63
64 QMenu * ControlPanel::CreateScreenMenu()
65 {
66         QMenu * screen = menuBar()->addMenu("&Screen");
67         
68         m_screen_gpu_rendering = new QAction("&GPU Rendering", this);
69         m_screen_gpu_rendering->setCheckable(true);
70         
71         m_screen_cpu_rendering = new QAction("&CPU Rendering", this);
72         m_screen_cpu_rendering->setCheckable(true);
73                 
74         screen->addAction(m_screen_gpu_rendering);
75         screen->addAction(m_screen_cpu_rendering);
76         
77         connect(m_screen_gpu_rendering, SIGNAL(triggered()), this, SLOT(SetGPURendering()));
78         connect(m_screen_cpu_rendering, SIGNAL(triggered()), this, SLOT(SetCPURendering()));
79         
80         return screen;
81 }
82
83 void ControlPanel::UpdateAll()
84 {
85         bool using_gpu_rendering = m_view.UsingGPURendering();
86         m_screen_gpu_rendering->setChecked(using_gpu_rendering);
87         m_screen_cpu_rendering->setChecked(!using_gpu_rendering);       
88 }
89
90 void ControlPanel::SetGPURendering()
91 {
92         m_view.SetGPURendering(true);
93         UpdateAll();
94 }
95
96 void ControlPanel::SetCPURendering()
97 {
98         m_view.SetGPURendering(false);
99         UpdateAll();
100 }
101
102 ControlPanel * ControlPanel::g_panel = NULL;
103
104 int ControlPanel::Run(void * args)
105 {
106         ControlPanel::RunArgs * a = (ControlPanel::RunArgs*)args;
107         QApplication app(a->argc, a->argv);
108         g_panel = new ControlPanel(*a);
109         g_panel->show();
110         int result = app.exec();
111         a->screen.RequestQuit();
112         delete g_panel;
113         return result;
114 }
115         
116         
117 }
118
119 #endif //CONTROLPANEL_ENABLED
120

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