-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgenerictextinputdialog.cpp
90 lines (70 loc) · 2.32 KB
/
generictextinputdialog.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
#include "generictextinputdialog.h"
#include "ui_generictextinputdialog.h"
#include "writingsystem.h"
#include "databaseadapter.h"
#include <QDebug>
GenericTextInputDialog::GenericTextInputDialog(DatabaseAdapter *dbAdapter, QWidget *parent) :
QDialog(parent),
ui(new Ui::GenericTextInputDialog)
{
ui->setupUi(this);
mWritingSystems = dbAdapter->writingSystems();
connect(ui->writingSystemCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(changeCurrentWritingSystem(int)));
fillWritingSystems();
}
GenericTextInputDialog::GenericTextInputDialog(const WritingSystem & writingSystem, QWidget *parent) :
QDialog(parent),
ui(new Ui::GenericTextInputDialog)
{
ui->setupUi(this);
ui->writingSystemCombo->hide();
mWritingSystem = writingSystem;
ui->textEdit->setWritingSystem( mWritingSystem );
}
GenericTextInputDialog::GenericTextInputDialog(const TextBit & bit, QWidget *parent) :
QDialog(parent),
ui(new Ui::GenericTextInputDialog)
{
ui->setupUi(this);
ui->writingSystemCombo->hide();
mWritingSystem = bit.writingSystem();
ui->textEdit->setTextBit(bit);
}
GenericTextInputDialog::~GenericTextInputDialog()
{
delete ui;
}
void GenericTextInputDialog::suggestInput(const TextBit &bit)
{
ui->textEdit->setTextBit( bit );
ui->textEdit->setSelection( 0, ui->textEdit->text().length() );
}
void GenericTextInputDialog::fillWritingSystems()
{
for(int i=0; i<mWritingSystems.count(); i++)
ui->writingSystemCombo->addItem( tr("%1 (%2)").arg(mWritingSystems.at(i).name()).arg(mWritingSystems.at(i).flexString()), i );
}
void GenericTextInputDialog::changeCurrentWritingSystem(int index)
{
ui->textEdit->setWritingSystem( mWritingSystems.at(index) );
mWritingSystem = mWritingSystems.at(index);
}
QString GenericTextInputDialog::text() const
{
return ui->textEdit->text();
}
TextBit GenericTextInputDialog::textBit() const
{
return ui->textEdit->textBit();
}
WritingSystem GenericTextInputDialog::writingSystem() const
{
if( ui->writingSystemCombo->isVisible() )
return mWritingSystems.at( ui->writingSystemCombo->itemData( ui->writingSystemCombo->currentIndex() ).toInt() );
else
return mWritingSystem;
}
void GenericTextInputDialog::setCursorPosition(int position)
{
ui->textEdit->setCursorPosition(position);
}