kexidisplayutils.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2005-2006 Jaroslaw Staniek <js@iidea.pl>
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "kexidisplayutils.h"
21
22#include <tqpixmap.h>
23#include <tqpainter.h>
24#include <tqimage.h>
25#include <tqwidget.h>
26
27#include <tdelocale.h>
28#include <kstaticdeleter.h>
29
30// a color for displaying default values or autonumbers
31#define SPECIAL_TEXT_COLOR TQt::blue
32
33static KStaticDeleter<TQPixmap> KexiDisplayUtils_autonum_deleter;
34TQPixmap* KexiDisplayUtils_autonum = 0;
35
36static const unsigned int autonumber_png_len = 245;
37static const unsigned char autonumber_png_data[] = {
38 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,
39 0x44,0x52,0x00,0x00,0x00,0x0b,0x00,0x00,0x00,0x0d,0x08,0x06,0x00,0x00,
40 0x00,0x7f,0xf5,0x94,0x3b,0x00,0x00,0x00,0x06,0x62,0x4b,0x47,0x44,0x00,
41 0xff,0x00,0xff,0x00,0xff,0xa0,0xbd,0xa7,0x93,0x00,0x00,0x00,0x09,0x70,
42 0x48,0x59,0x73,0x00,0x00,0x0b,0x11,0x00,0x00,0x0b,0x11,0x01,0x7f,0x64,
43 0x5f,0x91,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd4,0x08,0x14,
44 0x0c,0x09,0x11,0x18,0x18,0x1d,0x4f,0x00,0x00,0x00,0x82,0x49,0x44,0x41,
45 0x54,0x78,0x9c,0x8d,0x91,0x41,0x0e,0x03,0x31,0x08,0x03,0x87,0xbe,0x2e,
46 0x1c,0xb3,0xff,0xbf,0xf6,0x1d,0xee,0x81,0xa0,0x05,0xaa,0x55,0x6b,0x29,
47 0x92,0x03,0x06,0x59,0x06,0x49,0x48,0x02,0xa4,0xe4,0xf1,0x5f,0x1b,0xa4,
48 0x78,0x6b,0xc3,0xc2,0x24,0x61,0x86,0x00,0x24,0x8c,0x83,0x53,0x33,0xe9,
49 0xe6,0xaf,0x29,0x4a,0x48,0x29,0xf4,0x0d,0xbc,0xc1,0xe1,0xc9,0x46,0xb5,
50 0x72,0xfa,0xcf,0xe2,0x2a,0x4c,0x71,0xf3,0x5c,0x2d,0xd5,0x5a,0xc0,0xcd,
51 0x62,0xea,0x6f,0xf4,0x88,0x86,0x95,0xf0,0x4a,0xf2,0xee,0x6b,0xf8,0x1e,
52 0x03,0x55,0xf8,0x73,0xf3,0x28,0x7e,0x6d,0x6e,0x69,0xc4,0xc6,0xfb,0x52,
53 0x23,0x8d,0x3c,0x56,0x5e,0xd0,0x2f,0x40,0xd1,0xf4,0x6b,0xc4,0xd5,0xf8,
54 0x07,0x69,0x14,0xc6,0x69,0x9a,0x12,0x79,0x9a,0x00,0x00,0x00,0x00,0x49,
55 0x45,0x4e,0x44,0xae,0x42,0x60,0x82
56};
57
58/* Generated by qembed */
59#include <tqcstring.h>
60#include <tqdict.h>
61static struct Embed {
62 unsigned int size;
63 const unsigned char *data;
64 const char *name;
65} embed_vec[] = {
66 { 245, autonumber_png_data, "autonumber.png" },
67 { 0, 0, 0 }
68};
69
70TQPixmap* getPix(int id)
71{
72// TQByteArray ba;
73// ba.setRawData( (char*)embed_vec[id].data, embed_vec[id].size );
74 TQPixmap *pix = new TQPixmap();
75 pix->loadFromData( embed_vec[id].data, embed_vec[id].size );
76 return pix;
77}
78
79static void initDisplayUtilsImages()
80{
81 if (!KexiDisplayUtils_autonum) {
83 KexiDisplayUtils_autonum_deleter.setObject( KexiDisplayUtils_autonum, getPix(0) );
84 }
85}
86
87//-----------------
88
92
94{
95 textColor = w->palette().active().foreground();
96 selectedTextColor = w->palette().active().highlightedText();
97 font = w->font();
98}
99
101{
102 initDisplayUtilsImages();
103
104 par.textColor = SPECIAL_TEXT_COLOR;
105 par.selectedTextColor = SPECIAL_TEXT_COLOR; //hmm, unused anyway
106 par.font = widget->font();
107 par.font.setItalic(true);
108 TQFontMetrics fm(par.font);
109 par.textWidth = fm.width(i18n("(autonumber)"));
110 par.textHeight = fm.height();
111}
112
114{
115 par.textColor = SPECIAL_TEXT_COLOR;
116 par.selectedTextColor = widget->palette().active().highlightedText();
117 par.font = widget->font();
118 par.font.setItalic(true);
119}
120
121void KexiDisplayUtils::paintAutonumberSign(const DisplayParameters& par, TQPainter* painter,
122 int x, int y, int width, int height, int align, bool overrideColor)
123{
124 painter->save();
125
126 painter->setFont(par.font);
127 if (!overrideColor)
128 painter->setPen(par.textColor);
129
130// int text_x = x;
131 if (!(align & TQt::AlignVertical_Mask))
132 align |= TQt::AlignVCenter;
133 if (!(align & TQt::AlignHorizontal_Mask))
134 align |= TQt::AlignLeft;
135
136 int y_pixmap_pos = 0;
137 if (align & TQt::AlignVCenter) {
138 y_pixmap_pos = TQMAX(0, y+1 + (height - KexiDisplayUtils_autonum->height())/2);
139 }
140 else if (align & TQt::AlignTop) {
141 y_pixmap_pos = y + TQMAX(0, (par.textHeight - KexiDisplayUtils_autonum->height())/2);
142 }
143 else if (align & TQt::AlignBottom) {
144 y_pixmap_pos = y+1 + height - KexiDisplayUtils_autonum->height()
145 - TQMAX(0, (par.textHeight - KexiDisplayUtils_autonum->height())/2);
146 }
147
148 if (align & (TQt::AlignLeft | TQt::AlignJustify)) {
149// text_x = x + KexiDisplayUtils_autonum->width() + 2;
150 if (!overrideColor) {
151 painter->drawPixmap( x, y_pixmap_pos, *KexiDisplayUtils_autonum );
152 x += (KexiDisplayUtils_autonum->width() + 4);
153 }
154 }
155 else if (align & TQt::AlignRight) {
156 if (!overrideColor) {
157 painter->drawPixmap( x + width - par.textWidth - KexiDisplayUtils_autonum->width() - 4,
158 y_pixmap_pos, *KexiDisplayUtils_autonum );
159 }
160 }
161 else if (align & TQt::AlignCenter) {
163 if (!overrideColor)
164 painter->drawPixmap( x + (width - par.textWidth)/2 - KexiDisplayUtils_autonum->width() - 4,
165 y_pixmap_pos, *KexiDisplayUtils_autonum );
166 }
167
168 painter->drawText(x, y, width, height, align, i18n("(autonumber)"));
169
170 painter->restore();
171}
172
Stores set of display parameters used in utility functions.
int textHeight
used for "(autonumber)" text only
DisplayParameters()
Creates uninitialized parameters.
static void initDisplayForDefaultValue(DisplayParameters &par, TQWidget *widget)
Initializes display parameters for default value.
static void paintAutonumberSign(const DisplayParameters &par, TQPainter *painter, int x, int y, int width, int height, int align, bool overrideColor=false)
Paints autonumber sign using par parameters.
static void initDisplayForAutonumberSign(DisplayParameters &par, TQWidget *widget)
Initializes display parameters for autonumber sign.