-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsecqlineedit.cpp
1957 lines (1688 loc) · 50.1 KB
/
secqlineedit.cpp
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* secqlineedit.cpp - Secure version of TQLineEdit.
* Copyright (C) 1992-2002 Trolltech AS. All rights reserved.
* Copyright (C) 2003 g10 Code GmbH
*
* The license of the original qlineedit.cpp file from which this file
* is derived can be found below. Modified by Marcus Brinkmann
* <marcus@g10code.de>. All modifications are licensed as follows, so
* that the intersection of the two licenses is then the GNU General
* Public License version 2.
*
* 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.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <https://www.gnu.org/licenses/>.
* SPDX-License-Identifier: GPL-2.0
*/
/* Undo/Redo is disabled, because it uses unsecure memory for the
history buffer. */
#define SECURE_NO_UNDO 1
/**********************************************************************
** $Id$
**
** Implementation of SecTQLineEdit widget class
**
** Created : 941011
**
** Copyright (C) 1992-2002 Trolltech AS. All rights reserved.
**
** This file is part of the widgets module of the TQt GUI Toolkit.
**
** This file may be distributed under the terms of the Q Public License
** as defined by Trolltech AS of Norway and appearing in the file
** LICENSE.TQPL included in the packaging of this file.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** Licensees holding valid TQt Enterprise Edition or TQt Professional Edition
** licenses may use this file in accordance with the TQt Commercial License
** Agreement provided with the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
** information about TQt Commercial License Agreements.
** See http://www.trolltech.com/qpl/ for TQPL licensing information.
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include "secqlineedit.h"
#include "ntqpainter.h"
#include "ntqdrawutil.h"
#include "ntqfontmetrics.h"
#include "ntqpixmap.h"
#include "ntqclipboard.h"
#include "ntqapplication.h"
#include "ntqtimer.h"
#include "ntqpopupmenu.h"
#include "ntqstringlist.h"
#include "ntqguardedptr.h"
#include "ntqstyle.h"
#include "ntqwhatsthis.h"
#include "secqinternal_p.h"
#include "private/qtextlayout_p.h"
#include "ntqvaluevector.h"
#if defined(QT_ACCESSIBILITY_SUPPORT)
#include "ntqaccessible.h"
#endif
#ifndef QT_NO_ACCEL
#include "ntqkeysequence.h"
#define ACCEL_KEY(k) "\t" + TQString(TQKeySequence( TQt::CTRL | TQt::Key_ ## k ))
#else
#define ACCEL_KEY(k) "\t" + TQString("Ctrl+" #k)
#endif
#define innerMargin 1
struct SecTQLineEditPrivate : public TQt
{
SecTQLineEditPrivate( SecTQLineEdit *q )
: q(q), cursor(0), cursorTimer(0), tripleClickTimer(0), frame(1),
cursorVisible(0), separator(0), readOnly(0), modified(0),
direction(TQChar::DirON), alignment(0),
echoMode(0), textDirty(0), selDirty(0),
ascent(0), maxLength(32767), menuId(0),
hscroll(0),
undoState(0), selstart(0), selend(0),
imstart(0), imend(0), imselstart(0), imselend(0)
{}
void init( const SecTQString&);
SecTQLineEdit *q;
SecTQString text;
int cursor;
int cursorTimer;
TQPoint tripleClick;
int tripleClickTimer;
uint frame : 1;
uint cursorVisible : 1;
uint separator : 1;
uint readOnly : 1;
uint modified : 1;
uint direction : 5;
uint alignment : 3;
uint echoMode : 2;
uint textDirty : 1;
uint selDirty : 1;
int ascent;
int maxLength;
int menuId;
int hscroll;
void finishChange( int validateFromState = -1, bool setModified = TRUE );
void setCursorVisible( bool visible );
// undo/redo handling
enum CommandType { Separator, Insert, Remove, Delete, RemoveSelection, DeleteSelection };
struct Command {
inline Command(){}
inline Command( CommandType type, int pos, TQChar c )
:type(type),c(c),pos(pos){}
uint type : 4;
TQChar c;
int pos;
};
int undoState;
TQValueVector<Command> history;
#ifndef SECURE_NO_UNDO
void addCommand( const Command& cmd );
#endif /* SECURE_NO_UNDO */
void insert( const SecTQString& s );
void del( bool wasBackspace = FALSE );
void remove( int pos );
inline void separate() { separator = TRUE; }
#ifndef SECURE_NO_UNDO
inline void undo( int until = -1 ) {
if ( !isUndoAvailable() )
return;
deselect();
while ( undoState && undoState > until ) {
Command& cmd = history[--undoState];
switch ( cmd.type ) {
case Insert:
text.remove( cmd.pos, 1);
cursor = cmd.pos;
break;
case Remove:
case RemoveSelection:
text.insert( cmd.pos, cmd.c );
cursor = cmd.pos + 1;
break;
case Delete:
case DeleteSelection:
text.insert( cmd.pos, cmd.c );
cursor = cmd.pos;
break;
case Separator:
continue;
}
if ( until < 0 && undoState ) {
Command& next = history[undoState-1];
if ( next.type != cmd.type && next.type < RemoveSelection
&& !( cmd.type >= RemoveSelection && next.type != Separator ) )
break;
}
}
modified = ( undoState != 0 );
textDirty = TRUE;
}
inline void redo() {
if ( !isRedoAvailable() )
return;
deselect();
while ( undoState < (int)history.size() ) {
Command& cmd = history[undoState++];
switch ( cmd.type ) {
case Insert:
text.insert( cmd.pos, cmd.c );
cursor = cmd.pos + 1;
break;
case Remove:
case Delete:
case RemoveSelection:
case DeleteSelection:
text.remove( cmd.pos, 1 );
cursor = cmd.pos;
break;
case Separator:
continue;
}
if ( undoState < (int)history.size() ) {
Command& next = history[undoState];
if ( next.type != cmd.type && cmd.type < RemoveSelection
&& !( next.type >= RemoveSelection && cmd.type != Separator ) )
break;
}
}
textDirty = TRUE;
}
#endif /* SECURE_NO_UNDO */
inline bool isUndoAvailable() const { return !readOnly && undoState; }
inline bool isRedoAvailable() const { return !readOnly && undoState < (int)history.size(); }
// bidi
inline bool isRightToLeft() const { return direction==TQChar::DirON?text.isRightToLeft():(direction==TQChar::DirR); }
// selection
int selstart, selend;
inline bool allSelected() const { return !text.isEmpty() && selstart == 0 && selend == (int)text.length(); }
inline bool hasSelectedText() const { return !text.isEmpty() && selend > selstart; }
inline void deselect() { selDirty |= (selend > selstart); selstart = selend = 0; }
void removeSelectedText();
#ifndef QT_NO_CLIPBOARD
void copy( bool clipboard = TRUE ) const;
#endif
inline bool inSelection( int x ) const
{ if ( selstart >= selend ) return FALSE;
int pos = xToPos( x, TQTextItem::OnCharacters ); return pos >= selstart && pos < selend; }
// input methods
int imstart, imend, imselstart, imselend;
// complex text layout
TQTextLayout textLayout;
void updateTextLayout();
void moveCursor( int pos, bool mark = FALSE );
void setText( const SecTQString& txt );
int xToPos( int x, TQTextItem::CursorPosition = TQTextItem::BetweenCharacters ) const;
inline int visualAlignment() const { return alignment ? alignment : int( isRightToLeft() ? AlignRight : AlignLeft ); }
TQRect cursorRect() const;
void updateMicroFocusHint();
};
/*!
\class SecTQLineEdit
\brief The SecTQLineEdit widget is a one-line text editor.
\ingroup basic
\mainclass
A line edit allows the user to enter and edit a single line of
plain text with a useful collection of editing functions,
including undo and redo, cut and paste,
By changing the echoMode() of a line edit, it can also be used as
a "write-only" field, for inputs such as passwords.
The length of the text can be constrained to maxLength().
A related class is TQTextEdit which allows multi-line, rich-text
editing.
You can change the text with setText() or insert(). The text is
retrieved with text(); the displayed text (which may be different,
see \l{EchoMode}) is retrieved with displayText(). Text can be
selected with setSelection() or selectAll(), and the selection can
be cut(), copy()ied and paste()d. The text can be aligned with
setAlignment().
When the text changes the textChanged() signal is emitted; when
the Return or Enter key is pressed the returnPressed() signal is
emitted.
When the text changes the textModified() signal is emitted in all
cases.
By default, SecTQLineEdits have a frame as specified by the Windows
and Motif style guides; you can turn it off by calling
setFrame(FALSE).
The default key bindings are described below.
\target desc
\table
\header \i Keypress \i Action
\row \i Left Arrow \i Moves the cursor one character to the left.
\row \i Shift+Left Arrow \i Moves and selects text one character to the left.
\row \i Right Arrow \i Moves the cursor one character to the right.
\row \i Shift+Right Arrow \i Moves and selects text one character to the right.
\row \i Home \i Moves the cursor to the beginning of the line.
\row \i End \i Moves the cursor to the end of the line.
\row \i Backspace \i Deletes the character to the left of the cursor.
\row \i Ctrl+Backspace \i Deletes the word to the left of the cursor.
\row \i Delete \i Deletes the character to the right of the cursor.
\row \i Ctrl+Delete \i Deletes the word to the right of the cursor.
\row \i Ctrl+A \i Moves the cursor to the beginning of the line.
\row \i Ctrl+B \i Moves the cursor one character to the left.
\row \i Ctrl+C \i Copies the selected text to the clipboard.
(Windows also supports Ctrl+Insert for this operation.)
\row \i Ctrl+D \i Deletes the character to the right of the cursor.
\row \i Ctrl+E \i Moves the cursor to the end of the line.
\row \i Ctrl+F \i Moves the cursor one character to the right.
\row \i Ctrl+H \i Deletes the character to the left of the cursor.
\row \i Ctrl+K \i Deletes to the end of the line.
\row \i Ctrl+V \i Pastes the clipboard text into line edit.
(Windows also supports Shift+Insert for this operation.)
\row \i Ctrl+X \i Deletes the selected text and copies it to the clipboard.
(Windows also supports Shift+Delete for this operation.)
\row \i Ctrl+Z \i Undoes the last operation.
\row \i Ctrl+Y \i Redoes the last undone operation.
\endtable
Any other key sequence that represents a valid character, will
cause the character to be inserted into the line edit.
<img src=qlined-m.png> <img src=qlined-w.png>
\sa TQTextEdit TQLabel TQComboBox
\link guibooks.html#fowler GUI Design Handbook: Field, Entry\endlink
*/
/*!
\fn void SecTQLineEdit::textChanged( const SecTQString& )
This signal is emitted whenever the text changes. The argument is
the new text.
*/
/*!
\fn void SecTQLineEdit::selectionChanged()
This signal is emitted whenever the selection changes.
\sa hasSelectedText(), selectedText()
*/
/*!
\fn void SecTQLineEdit::lostFocus()
This signal is emitted when the line edit has lost focus.
\sa hasFocus(), TQWidget::focusInEvent(), TQWidget::focusOutEvent()
*/
/*!
Constructs a line edit with no text.
The maximum text length is set to 32767 characters.
The \a parent and \a name arguments are sent to the TQWidget constructor.
\sa setText(), setMaxLength()
*/
SecTQLineEdit::SecTQLineEdit( TQWidget* parent, const char* name )
: TQFrame( parent, name, WNoAutoErase ), d(new SecTQLineEditPrivate( this ))
{
d->init( SecTQString::null );
}
/*!
Constructs a line edit containing the text \a contents.
The cursor position is set to the end of the line and the maximum
text length to 32767 characters.
The \a parent and \a name arguments are sent to the TQWidget
constructor.
\sa text(), setMaxLength()
*/
SecTQLineEdit::SecTQLineEdit( const SecTQString& contents, TQWidget* parent, const char* name )
: TQFrame( parent, name, WNoAutoErase ), d(new SecTQLineEditPrivate( this ))
{
d->init( contents );
}
/*!
Destroys the line edit.
*/
SecTQLineEdit::~SecTQLineEdit()
{
delete d;
}
/*!
\property SecTQLineEdit::text
\brief the line edit's text
Setting this property clears the selection, clears the undo/redo
history, moves the cursor to the end of the line and resets the
\c modified property to FALSE.
The text is truncated to maxLength() length.
\sa insert()
*/
SecTQString SecTQLineEdit::text() const
{
return ( d->text.isNull() ? SecTQString ("") : d->text );
}
void SecTQLineEdit::setText( const SecTQString& text)
{
resetInputContext();
d->setText( text );
d->modified = FALSE;
d->finishChange( -1, FALSE );
}
/*!
\property SecTQLineEdit::displayText
\brief the displayed text
If \c EchoMode is \c Normal this returns the same as text(); if
\c EchoMode is \c Password it returns a string of asterisks
text().length() characters long, e.g. "******"; if \c EchoMode is
\c NoEcho returns an empty string, "".
\sa setEchoMode() text() EchoMode
*/
TQString SecTQLineEdit::displayText() const
{
if ( d->echoMode == NoEcho )
return TQString::fromLatin1("");
TQChar pwd_char = TQChar (style().styleHint( TQStyle::SH_LineEdit_PasswordCharacter, this));
TQString res;
res.fill (pwd_char, d->text.length ());
return res;
}
/*!
\property SecTQLineEdit::maxLength
\brief the maximum permitted length of the text
If the text is too long, it is truncated at the limit.
If truncation occurs any selected text will be unselected, the
cursor position is set to 0 and the first part of the string is
shown.
*/
int SecTQLineEdit::maxLength() const
{
return d->maxLength;
}
void SecTQLineEdit::setMaxLength( int maxLength )
{
d->maxLength = maxLength;
setText( d->text );
}
/*!
\property SecTQLineEdit::frame
\brief whether the line edit draws itself with a frame
If enabled (the default) the line edit draws itself inside a
two-pixel frame, otherwise the line edit draws itself without any
frame.
*/
bool SecTQLineEdit::frame() const
{
return frameShape() != NoFrame;
}
void SecTQLineEdit::setFrame( bool enable )
{
setFrameStyle( enable ? ( LineEditPanel | Sunken ) : NoFrame );
}
/*!
\enum SecTQLineEdit::EchoMode
This enum type describes how a line edit should display its
contents.
\value Normal Display characters as they are entered. This is the
default.
\value NoEcho Do not display anything. This may be appropriate
for passwords where even the length of the
password should be kept secret.
\value Password Display asterisks instead of the characters
actually entered.
\sa setEchoMode() echoMode()
*/
/*!
\property SecTQLineEdit::echoMode
\brief the line edit's echo mode
The initial setting is \c Normal, but SecTQLineEdit also supports \c
NoEcho and \c Password modes.
The widget's display and the ability to copy the text is affected
by this setting.
\sa EchoMode displayText()
*/
SecTQLineEdit::EchoMode SecTQLineEdit::echoMode() const
{
return (EchoMode) d->echoMode;
}
void SecTQLineEdit::setEchoMode( EchoMode mode )
{
d->echoMode = mode;
d->updateTextLayout();
update();
}
/*!
Returns a recommended size for the widget.
The width returned, in pixels, is usually enough for about 15 to
20 characters.
*/
TQSize SecTQLineEdit::sizeHint() const
{
constPolish();
TQFontMetrics fm( font() );
int h = TQMAX(fm.lineSpacing(), 14) + 2*innerMargin;
int w = fm.width( 'x' ) * 17; // "some"
int m = frameWidth() * 2;
return (style().sizeFromContents(TQStyle::CT_LineEdit, this,
TQSize( w + m, h + m ).
expandedTo(TQApplication::globalStrut())));
}
/*!
Returns a minimum size for the line edit.
The width returned is enough for at least one character.
*/
TQSize SecTQLineEdit::minimumSizeHint() const
{
constPolish();
TQFontMetrics fm = fontMetrics();
int h = fm.height() + TQMAX( 2*innerMargin, fm.leading() );
int w = fm.maxWidth();
int m = frameWidth() * 2;
return TQSize( w + m, h + m );
}
/*!
\property SecTQLineEdit::cursorPosition
\brief the current cursor position for this line edit
Setting the cursor position causes a repaint when appropriate.
*/
int SecTQLineEdit::cursorPosition() const
{
return d->cursor;
}
void SecTQLineEdit::setCursorPosition( int pos )
{
if ( pos <= (int) d->text.length() )
d->moveCursor( pos );
}
/*!
\property SecTQLineEdit::alignment
\brief the alignment of the line edit
Possible Values are \c TQt::AlignAuto, \c TQt::AlignLeft, \c
TQt::AlignRight and \c TQt::AlignHCenter.
Attempting to set the alignment to an illegal flag combination
does nothing.
\sa TQt::AlignmentFlags
*/
int SecTQLineEdit::alignment() const
{
return d->alignment;
}
void SecTQLineEdit::setAlignment( int flag )
{
d->alignment = flag & 0x7;
update();
}
/*!
\obsolete
\fn void SecTQLineEdit::cursorRight( bool, int )
Use cursorForward() instead.
\sa cursorForward()
*/
/*!
\obsolete
\fn void SecTQLineEdit::cursorLeft( bool, int )
For compatibilty with older applications only. Use cursorBackward()
instead.
\sa cursorBackward()
*/
/*!
Moves the cursor forward \a steps characters. If \a mark is TRUE
each character moved over is added to the selection; if \a mark is
FALSE the selection is cleared.
\sa cursorBackward()
*/
void SecTQLineEdit::cursorForward( bool mark, int steps )
{
int cursor = d->cursor;
if ( steps > 0 ) {
while( steps-- )
cursor = d->textLayout.nextCursorPosition( cursor );
} else if ( steps < 0 ) {
while ( steps++ )
cursor = d->textLayout.previousCursorPosition( cursor );
}
d->moveCursor( cursor, mark );
}
/*!
Moves the cursor back \a steps characters. If \a mark is TRUE each
character moved over is added to the selection; if \a mark is
FALSE the selection is cleared.
\sa cursorForward()
*/
void SecTQLineEdit::cursorBackward( bool mark, int steps )
{
cursorForward( mark, -steps );
}
/*!
Moves the cursor one word forward. If \a mark is TRUE, the word is
also selected.
\sa cursorWordBackward()
*/
void SecTQLineEdit::cursorWordForward( bool mark )
{
d->moveCursor( d->textLayout.nextCursorPosition(d->cursor, TQTextLayout::SkipWords), mark );
}
/*!
Moves the cursor one word backward. If \a mark is TRUE, the word
is also selected.
\sa cursorWordForward()
*/
void SecTQLineEdit::cursorWordBackward( bool mark )
{
d->moveCursor( d->textLayout.previousCursorPosition(d->cursor, TQTextLayout::SkipWords), mark );
}
/*!
If no text is selected, deletes the character to the left of the
text cursor and moves the cursor one position to the left. If any
text is selected, the cursor is moved to the beginning of the
selected text and the selected text is deleted.
\sa del()
*/
void SecTQLineEdit::backspace()
{
int priorState = d->undoState;
if ( d->hasSelectedText() ) {
d->removeSelectedText();
} else if ( d->cursor ) {
--d->cursor;
d->del( TRUE );
}
d->finishChange( priorState );
emit backspacePressed();
}
/*!
If no text is selected, deletes the character to the right of the
text cursor. If any text is selected, the cursor is moved to the
beginning of the selected text and the selected text is deleted.
\sa backspace()
*/
void SecTQLineEdit::del()
{
int priorState = d->undoState;
if ( d->hasSelectedText() ) {
d->removeSelectedText();
} else {
int n = d->textLayout.nextCursorPosition( d->cursor ) - d->cursor;
while ( n-- )
d->del();
}
d->finishChange( priorState );
}
/*!
Moves the text cursor to the beginning of the line unless it is
already there. If \a mark is TRUE, text is selected towards the
first position; otherwise, any selected text is unselected if the
cursor is moved.
\sa end()
*/
void SecTQLineEdit::home( bool mark )
{
d->moveCursor( 0, mark );
}
/*!
Moves the text cursor to the end of the line unless it is already
there. If \a mark is TRUE, text is selected towards the last
position; otherwise, any selected text is unselected if the cursor
is moved.
\sa home()
*/
void SecTQLineEdit::end( bool mark )
{
d->moveCursor( d->text.length(), mark );
}
/*!
\property SecTQLineEdit::modified
\brief whether the line edit's contents has been modified by the user
The modified flag is never read by SecTQLineEdit; it has a default value
of FALSE and is changed to TRUE whenever the user changes the line
edit's contents.
This is useful for things that need to provide a default value but
do not start out knowing what the default should be (perhaps it
depends on other fields on the form). Start the line edit without
the best default, and when the default is known, if modified()
returns FALSE (the user hasn't entered any text), insert the
default value.
Calling clearModified() or setText() resets the modified flag to
FALSE.
*/
bool SecTQLineEdit::isModified() const
{
return d->modified;
}
/*!
Resets the modified flag to FALSE.
\sa isModified()
*/
void SecTQLineEdit::clearModified()
{
d->modified = FALSE;
d->history.clear();
d->undoState = 0;
}
/*!
\obsolete
\property SecTQLineEdit::edited
\brief whether the line edit has been edited. Use modified instead.
*/
bool SecTQLineEdit::edited() const { return d->modified; }
void SecTQLineEdit::setEdited( bool on ) { d->modified = on; }
/*!
\obsolete
\property SecTQLineEdit::hasMarkedText
\brief whether part of the text has been selected by the user. Use hasSelectedText instead.
*/
/*!
\property SecTQLineEdit::hasSelectedText
\brief whether there is any text selected
hasSelectedText() returns TRUE if some or all of the text has been
selected by the user; otherwise returns FALSE.
\sa selectedText()
*/
bool SecTQLineEdit::hasSelectedText() const
{
return d->hasSelectedText();
}
/*!
\obsolete
\property SecTQLineEdit::markedText
\brief the text selected by the user. Use selectedText instead.
*/
/*!
\property SecTQLineEdit::selectedText
\brief the selected text
If there is no selected text this property's value is
TQString::null.
\sa hasSelectedText()
*/
SecTQString SecTQLineEdit::selectedText() const
{
if ( d->hasSelectedText() )
return d->text.mid( d->selstart, d->selend - d->selstart );
return SecTQString::null;
}
/*!
selectionStart() returns the index of the first selected character in the
line edit or -1 if no text is selected.
\sa selectedText()
*/
int SecTQLineEdit::selectionStart() const
{
return d->hasSelectedText() ? d->selstart : -1;
}
/*!
Selects text from position \a start and for \a length characters.
\sa deselect() selectAll()
*/
void SecTQLineEdit::setSelection( int start, int length )
{
if ( start < 0 || start > (int)d->text.length() || length < 0 ) {
d->selstart = d->selend = 0;
} else {
d->selstart = start;
d->selend = TQMIN( start + length, (int)d->text.length() );
d->cursor = d->selend;
}
update();
}
/*!
\property SecTQLineEdit::undoAvailable
\brief whether undo is available
*/
bool SecTQLineEdit::isUndoAvailable() const
{
return d->isUndoAvailable();
}
/*!
\property SecTQLineEdit::redoAvailable
\brief whether redo is available
*/
bool SecTQLineEdit::isRedoAvailable() const
{
return d->isRedoAvailable();
}
/*!
Selects all the text (i.e. highlights it) and moves the cursor to
the end. This is useful when a default value has been inserted
because if the user types before clicking on the widget, the
selected text will be deleted.
\sa setSelection() deselect()
*/
void SecTQLineEdit::selectAll()
{
d->selstart = d->selend = d->cursor = 0;
d->moveCursor( d->text.length(), TRUE );
}
/*!
Deselects any selected text.
\sa setSelection() selectAll()
*/
void SecTQLineEdit::deselect()
{
d->deselect();
d->finishChange();
}
/*!
Deletes any selected text, inserts \a newText and sets it as the
new contents of the line edit.
*/
void SecTQLineEdit::insert( const SecTQString &newText )
{
// q->resetInputContext(); //#### FIX ME IN QT
int priorState = d->undoState;
d->removeSelectedText();
d->insert( newText );
d->finishChange( priorState );
}
/*!
Clears the contents of the line edit.
*/
void SecTQLineEdit::clear()
{
int priorState = d->undoState;
resetInputContext();
d->selstart = 0;
d->selend = d->text.length();
d->removeSelectedText();
d->separate();
d->finishChange( priorState );
}
/*!
Undoes the last operation if undo is \link
SecTQLineEdit::undoAvailable available\endlink. Deselects any current
selection, and updates the selection start to the current cursor
position.
*/
void SecTQLineEdit::undo()
{
#ifndef SECURE_NO_UNDO
resetInputContext();
d->undo();
d->finishChange( -1, FALSE );
#endif
}
/*!
Redoes the last operation if redo is \link
SecTQLineEdit::redoAvailable available\endlink.
*/
void SecTQLineEdit::redo()
{
#ifndef SECURE_NO_UNDO
resetInputContext();
d->redo();
d->finishChange();
#endif
}