-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditor.cpp
More file actions
92 lines (82 loc) · 2.7 KB
/
editor.cpp
File metadata and controls
92 lines (82 loc) · 2.7 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
#include <QApplication>
#include <QClipboard>
#include "editor.h"
Editor::Editor(QWidget* parent) : QTextEdit(parent)
{
}
void Editor::keyPressEvent(QKeyEvent *e){
setFontPointSize(s->getInt("font/size"));
setFontFamily(s->getString("font/family"));
if(s->getInt("prices/keyStroke")>s->getInt("credits/count"))return;
s->decrement("credits/count",s->getInt("prices/keyStroke"));
emit keystroke();
if(e->key()==Qt::Key_Backspace && !s->getBool("upgrades/backspace"))return;
if((e->key()==Qt::Key_PageUp || e->key()==Qt::Key_PageDown) && !s->getBool("upgrades/pageUpDown"))return;
if(s->getBool("upgrades/readOnly"))return;
bool isText=e->text().at(0).isPrint();
isText |= (e->key()==Qt::Key_Return);
isText |= (e->key()==Qt::Key_Space);
//qDebug() << "key code: " << e->key();
if(!isText){
qDebug("not text");
if(e->key()==Qt::Key_Backspace){
if(!s->getBool("upgrades/backspace"))return;
textCursor().deletePreviousChar();
}
if(e->key()==Qt::Key_Delete){
if(!s->getBool("upgrades/backspace"))return;
textCursor().deleteChar();
}
if(e->key()==90){ //Ctrl-Z
if(!s->getBool("upgrades/undoRedo"))return;
this->undo();
}
if(e->key()==82){ //Ctrl-R
if(!s->getBool("upgrades/undoRedo"))return;
this->redo();
}
if(e->key()==67){ //Ctrl-C
if(!s->getBool("upgrades/paste"))return;
this->copy();
}
if(e->key()==86){ //Ctrl-V
if(!s->getBool("upgrades/paste"))return;
qDebug() << QApplication::clipboard()->text();
this->insertPlainText(QApplication::clipboard()->text());
}
QTextEdit::keyPressEvent(e);
}else{
int pos = klavesy.length();
if(!s->getBool("upgrades/synchronize"))
pos = rand() % (klavesy.length()+1);
klavesy.insert(pos,e->text());
int delay = s->getInt("screensaver/delay0");
if(s->getBool("upgrades/delay1"))delay = s->getInt("screensaver/delay1");
if(s->getBool("upgrades/delay2"))delay = s->getInt("screensaver/delay2");
QTimer::singleShot(delay,this,SLOT(delayedKey()));
}
lastEditTime = QTime::currentTime();
}
void Editor::delayedKey(){
qDebug() << klavesy.length();
if(klavesy.isEmpty())return;
qDebug() << "not empty";
qDebug() << klavesy.head();
insertPlainText(klavesy.dequeue());
}
void Editor::mousePressEvent(QMouseEvent *e){
if(!s->getBool("upgrades/mouseInteraction"))return;
QTextEdit::mousePressEvent(e);
}
void Editor::insertFromMimeData(const QMimeData *source){
if(s->getBool("upgrades/paste"))
QTextEdit::insertFromMimeData(source);
}
InputEditor::InputEditor(QWidget *parent) : QPlainTextEdit(parent)
{
}
QMimeData* InputEditor::createMimeDataFromSelection() const{
QMimeData* m = new QMimeData();
m->text() = "";
return m;
}