-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
89 lines (68 loc) · 1.82 KB
/
mainwindow.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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
setWindowTitle("吞食孔明传金手指 支持游戏版本:v4.3");
setFixedSize(810,620);
setWindowIcon(QIcon(":/images/1.jpg"));
try {
m_sundry = Sundry::getInstance();
getGoldValue();
} catch (RuntimeException &runtime) {
QMessageBox::critical(this,"Error",runtime.getMessage());
}
m_goldTimerId = startTimer(1000);
ui->lineEditGold->installEventFilter(this);
}
void MainWindow::getGoldValue()
{
ui->lineEditGold->setText(QString::number(m_sundry->getGoldValue()));
ui->lineEditGold->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
}
void MainWindow::timerEvent(QTimerEvent *e)
{
try {
if (e->timerId() == m_goldTimerId)
{
getGoldValue();
}
} catch (RuntimeException &runtime) {
qDebug() << runtime.getMessage();
}
}
bool MainWindow::eventFilter(QObject *obj, QEvent *e)
{
if (obj == ui->lineEditGold && e->type() == QEvent::MouseButtonPress && m_goldTimerId)
{
killTimer(m_goldTimerId);
m_goldTimerId = 0;
return true;
}
if (obj == ui->lineEditGold && e->type() == QEvent::Enter && !m_goldTimerId)
{
m_goldTimerId = startTimer(1000);
return true;
}
return QWidget::eventFilter(obj,e);
}
void MainWindow::on_lineEditGold_editingFinished()
{
if (!m_goldTimerId)
{
m_goldTimerId = startTimer(1000);
}
try {
m_sundry->setGoldValue(ui->lineEditGold->text().toInt());
} catch (RuntimeException &runtime) {
qDebug() << runtime.getMessage();
}
}
MainWindow::~MainWindow()
{
delete ui;
}