2 * Definitions for Qt4 based control panel
5 #include "controlpanel.h"
7 #ifndef CONTROLPANEL_DISABLED
21 ControlPanel::ControlPanel(RunArgs & args, QWidget * p) : QMainWindow(p),
22 m_view(args.view), m_doc(args.doc), m_screen(args.screen), m_width(300), m_height(300),
23 m_state(ControlPanel::ABOUT), m_on_ok(NULL)
26 resize(m_width,m_height);
40 void ControlPanel::CreateLayout()
42 m_text_edit = new QTextEdit(this);
43 m_text_edit->setGeometry(10,35,m_width-20,m_height-100);
45 m_ok_button = new QPushButton("OK", this);
46 m_ok_button->setGeometry(10,35+m_height-90, m_width-20, 50);
47 connect(m_ok_button, SIGNAL(clicked()), this, SLOT(PressOK()));
50 QMenu * ControlPanel::CreateMainMenu()
52 QMenu * main = menuBar()->addMenu("&Main");
54 QAction * about = new QAction("&About", this);
55 main->addAction(about);
56 connect(about, SIGNAL(triggered()), this, SLOT(StateAbout()));
60 QAction * quit = new QAction("&Quit", this);
61 main->addAction(quit);
62 connect(quit, SIGNAL(triggered()), qApp, SLOT(quit()));
66 QMenu * ControlPanel::CreateDocumentMenu()
68 QMenu * document = menuBar()->addMenu("&Document");
70 m_document_set_font = new QAction("&Set Insertion Font", this);
71 document->addAction(m_document_set_font);
72 connect(m_document_set_font, SIGNAL(triggered()), this, SLOT(SetDocumentFont()));
74 m_document_insert_text = new QAction("&Insert Text", this);
75 document->addAction(m_document_insert_text);
76 connect(m_document_insert_text, SIGNAL(triggered()), this, SLOT(StateInsertText()));
78 m_document_load_svg = new QAction("&Load SVG From File", this);
79 document->addAction(m_document_load_svg);
80 connect(m_document_load_svg, SIGNAL(triggered()), this, SLOT(LoadSVGIntoDocument()));
82 m_document_parse_svg = new QAction("&Input SVG Manually", this);
83 document->addAction(m_document_parse_svg);
84 connect(m_document_parse_svg, SIGNAL(triggered()), this, SLOT(StateParseSVG()));
90 QMenu * ControlPanel::CreateViewMenu()
92 QMenu * view = menuBar()->addMenu("&View");
94 m_view_set_bounds = new QAction("&Set bounds", this);
95 view->addAction(m_view_set_bounds);
96 connect(m_view_set_bounds, SIGNAL(triggered()), this, SLOT(SetViewBounds()));
98 m_view_show_object_bounds = new QAction("&Show Object Bounds", this);
99 m_view_show_object_bounds->setCheckable(true);
100 view->addAction(m_view_show_object_bounds);
101 connect(m_view_show_object_bounds, SIGNAL(triggered()), this, SLOT(ToggleShowObjectBounds()));
103 m_view_enable_shading = new QAction("&Enable Shading", this);
104 m_view_enable_shading->setCheckable(true);
105 view->addAction(m_view_enable_shading);
106 connect(m_view_enable_shading, SIGNAL(triggered()), this, SLOT(ToggleEnableShading()));
113 QMenu * ControlPanel::CreateScreenMenu()
115 QMenu * screen = menuBar()->addMenu("&Screen");
117 m_screen_gpu_rendering = new QAction("&GPU Rendering", this);
118 m_screen_gpu_rendering->setCheckable(true);
119 m_screen_gpu_rendering->setToolTip("Uses the GPU for Rendering");
121 m_screen_cpu_rendering = new QAction("&CPU Rendering", this);
122 m_screen_cpu_rendering->setCheckable(true);
123 m_screen_gpu_rendering->setToolTip("Uses the CPU for Rendering");
125 screen->addAction(m_screen_gpu_rendering);
126 screen->addAction(m_screen_cpu_rendering);
128 connect(m_screen_gpu_rendering, SIGNAL(triggered()), this, SLOT(SetGPURendering()));
129 connect(m_screen_cpu_rendering, SIGNAL(triggered()), this, SLOT(SetCPURendering()));
131 m_screen_show_debug = new QAction("&Print Debug Info", this);
132 m_screen_show_debug->setCheckable(true);
134 screen->addAction(m_screen_show_debug);
135 connect(m_screen_show_debug, SIGNAL(triggered()), this, SLOT(ToggleScreenDebugFont()));
140 void ControlPanel::paintEvent(QPaintEvent * e)
146 void ControlPanel::ChangeState(State next_state)
148 m_state = next_state;
153 void ControlPanel::UpdateAll()
155 bool using_gpu_rendering = m_view.UsingGPURendering();
156 m_screen_gpu_rendering->setChecked(using_gpu_rendering);
157 m_screen_cpu_rendering->setChecked(!using_gpu_rendering);
158 m_screen_show_debug->setChecked(m_screen.DebugFontShown());
160 m_view_show_object_bounds->setChecked(m_view.ShowingObjectBounds());
161 m_view_enable_shading->setChecked(m_view.PerformingShading());
163 // update things based on state
165 const char * tooltip;
169 title = "Insert Text";
170 tooltip = "Type text to insert, press OK, simple.";
173 m_on_ok = &ControlPanel::InsertTextIntoDocument;
174 if (m_text_edit->toPlainText() == "")
175 m_text_edit->setText("The quick brown\nfox jumps over\nthe lazy dog.");
179 tooltip = "Enter valid SVG and press OK to insert.";
182 m_on_ok = &ControlPanel::InsertSVGIntoDocument;
183 if (m_text_edit->toPlainText() == "")
184 m_text_edit->setText("<svg width=\"104\" height=\"186\">\n<path d = \"m 57,185\n\t c 0,0 57,-13 32,-43\n\t -25,-30 -53,2 -25, -30\n\t 28,-32 52,17 28,-32\n\t -24,-50 -16,44 -35,12\n\t-19,-32 13,-64 13,-64\n\t 0,0 40,-50 -0,-14\n\t -40,36 -94,68 -59,109\n\t 35,41 45,62 45,62 z\"/>\n</svg>");
189 title = "IPDF Control Panel";
190 tooltip = "This is the IPDF Control Panel\nDo you feel in control?";
198 setWindowTitle(title);
203 void ControlPanel::ToggleShowObjectBounds()
205 bool state = m_view.ShowingObjectBounds();
206 m_view.ShowObjectBounds(!state);
210 void ControlPanel::ToggleEnableShading()
212 bool state = m_view.PerformingShading();
213 m_view.PerformShading(!state);
217 void ControlPanel::SetGPURendering()
219 m_view.SetGPURendering(true);
223 void ControlPanel::SetCPURendering()
225 m_view.SetGPURendering(false);
229 void ControlPanel::ToggleScreenDebugFont()
231 bool state = m_screen.DebugFontShown();
232 m_screen.ShowDebugFont(!state);
237 void ControlPanel::SetViewBounds()
240 Real xx = QInputDialog::getDouble(this, "View X Coordinate", "Enter X coordinate:", 0, -2e-30, 2e30,30,&ok);
242 Real yy = QInputDialog::getDouble(this, "View Y Coordinate", "Enter Y coordinate:", 0, -2e-30, 2e30,30,&ok);
244 Real w = QInputDialog::getDouble(this, "View Width", "Enter Width:", 1, -2e-30, 2e30,30,&ok);
246 Real h = QInputDialog::getDouble(this, "View Height", "Enter Height:", 1, -2e-30, 2e30,30,&ok);
247 m_view.SetBounds(Rect(xx,yy,w,h));
251 void ControlPanel::InsertTextIntoDocument()
253 const Rect & bounds = m_view.GetBounds();
255 Real yy = bounds.y + bounds.h/Real(2);
257 string msg = m_text_edit->toPlainText().toStdString();
258 Real scale = bounds.h / Real(2);
259 Debug("Insert \"%s\" at %f, %f, scale %f", msg.c_str(), Float(xx), Float(yy), Float(scale));
260 m_doc.AddText(msg, scale, xx, yy);
261 m_view.ForceRenderDirty();
262 m_view.ForceBufferDirty();
263 m_view.ForceBoundsDirty();
265 void ControlPanel::InsertSVGIntoDocument()
267 Rect bounds(m_view.GetBounds());
268 bounds.w /= Real(m_screen.ViewportWidth());
269 bounds.h /= Real(m_screen.ViewportHeight());
271 m_doc.ParseSVG(m_text_edit->toPlainText().toStdString(), bounds);
272 m_view.ForceRenderDirty();
273 m_view.ForceBufferDirty();
274 m_view.ForceBoundsDirty();
277 void ControlPanel::LoadSVGIntoDocument()
280 QString filename = QFileDialog::getOpenFileName(this, "Open SVG", "svg-tests", "Image Files (*.svg)");
284 Rect bounds(m_view.GetBounds());
285 bounds.w /= Real(m_screen.ViewportWidth());
286 bounds.h /= Real(m_screen.ViewportHeight());
288 m_doc.LoadSVG(filename.toStdString(), bounds);
289 m_view.ForceRenderDirty();
290 m_view.ForceBufferDirty();
291 m_view.ForceBoundsDirty();
294 void ControlPanel::SetDocumentFont()
296 QString filename = QFileDialog::getOpenFileName(this, "Set Font", "fonts", "True Type Fonts (*.ttf)");
298 m_doc.SetFont(filename.toStdString());
301 ControlPanel * ControlPanel::g_panel = NULL;
303 int ControlPanel::Run(void * args)
305 ControlPanel::RunArgs * a = (ControlPanel::RunArgs*)args;
306 QApplication app(a->argc, a->argv);
307 g_panel = new ControlPanel(*a);
309 int result = app.exec();
310 a->screen.RequestQuit();
318 #endif //CONTROLPANEL_ENABLED