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()));
103 QMenu * ControlPanel::CreateScreenMenu()
105 QMenu * screen = menuBar()->addMenu("&Screen");
107 m_screen_gpu_rendering = new QAction("&GPU Rendering", this);
108 m_screen_gpu_rendering->setCheckable(true);
109 m_screen_gpu_rendering->setToolTip("Uses the GPU for Rendering");
111 m_screen_cpu_rendering = new QAction("&CPU Rendering", this);
112 m_screen_cpu_rendering->setCheckable(true);
113 m_screen_gpu_rendering->setToolTip("Uses the CPU for Rendering");
115 screen->addAction(m_screen_gpu_rendering);
116 screen->addAction(m_screen_cpu_rendering);
118 connect(m_screen_gpu_rendering, SIGNAL(triggered()), this, SLOT(SetGPURendering()));
119 connect(m_screen_cpu_rendering, SIGNAL(triggered()), this, SLOT(SetCPURendering()));
121 m_screen_show_debug = new QAction("&Print Debug Info", this);
122 m_screen_show_debug->setCheckable(true);
124 screen->addAction(m_screen_show_debug);
125 connect(m_screen_show_debug, SIGNAL(triggered()), this, SLOT(ToggleScreenDebugFont()));
130 void ControlPanel::paintEvent(QPaintEvent * e)
136 void ControlPanel::ChangeState(State next_state)
138 m_state = next_state;
143 void ControlPanel::UpdateAll()
145 bool using_gpu_rendering = m_view.UsingGPURendering();
146 m_screen_gpu_rendering->setChecked(using_gpu_rendering);
147 m_screen_cpu_rendering->setChecked(!using_gpu_rendering);
148 m_screen_show_debug->setChecked(m_screen.DebugFontShown());
150 // update things based on state
152 const char * tooltip;
156 title = "Insert Text";
157 tooltip = "Type text to insert, press OK, simple.";
160 m_on_ok = &ControlPanel::InsertTextIntoDocument;
161 if (m_text_edit->toPlainText() == "")
162 m_text_edit->setText("The quick brown\nfox jumps over\nthe lazy dog.");
166 tooltip = "Enter valid SVG and press OK to insert.";
169 m_on_ok = &ControlPanel::InsertSVGIntoDocument;
170 if (m_text_edit->toPlainText() == "")
171 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>");
176 title = "IPDF Control Panel";
177 tooltip = "This is the IPDF Control Panel\nDo you feel in control?";
185 setWindowTitle(title);
190 void ControlPanel::SetGPURendering()
192 m_view.SetGPURendering(true);
196 void ControlPanel::SetCPURendering()
198 m_view.SetGPURendering(false);
202 void ControlPanel::ToggleScreenDebugFont()
204 bool state = m_screen.DebugFontShown();
205 m_screen.ShowDebugFont(!state);
210 void ControlPanel::SetViewBounds()
213 Real xx = QInputDialog::getDouble(this, "View X Coordinate", "Enter X coordinate:", 0, -2e-30, 2e30,30,&ok);
215 Real yy = QInputDialog::getDouble(this, "View Y Coordinate", "Enter Y coordinate:", 0, -2e-30, 2e30,30,&ok);
217 Real w = QInputDialog::getDouble(this, "View Width", "Enter Width:", 1, -2e-30, 2e30,30,&ok);
219 Real h = QInputDialog::getDouble(this, "View Height", "Enter Height:", 1, -2e-30, 2e30,30,&ok);
220 m_view.SetBounds(Rect(xx,yy,w,h));
224 void ControlPanel::InsertTextIntoDocument()
226 const Rect & bounds = m_view.GetBounds();
228 Real yy = bounds.y + bounds.h/Real(2);
230 string msg = m_text_edit->toPlainText().toStdString();
231 Real scale = bounds.h / Real(2);
232 Debug("Insert \"%s\" at %f, %f, scale %f", msg.c_str(), Float(xx), Float(yy), Float(scale));
233 m_doc.AddText(msg, scale, xx, yy);
234 m_view.ForceRenderDirty();
235 m_view.ForceBufferDirty();
236 m_view.ForceBoundsDirty();
238 void ControlPanel::InsertSVGIntoDocument()
240 Rect bounds(m_view.GetBounds());
241 bounds.w /= Real(m_screen.ViewportWidth());
242 bounds.h /= Real(m_screen.ViewportHeight());
244 m_doc.ParseSVG(m_text_edit->toPlainText().toStdString(), bounds);
245 m_view.ForceRenderDirty();
246 m_view.ForceBufferDirty();
247 m_view.ForceBoundsDirty();
250 void ControlPanel::LoadSVGIntoDocument()
253 QString filename = QFileDialog::getOpenFileName(this, "Open SVG", "svg-tests", "Image Files (*.svg)");
257 Rect bounds(m_view.GetBounds());
258 bounds.w /= Real(m_screen.ViewportWidth());
259 bounds.h /= Real(m_screen.ViewportHeight());
261 m_doc.LoadSVG(filename.toStdString(), bounds);
262 m_view.ForceRenderDirty();
263 m_view.ForceBufferDirty();
264 m_view.ForceBoundsDirty();
267 void ControlPanel::SetDocumentFont()
269 QString filename = QFileDialog::getOpenFileName(this, "Set Font", "fonts", "True Type Fonts (*.ttf)");
271 m_doc.SetFont(filename.toStdString());
274 ControlPanel * ControlPanel::g_panel = NULL;
276 int ControlPanel::Run(void * args)
278 ControlPanel::RunArgs * a = (ControlPanel::RunArgs*)args;
279 QApplication app(a->argc, a->argv);
280 g_panel = new ControlPanel(*a);
282 int result = app.exec();
283 a->screen.RequestQuit();
291 #endif //CONTROLPANEL_ENABLED