9 #include "RScannerWidget.h"
10 #include "ListModel.h"
13 using namespace freeRecite
;
15 RScannerWidget::RScannerWidget(QWidget
*parent
)
16 :BaseScannerWidget(parent
)
19 QSettings
settings("QFreeRecite");
21 textBrowser
->setFontFamily(settings
.value("BrowserFont").toString());
22 listModel
= new ListModel(this);
23 listView
->setModel(listModel
);
24 listView
->setAlternatingRowColors(true);
25 connect(yesButton
,SIGNAL(clicked()),
26 this,SLOT(testYes()));
27 connect(noButton
,SIGNAL(clicked()),
29 connect(showAnswerButton
,SIGNAL(clicked()),
30 this,SLOT(showAnswer()));
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(stopButton
,SIGNAL(clicked()),
40 this,SIGNAL(finished()));
43 RScannerWidget::~RScannerWidget() {
44 D_OUTPUT("~RScannerWidget()")
47 void RScannerWidget::keyPressEvent(QKeyEvent
* event
) {
48 if(event
->key() == Qt::Key_Down
&& showAnswerButton
->isVisible()) {
49 Speaker::play("buttondown");
51 Speaker::play("buttonup");
52 }else if(event
->key() == Qt::Key_Left
&& yesButton
->isVisible()) {
53 Speaker::play("buttondown");
55 Speaker::play("buttonup");
56 }else if(event
->key() == Qt::Key_Right
&& noButton
->isVisible()) {
57 Speaker::play("buttondown");
59 Speaker::play("buttonup");
60 }else if(event
->key() == Qt::Key_Up
) {
63 QWidget::keyPressEvent(event
);
67 void RScannerWidget::showNext() {
68 if(!scanner
->isValid()){
73 textBrowser
->clearHistory();
74 textBrowser
->setStyleSheet("background-image: url(:/icon/quote.png)");
75 answerLabel
->setText(scanner
->getWord().c_str());
78 showAnswerButton
->show();
81 void RScannerWidget::testYes() {
82 unsigned tmp
= scanner
->size();
84 if(tmp
!= scanner
->size()) {
85 listModel
->addToList( dictionary
.word().c_str());
86 listView
->scrollTo(listModel
->index(listModel
->rowCount() - 1));
92 void RScannerWidget::testNo() {
93 unsigned tmp
= scanner
->size();
95 //Call this to skip the current word in reverse mode.
97 if(tmp
!= scanner
->size()) {
98 listModel
->addToList( dictionary
.word().c_str());
99 listView
->scrollTo(listModel
->index(listModel
->rowCount() - 1));
105 void RScannerWidget::showAnswer() {
108 showAnswerButton
->hide();
109 QString text
= scanner
->getWord().c_str();
110 answerLabel
->setText(text
);
111 if(dictionary
.lookUp(scanner
->getWord())) {
112 if(!dictionary
.phonetics().empty()) {
113 text
.append(QString::fromUtf8("<br />["))
114 .append(QString::fromUtf8(dictionary
.phonetics().c_str()))
115 .append(QString::fromUtf8("]"));
117 text
.append("<br />");
118 text
.append(QString::fromUtf8(dictionary
.translation().c_str()));
119 if(!dictionary
.example().empty())
120 text
+= "<br /><br />Examples:<br />" + QString::fromUtf8(dictionary
.example().c_str());
122 }else { //The word can't be found!
123 text
= QString(scanner
->getWord().c_str()) + QString(" can't be found!\n");
125 textBrowser
->clearHistory();
126 textBrowser
->setStyleSheet("");
127 textBrowser
->setText(text
);
130 void RScannerWidget::pronounce(){
131 Speaker::speak(scanner
->getWord().c_str());
135 void RScannerWidget::setInfo(){
136 amountLabel
->setText(QVariant(scanner
->capability()).toString());
137 rawLabel
->setText(QVariant(scanner
->size()).toString());
138 r_timesLabel
->setText(QVariant(scanner
->times()).toString());