summaryrefslogtreecommitdiff
path: root/client/docgen/genimage.cc
diff options
context:
space:
mode:
Diffstat (limited to 'client/docgen/genimage.cc')
-rw-r--r--client/docgen/genimage.cc163
1 files changed, 163 insertions, 0 deletions
diff --git a/client/docgen/genimage.cc b/client/docgen/genimage.cc
new file mode 100644
index 0000000..332887c
--- /dev/null
+++ b/client/docgen/genimage.cc
@@ -0,0 +1,163 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set et sw=2 ts=2: */
+/***************************************************************************
+ * genimage.cc
+ *
+ * Wed Mar 16 11:56:22 CET 2011
+ * Copyright 2011 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of Pracro.
+ *
+ * Pracro is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Pracro is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Pracro; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "genimage.h"
+
+#include <QImage>
+#include <QPixmap>
+
+#include <QDir>
+#include <QDomDocument>
+
+#include <viewer.h>
+#include <widgets.h>
+
+QString cpr;
+QString user;
+QFont fixedfont;
+
+Viewer *viewer = NULL;
+
+extern QString output;
+
+void genImage(QString widget)
+{
+ QDomDocument node;
+
+ QDomElement elem = node.createElement(widget);
+ elem.setAttribute("name", widget);
+ elem.setAttribute("caption", "Caption");
+ elem.setAttribute("layout", "vbox");
+
+ if(widget == "lineedit" || widget == "textedit") {
+ elem.setAttribute("value", "Some text");
+ }
+
+ if(widget == "checkbox" || widget == "checkgroupbox") {
+ elem.setAttribute("truevalue", "true");
+ elem.setAttribute("falsevalue", "false");
+ elem.setAttribute("value", "true");
+ }
+
+ if(widget == "combobox" || widget == "listbox") {
+ {
+ QDomElement e = node.createElement("item");
+ e.setAttribute("caption", "List item 1");
+ e.setAttribute("value", "item1");
+ elem.appendChild(e);
+ }
+ {
+ QDomElement e = node.createElement("item");
+ e.setAttribute("caption", "List item 2");
+ e.setAttribute("value", "item2");
+ elem.appendChild(e);
+ }
+
+ {
+ QDomElement e = node.createElement("item");
+ e.setAttribute("caption", "List item 3");
+ e.setAttribute("value", "item3");
+ elem.appendChild(e);
+ }
+
+ elem.setAttribute("value", "item1");
+ }
+
+ if(widget == "altcombobox") {
+ QDomElement e = node.createElement("altitem");
+ e.setAttribute("caption", "Alt item");
+ e.setAttribute("value", "altitem");
+ e.setAttribute("innerwidget", "altitem");
+ elem.appendChild(e);
+
+ QDomElement a = node.createElement("lineedit");
+ a.setAttribute("name", "altitem");
+ a.setAttribute("value", "Some alt text");
+ e.appendChild(a);
+
+ elem.setAttribute("value", "altitem");
+ }
+
+ if(widget == "multilist") {
+ QDomElement a = node.createElement("lineedit");
+ a.setAttribute("name", "altitem");
+ a.setAttribute("value", "Value ready to be added");
+ elem.appendChild(a);
+ elem.setAttribute("value", "Some value\nAnother value");
+ }
+
+ if(widget == "frame" || widget == "checkgroupbox") {
+ QDomElement e = node.createElement("label");
+ e.setAttribute("caption", "Contained widgets.");
+ elem.appendChild(e);
+ }
+
+ if(widget == "radiobuttons") {
+ QDomElement e1 = node.createElement("radiobutton");
+ e1.setAttribute("caption", "Radio Button 1");
+ elem.appendChild(e1);
+
+ QDomElement e2 = node.createElement("radiobutton");
+ e2.setAttribute("caption", "Radio Button 2");
+ elem.appendChild(e2);
+ }
+
+ node.appendChild(elem);
+
+ Window w(node, NULL);
+ w.setValues();
+ w.qwidget()->show();
+ QPixmap pix = QPixmap::grabWidget(w.qwidget(), 0, 0);
+ QImage img = pix.toImage();
+ QRgb bg = img.pixel(img.width() - 1, img.height() - 1);
+
+ int cropvert = img.height();
+ int crophorz = img.width();
+ for(int y = img.height() - 1; y > 0; y--) {
+ for(int x = 0; x < img.width(); x++) {
+ if(img.pixel(x, y) != bg) {
+ cropvert = y;
+ y = -1; // break out of y for-loop
+ break;
+ }
+ }
+ }
+
+ for(int x = img.width() - 1; x > 0; x--) {
+ for(int y = 0; y < img.height(); y++) {
+ if(img.pixel(x, y) != bg) {
+ crophorz = x;
+ x = -1; // break out of x for-loop
+ break;
+ }
+ }
+ }
+
+ img = img.copy(0,0, crophorz + 12, cropvert + 12);
+ QDir d;d.mkdir(output + "/gfx/");
+ img.save(output + "/gfx/" + widget + ".png");
+}