added interactive message implementation

This commit is contained in:
Igor Korsukov 2020-06-27 11:01:03 +02:00
parent 16783c4a99
commit 2dd25ed7c6
5 changed files with 67 additions and 2 deletions

View file

@ -94,7 +94,7 @@ public:
enum class Type {
Info,
Warning,
Error
Critical
};
virtual void message(Type type, const std::string& title, const std::string& text) const = 0;

View file

@ -23,6 +23,8 @@
#include <QMessageBox>
#include <QPushButton>
#include <QMap>
#include <QSpacerItem>
#include <QGridLayout>
#include "log.h"
#include "translation.h"
@ -77,6 +79,10 @@ int Interactive::question(const std::string& title, const Text& text, const Butt
}
}
QGridLayout* layout = (QGridLayout*)msgBox.layout();
QSpacerItem* hSpacer = new QSpacerItem(300, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
layout->addItem(hSpacer, layout->rowCount(), 0, 1, layout->columnCount());
msgBox.exec();
QAbstractButton* clickedBtn = msgBox.clickedButton();
@ -115,13 +121,35 @@ IInteractive::ButtonData Interactive::buttonData(Button b) const
void Interactive::message(Type type, const std::string& title, const std::string& text) const
{
//! NOTE Temporarily, need to replace the qml dialog
auto icon = [](Type type) {
switch (type) {
case Type::Info: return QMessageBox::Information;
case Type::Warning: return QMessageBox::Warning;
case Type::Critical: return QMessageBox::Critical;
}
return QMessageBox::NoIcon;
};
QMessageBox msgBox;
msgBox.setWindowTitle(QString::fromStdString(title));
msgBox.setText(QString::fromStdString(text));
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setIcon(icon(type));
QGridLayout* layout = (QGridLayout*)msgBox.layout();
QSpacerItem* hSpacer = new QSpacerItem(300, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
layout->addItem(hSpacer, layout->rowCount(), 0, 1, layout->columnCount());
msgBox.exec();
}
mu::io::path Interactive::selectOpeningFile(const std::string& title,
const std::string& dir,
const std::string& filter)
{
QString path = QFileDialog::getOpenFileName(nullptr, /*parent*/
QString path = QFileDialog::getOpenFileName(nullptr, /*parent*/
QString::fromStdString(title),
QString::fromStdString(dir),
QString::fromStdString(filter));

View file

@ -82,3 +82,18 @@ void LauncherTestsModel::customQuestion()
LOGE() << "No!!";
}
}
void LauncherTestsModel::information()
{
interactive()->message(IInteractive::Type::Info, "Test", "this is info");
}
void LauncherTestsModel::warning()
{
interactive()->message(IInteractive::Type::Warning, "Test", "this is info");
}
void LauncherTestsModel::critical()
{
interactive()->message(IInteractive::Type::Critical, "Test", "this is info");
}

View file

@ -48,6 +48,10 @@ public:
Q_INVOKABLE void question();
Q_INVOKABLE void customQuestion();
Q_INVOKABLE void information();
Q_INVOKABLE void warning();
Q_INVOKABLE void critical();
signals:
void currentUriChanged(QString currentUri);

View file

@ -75,5 +75,23 @@ Rectangle {
text: "Custom question"
onClicked: testModel.customQuestion()
}
FlatButton {
width: 200
text: "Information"
onClicked: testModel.information()
}
FlatButton {
width: 200
text: "Warning"
onClicked: testModel.warning()
}
FlatButton {
width: 200
text: "Critical"
onClicked: testModel.critical()
}
}
}