00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kexidisplayutils.h"
00021
00022 #include <qpixmap.h>
00023 #include <qpainter.h>
00024 #include <qimage.h>
00025 #include <qwidget.h>
00026
00027 #include <klocale.h>
00028 #include <kstaticdeleter.h>
00029
00030
00031 #define SPECIAL_TEXT_COLOR Qt::blue
00032
00033 static KStaticDeleter<QPixmap> KexiDisplayUtils_autonum_deleter;
00034 QPixmap* KexiDisplayUtils_autonum = 0;
00035
00036 static const unsigned int autonumber_png_len = 245;
00037 static const unsigned char autonumber_png_data[] = {
00038 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,
00039 0x44,0x52,0x00,0x00,0x00,0x0b,0x00,0x00,0x00,0x0d,0x08,0x06,0x00,0x00,
00040 0x00,0x7f,0xf5,0x94,0x3b,0x00,0x00,0x00,0x06,0x62,0x4b,0x47,0x44,0x00,
00041 0xff,0x00,0xff,0x00,0xff,0xa0,0xbd,0xa7,0x93,0x00,0x00,0x00,0x09,0x70,
00042 0x48,0x59,0x73,0x00,0x00,0x0b,0x11,0x00,0x00,0x0b,0x11,0x01,0x7f,0x64,
00043 0x5f,0x91,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd4,0x08,0x14,
00044 0x0c,0x09,0x11,0x18,0x18,0x1d,0x4f,0x00,0x00,0x00,0x82,0x49,0x44,0x41,
00045 0x54,0x78,0x9c,0x8d,0x91,0x41,0x0e,0x03,0x31,0x08,0x03,0x87,0xbe,0x2e,
00046 0x1c,0xb3,0xff,0xbf,0xf6,0x1d,0xee,0x81,0xa0,0x05,0xaa,0x55,0x6b,0x29,
00047 0x92,0x03,0x06,0x59,0x06,0x49,0x48,0x02,0xa4,0xe4,0xf1,0x5f,0x1b,0xa4,
00048 0x78,0x6b,0xc3,0xc2,0x24,0x61,0x86,0x00,0x24,0x8c,0x83,0x53,0x33,0xe9,
00049 0xe6,0xaf,0x29,0x4a,0x48,0x29,0xf4,0x0d,0xbc,0xc1,0xe1,0xc9,0x46,0xb5,
00050 0x72,0xfa,0xcf,0xe2,0x2a,0x4c,0x71,0xf3,0x5c,0x2d,0xd5,0x5a,0xc0,0xcd,
00051 0x62,0xea,0x6f,0xf4,0x88,0x86,0x95,0xf0,0x4a,0xf2,0xee,0x6b,0xf8,0x1e,
00052 0x03,0x55,0xf8,0x73,0xf3,0x28,0x7e,0x6d,0x6e,0x69,0xc4,0xc6,0xfb,0x52,
00053 0x23,0x8d,0x3c,0x56,0x5e,0xd0,0x2f,0x40,0xd1,0xf4,0x6b,0xc4,0xd5,0xf8,
00054 0x07,0x69,0x14,0xc6,0x69,0x9a,0x12,0x79,0x9a,0x00,0x00,0x00,0x00,0x49,
00055 0x45,0x4e,0x44,0xae,0x42,0x60,0x82
00056 };
00057
00058
00059 #include <qcstring.h>
00060 #include <qdict.h>
00061 static struct Embed {
00062 unsigned int size;
00063 const unsigned char *data;
00064 const char *name;
00065 } embed_vec[] = {
00066 { 245, autonumber_png_data, "autonumber.png" },
00067 { 0, 0, 0 }
00068 };
00069
00070 QPixmap* getPix(int id)
00071 {
00072
00073
00074 QPixmap *pix = new QPixmap();
00075 pix->loadFromData( embed_vec[id].data, embed_vec[id].size );
00076 return pix;
00077 }
00078
00079 static void initDisplayUtilsImages()
00080 {
00081 if (!KexiDisplayUtils_autonum) {
00083 KexiDisplayUtils_autonum_deleter.setObject( KexiDisplayUtils_autonum, getPix(0) );
00084 }
00085 }
00086
00087
00088
00089 KexiDisplayUtils::DisplayParameters::DisplayParameters()
00090 {
00091 }
00092
00093 KexiDisplayUtils::DisplayParameters::DisplayParameters(QWidget *w)
00094 {
00095 textColor = w->palette().active().foreground();
00096 selectedTextColor = w->palette().active().highlightedText();
00097 font = w->font();
00098 }
00099
00100 void KexiDisplayUtils::initDisplayForAutonumberSign(DisplayParameters& par, QWidget *widget)
00101 {
00102 initDisplayUtilsImages();
00103
00104 par.textColor = SPECIAL_TEXT_COLOR;
00105 par.selectedTextColor = SPECIAL_TEXT_COLOR;
00106 par.font = widget->font();
00107 par.font.setItalic(true);
00108 QFontMetrics fm(par.font);
00109 par.textWidth = fm.width(i18n("(autonumber)"));
00110 par.textHeight = fm.height();
00111 }
00112
00113 void KexiDisplayUtils::initDisplayForDefaultValue(DisplayParameters& par, QWidget *widget)
00114 {
00115 par.textColor = SPECIAL_TEXT_COLOR;
00116 par.selectedTextColor = widget->palette().active().highlightedText();
00117 par.font = widget->font();
00118 par.font.setItalic(true);
00119 }
00120
00121 void KexiDisplayUtils::paintAutonumberSign(const DisplayParameters& par, QPainter* painter,
00122 int x, int y, int width, int height, int align, bool overrideColor)
00123 {
00124 painter->save();
00125
00126 painter->setFont(par.font);
00127 if (!overrideColor)
00128 painter->setPen(par.textColor);
00129
00130
00131 if (!(align & Qt::AlignVertical_Mask))
00132 align |= Qt::AlignVCenter;
00133 if (!(align & Qt::AlignHorizontal_Mask))
00134 align |= Qt::AlignLeft;
00135
00136 int y_pixmap_pos = 0;
00137 if (align & Qt::AlignVCenter) {
00138 y_pixmap_pos = QMAX(0, y+1 + (height - KexiDisplayUtils_autonum->height())/2);
00139 }
00140 else if (align & Qt::AlignTop) {
00141 y_pixmap_pos = y + QMAX(0, (par.textHeight - KexiDisplayUtils_autonum->height())/2);
00142 }
00143 else if (align & Qt::AlignBottom) {
00144 y_pixmap_pos = y+1 + height - KexiDisplayUtils_autonum->height()
00145 - QMAX(0, (par.textHeight - KexiDisplayUtils_autonum->height())/2);
00146 }
00147
00148 if (align & (Qt::AlignLeft | Qt::AlignJustify)) {
00149
00150 if (!overrideColor) {
00151 painter->drawPixmap( x, y_pixmap_pos, *KexiDisplayUtils_autonum );
00152 x += (KexiDisplayUtils_autonum->width() + 4);
00153 }
00154 }
00155 else if (align & Qt::AlignRight) {
00156 if (!overrideColor) {
00157 painter->drawPixmap( x + width - par.textWidth - KexiDisplayUtils_autonum->width() - 4,
00158 y_pixmap_pos, *KexiDisplayUtils_autonum );
00159 }
00160 }
00161 else if (align & Qt::AlignCenter) {
00163 if (!overrideColor)
00164 painter->drawPixmap( x + (width - par.textWidth)/2 - KexiDisplayUtils_autonum->width() - 4,
00165 y_pixmap_pos, *KexiDisplayUtils_autonum );
00166 }
00167
00168 painter->drawText(x, y, width, height, align, i18n("(autonumber)"));
00169
00170 painter->restore();
00171 }
00172