summaryrefslogtreecommitdiff
path: root/client/docgen/genimage.cc
blob: f5985533ea5bc6a9082d21ff57a212eb8b864765 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/* -*- 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") {

    if(widget == "listbox") {
      QDomElement e = node.createElement("item");
      e.setAttribute("type", "header");
      e.setAttribute("caption", "Header 1");
      e.setAttribute("value", "Header 1");
      elem.appendChild(e);
    }

    {
      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);
    }

    if(widget == "listbox") {
      QDomElement e = node.createElement("item");
      e.setAttribute("type", "separator");
      e.setAttribute("caption", "sep 1");
      e.setAttribute("value", "sep 1");
      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");
}