-
Notifications
You must be signed in to change notification settings - Fork 1
/
lingtextedit.cpp
53 lines (44 loc) · 1.25 KB
/
lingtextedit.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
#include "lingtextedit.h"
#include <QProcess>
LingTextEdit::LingTextEdit(QWidget *parent) :
QTextEdit(parent)
{
}
LingTextEdit::LingTextEdit(const TextBit &bit, QWidget *parent) : QTextEdit(parent)
{
setWritingSystem( bit.writingSystem() );
setText( bit.text() );
}
TextBit LingTextEdit::textBit() const
{
return TextBit( toPlainText() , mWritingSystem );
}
void LingTextEdit::setTextBit(const TextBit &bit)
{
setWritingSystem( bit.writingSystem() );
setText( bit.text() );
}
void LingTextEdit::setWritingSystem(const WritingSystem &ws)
{
if( mWritingSystem != ws )
{
mWritingSystem = ws;
refreshStyle();
setLayoutDirection(ws.layoutDirection());
setToolTip(ws.name());
}
}
void LingTextEdit::refreshStyle()
{
if( mWritingSystem.isNull() ) return;
setStyleSheet( QString(" QTextEdit { font-family: %1; font-size: %2pt; border: 1px solid #000; }")
.arg(mWritingSystem.fontFamily()).arg( mWritingSystem.fontSize() ) );
}
void LingTextEdit::focusInEvent(QFocusEvent *e)
{
QTextEdit::focusInEvent(e);
// http://msdn.microsoft.com/en-us/goglobal/bb896001
QProcess switchInput;
switchInput.start( mWritingSystem.keyboardCommand() );
switchInput.waitForFinished();
}