-
Notifications
You must be signed in to change notification settings - Fork 0
/
consoledialog.cpp
192 lines (160 loc) · 5.31 KB
/
consoledialog.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include "consoledialog.h"
#include "ui_consoledialog.h"
#include "blockchain.h"
#include "debug_log.h"
#include "rpcthread.h"
#include <QTextCodec>
#include <QPainter>
#include <QKeyEvent>
#include <QDesktopWidget>
ConsoleDialog::ConsoleDialog(QWidget *parent) :
QDialog(parent),
cmdIndex(0),
ui(new Ui::ConsoleDialog)
{
DLOG_QT_WALLET_FUNCTION_BEGIN;
ui->setupUi(this);
setWindowFlags(Qt::FramelessWindowHint);
ui->consoleLineEdit->installEventFilter(this);
connect( Blockchain::getInstance(), SIGNAL(jsonDataUpdated(QString)), this, SLOT(jsonDataUpdated(QString)));
ui->closeBtn->setStyleSheet("QToolButton{background-image:url(:/pic/pic2/close4.png);background-repeat: repeat-xy;background-position: center;background-attachment: fixed;background-clip: padding;border-style: flat;}");
ui->consoleLineEdit->setFocus();
ui->checkBox->setStyleSheet("QCheckBox::indicator{ image:url(:/pic/pic2/checkBox_unchecked.png); }"
"QCheckBox::indicator:checked{ image:url(:/pic/cplpic/checkBox_checked.png); }");
DLOG_QT_WALLET_FUNCTION_END;
}
ConsoleDialog::~ConsoleDialog()
{
DLOG_QT_WALLET_FUNCTION_BEGIN;
qDebug() << "ConsoleDialog delete";
// Fry::getInstance()->currentDialog = NULL;
// Fry::getInstance()->removeCurrentDialogVector(this);
delete ui;
DLOG_QT_WALLET_FUNCTION_END;
}
void ConsoleDialog::pop()
{
move( (QApplication::desktop()->width() - this->width())/2 , (QApplication::desktop()->height() - this->height())/2);
exec();
}
void ConsoleDialog::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setPen(QPen(QColor(40,28,64),Qt::SolidLine));
painter.setBrush(QBrush(QColor(40,28,64),Qt::SolidPattern));
painter.drawRect(0,0,628,50);
}
bool ConsoleDialog::eventFilter(QObject *watched, QEvent *e)
{
if(watched == ui->consoleLineEdit)
{
if(e->type() == QEvent::KeyPress)
{
QKeyEvent* event = static_cast<QKeyEvent*>(e);
if( event->key() == Qt::Key_Up)
{
cmdIndex--;
if( cmdIndex >= 0 && cmdIndex <= cmdVector.size() - 1)
{
ui->consoleLineEdit->setText(cmdVector.at(cmdIndex));
}
if( cmdIndex < 0)
{
cmdIndex = 0;
}
}
else if( event->key() == Qt::Key_Down)
{
cmdIndex++;
if( cmdIndex >= 0 && cmdIndex <= cmdVector.size() - 1)
{
ui->consoleLineEdit->setText(cmdVector.at(cmdIndex));
}
if( cmdIndex > cmdVector.size() - 1)
{
cmdIndex = cmdVector.size() - 1;
}
}
}
}
return QWidget::eventFilter(watched,e);
}
void ConsoleDialog::on_closeBtn_clicked()
{
close();
}
void ConsoleDialog::mousePressEvent(QMouseEvent *event)
{
if(event->button() == Qt::LeftButton)
{
mouse_press = true;
// //鼠标相对于窗体的位置(或者使用event->globalPos() - this->pos())
move_point = event->pos();;
}
}
void ConsoleDialog::mouseMoveEvent(QMouseEvent *event)
{
// //若鼠标左键被按下
if(mouse_press)
{
// //鼠标相对于屏幕的位置
QPoint move_pos = event->globalPos();
// //移动主窗体位置
this->move(move_pos - move_point);
}
}
void ConsoleDialog::mouseReleaseEvent(QMouseEvent *)
{
mouse_press = false;
}
void ConsoleDialog::on_consoleLineEdit_returnPressed()
{
DLOG_QT_WALLET_FUNCTION_BEGIN;
QString command = ui->consoleLineEdit->text().simplified();
if (command.split(' ').at(0) == "stop")
{
return;
}
if( !command.isEmpty())
{
cmdVector.removeAll(ui->consoleLineEdit->text());
cmdVector.append(ui->consoleLineEdit->text());
cmdIndex = cmdVector.size();
}
if( ui->checkBox->isChecked())
{
QString str = ui->consoleLineEdit->text();
QStringList paramaters = str.split(' ');
QString command = paramaters.at(0);
paramaters.removeFirst();
if( paramaters.isEmpty()) paramaters << "";
Blockchain::getInstance()->postRPC( toJsonFormat( "console_" + str, command, paramaters ));
ui->consoleLineEdit->clear();
return;
}
QString str = ui->consoleLineEdit->text() + '\n';
Blockchain::getInstance()->write(str);
QString result = Blockchain::getInstance()->read();
ui->consoleBrowser->append(">>>" + str);
ui->consoleBrowser->append(result);
ui->consoleLineEdit->clear();
DLOG_QT_WALLET_FUNCTION_END;
}
//void ConsoleDialog::setVisible(bool visiable)
//{
// QWidget::setVisible(visiable);
//}
void ConsoleDialog::jsonDataUpdated(QString id)
{
if( id.startsWith("console_"))
{
ui->consoleBrowser->append(">>>" + id.mid(8));
ui->consoleBrowser->append( Blockchain::getInstance()->jsonDataValue(id));
ui->consoleBrowser->append("\n");
return;
}
}
void ConsoleDialog::on_clearBtn_clicked()
{
ui->consoleBrowser->clear();
}