-
Notifications
You must be signed in to change notification settings - Fork 0
/
textEdit.cpp
108 lines (87 loc) · 2.22 KB
/
textEdit.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
//textEdit.cpp
#include "textEdit.h"
MyMultiLineEdit::MyMultiLineEdit( QWidget* parent, const char* name ) : QMultiLineEdit( parent, name )
{}
bool MyMultiLineEdit::myHasMarkedText()
{
return this->hasMarkedText();
}
void MyMultiLineEdit::myDel()
{
this->del();
}
void MyMultiLineEdit::setFound( wchar_t uni )
{
if( uni == L'\b' )
{
this->backspace();
}
else if( uni == L'\r' )
{
this->newLine();
}
else
{
this->insert( QString( QChar( uni ) ) );
}
}
void MyMultiLineEdit::myEnd()
{
this->setCursorPosition( this->numLines() - 1, this->lineLength( this->numLines() - 1 ) );
}
textEdit::textEdit( QWidget* parent, const char* name ) : QWidget( parent, name )
{
mainLay = new QVBoxLayout( this );
mainLay->setSpacing( 2 );
mainLay->setMargin( 3 );
//text box
textbox = new MyMultiLineEdit ( this, "textbox" );
textbox->setUndoEnabled( TRUE );
textbox->setWordWrap( QMultiLineEdit::WidgetWidth );
textbox->setWrapPolicy( QMultiLineEdit::AtWhiteSpace );
mainLay->addWidget( textbox );
//spacer
topShim = new QSpacerItem( 10, 5, QSizePolicy::Expanding, QSizePolicy::Fixed );
mainLay->addItem( topShim );
//draw area label
textLab = new QLabel( QString( "Handwriting Area" ), this, "textLab" );
mainLay->addWidget( textLab );
//draw area
entry = new recogArea( this, "entry" );
mainLay->addWidget( entry );
//spacer
bottomShim = new QSpacerItem( 10, 5, QSizePolicy::Expanding, QSizePolicy::Fixed );
mainLay->addItem( bottomShim );
//signals and slots connections
connect( entry, SIGNAL( found( wchar_t ) ), textbox, SLOT( setFound( wchar_t ) ) );
//set focus
textbox->setFocus();
}
textEdit::~textEdit()
{
delete textbox;
delete entry;
}
void textEdit::setText( QString newtext )
{
textbox->setText( newtext );
textbox->myEnd();
textbox->setEdited( false );
entry->setText();
}
QMultiLineEdit* textEdit::getMyMultiLineEdit()
{
return textbox;
}
recogArea* textEdit::getRecogArea()
{
return entry;
}
QSize textEdit::sizeHint() const
{
return QSize( 210, 290 );
}
QSizePolicy textEdit::sizePolicy() const
{
return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
}