-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusernoteinput.cpp
81 lines (64 loc) · 2.1 KB
/
usernoteinput.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
#include "usernoteinput.h"
#include <QDebug>
UserNoteInput::UserNoteInput(QWidget *parent) : QWidget(parent)
{
qDebug() << "note input constructor";
p_central_vertical_layout = new QVBoxLayout;
setLayout(p_central_vertical_layout);
p_label = new QLabel;
p_text_edit = new QTextEdit;
p_next_button = new QPushButton("Next");
p_central_vertical_layout->addWidget(p_label);
p_central_vertical_layout->addWidget(p_text_edit);
p_central_vertical_layout->addWidget(p_next_button);
p_central_vertical_layout->setAlignment(Qt::AlignCenter);
p_label->setFont(QFont("phosphate", 35));
p_label->setAlignment(Qt::AlignCenter);
p_label->setFixedHeight(60);
p_next_button->setFixedHeight(70);
p_text_edit->setFixedWidth(300);
p_text_edit->setFont(QFont("Arial", 20));
p_next_button->setCursor(Qt::OpenHandCursor);
connect(p_next_button, SIGNAL(clicked(bool)), SLOT(nextButtonClicked()));
}
void UserNoteInput::nextButtonClicked()
{
qDebug() << "note input next button clicked";
if(p_text_edit->toPlainText().length() == 0)
p_text_edit->setText(" ");
std::string temp = p_text_edit->toPlainText().toStdString();
//delete of last \n simbols
if(temp.at(temp.length() - 1) == '\n')
{
for(int i = temp.length() - 1; temp.at(i) == '\n'; --i)
temp.erase(i, 1);
}
//repplace of \n simbols inside the text for one \n simbol
for(int i = 0, j = 0; i < temp.length(); ++i, j = 0)
{
if(temp.at(i) == '\n')
{
for(j = i + 1; temp.at(j) == '\n'; ++j);
temp.replace(i, j - i, "\n");
}
}
for(int i = 0; i < temp.length(); ++i)
{
if(temp.at(i) == '\n')
temp.replace(i, 1, "\a");
}
QString buffer = QString::fromStdString(temp);
emit sendNote(buffer);
setVisible(false);
}
void UserNoteInput::setText(QString string)
{
qDebug() << "note input set text " << string;
p_label->setText(string);
}
void UserNoteInput::clearInput()
{
qDebug() << "note input clear input";
p_text_edit->clear();
p_text_edit->setFocus();
}