~ubuntu-branches/ubuntu/breezy/koffice/breezy

« back to all changes in this revision

Viewing changes to kugar/kudesigner_lib/clabel.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040509113300-vfrdadqsvjfuhn3b
Tags: 1:1.3.1-1
* New upstream bugfix release.
* Built against newer imagemagick (closes: #246623).
* Made koffice-libs/kformula recommend/depend on latex-xft-fonts, which
  provides mathematical fonts that the formula editor can use.  Also
  patched the kformula part to make these fonts the default.
* Changed kword menu hint from "WordProcessors" to "Word processors"
  (closes: #246209).
* Spellchecker configuration is now fixed (closes: #221256, #227568).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                          clabel.cpp  -  description
 
3
                             -------------------
 
4
    begin                : 07.06.2002
 
5
    copyright            : (C) 2002 by Alexander Dymo
 
6
    email                : cloudtemple@mksat.net
 
7
 ***************************************************************************/
 
8
 
 
9
/***************************************************************************
 
10
 *                                                                         *
 
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.                       *
 
15
 *                                                                         *
 
16
 ***************************************************************************/
 
17
#ifndef PURE_QT
 
18
#include <klocale.h>
 
19
#include <klineeditdlg.h>
 
20
#else
 
21
#include "qlocale.h"
 
22
#include <qinputdialog.h>
 
23
#endif
 
24
 
 
25
#include <qpainter.h>
 
26
 
 
27
#include "clabel.h"
 
28
#include "property.h"
 
29
#include "canvband.h"
 
30
 
 
31
CanvasLabel::CanvasLabel(int x, int y, int width, int height, QCanvas * canvas):
 
32
    CanvasReportItem(x, y, width, height, canvas)
 
33
{
 
34
    std::map<QString, QString> m;
 
35
 
 
36
    props["Text"] = *(new PropPtr(new Property(StringValue, "Text", i18n("Text to display"), i18n("Text"))));
 
37
 
 
38
    props["X"] = *(new PropPtr(new Property(IntegerValue, "X", i18n("X coordinate corresponding to section"), QString("%1").arg(x))));
 
39
 
 
40
    props["Y"] = *(new PropPtr(new Property(IntegerValue, "Y", i18n("Y coordinate corresponding to section"), QString("%1").arg(y))));
 
41
 
 
42
    props["Width"] = *(new PropPtr(new Property(IntegerValue, "Width", i18n("Width"), QString("%1").arg(width))));
 
43
 
 
44
    props["Height"] = *(new PropPtr(new Property(IntegerValue, "Height", i18n("Height"), QString("%1").arg(height))));
 
45
 
 
46
    props["BackgroundColor"] = *(new PropPtr(new Property(Color, "BackgroundColor", i18n("Background color"), "255,255,255")));
 
47
 
 
48
    props["ForegroundColor"] = *(new PropPtr(new Property(Color, "ForegroundColor", i18n("Text color"), "0,0,0")));
 
49
 
 
50
    props["BorderColor"] = *(new PropPtr(new Property(Color, "BorderColor", i18n("Border color"), "0,0,0")));
 
51
 
 
52
    props["BorderWidth"] = *(new PropPtr(new Property(IntegerValue, "BorderWidth", i18n("Border width"), "1")));
 
53
 
 
54
    props["BorderStyle"] = *(new PropPtr(new Property(LineStyle, "BorderStyle", i18n("Border style"), "1")));
 
55
 
 
56
    props["FontFamily"] = *(new PropPtr(new Property(FontName, "FontFamily", i18n("Font family"), "Times New Roman")));
 
57
 
 
58
    props["FontSize"] = *(new PropPtr(new Property(IntegerValue, "FontSize", i18n("Font size"), "12")));
 
59
 
 
60
    m["Light"] = "25";
 
61
    m["Normal"] = "50";
 
62
    m["DemiBold"] = "63";
 
63
    m["Bold"] = "75";
 
64
    m["Black"] = "87";
 
65
    props["FontWeight"] = *(new PropPtr(new Property("FontWeight", m, i18n("Font weight"), "50")));
 
66
    m.clear();
 
67
 
 
68
    m["Regular"] = "0";
 
69
    m["Italic"] = "1";
 
70
    props["FontItalic"] = *(new PropPtr(new Property("FontItalic", m, i18n("Italic font"), "0")));
 
71
    m.clear();
 
72
 
 
73
    m["Left"] = "0";
 
74
    m["Center"] = "1";
 
75
    m["Right"] = "2";
 
76
    props["HAlignment"] = *(new PropPtr(new Property("HAlignment", m, i18n("Text horizontal alignment"),
 
77
        QString("").isRightToLeft()?"2":"0")));
 
78
    m.clear();
 
79
 
 
80
    m["Top"] = "0";
 
81
    m["Middle"] = "1";
 
82
    m["Bottom"] = "2";
 
83
    props["VAlignment"] = *(new PropPtr(new Property("VAlignment", m, i18n("Text vertical alignment"), "1")));
 
84
    m.clear();
 
85
 
 
86
    m["False"] = "0";
 
87
    m["True"] = "1";
 
88
    props["WordWrap"] = *(new PropPtr(new Property("WordWrap", m, i18n("Word wrap"), "0")));
 
89
}
 
90
 
 
91
int CanvasLabel::getTextAlignment()
 
92
{
 
93
    int result = 0;
 
94
    switch (props["HAlignment"]->value().toInt())
 
95
    {
 
96
        case 0: result = AlignLeft;
 
97
            break;
 
98
        case 1: result = AlignHCenter;
 
99
            break;
 
100
        case 2: result = AlignRight;
 
101
            break;
 
102
        default: result = AlignHCenter;
 
103
    }
 
104
    switch (props["VAlignment"]->value().toInt())
 
105
    {
 
106
        case 0: result = result | AlignTop;
 
107
            break;
 
108
        case 1: result = result | AlignVCenter;
 
109
            break;
 
110
        case 2: result = result | AlignBottom;
 
111
            break;
 
112
        default: result = result | AlignVCenter;
 
113
    }
 
114
    return result;
 
115
}
 
116
 
 
117
int CanvasLabel::getTextWrap()
 
118
{
 
119
    switch (props["WordWrap"]->value().toInt())
 
120
    {
 
121
        case 0: return SingleLine;
 
122
            break;
 
123
        case 1: return WordBreak;
 
124
            break;
 
125
        default: return SingleLine;
 
126
    }
 
127
}
 
128
 
 
129
QFont CanvasLabel::getFont()
 
130
{
 
131
    return QFont(props["FontFamily"]->value(),
 
132
        props["FontSize"]->value().toInt(),
 
133
        props["FontWeight"]->value().toInt(),
 
134
        props["FontItalic"]->value().toInt());
 
135
}
 
136
 
 
137
QPen CanvasLabel::getPenForText()
 
138
{
 
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()));
 
142
}
 
143
 
 
144
QPen CanvasLabel::getPenForShape()
 
145
{
 
146
    PenStyle style = SolidLine;
 
147
    switch (props["BorderStyle"]->value().toInt())
 
148
    {
 
149
        case 0: style = NoPen;
 
150
            break;
 
151
        case 1: style = SolidLine;
 
152
            break;
 
153
        case 2: style = DashLine;
 
154
            break;
 
155
        case 3: style = DotLine;
 
156
            break;
 
157
        case 4: style = DashDotLine;
 
158
            break;
 
159
        case 5: style = DashDotDotLine;
 
160
            break;
 
161
    }
 
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);
 
166
}
 
167
 
 
168
QBrush CanvasLabel::getBrush()
 
169
{
 
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()));
 
173
}
 
174
 
 
175
void CanvasLabel::draw(QPainter &painter)
 
176
{
 
177
    //update dimensions
 
178
    if (!section()) return;
 
179
 
 
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());
 
183
 
 
184
    //draw border and background
 
185
    painter.setPen(getPenForShape());
 
186
    painter.setBrush(getBrush());
 
187
    painter.drawRect(rect());
 
188
 
 
189
    //draw text inside
 
190
    painter.setFont(getFont());
 
191
    painter.setPen(getPenForText());
 
192
    painter.drawText((int)x(), (int)y(), width(), height(),
 
193
        getTextAlignment() | getTextWrap(),
 
194
        props["Text"]->value());
 
195
 
 
196
    //draw resizable region
 
197
//    if (isSelected())
 
198
//        drawHolders(painter);
 
199
//    CanvasReportItem::draw(painter);
 
200
}
 
201
 
 
202
QString CanvasLabel::getXml()
 
203
{
 
204
    return "\t\t<Label" + CanvasReportItem::getXml() + " />\n";
 
205
}
 
206
 
 
207
void CanvasLabel::fastProperty()
 
208
{
 
209
    bool accepted;
 
210
 
 
211
#ifndef PURE_QT
 
212
    QString sText = KLineEditDlg::getText( i18n( "Change Label" ),
 
213
            "Enter label name:", props["Text"]->value(), &accepted );
 
214
#else
 
215
    QString sText = QInputDialog::getText( i18n( "Change Label" ),
 
216
            "Enter label name:", QLineEdit::Normal, props["Text"]->value(), &accepted );
 
217
#endif
 
218
 
 
219
    if ( accepted )
 
220
        props["Text"]->setValue( sText );
 
221
}
 
222