1
/***************************************************************************
2
clabel.cpp - description
5
copyright : (C) 2002 by Alexander Dymo
6
email : cloudtemple@mksat.net
7
***************************************************************************/
9
/***************************************************************************
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU Library General Public License as *
13
* published by the Free Software Foundation; either version 2 of the *
14
* License, or (at your option) any later version. *
16
***************************************************************************/
19
#include <klineeditdlg.h>
22
#include <qinputdialog.h>
31
CanvasLabel::CanvasLabel(int x, int y, int width, int height, QCanvas * canvas):
32
CanvasReportItem(x, y, width, height, canvas)
34
std::map<QString, QString> m;
36
props["Text"] = *(new PropPtr(new Property(StringValue, "Text", i18n("Text to display"), i18n("Text"))));
38
props["X"] = *(new PropPtr(new Property(IntegerValue, "X", i18n("X coordinate corresponding to section"), QString("%1").arg(x))));
40
props["Y"] = *(new PropPtr(new Property(IntegerValue, "Y", i18n("Y coordinate corresponding to section"), QString("%1").arg(y))));
42
props["Width"] = *(new PropPtr(new Property(IntegerValue, "Width", i18n("Width"), QString("%1").arg(width))));
44
props["Height"] = *(new PropPtr(new Property(IntegerValue, "Height", i18n("Height"), QString("%1").arg(height))));
46
props["BackgroundColor"] = *(new PropPtr(new Property(Color, "BackgroundColor", i18n("Background color"), "255,255,255")));
48
props["ForegroundColor"] = *(new PropPtr(new Property(Color, "ForegroundColor", i18n("Text color"), "0,0,0")));
50
props["BorderColor"] = *(new PropPtr(new Property(Color, "BorderColor", i18n("Border color"), "0,0,0")));
52
props["BorderWidth"] = *(new PropPtr(new Property(IntegerValue, "BorderWidth", i18n("Border width"), "1")));
54
props["BorderStyle"] = *(new PropPtr(new Property(LineStyle, "BorderStyle", i18n("Border style"), "1")));
56
props["FontFamily"] = *(new PropPtr(new Property(FontName, "FontFamily", i18n("Font family"), "Times New Roman")));
58
props["FontSize"] = *(new PropPtr(new Property(IntegerValue, "FontSize", i18n("Font size"), "12")));
65
props["FontWeight"] = *(new PropPtr(new Property("FontWeight", m, i18n("Font weight"), "50")));
70
props["FontItalic"] = *(new PropPtr(new Property("FontItalic", m, i18n("Italic font"), "0")));
76
props["HAlignment"] = *(new PropPtr(new Property("HAlignment", m, i18n("Text horizontal alignment"),
77
QString("").isRightToLeft()?"2":"0")));
83
props["VAlignment"] = *(new PropPtr(new Property("VAlignment", m, i18n("Text vertical alignment"), "1")));
88
props["WordWrap"] = *(new PropPtr(new Property("WordWrap", m, i18n("Word wrap"), "0")));
91
int CanvasLabel::getTextAlignment()
94
switch (props["HAlignment"]->value().toInt())
96
case 0: result = AlignLeft;
98
case 1: result = AlignHCenter;
100
case 2: result = AlignRight;
102
default: result = AlignHCenter;
104
switch (props["VAlignment"]->value().toInt())
106
case 0: result = result | AlignTop;
108
case 1: result = result | AlignVCenter;
110
case 2: result = result | AlignBottom;
112
default: result = result | AlignVCenter;
117
int CanvasLabel::getTextWrap()
119
switch (props["WordWrap"]->value().toInt())
121
case 0: return SingleLine;
123
case 1: return WordBreak;
125
default: return SingleLine;
129
QFont CanvasLabel::getFont()
131
return QFont(props["FontFamily"]->value(),
132
props["FontSize"]->value().toInt(),
133
props["FontWeight"]->value().toInt(),
134
props["FontItalic"]->value().toInt());
137
QPen CanvasLabel::getPenForText()
139
return QPen(QColor(props["ForegroundColor"]->value().section(',', 0, 0).toInt(),
140
props["ForegroundColor"]->value().section(',', 1, 1).toInt(),
141
props["ForegroundColor"]->value().section(',', 2, 2).toInt()));
144
QPen CanvasLabel::getPenForShape()
146
PenStyle style = SolidLine;
147
switch (props["BorderStyle"]->value().toInt())
149
case 0: style = NoPen;
151
case 1: style = SolidLine;
153
case 2: style = DashLine;
155
case 3: style = DotLine;
157
case 4: style = DashDotLine;
159
case 5: style = DashDotDotLine;
162
return QPen(QColor(props["BorderColor"]->value().section(',', 0, 0).toInt(),
163
props["BorderColor"]->value().section(',', 1, 1).toInt(),
164
props["BorderColor"]->value().section(',', 2, 2).toInt()),
165
props["BorderWidth"]->value().toInt(), style);
168
QBrush CanvasLabel::getBrush()
170
return QBrush(QColor(props["BackgroundColor"]->value().section(',', 0, 0).toInt(),
171
props["BackgroundColor"]->value().section(',', 1, 1).toInt(),
172
props["BackgroundColor"]->value().section(',', 2, 2).toInt()));
175
void CanvasLabel::draw(QPainter &painter)
178
if (!section()) return;
180
setX(props["X"]->value().toInt() + section()->x());
181
setY(props["Y"]->value().toInt() + section()->y());
182
setSize(props["Width"]->value().toInt(), props["Height"]->value().toInt());
184
//draw border and background
185
painter.setPen(getPenForShape());
186
painter.setBrush(getBrush());
187
painter.drawRect(rect());
190
painter.setFont(getFont());
191
painter.setPen(getPenForText());
192
painter.drawText((int)x(), (int)y(), width(), height(),
193
getTextAlignment() | getTextWrap(),
194
props["Text"]->value());
196
//draw resizable region
198
// drawHolders(painter);
199
// CanvasReportItem::draw(painter);
202
QString CanvasLabel::getXml()
204
return "\t\t<Label" + CanvasReportItem::getXml() + " />\n";
207
void CanvasLabel::fastProperty()
212
QString sText = KLineEditDlg::getText( i18n( "Change Label" ),
213
"Enter label name:", props["Text"]->value(), &accepted );
215
QString sText = QInputDialog::getText( i18n( "Change Label" ),
216
"Enter label name:", QLineEdit::Normal, props["Text"]->value(), &accepted );
220
props["Text"]->setValue( sText );