Qt input: pass QString by reference (#20467)
* simple arry for keyboard layout * revert some changes
This commit is contained in:
parent
3d48bd934d
commit
f7957f681d
|
@ -3,7 +3,7 @@
|
||||||
#include "input.hpp"
|
#include "input.hpp"
|
||||||
#include "qt_window.hpp"
|
#include "qt_window.hpp"
|
||||||
|
|
||||||
InputDialog::InputDialog(QString prompt_text, QWidget *parent):QDialog(parent) {
|
InputDialog::InputDialog(const QString &prompt_text, QWidget *parent) : QDialog(parent) {
|
||||||
layout = new QVBoxLayout();
|
layout = new QVBoxLayout();
|
||||||
layout->setContentsMargins(50, 50, 50, 50);
|
layout->setContentsMargins(50, 50, 50, 50);
|
||||||
layout->setSpacing(20);
|
layout->setSpacing(20);
|
||||||
|
@ -43,7 +43,7 @@ InputDialog::InputDialog(QString prompt_text, QWidget *parent):QDialog(parent) {
|
||||||
layout->addWidget(line, 1, Qt::AlignTop);
|
layout->addWidget(line, 1, Qt::AlignTop);
|
||||||
|
|
||||||
k = new Keyboard(this);
|
k = new Keyboard(this);
|
||||||
QObject::connect(k, SIGNAL(emitButton(QString)), this, SLOT(handleInput(QString)));
|
QObject::connect(k, SIGNAL(emitButton(const QString&)), this, SLOT(handleInput(const QString&)));
|
||||||
layout->addWidget(k, 2, Qt::AlignBottom);
|
layout->addWidget(k, 2, Qt::AlignBottom);
|
||||||
|
|
||||||
setStyleSheet(R"(
|
setStyleSheet(R"(
|
||||||
|
@ -56,7 +56,7 @@ InputDialog::InputDialog(QString prompt_text, QWidget *parent):QDialog(parent) {
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString InputDialog::getText(const QString prompt, int minLength) {
|
QString InputDialog::getText(const QString &prompt, int minLength) {
|
||||||
InputDialog d = InputDialog(prompt);
|
InputDialog d = InputDialog(prompt);
|
||||||
d.setMinLength(minLength);
|
d.setMinLength(minLength);
|
||||||
const int ret = d.exec();
|
const int ret = d.exec();
|
||||||
|
@ -76,7 +76,7 @@ void InputDialog::show(){
|
||||||
setMainWindow(this);
|
setMainWindow(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputDialog::handleInput(QString s) {
|
void InputDialog::handleInput(const QString &s) {
|
||||||
if (!QString::compare(s,"⌫")) {
|
if (!QString::compare(s,"⌫")) {
|
||||||
line->backspace();
|
line->backspace();
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ void InputDialog::handleInput(QString s) {
|
||||||
line->insert(s.left(1));
|
line->insert(s.left(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputDialog::setMessage(QString message, bool clearInputField){
|
void InputDialog::setMessage(const QString &message, bool clearInputField){
|
||||||
label->setText(message);
|
label->setText(message);
|
||||||
if (clearInputField){
|
if (clearInputField){
|
||||||
line->setText("");
|
line->setText("");
|
||||||
|
@ -112,7 +112,7 @@ void InputDialog::setMinLength(int length){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ConfirmationDialog::ConfirmationDialog(QString prompt_text, QString confirm_text, QString cancel_text,
|
ConfirmationDialog::ConfirmationDialog(const QString &prompt_text, const QString &confirm_text, const QString &cancel_text,
|
||||||
QWidget *parent):QDialog(parent) {
|
QWidget *parent):QDialog(parent) {
|
||||||
setWindowFlags(Qt::Popup);
|
setWindowFlags(Qt::Popup);
|
||||||
layout = new QVBoxLayout();
|
layout = new QVBoxLayout();
|
||||||
|
@ -161,12 +161,12 @@ ConfirmationDialog::ConfirmationDialog(QString prompt_text, QString confirm_text
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfirmationDialog::alert(const QString prompt_text) {
|
bool ConfirmationDialog::alert(const QString &prompt_text) {
|
||||||
ConfirmationDialog d = ConfirmationDialog(prompt_text, "Ok", "");
|
ConfirmationDialog d = ConfirmationDialog(prompt_text, "Ok", "");
|
||||||
return d.exec();
|
return d.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfirmationDialog::confirm(const QString prompt_text) {
|
bool ConfirmationDialog::confirm(const QString &prompt_text) {
|
||||||
ConfirmationDialog d = ConfirmationDialog(prompt_text);
|
ConfirmationDialog d = ConfirmationDialog(prompt_text);
|
||||||
return d.exec();
|
return d.exec();
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,10 +13,10 @@ class InputDialog : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit InputDialog(QString prompt_text, QWidget* parent = 0);
|
explicit InputDialog(const QString &prompt_text, QWidget* parent = 0);
|
||||||
static QString getText(QString prompt, int minLength = -1);
|
static QString getText(const QString &prompt, int minLength = -1);
|
||||||
QString text();
|
QString text();
|
||||||
void setMessage(QString message, bool clearInputField=true);
|
void setMessage(const QString &message, bool clearInputField = true);
|
||||||
void setMinLength(int length);
|
void setMinLength(int length);
|
||||||
void show();
|
void show();
|
||||||
|
|
||||||
|
@ -31,21 +31,21 @@ public slots:
|
||||||
int exec() override;
|
int exec() override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void handleInput(QString s);
|
void handleInput(const QString &s);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void cancel();
|
void cancel();
|
||||||
void emitText(QString text);
|
void emitText(const QString &text);
|
||||||
};
|
};
|
||||||
|
|
||||||
class ConfirmationDialog : public QDialog {
|
class ConfirmationDialog : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ConfirmationDialog(QString prompt_text, QString confirm_text = "Ok",
|
explicit ConfirmationDialog(const QString &prompt_text, const QString &confirm_text = "Ok",
|
||||||
QString cancel_text = "Cancel", QWidget* parent = 0);
|
const QString &cancel_text = "Cancel", QWidget* parent = 0);
|
||||||
static bool alert(QString prompt_text);
|
static bool alert(const QString &prompt_text);
|
||||||
static bool confirm(QString prompt_text);
|
static bool confirm(const QString &prompt_text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QLabel *prompt;
|
QLabel *prompt;
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
const int DEFAULT_STRETCH = 1;
|
const int DEFAULT_STRETCH = 1;
|
||||||
const int SPACEBAR_STRETCH = 3;
|
const int SPACEBAR_STRETCH = 3;
|
||||||
|
|
||||||
KeyboardLayout::KeyboardLayout(QWidget *parent, std::vector<QVector<QString>> layout) : QWidget(parent) {
|
KeyboardLayout::KeyboardLayout(QWidget* parent, const std::vector<QVector<QString>>& layout) : QWidget(parent) {
|
||||||
QVBoxLayout* vlayout = new QVBoxLayout;
|
QVBoxLayout* vlayout = new QVBoxLayout;
|
||||||
vlayout->setMargin(0);
|
vlayout->setMargin(0);
|
||||||
vlayout->setSpacing(35);
|
vlayout->setSpacing(35);
|
||||||
|
|
|
@ -12,7 +12,7 @@ class KeyboardLayout : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit KeyboardLayout(QWidget *parent, std::vector<QVector<QString>> layout);
|
explicit KeyboardLayout(QWidget* parent, const std::vector<QVector<QString>>& layout);
|
||||||
};
|
};
|
||||||
|
|
||||||
class Keyboard : public QFrame {
|
class Keyboard : public QFrame {
|
||||||
|
@ -28,5 +28,5 @@ private slots:
|
||||||
void handleButton(QAbstractButton* m_button);
|
void handleButton(QAbstractButton* m_button);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void emitButton(QString s);
|
void emitButton(const QString &s);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue