• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • superkaramba
 

superkaramba

  • superkaramba
  • src
richtextlabel.cpp
1/***************************************************************************
2 * Copyright (C) 2003 by Wilfried Huss *
3 * Wilfried.Huss@gmx.at *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 ***************************************************************************/
10
11#include <krun.h>
12#include <kdebug.h>
13#include "karamba.h"
14#include "richtextlabel.h"
15
16RichTextLabel::RichTextLabel(karamba* k) :
17 Meter(k, 0, 0, 100, 100),
18 text(0),
19 source(""),
20 colorGrp(k->colorGroup()),
21 underlineLinks(false)
22{
23 originalSize = TQSize(0, 0);
24}
25
26RichTextLabel::RichTextLabel(karamba* k, int x, int y, int w, int h) :
27 Meter(k, x, y, w, h),
28 text(0),
29 source(""),
30 colorGrp(k->colorGroup()),
31 underlineLinks(false)
32{
33 kdDebug() << k_funcinfo << x << ", " << y << ", " << w << ", " << h << endl;
34 originalSize = TQSize(w, h);
35}
36
37RichTextLabel::~RichTextLabel()
38{
39 if (text != 0)
40 {
41 delete text;
42 text = 0;
43 }
44}
45
46void RichTextLabel::setText(TQString t, bool linkUnderline)
47{
48 source = t;
49 if (text != 0)
50 {
51 delete text;
52 text = 0;
53 }
54 else
55 {
56 // set underlineLinks only when RichTextLabel is created, not
57 // when text is changed.
58 underlineLinks = linkUnderline;
59 }
60
61 text = new TQSimpleRichText(t, font, m_karamba->theme().path(),
62 0, // default TQStyleSheet*
63 0, // default TQMimeSourceFactory
64 -1, // no pageBreak
65 TQt::blue, // (has no effect) link Color
66 underlineLinks);
67
68 // set the text to a reasonable size
69 text->adjustSize();
70 if(originalSize.width() < 1)
71 setWidth(text->width());
72 else
73 text->setWidth(getWidth());
74 if(originalSize.height() < 1)
75 setHeight(text->height());
76}
77
78void RichTextLabel::setValue(TQString text)
79{
80 setText(text);
81}
82
83void RichTextLabel::setValue(long v)
84{
85 setText(TQString::number(v));
86}
87
88void RichTextLabel::setFont(TQString f)
89{
90 font.setFamily(f);
91 if(text != 0)
92 text->setDefaultFont(font);
93}
94
95TQString RichTextLabel::getFont() const
96{
97 return font.family();
98}
99
100void RichTextLabel::setFontSize(int size)
101{
102 font.setPixelSize(size);
103 if(text != 0)
104 text->setDefaultFont(font);
105}
106
107int RichTextLabel::getFontSize() const
108{
109 return font.pixelSize();
110}
111
112void RichTextLabel::setFixedPitch(bool fp)
113{
114 font.setFixedPitch(fp);
115 if(text != 0)
116 text->setDefaultFont(font);
117}
118
119bool RichTextLabel::getFixedPitch() const
120{
121 return font.fixedPitch();
122}
123
124void RichTextLabel::setTextProps(TextField* t)
125{
126 if(t)
127 {
128 setFontSize(t->getFontSize());
129 setFont(t->getFont());
130 colorGrp.setColor(TQColorGroup::Text, t->getColor());
131 }
132}
133
134void RichTextLabel::setWidth(int width)
135{
136 Meter::setWidth(width);
137 // rearrange text
138 text->setWidth(getWidth());
139 if(originalSize.height() < 1)
140 setHeight(text->height());
141}
142
143void RichTextLabel::mUpdate(TQPainter* p)
144{
145 if (hidden || text == 0)
146 {
147 return;
148 }
149
150 int x = getX();
151 int y = getY();
152 int w = getWidth();
153 int h = getHeight();
154 TQRect clipRect(x, y, w, h);
155 text->draw(p, x, y, clipRect, colorGrp, 0 /* no background */);
156}
157
158bool RichTextLabel::click(TQMouseEvent* e)
159{
160 if (hidden)
161 {
162 return false;
163 }
164 TQPoint point(e->x() - getX(), e->y() - getY());
165 TQString anchor = text->anchorAt(point);
166 if (anchor[0] != '#')
167 {
168 if (e->button() == TQt::LeftButton)
169 {
170 KRun :: runCommand(anchor);
171 }
172 return false;
173 }
174 else
175 {
176 //call callback meterClicked
177 return true;
178 }
179}
180
181TQString RichTextLabel::anchorAt(int x, int y)
182{
183 TQPoint point(x - getX(), y - getY());
184 TQString anchor = text->anchorAt(point);
185 if (anchor[0] == '#')
186 {
187 return anchor.remove(0, 1);
188 }
189 else
190 {
191 // ASSERT: should never happen
192 return "";
193 }
194}
195
196bool RichTextLabel::insideActiveArea(int x, int y)
197{
198 TQPoint point(x - getX(), y - getY());
199 return text->anchorAt(point) != ""; // && text -> inText(point);
200}
201
202void RichTextLabel::setColorGroup(const TQColorGroup &colorg)
203{
204 colorGrp = colorg;
205}
206
207const TQColorGroup & RichTextLabel::getColorGroup() const
208{
209 return colorGrp;
210}
211
212#include "richtextlabel.moc"
TextField
Ralph M.
Definition: textfield.h:22

superkaramba

Skip menu "superkaramba"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members

superkaramba

Skip menu "superkaramba"
  • kcalc
  •   knumber
  • superkaramba
Generated for superkaramba by doxygen 1.9.4
This website is maintained by Timothy Pearson.