You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
168 lines
4.2 KiB
168 lines
4.2 KiB
4 years ago
|
#include <QPushButton>
|
||
|
|
||
4 years ago
|
#include "input.hpp"
|
||
4 years ago
|
#include "qt_window.hpp"
|
||
4 years ago
|
|
||
4 years ago
|
InputDialog::InputDialog(QString prompt_text, QWidget *parent):QDialog(parent) {
|
||
4 years ago
|
layout = new QVBoxLayout();
|
||
|
layout->setContentsMargins(50, 50, 50, 50);
|
||
|
layout->setSpacing(20);
|
||
4 years ago
|
|
||
4 years ago
|
// build header
|
||
|
QHBoxLayout *header_layout = new QHBoxLayout();
|
||
4 years ago
|
|
||
4 years ago
|
label = new QLabel(prompt_text, this);
|
||
|
label->setStyleSheet(R"(font-size: 75px; font-weight: 500;)");
|
||
|
header_layout->addWidget(label, 1, Qt::AlignLeft);
|
||
|
|
||
|
QPushButton* cancel_btn = new QPushButton("Cancel");
|
||
|
cancel_btn->setStyleSheet(R"(
|
||
|
padding: 30px;
|
||
|
padding-right: 45px;
|
||
|
padding-left: 45px;
|
||
|
border-radius: 7px;
|
||
|
font-size: 45px;
|
||
|
background-color: #444444;
|
||
|
)");
|
||
|
header_layout->addWidget(cancel_btn, 0, Qt::AlignRight);
|
||
|
QObject::connect(cancel_btn, SIGNAL(released()), this, SLOT(reject()));
|
||
4 years ago
|
QObject::connect(cancel_btn, SIGNAL(released()), this, SIGNAL(cancel()));
|
||
4 years ago
|
|
||
|
layout->addLayout(header_layout);
|
||
4 years ago
|
|
||
|
// text box
|
||
4 years ago
|
layout->addSpacing(20);
|
||
4 years ago
|
line = new QLineEdit();
|
||
|
line->setStyleSheet(R"(
|
||
4 years ago
|
border: none;
|
||
4 years ago
|
background-color: #444444;
|
||
|
font-size: 80px;
|
||
|
font-weight: 500;
|
||
|
padding: 10px;
|
||
4 years ago
|
)");
|
||
4 years ago
|
layout->addWidget(line, 1, Qt::AlignTop);
|
||
4 years ago
|
|
||
|
k = new Keyboard(this);
|
||
4 years ago
|
QObject::connect(k, SIGNAL(emitButton(QString)), this, SLOT(handleInput(QString)));
|
||
|
layout->addWidget(k, 2, Qt::AlignBottom);
|
||
|
|
||
|
setStyleSheet(R"(
|
||
|
* {
|
||
|
color: white;
|
||
|
background-color: black;
|
||
|
}
|
||
|
)");
|
||
4 years ago
|
|
||
|
setLayout(layout);
|
||
|
}
|
||
|
|
||
4 years ago
|
QString InputDialog::getText(const QString prompt, int minLength) {
|
||
4 years ago
|
InputDialog d = InputDialog(prompt);
|
||
4 years ago
|
d.setMinLength(minLength);
|
||
4 years ago
|
const int ret = d.exec();
|
||
4 years ago
|
return ret ? d.text() : QString();
|
||
4 years ago
|
}
|
||
|
|
||
|
QString InputDialog::text() {
|
||
|
return line->text();
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
int InputDialog::exec() {
|
||
|
setMainWindow(this);
|
||
|
return QDialog::exec();
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
void InputDialog::handleInput(QString s) {
|
||
4 years ago
|
if (!QString::compare(s,"⌫")) {
|
||
4 years ago
|
line->backspace();
|
||
|
}
|
||
|
|
||
4 years ago
|
if (!QString::compare(s,"⏎")) {
|
||
4 years ago
|
if (line->text().length() > minLength){
|
||
|
done(QDialog::Accepted);
|
||
|
emitText(line->text());
|
||
|
} else {
|
||
|
setMessage("Need at least "+QString::number(minLength)+" characters!", false);
|
||
|
}
|
||
4 years ago
|
}
|
||
|
|
||
|
QVector<QString> control_buttons {"⇧", "↑", "ABC", "⏎", "#+=", "⌫", "123"};
|
||
4 years ago
|
for(QString c : control_buttons) {
|
||
|
if (!QString::compare(s, c)) {
|
||
4 years ago
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
line->insert(s.left(1));
|
||
|
}
|
||
|
|
||
4 years ago
|
void InputDialog::setMessage(QString message, bool clearInputField){
|
||
|
label->setText(message);
|
||
|
if (clearInputField){
|
||
|
line->setText("");
|
||
|
}
|
||
|
}
|
||
4 years ago
|
|
||
|
void InputDialog::setMinLength(int length){
|
||
|
minLength = length;
|
||
4 years ago
|
}
|
||
|
|
||
|
|
||
|
|
||
|
ConfirmationDialog::ConfirmationDialog(QString prompt_text, QString confirm_text, QString cancel_text,
|
||
|
QWidget *parent):QDialog(parent) {
|
||
|
layout = new QVBoxLayout();
|
||
|
layout->setMargin(25);
|
||
|
|
||
|
prompt = new QLabel(prompt_text, this);
|
||
|
prompt->setWordWrap(true);
|
||
|
prompt->setAlignment(Qt::AlignHCenter);
|
||
|
prompt->setStyleSheet(R"(font-size: 55px; font-weight: 400;)");
|
||
|
layout->addWidget(prompt, 1, Qt::AlignTop | Qt::AlignHCenter);
|
||
|
|
||
|
// cancel + confirm buttons
|
||
|
QHBoxLayout *btn_layout = new QHBoxLayout();
|
||
|
btn_layout->setSpacing(20);
|
||
|
btn_layout->addStretch(1);
|
||
|
layout->addLayout(btn_layout);
|
||
|
|
||
|
QPushButton* cancel_btn = new QPushButton(cancel_text);
|
||
|
btn_layout->addWidget(cancel_btn, 0, Qt::AlignRight);
|
||
|
QObject::connect(cancel_btn, SIGNAL(released()), this, SLOT(reject()));
|
||
|
|
||
|
QPushButton* confirm_btn = new QPushButton(confirm_text);
|
||
|
btn_layout->addWidget(confirm_btn, 0, Qt::AlignRight);
|
||
|
QObject::connect(confirm_btn, SIGNAL(released()), this, SLOT(accept()));
|
||
|
|
||
|
setFixedSize(900, 350);
|
||
|
setStyleSheet(R"(
|
||
|
* {
|
||
|
color: black;
|
||
|
background-color: white;
|
||
|
}
|
||
|
QPushButton {
|
||
|
font-size: 40px;
|
||
|
padding: 30px;
|
||
|
padding-right: 45px;
|
||
|
padding-left: 45px;
|
||
|
border-radius: 7px;
|
||
|
background-color: #44444400;
|
||
|
}
|
||
|
)");
|
||
|
|
||
|
setLayout(layout);
|
||
|
}
|
||
|
|
||
|
bool ConfirmationDialog::confirm(const QString prompt_text) {
|
||
|
ConfirmationDialog d = ConfirmationDialog(prompt_text);
|
||
|
return d.exec();
|
||
|
}
|
||
|
|
||
|
int ConfirmationDialog::exec() {
|
||
|
// TODO: make this work without fullscreen
|
||
|
#ifdef QCOM2
|
||
|
setMainWindow(this);
|
||
|
#endif
|
||
|
return QDialog::exec();
|
||
|
}
|