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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
/******************************************************************/
/* KCharSelectDia - (c) by Reginald Stadlbauer 1999 */
/* Author: Reginald Stadlbauer */
/* E-Mail: [email protected] */
/* RTL support by Bryce Nesbitt */
/******************************************************************/
#include "kcharselectdia.moc"
#include <stdlib.h>
#include <kdialog.h>
#include <tdeapplication.h>
#include <tdeaccel.h>
#include <tdeconfig.h>
#include <tdelocale.h>
#include <tdeaction.h>
/******************************************************************/
/* class KCharSelectDia */
/******************************************************************/
//==================================================================
KCharSelectDia::KCharSelectDia(TQWidget *parent,const char *name,
const TQChar &_chr,const TQString &_font,
int _tableNum, bool direction)
: TDEMainWindow(parent,name), vChr(_chr), vFont(_font)
{
setCaption(TQString()); // Standard caption
TQWidget *mainWidget = new TQWidget(this);
setCentralWidget(mainWidget);
grid = new TQGridLayout( mainWidget, 3, 4, KDialog::marginHint(), KDialog::spacingHint() );
// Add character selection widget from library tdeui
charSelect = new KCharSelect(mainWidget,"",vFont,vChr,_tableNum);
charSelect->resize(charSelect->sizeHint());
connect(charSelect,TQT_SIGNAL(highlighted(const TQChar &)),
TQT_SLOT(charChanged(const TQChar &)));
connect(charSelect,TQT_SIGNAL(activated(const TQChar &)),
TQT_SLOT(add(const TQChar &)));
connect(charSelect,TQT_SIGNAL(fontChanged(const TQString &)),
TQT_SLOT(fontSelected(const TQString &)));
grid->addMultiCellWidget(charSelect, 0, 0, 0, 3);
// Build line editor
lined = new TQLineEdit(mainWidget);
lined->resize(lined->sizeHint());
TQFont font = lined->font();
font.setFamily( vFont );
lined->setFont( font );
connect(lined,TQT_SIGNAL(textChanged(const TQString &)),
TQT_SLOT(lineEditChanged()));
grid->addMultiCellWidget(lined, 1, 1, 0, 3);
// Build some buttons
bHelp = new KPushButton( KStdGuiItem::help(), mainWidget );
connect(bHelp,TQT_SIGNAL(clicked()),this,TQT_SLOT(help()));
bHelp->setFixedSize( bHelp->sizeHint() );
grid->addWidget( bHelp, 2, 0 );
TQSpacerItem *space = new TQSpacerItem( 20, 20, TQSizePolicy::Expanding );
grid->addItem( space, 2, 1 );
bClear = new KPushButton( KStdGuiItem::clear(), mainWidget );
connect(bClear,TQT_SIGNAL(clicked()),this,TQT_SLOT(clear()));
bClear->setFixedSize( bClear->sizeHint() );
grid->addWidget( bClear, 2, 2 );
bClip = new KPushButton( KGuiItem( i18n( "&To Clipboard" ),
"edit-copy" ), mainWidget );
bClip->setFixedSize( bClip->sizeHint() );
connect(bClip,TQT_SIGNAL(clicked()),this,TQT_SLOT(toClip()));
grid->addWidget( bClip, 2, 3 );
// Build menu
KStdAction::quit( TQT_TQOBJECT(this), TQT_SLOT(_exit()), actionCollection() );
new TDEAction(i18n("&To Clipboard"), "edit-copy",
TDEStdAccel::shortcut(TDEStdAccel::Copy), TQT_TQOBJECT(this), TQT_SLOT(toClip()), actionCollection(), "copy_clip" );
(void)new TDEAction(i18n("To Clipboard &UTF-8"), 0, TQT_TQOBJECT(this),
TQT_SLOT(toClipUTF8()), actionCollection(), "copy_utf_8" );
(void)new TDEAction(i18n("To Clipboard &HTML"), 0, TQT_TQOBJECT(this),
TQT_SLOT(toClipHTML()), actionCollection(), "copy_html" );
new TDEAction(i18n("&From Clipboard"), "edit-paste",
TDEStdAccel::shortcut(TDEStdAccel::Paste), TQT_TQOBJECT(this), TQT_SLOT(fromClip()), actionCollection(), "from_clip" );
(void)new TDEAction(i18n("From Clipboard UTF-8"), 0, TQT_TQOBJECT(this),
TQT_SLOT(fromClipUTF8()), actionCollection(), "from_clip_utf8" );
i18n("From Clipboard HTML"); // Intended for future use
KStdAction::clear(TQT_TQOBJECT(this), TQT_SLOT(clear()), actionCollection(), "clear");
(void)new TDEAction(i18n("&Flip"), 0, TQT_TQOBJECT(this),
TQT_SLOT(flipText()), actionCollection(), "flip" );
(void)new TDEAction(i18n("&Alignment"), 0, TQT_TQOBJECT(this),
TQT_SLOT(toggleEntryDirection()), actionCollection(), "alignment" );
charSelect->setFocus();
entryDirection = direction;
if( entryDirection )
lined->setAlignment( TQt::AlignRight );
else
lined->setAlignment( TQt::AlignLeft );
setupGUI(Keys|StatusBar|Save|Create);
}
//==================================================================
void KCharSelectDia::charChanged(const TQChar &_chr)
{
vChr = _chr;
}
//==================================================================
void KCharSelectDia::fontSelected(const TQString &_font)
{
charSelect->setFont(_font);
TQFont font = lined->font();
font.setFamily( _font );
lined->setFont( font );
vFont = _font;
}
//==================================================================
void KCharSelectDia::add(const TQChar &_chr)
{
TQString str;
int cursorPos;
charChanged(_chr);
str = lined->text();
cursorPos = lined->cursorPosition();
str.insert( cursorPos, vChr );
lined->setText(str);
cursorPos++;
lined->setCursorPosition( cursorPos );
}
//==================================================================
void KCharSelectDia::toClip()
{
TQClipboard *cb = TQApplication::clipboard();
cb->setSelectionMode( true );
cb->setText(lined->text());
cb->setSelectionMode( false );
cb->setText(lined->text());
}
//==================================================================
// UTF-8 is rapidly becoming the favored 8-bit encoding for
// Unicode (iso10646-1).
//
void KCharSelectDia::toClipUTF8()
{
TQClipboard *cb = TQApplication::clipboard();
TQString str = lined->text();
cb->setText(str.utf8());
}
//==================================================================
// Put valid HTML 4.0 into the clipboard. Valid ISO-8859-1 Latin 1
// characters are left undisturbed. Everything else, including the
// "c0 control characters" often used by Windows, are clipped
// as a HTML entity.
//
void KCharSelectDia::toClipHTML()
{
TQClipboard *cb = TQApplication::clipboard();
TQString input;
TQString html;
TQString tempstring;
TQChar tempchar;
uint i;
input = lined->text();
for(i=0; i< input.length(); i++ )
{
tempchar = input.at(i);
if( tempchar.latin1() && ((tempchar.unicode() < 128) || (tempchar.unicode() >= 128+32)) )
{
html.append(input.at(i));
}
else
{
html.append(tempstring.sprintf("&#x%x;", tempchar.unicode()));
}
}
cb->setText(html);
}
//==================================================================
//
void KCharSelectDia::fromClip()
{
TQClipboard *cb = TQApplication::clipboard();
lined->setText( cb->text() );
}
//==================================================================
// UTF-8 is rapidly becoming the favored 8-bit encoding for
// Unicode (iso10646-1). This function is handy for decoding
// UTF-8 found in legacy applications, consoles, filenames, webpages,
// etc.
//
void KCharSelectDia::fromClipUTF8()
{
TQClipboard *cb = TQApplication::clipboard();
TQString str = cb->text();
lined->setText( str.fromUtf8( str.latin1() ) );
}
//==================================================================
// Reverse the text held in the line edit buffer. This is crucial
// for dealing with visual vs. logical representations of
// right to left languages, and handy for working around all
// manner of legacy character order issues.
//
void KCharSelectDia::flipText()
{
TQString input;
TQString output;
uint i;
input = lined->text();
for(i=0; i< input.length(); i++ )
{
output.prepend( input.at(i) );
}
lined->setText(output);
}
//==================================================================
void KCharSelectDia::toggleEntryDirection()
{
entryDirection ^= 1;
if( entryDirection )
lined->setAlignment( TQt::AlignRight );
else
lined->setAlignment( TQt::AlignLeft );
}
//==================================================================
void KCharSelectDia::lineEditChanged()
{
if( entryDirection )
{
if(lined->cursorPosition())
lined->setCursorPosition( lined->cursorPosition() - 1 );
}
}
//==================================================================
void KCharSelectDia::_exit()
{
TDEConfig *config = kapp->config();
config->setGroup("General");
config->writeEntry("selectedFont",vFont);
config->writeEntry("char",static_cast<int>(vChr.unicode()));
config->writeEntry("table",charSelect->tableNum());
config->writeEntry("entryDirection",entryDirection);
config->sync();
delete this;
exit(0);
}
//==================================================================
void KCharSelectDia::clear()
{
lined->clear();
}
//==================================================================
void KCharSelectDia::help()
{
kapp->invokeHelp();
}
|