-
Notifications
You must be signed in to change notification settings - Fork 0
/
messinput.cpp
64 lines (55 loc) · 1.41 KB
/
messinput.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
#include "messinput.h"
#include <QKeyEvent>
#include <QDebug>
#include <QMimeData>
messInput::messInput(QWidget *parent) :
QTextEdit(parent)
{
//connect(this,SIGNAL(textChanged()),this,SLOT(paste()));
}
void messInput::keyPressEvent(QKeyEvent *event)
{
if ( event->key() == Qt::Key_Return|| event->key() == Qt::Key_Enter)
{
qDebug()<<"Hажата ентер";
this->setStyleSheet("");
if((event->modifiers() & Qt::SHIFT))
{
this->insertPlainText("\n");
}
else
{
emit giveText(toPlainText());
this->clear();
}
}
else
{
if(toPlainText().length()>256)
{
if(event->key() == Qt::Key_Backspace||event->key() == Qt::Key_Delete)
QTextEdit::keyPressEvent(event);
else
this->setStyleSheet("background-color: red;");
}
else
{
this->setStyleSheet("");
QTextEdit::keyPressEvent(event);
}
}
}
bool messInput::canInsertFromMimeData(const QMimeData *source) const
{
if(source->text().length()>256)
return false;
else return true;
}
void messInput::insertFromMimeData(const QMimeData *source)
{
if(source->hasText()){
if(source->text().length()>256)
insertPlainText(source->text().mid(0,255));
else insertPlainText(source->text());
}
}