*/
#include "controlpanel.h"
+
+#ifndef CONTROLPANEL_DISABLED
+
#include "view.h"
#include "screen.h"
#include "document.h"
+#include <string>
+#include <algorithm>
-#ifndef CONTROLPANEL_DISABLED
+using namespace std;
namespace IPDF
{
ControlPanel::ControlPanel(RunArgs & args, QWidget * p) : QMainWindow(p),
- m_view(args.view), m_doc(args.doc), m_screen(args.screen)
+ m_view(args.view), m_doc(args.doc), m_screen(args.screen), m_width(300), m_height(300),
+ m_state(ControlPanel::ABOUT), m_on_ok(NULL)
{
// Size
- resize(300,300);
- // Title
- setWindowTitle("IPDF Control Panel");
- // Tooltip
- setToolTip("This is the IPDF Control Panel.\nDo you feel in control?");
+ resize(m_width,m_height);
+
// Main menues
CreateMainMenu();
CreateDocumentMenu();
CreateScreenMenu();
+ CreateLayout();
+
UpdateAll();
+}
+void ControlPanel::CreateLayout()
+{
+ m_text_edit = new QTextEdit(this);
+ m_text_edit->setGeometry(10,35,m_width-20,m_height-100);
+
+ m_ok_button = new QPushButton("OK", this);
+ m_ok_button->setGeometry(10,35+m_height-90, m_width-20, 50);
+ connect(m_ok_button, SIGNAL(clicked()), this, SLOT(PressOK()));
}
QMenu * ControlPanel::CreateMainMenu()
{
QMenu * main = menuBar()->addMenu("&Main");
+ QAction * about = new QAction("&About", this);
+ main->addAction(about);
+ connect(about, SIGNAL(triggered()), this, SLOT(StateAbout()));
+
+
// Quit entry
QAction * quit = new QAction("&Quit", this);
main->addAction(quit);
QMenu * ControlPanel::CreateDocumentMenu()
{
QMenu * document = menuBar()->addMenu("&Document");
+
+ m_document_set_font = new QAction("&Set Insertion Font", this);
+ document->addAction(m_document_set_font);
+ connect(m_document_set_font, SIGNAL(triggered()), this, SLOT(SetDocumentFont()));
+
+ m_document_insert_text = new QAction("&Insert Text", this);
+ document->addAction(m_document_insert_text);
+ connect(m_document_insert_text, SIGNAL(triggered()), this, SLOT(StateInsertText()));
+
+ m_document_load_svg = new QAction("&Load SVG From File", this);
+ document->addAction(m_document_load_svg);
+ connect(m_document_load_svg, SIGNAL(triggered()), this, SLOT(LoadSVGIntoDocument()));
+
+ m_document_parse_svg = new QAction("&Input SVG Manually", this);
+ document->addAction(m_document_parse_svg);
+ connect(m_document_parse_svg, SIGNAL(triggered()), this, SLOT(StateParseSVG()));
+
+
return document;
}
{
QMenu * view = menuBar()->addMenu("&View");
-
+ m_view_set_bounds = new QAction("&Set bounds", this);
+ view->addAction(m_view_set_bounds);
+ connect(m_view_set_bounds, SIGNAL(triggered()), this, SLOT(SetViewBounds()));
return view;
}
m_screen_gpu_rendering = new QAction("&GPU Rendering", this);
m_screen_gpu_rendering->setCheckable(true);
+ m_screen_gpu_rendering->setToolTip("Uses the GPU for Rendering");
m_screen_cpu_rendering = new QAction("&CPU Rendering", this);
m_screen_cpu_rendering->setCheckable(true);
+ m_screen_gpu_rendering->setToolTip("Uses the CPU for Rendering");
screen->addAction(m_screen_gpu_rendering);
screen->addAction(m_screen_cpu_rendering);
connect(m_screen_gpu_rendering, SIGNAL(triggered()), this, SLOT(SetGPURendering()));
connect(m_screen_cpu_rendering, SIGNAL(triggered()), this, SLOT(SetCPURendering()));
+ m_screen_show_debug = new QAction("&Print Debug Info", this);
+ m_screen_show_debug->setCheckable(true);
+
+ screen->addAction(m_screen_show_debug);
+ connect(m_screen_show_debug, SIGNAL(triggered()), this, SLOT(ToggleScreenDebugFont()));
+
return screen;
}
+void ControlPanel::paintEvent(QPaintEvent * e)
+{
+// Debug("Called");
+
+}
+
+void ControlPanel::ChangeState(State next_state)
+{
+ m_state = next_state;
+ UpdateAll();
+}
+
+
void ControlPanel::UpdateAll()
{
bool using_gpu_rendering = m_view.UsingGPURendering();
m_screen_gpu_rendering->setChecked(using_gpu_rendering);
m_screen_cpu_rendering->setChecked(!using_gpu_rendering);
+ m_screen_show_debug->setChecked(m_screen.DebugFontShown());
+
+ // update things based on state
+ const char * title;
+ const char * tooltip;
+ switch (m_state)
+ {
+ case INSERT_TEXT:
+ title = "Insert Text";
+ tooltip = "Type text to insert, press OK, simple.";
+ m_text_edit->show();
+ m_ok_button->show();
+ m_on_ok = &ControlPanel::InsertTextIntoDocument;
+ if (m_text_edit->toPlainText() == "")
+ m_text_edit->setText("The quick brown\nfox jumps over\nthe lazy dog.");
+ break;
+ case PARSE_SVG:
+ title = "Parse SVG";
+ tooltip = "Enter valid SVG and press OK to insert.";
+ m_text_edit->show();
+ m_ok_button->show();
+ m_on_ok = &ControlPanel::InsertSVGIntoDocument;
+ if (m_text_edit->toPlainText() == "")
+ 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>");
+
+ break;
+ case ABOUT:
+ default:
+ title = "IPDF Control Panel";
+ tooltip = "This is the IPDF Control Panel\nDo you feel in control?";
+ m_text_edit->hide();
+ m_ok_button->hide();
+ m_on_ok = NULL;
+ break;
+ }
+
+ // Title
+ setWindowTitle(title);
+ // Tooltip
+ setToolTip(tooltip);
}
void ControlPanel::SetGPURendering()
UpdateAll();
}
+void ControlPanel::ToggleScreenDebugFont()
+{
+ bool state = m_screen.DebugFontShown();
+ m_screen.ShowDebugFont(!state);
+ UpdateAll();
+
+}
+
+void ControlPanel::SetViewBounds()
+{
+ bool ok;
+ Real xx = QInputDialog::getDouble(this, "View X Coordinate", "Enter X coordinate:", 0, -2e-30, 2e30,30,&ok);
+
+ Real yy = QInputDialog::getDouble(this, "View Y Coordinate", "Enter Y coordinate:", 0, -2e-30, 2e30,30,&ok);
+
+ Real w = QInputDialog::getDouble(this, "View Width", "Enter Width:", 1, -2e-30, 2e30,30,&ok);
+
+ Real h = QInputDialog::getDouble(this, "View Height", "Enter Height:", 1, -2e-30, 2e30,30,&ok);
+ m_view.SetBounds(Rect(xx,yy,w,h));
+
+}
+
+void ControlPanel::InsertTextIntoDocument()
+{
+ const Rect & bounds = m_view.GetBounds();
+ Real xx = bounds.x + bounds.w/Real(2);
+ Real yy = bounds.y + bounds.h/Real(2);
+
+ string msg = m_text_edit->toPlainText().toStdString();
+ Real scale = bounds.w / Real(2);
+ Debug("Insert \"%s\" at %f, %f, scale %f", msg.c_str(), Float(xx), Float(yy), Float(scale));
+ //m_doc.Add(RECT_OUTLINE, bounds, 0); // debugging; text needs to go in the boujnds
+ m_doc.AddText(msg, xx, yy, scale);
+ m_view.ForceRenderDirty();
+ m_view.ForceBufferDirty();
+ m_view.ForceBoundsDirty();
+}
+void ControlPanel::InsertSVGIntoDocument()
+{
+ Rect bounds(m_view.GetBounds());
+ bounds.w /= Real(m_screen.ViewportWidth());
+ bounds.h /= Real(m_screen.ViewportHeight());
+
+ m_doc.ParseSVG(m_text_edit->toPlainText().toStdString(), bounds);
+ m_view.ForceRenderDirty();
+ m_view.ForceBufferDirty();
+ m_view.ForceBoundsDirty();
+}
+
+void ControlPanel::LoadSVGIntoDocument()
+{
+
+ QString filename = QFileDialog::getOpenFileName(this, "Open SVG", "svg-tests", "Image Files (*.svg)");
+ if (filename == "")
+ return;
+
+ Rect bounds(m_view.GetBounds());
+ bounds.w /= Real(m_screen.ViewportWidth());
+ bounds.h /= Real(m_screen.ViewportHeight());
+
+ m_doc.LoadSVG(filename.toStdString(), bounds);
+ m_view.ForceRenderDirty();
+ m_view.ForceBufferDirty();
+ m_view.ForceBoundsDirty();
+}
+
+void ControlPanel::SetDocumentFont()
+{
+ QString filename = QFileDialog::getOpenFileName(this, "Set Font", "fonts", "True Type Fonts (*.ttf)");
+ if (filename != "")
+ m_doc.SetFont(filename.toStdString());
+}
+
ControlPanel * ControlPanel::g_panel = NULL;
int ControlPanel::Run(void * args)