-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditor.cpp
174 lines (156 loc) · 5.11 KB
/
editor.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
#include "editor.h"
#include "ui_editor.h"
#include <QFileDialog>
#include <QMessageBox>
#include <QDir>
#include <QFile>
#include <QMouseEvent>
#include <QThread>
#include <QGraphicsOpacityEffect>
#include <QPropertyAnimation>
editor::editor(QWidget *parent) :
QDialog(parent),
ui(new Ui::editor)
{
ui->setupUi(this);
ui->tutor->hide();
ui->ok->hide();
this->setWindowFlag(Qt::FramelessWindowHint, true);
setWindowOpacity(0.0);
QPropertyAnimation *a = new QPropertyAnimation(this,"windowOpacity");
a->setStartValue(0.0);
a->setDuration(400);
a->setEndValue(1.0);
a->setEasingCurve(QEasingCurve::InSine);
a->start(QPropertyAnimation::DeleteWhenStopped);
extern QString file_name;
if(file_name.mid(file_name.size()-3, 3) == "txt") {
extern QString all_str;
ui->textEdit->setText(all_str);
}
}
editor::~editor()
{
delete ui;
}
void editor::on_apply_clicked()
{
QString file_path, text;
file_path = QFileDialog::getSaveFileName( this,
tr("Сохранить файл как"),
QDir::homePath(),
tr("Slicer file (*.slc)")
);
QFile file(file_path);
if(file.open(QIODevice::ReadWrite)) {
QTextStream in (&file);
text = ui->textEdit->toPlainText();
Replace(text);
file.write(text.toLocal8Bit());
}
QPropertyAnimation *a = new QPropertyAnimation(this,"windowOpacity");
a->setStartValue(1.0);
a->setDuration(400);
a->setEndValue(0.0);
a->setEasingCurve(QEasingCurve::InSine);
a->start(QPropertyAnimation::DeleteWhenStopped);
this->parentWidget()->setWindowOpacity(1.0);
this->parentWidget()->move(geometry().x(),geometry().y());
this->parentWidget()->show();
connect(a,SIGNAL(finished()),this,SLOT(close()));
}
void editor::on_swish_clicked()
{
QPropertyAnimation *a = new QPropertyAnimation(this,"windowOpacity");
a->setStartValue(1.0);
a->setDuration(400);
a->setEndValue(0.0);
a->setEasingCurve(QEasingCurve::InSine);
a->start(QPropertyAnimation::DeleteWhenStopped);
this->parentWidget()->setWindowOpacity(1.0);
this->parentWidget()->move(geometry().x(),geometry().y());
this->parentWidget()->show();
connect(a,SIGNAL(finished()),this,SLOT(close()));
}
void editor::on_pull_clicked()
{
QPropertyAnimation *a = new QPropertyAnimation(this,"windowOpacity");
a->setStartValue(1.0);
a->setDuration(200);
a->setEndValue(0.5);
a->setEasingCurve(QEasingCurve::InSine);
a->start(QPropertyAnimation::DeleteWhenStopped);
ui->textEdit->hide();
ui->pull->hide();
ui->apply->hide();
ui->ok->show();
ui->tutor->show();
a->setStartValue(0.5);
a->setDuration(200);
a->setEndValue(1.0);
a->setEasingCurve(QEasingCurve::InSine);
this->parentWidget()->show();
a->start(QPropertyAnimation::DeleteWhenStopped);
}
void editor::on_ok_clicked()
{
QPropertyAnimation *a = new QPropertyAnimation(this,"windowOpacity");
a->setStartValue(1.0);
a->setDuration(200);
a->setEndValue(0.5);
a->setEasingCurve(QEasingCurve::InSine);
a->start(QPropertyAnimation::DeleteWhenStopped);
ui->textEdit->show();
ui->pull->show();
ui->apply->show();
ui->ok->hide();
ui->tutor->hide();
a->setStartValue(0.5);
a->setDuration(200);
a->setEndValue(1.0);
a->setEasingCurve(QEasingCurve::InSine);
a->start(QPropertyAnimation::DeleteWhenStopped);
}
void editor::mousePressEvent(QMouseEvent *event) {
m_nMouseClick_X_Coordinate = event->position().x();
m_nMouseClick_Y_Coordinate = event->position().y();
qDebug() << m_nMouseClick_X_Coordinate << " -settings- " << m_nMouseClick_Y_Coordinate;
}
void editor::mouseMoveEvent(QMouseEvent *event) {
move(event->globalPosition().x()-m_nMouseClick_X_Coordinate,event->globalPosition().y()-m_nMouseClick_Y_Coordinate);
}
void editor::Replace(QString &text) {
QMap<QString, QString> replace {
{"0", "?!*(#-=#"},
{"1", "!*!(#-#--"},
{"2", "*))!(#=@"},
{"3", "?*#)=#-=#"},
{"4", "-!(#-=!#="},
{"5", "=$:;==--"},
{"6", "Ap;l==#-$"},
{"7", "-#=#-??*"},
{"а", "###-=-@@@"},
{"б", "@@@-=-###"},
{"в", "###===@@$"},
{"г", "$##---@@@"},
{"д", "$##===-@@"},
{"е", "@-=-!##$#"},
{"ж", "#%=%@@@-#"},
{"з", "##====@@$"},
{"и", "##$$$=-=#"},
{"к", "#!!#$=$##"},
{"л", "#$#$#$=--"},
{"м", "$#$#$#!-!"},
{"н", "!#!#!#!-$"},
{"о", "!#!#!#!=$"},
{"п", "%#%#%#%-!"},
{"с", "$!$!-#=#!"},
{"у", "(#(#=-$!%"},
{"х", "##-(%-=#!"}
};
QMap<QString, QString>::const_iterator i = replace.constBegin();
while (i != replace.constEnd()) {
text.replace(i.key(), i.value());
++i;
}
}