-
Notifications
You must be signed in to change notification settings - Fork 0
/
widgetdefinition.cpp
98 lines (83 loc) · 2.38 KB
/
widgetdefinition.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
#include "widgetdefinition.h"
#include "ui_widgetdefinition.h"
#include <QMessageBox>
#include "App.h"
WidgetDefinition::WidgetDefinition(QWidget *parent) :
QWidget(parent),
ui(new Ui::WidgetDefinition)
{
ui->setupUi(this);
widgetSearch = reinterpret_cast<WidgetSearch*>(parent);
}
WidgetDefinition::~WidgetDefinition()
{
delete ui;
}
void WidgetDefinition::setDefinition(const QString &definition)
{
ui->labelDefinition->setText(definition);
}
void WidgetDefinition::setWord(const QString &word)
{
ui->labelWord->setText(word);
}
void WidgetDefinition::openDialogEditWord()
{
QString word = ui->labelWord->text();
QString definition = ui->labelDefinition->text();
DialogEditWord dialogEditWord;
dialogEditWord.setDataEditWord(word, definition);
dialogEditWord.exec();
}
void WidgetDefinition::on_pushButtonEditWord_clicked()
{
openDialogEditWord();
QString word = ui->labelWord->text();
QString definition = App::get().getDefinition(word);
ui->labelDefinition->setText(definition);
}
void WidgetDefinition::setFavoriteState(const QString &word)
{
bool state = App::get().isWordInFavorite(word);
if (state)
{
ui->pushButtonSetFavorite->setText("Unlike");
}
else
{
ui->pushButtonSetFavorite->setText("Like");
}
}
const QString &WidgetDefinition::getWord() const
{
return QString(ui->labelWord->text());
}
void WidgetDefinition::on_pushButtonSetFavorite_clicked()
{
QString word = ui->labelWord->text();
bool state = App::get().isWordInFavorite(word);
if (state)
{
App::get().removeWordFromFavorite(word);
ui->pushButtonSetFavorite->setText("Like");
}
else
{
App::get().addWordToFavorite(word);
ui->pushButtonSetFavorite->setText("Unike");
}
}
void WidgetDefinition::on_pushButtonRemoveWord_clicked()
{
QMessageBox::StandardButton confirm = QMessageBox::question(this, "Title", "Are you sure to remove this word",
QMessageBox::Yes | QMessageBox::No);
if (confirm == QMessageBox::Yes)
{
QString removeWord = ui->labelWord->text();
App::get().removeWord(removeWord);
widgetSearch->clearLineEditSearch();
widgetSearch->removeCurrentTabDefinition();
widgetSearch->clearWidgetHistory();
widgetSearch->loadHistory();
}
}