forked from DFRobot/Mindplus-Desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParameter_Integer_Form.cpp
More file actions
151 lines (139 loc) · 3.73 KB
/
Parameter_Integer_Form.cpp
File metadata and controls
151 lines (139 loc) · 3.73 KB
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
#include "Parameter_Integer_Form.h"
#include <QPainter>
#include <QDebug>
#include <QKeyEvent>
#include "Animation.h"
Parameter_Integer_Form::Parameter_Integer_Form(const QRect rect, QWidget *parent)
: QWidget(parent)
, pParent_(parent)
, rect_(rect)
{
setupUi(this);
initSetting();
initGui();
}
void Parameter_Integer_Form::setValue(const QString &value)
{
value_ = value;
lineEdit->setText(value_);
}
void Parameter_Integer_Form::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
retranslateUi(this);
break;
default:
break;
}
}
void Parameter_Integer_Form::paintEvent(QPaintEvent *)
{
QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}
bool Parameter_Integer_Form::eventFilter(QObject *target, QEvent *event)
{
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if(lineEdit == target || this == target)
{
if(QEvent::KeyPress == event->type())
{
if(Qt::Key_Enter == keyEvent->key()
|| Qt::Key_Return == keyEvent->key())
{
this->on_pushButton_clicked();
}
else
{
return QWidget::eventFilter(target, event);
}
}
else
{
return QWidget::eventFilter(target, event);
}
}
else
{
return QWidget::eventFilter(target, event);
}
}
void Parameter_Integer_Form::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
QWidget *pParent_ = static_cast<QWidget *>(this->parent());
if(NULL == pParent_)
{
return;
}
offset_ = event->globalPos() - pParent_->frameGeometry().topLeft();
}
}
void Parameter_Integer_Form::mouseMoveEvent(QMouseEvent *event)
{
if (!(event->buttons() & Qt::LeftButton))
{
return;
}
if ((event->pos() - offset_).manhattanLength()
< QApplication::startDragDistance())
{
return;
}
pParent_->move(event->globalPos() - offset_);
}
void Parameter_Integer_Form::showEvent(QShowEvent *event)
{
this->setGeometry(rect_);
}
void Parameter_Integer_Form::initSetting()
{
//this->setWindowState(Qt::WindowActive);
lineEdit->installEventFilter(this);
this->installEventFilter(this);
lineEdit->setFocus();
this->setAttribute(Qt::WA_TranslucentBackground, true);
//恩原来是tool
this->setWindowFlags(Qt::FramelessWindowHint /*| Qt::Tool*/);
lineEdit->setValidator(new QDoubleValidator(-32768, 32767, 3));
connect(lineEdit, SIGNAL(textEdited(QString)), this, SLOT(slotTextEdited(QString)));
pushButton->setWindowFlags(Qt::FramelessWindowHint);
pushButton->setAttribute(Qt::WA_TranslucentBackground);
}
void Parameter_Integer_Form::initGui()
{
this->move(1, 1);
Animation::opacityAnimation(pushButton, 150, 0, 1, QEasingCurve::OutQuart);
Animation::posAnimation(pushButton, 150, pushButton->pos() + QPoint(50, 0) , pushButton->pos(), QEasingCurve::OutQuart);
}
void Parameter_Integer_Form::on_pushButton_clicked()
{
emit signalValue(value_);
close();
}
void Parameter_Integer_Form::slotTextEdited(const QString &value)
{
value_ = value;
if("" == value)
{
value_ = "0";
}
if(value_.size() > 1)
{
if(value_[0] == '.')
{
value_.insert(0, "0");
qDebug() << "添加0头的情况"<< value_;
}
else if(value_[0] == '0' && value_[1] != '.')
{
value_.remove(0,1);
qDebug() << "删除前面多余0头的情况" << value_;
}
}
}