9 #include "ScannerWidget.h"
10 #include "ListModel.h"
13 using namespace freeRecite
;
15 ScannerWidget::ScannerWidget(QWidget
*parent
)
16 :BaseScannerWidget(parent
)
19 QSettings
settings("QFreeRecite");
20 listModel
= new ListModel(this);
21 listView
->setModel(listModel
);
22 listView
->setAlternatingRowColors(true);
23 QFont
font(settings
.value("FontFamily").toString(),
24 settings
.value("FontSize").toInt(),
25 ( settings
.value("FontBold").toBool()
26 ? QFont::Bold
: QFont::Normal
),
27 settings
.value("FontItalic").toBool() );
28 textBrowser
->setCurrentFont(font
);
29 connect(lineEdit
,SIGNAL(returnPressed()),
30 this,SLOT(lineReturned()));
31 connect(addButton
,SIGNAL(clicked()),
33 connect(deleteButton
,SIGNAL(clicked()),
35 connect(modifyButton
,SIGNAL(clicked()),
37 connect(pronounceButton
,SIGNAL(clicked()),
38 this,SLOT(pronounce()));
39 connect(hintButton
,SIGNAL(clicked()),
41 connect(stopButton
,SIGNAL(clicked()),
42 this,SIGNAL(finished()));
45 ScannerWidget::~ScannerWidget() {
46 D_OUTPUT("~ScannerWidget()")
49 void ScannerWidget::lineReturned() {
51 if(lineEdit
->isFreeze()) {
58 void ScannerWidget::showNext() {
60 if(!scanner
->isValid()){
64 lineEdit
->setFreeze(false);
65 answerLabel
->setText(QString(""));
66 if(dictionary
.lookUp(scanner
->getWord())) {
67 text
= QString::fromUtf8(dictionary
.translation().c_str());
68 if(!dictionary
.example().empty())
69 text
+= "<br /><br />Examples:<br />" + QString::fromUtf8(dictionary
.example().c_str());
71 text
= QString(scanner
->getWord().c_str())
72 + QString(" can't be found!");
74 text
.replace(scanner
->getWord().c_str(),"~",Qt::CaseInsensitive
);
75 textBrowser
->setText(text
);
78 void ScannerWidget::showAnswer() {
79 lineEdit
->setFreeze(true);
80 if(lineEdit
->text().toStdString() != scanner
->getWord()) {
81 Speaker::play("fail");
82 answerLabel
->setText("<font color=red>" +
83 QString(scanner
->getWord().c_str()) +
87 answerLabel
->setText("<font color=green>" +
88 QString(scanner
->getWord().c_str()) +
92 if(dictionary
.lookUp(scanner
->getWord())) {
93 if(!dictionary
.phonetics().empty()) {
94 text
.append(dictionary
.word().c_str())
95 .append(QString::fromUtf8("<br />["))
96 .append(QString::fromUtf8(dictionary
.phonetics().c_str()))
97 .append(QString::fromUtf8("]"));
98 text
.append("<br />");
101 text
.append(QString::fromUtf8(dictionary
.translation().c_str()));
102 if(!dictionary
.example().empty())
103 text
.append("<br /><br />Examples:<br />")
104 .append(QString::fromUtf8(dictionary
.example().c_str()));
106 text
= QString(scanner
->getWord().c_str())
107 + QString(tr(" can't be found!\n"));
109 textBrowser
->clearHistory();
110 if(lineEdit
->text().toStdString() != scanner
->getWord())
111 textBrowser
->setText("<font color=red>" + text
+ "</font>");
113 textBrowser
->setText(text
);
114 unsigned tmp
= scanner
->size();
115 scanner
->test(lineEdit
->text().toStdString() == scanner
->getWord());
116 if(tmp
!= scanner
->size()) {
117 listModel
->addToList( dictionary
.word().c_str());
118 listView
->scrollTo(listModel
->index(listModel
->rowCount() - 1));
123 void ScannerWidget::setInfo(){
124 amountLabel
->setText(QVariant(scanner
->capability()).toString());
125 rawLabel
->setText(QVariant(scanner
->size()).toString());
126 r_timesLabel
->setText(QVariant(scanner
->times()).toString());
129 void ScannerWidget::pronounce(){
130 Speaker::speak(dictionary
.word().c_str());
133 void ScannerWidget::hint() {
134 if(!scanner
->isValid() || lineEdit
->isFreeze())
136 QString
hintText("");
137 for(unsigned i
=0,j
=4; i
< scanner
->getWord().size(); ++i
,++j
) {
138 if(j
== 4 || scanner
->getWord()[i
] == ' ') {
139 hintText
.append(QChar(scanner
->getWord().at(i
)));
140 if(scanner
->getWord()[i
] == ' ')
141 hintText
.append(QChar(scanner
->getWord().at(++i
)));
145 hintText
.append(QChar('-'));
147 answerLabel
->setText("<font color=blue>" +