1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
/***************************************************************************
richtexteditor.cpp - Widget providing simple rich text editing
-------------------
copyright : (C) 2002 by Marc Britton
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* KDE INCLUDES */
#include <klocale.h>
/* QT INCLUDES */
#include <tqlayout.h>
#include <tqevent.h>
#include <tqtextedit.h>
#include <tqframe.h>
#include <tqwidget.h>
#include <tqlayout.h>
#include <tqtoolbutton.h>
#include <tqpixmap.h>
#include <tqhbuttongroup.h>
#include <tqfont.h>
#include <tqstringlist.h>
#include <tqevent.h>
/* OTHER INCLUDES */
#include <specials.h>
#include "richtexteditor.h"
/* Pixmaps */
#include "pixmaps/textbold.xpm"
#include "pixmaps/textunder.xpm"
#include "pixmaps/textitalic.xpm"
#include "pixmaps/textcenter.xpm"
#include "pixmaps/textleft.xpm"
#include "pixmaps/textright.xpm"
RichTextEditor::RichTextEditor(TQWidget *a_parent, const char *a_name)
: TQWidget(a_parent, a_name), KommanderWidget(TQT_TQOBJECT(this))
{
TQStringList states;
states << "default";
setStates(states);
setDisplayStates(states);
// setup toolbar
m_toolbar = new TQFrame(this, "buttonBar");
m_toolbar->setMinimumSize(0, 32);
m_toolbar->setFrameShape(TQFrame::NoFrame);
m_toolbar->setFrameShadow(TQFrame::Plain);
//setup textedit
m_textedit = new TQTextEdit(this, "editor");
m_textedit->setTextFormat(RichText);
// tqlayout the widgets
TQVBoxLayout *tqlayout = new TQVBoxLayout(this);
tqlayout->addWidget(m_toolbar);
tqlayout->addWidget(m_textedit);
tqlayout->setSpacing(1);
// setup buttons
TQHBoxLayout *tbLayout = new TQHBoxLayout(m_toolbar);
//bold italic underline left right center link
m_formatGroup = new TQHButtonGroup(m_toolbar, "formatGroup");
//m_formatGroup->setFlat(true);
m_alignGroup = new TQHButtonGroup(m_toolbar, "alignGroup");
//m_alignGroup->setFlat(true);
m_alignGroup->setExclusive(true);
tbLayout->insertStretch(0);
tbLayout->addWidget(m_formatGroup);
tbLayout->addWidget(m_alignGroup);
tbLayout->insertStretch(3);
m_buttonTextBold = new TQToolButton(m_formatGroup, "textBold");
m_buttonTextBold->setPixmap(TQPixmap((const char **)bold_xpm));
m_buttonTextBold->setToggleButton(true);
connect(m_buttonTextBold, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(textBold(bool)));
m_buttonTextItalic = new TQToolButton(m_formatGroup, "textItalic");
m_buttonTextItalic->setPixmap(TQPixmap((const char **)italic_xpm));
m_buttonTextItalic->setToggleButton(true);
connect(m_buttonTextItalic, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(textItalic(bool)));
m_buttonTextUnder = new TQToolButton(m_formatGroup, "textUnder");
m_buttonTextUnder->setPixmap(TQPixmap((const char **)under_xpm));
m_buttonTextUnder->setToggleButton(true);
connect(m_buttonTextUnder, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(textUnder(bool)));
m_buttonTextLeft = new TQToolButton(m_alignGroup, "textLeft");
m_buttonTextLeft->setPixmap(TQPixmap((const char **)left_xpm));
m_buttonTextLeft->setToggleButton(true);
m_buttonTextCenter = new TQToolButton(m_alignGroup, "textCenter");
m_buttonTextCenter->setPixmap(TQPixmap((const char **)center_xpm));
m_buttonTextCenter->setToggleButton(true);
m_buttonTextRight = new TQToolButton(m_alignGroup, "textRight");
m_buttonTextRight->setPixmap(TQPixmap((const char **)right_xpm));
m_buttonTextRight->setToggleButton(true);
connect(m_alignGroup, TQT_SIGNAL(clicked(int)), this, TQT_SLOT(textAlign(int)));
connect(m_textedit, TQT_SIGNAL(currentFontChanged(const TQFont &)), this, TQT_SLOT(fontChanged(const TQFont &)));
connect(m_textedit, TQT_SIGNAL(currentAlignmentChanged(int)), this, TQT_SLOT(alignmentChanged(int)));
connect(m_textedit, TQT_SIGNAL(textChanged()), this, TQT_SLOT(setTextChanged()));
}
TQString RichTextEditor::currentState() const
{
return TQString("default");
}
RichTextEditor::~RichTextEditor()
{
}
bool RichTextEditor::isKommanderWidget() const
{
return true;
}
TQStringList RichTextEditor::associatedText() const
{
return KommanderWidget::associatedText();
}
void RichTextEditor::setAssociatedText(const TQStringList& a_at)
{
KommanderWidget::setAssociatedText(a_at);
}
void RichTextEditor::setPopulationText(const TQString& a_text)
{
KommanderWidget::setPopulationText( a_text );
}
TQString RichTextEditor::populationText() const
{
return KommanderWidget::populationText();
}
void RichTextEditor::populate()
{
TQString txt = KommanderWidget::evalAssociatedText( populationText() );
setWidgetText( txt );
}
void RichTextEditor::setWidgetText(const TQString &a_text)
{
m_textedit->setText(a_text);
emit widgetTextChanged(a_text);
}
void RichTextEditor::setTextChanged()
{
emit widgetTextChanged(m_textedit->text());
}
void RichTextEditor::textBold(bool a_isOn)
{
m_textedit->setBold(a_isOn);
}
void RichTextEditor::textUnder(bool a_isOn)
{
m_textedit->setUnderline(a_isOn);
}
void RichTextEditor::textItalic(bool a_isOn)
{
m_textedit->setItalic(a_isOn);
}
void RichTextEditor::textAlign(int a_id)
{
TQToolButton *b = (TQToolButton *)m_alignGroup->find(a_id);
if(b == m_buttonTextLeft)
m_textedit->tqsetAlignment(TQt::AlignLeft);
else if(b == m_buttonTextCenter)
m_textedit->tqsetAlignment(TQt::AlignCenter);
else if(b == m_buttonTextRight)
m_textedit->tqsetAlignment(TQt::AlignRight);
}
void RichTextEditor::fontChanged(const TQFont &a_font)
{
m_buttonTextBold->setOn(a_font.bold());
m_buttonTextItalic->setOn(a_font.italic());
m_buttonTextUnder->setOn(a_font.underline());
}
void RichTextEditor::alignmentChanged(int a_tqalignment)
{
if((a_tqalignment == AlignAuto) || (a_tqalignment & AlignLeft))
m_buttonTextLeft->setOn(true);
else if(a_tqalignment & AlignHCenter)
m_buttonTextCenter->setOn(true);
else if(a_tqalignment & AlignRight)
m_buttonTextRight->setOn(true);
}
void RichTextEditor::showEvent( TQShowEvent *e )
{
TQWidget::showEvent(e);
emit widgetOpened();
}
void RichTextEditor::contextMenuEvent( TQContextMenuEvent * e )
{
e->accept();
TQPoint p = e->globalPos();
emit contextMenuRequested(p.x(), p.y());
}
bool RichTextEditor::isFunctionSupported(int f)
{
return f == DCOP::text || f == DCOP::setText || f == DCOP::clear || f == DCOP::selection || f == DCOP::setEditable;
}
TQString RichTextEditor::handleDCOP(int function, const TQStringList& args)
{
switch (function) {
case DCOP::text:
return m_textedit->text();
case DCOP::setText:
setWidgetText(args[0]);
break;
case DCOP::selection:
return m_textedit->selectedText();
case DCOP::clear:
setWidgetText("");
break;
case DCOP::setEditable:
m_textedit->setReadOnly(args[0] == "false" || args[0] == "0");
break;
default:
return KommanderWidget::handleDCOP(function, args);
}
return TQString();
}
#include "richtexteditor.moc"
|