diff --git a/apps/OpenSpace/ext/launcher/CMakeLists.txt b/apps/OpenSpace/ext/launcher/CMakeLists.txt index e9f56eb834..3e8e47b685 100644 --- a/apps/OpenSpace/ext/launcher/CMakeLists.txt +++ b/apps/OpenSpace/ext/launcher/CMakeLists.txt @@ -32,6 +32,7 @@ set(HEADER_FILES include/launcherwindow.h include/marknodes.h include/meta.h + include/osmodules.h include/profileedit.h include/ui_addedscripts.h include/ui_assets.h @@ -41,6 +42,7 @@ set(HEADER_FILES include/ui_launcherwindow.h include/ui_marknodes.h include/ui_meta.h + include/ui_osmodules.h include/ui_profileedit.h ) @@ -56,6 +58,7 @@ set(SOURCE_FILES src/launcherwindow.cpp src/marknodes.cpp src/meta.cpp + src/osmodules.cpp src/profileedit.cpp ) diff --git a/apps/OpenSpace/ext/launcher/include/osmodules.h b/apps/OpenSpace/ext/launcher/include/osmodules.h new file mode 100644 index 0000000000..eebf754917 --- /dev/null +++ b/apps/OpenSpace/ext/launcher/include/osmodules.h @@ -0,0 +1,53 @@ +#ifndef OSMODULES_H +#define OSMODULES_H + +#include +#include +#include + +QT_BEGIN_NAMESPACE +namespace Ui { +class osmodules; +} +QT_END_NAMESPACE + +struct Module { + std::string name; + std::string loadedInstruction; + std::string notLoadedInstruction; +}; + +class osmodules : public QDialog +{ + Q_OBJECT + +public slots: + void listItemSelected(); + void listItemAdded(); + void listItemRemove(); + void listItemSave(); + void listItemCancelSave(); + void transitionToEditMode(); + void parseSelections(); + +public: + explicit osmodules(std::vector& imported, QWidget *parent = nullptr); + ~osmodules(); + +protected: + //void resizeEvent(QResizeEvent* event); + +private: + QString createOneLineSummary(Module m); + void transitionFromEditMode(); + void editBoxDisabled(bool disabled); + + Ui::osmodules *ui; + QWidget* _parent; + std::vector& _imported; + std::vector _data; + std::vector _modulesListItems; + bool _editModeNewItem = false; +}; + +#endif // OSMODULES_H diff --git a/apps/OpenSpace/ext/launcher/include/ui_osmodules.h b/apps/OpenSpace/ext/launcher/include/ui_osmodules.h new file mode 100644 index 0000000000..625c7f0a62 --- /dev/null +++ b/apps/OpenSpace/ext/launcher/include/ui_osmodules.h @@ -0,0 +1,160 @@ +/******************************************************************************** +** Form generated from reading UI file 'osmodules.ui' +** +** Created by: Qt User Interface Compiler version 5.15.0 +** +** WARNING! All changes made in this file will be lost when recompiling UI file! +********************************************************************************/ + +#ifndef UI_OSMODULES_H +#define UI_OSMODULES_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class Ui_osmodules +{ +public: + QDialogButtonBox *buttonBox; + QListWidget *list; + QPushButton *button_add; + QPushButton *button_remove; + QFrame *frame; + QLabel *label_module; + QLabel *label_loaded; + QLabel *label_notLoaded; + QLineEdit *line_module; + QPushButton *button_cancel; + QPushButton *button_save; + QTextEdit *line_loaded; + QTextEdit *line_notLoaded; + + void setupUi(QDialog *osmodules) + { + if (osmodules->objectName().isEmpty()) + osmodules->setObjectName(QString::fromUtf8("osmodules")); + osmodules->resize(591, 559); + buttonBox = new QDialogButtonBox(osmodules); + buttonBox->setObjectName(QString::fromUtf8("buttonBox")); + buttonBox->setGeometry(QRect(240, 520, 341, 32)); + buttonBox->setOrientation(Qt::Horizontal); + buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); + list = new QListWidget(osmodules); + list->setObjectName(QString::fromUtf8("list")); + list->setGeometry(QRect(10, 10, 571, 120)); + QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + sizePolicy.setHorizontalStretch(0); + sizePolicy.setVerticalStretch(0); + sizePolicy.setHeightForWidth(list->sizePolicy().hasHeightForWidth()); + list->setSizePolicy(sizePolicy); + list->setMinimumSize(QSize(0, 50)); + list->setMaximumSize(QSize(16777215, 120)); + QFont font; + font.setFamily(QString::fromUtf8("Arial")); + list->setFont(font); + list->setAlternatingRowColors(true); + list->setMovement(QListView::Free); + list->setResizeMode(QListView::Adjust); + button_add = new QPushButton(osmodules); + button_add->setObjectName(QString::fromUtf8("button_add")); + button_add->setGeometry(QRect(10, 140, 111, 25)); + button_remove = new QPushButton(osmodules); + button_remove->setObjectName(QString::fromUtf8("button_remove")); + button_remove->setGeometry(QRect(160, 140, 111, 25)); + frame = new QFrame(osmodules); + frame->setObjectName(QString::fromUtf8("frame")); + frame->setGeometry(QRect(10, 190, 571, 311)); + frame->setFrameShape(QFrame::StyledPanel); + frame->setFrameShadow(QFrame::Raised); + label_module = new QLabel(frame); + label_module->setObjectName(QString::fromUtf8("label_module")); + label_module->setGeometry(QRect(10, 10, 357, 20)); + QFont font1; + font1.setFamily(QString::fromUtf8("Arial")); + font1.setPointSize(12); + label_module->setFont(font1); + label_loaded = new QLabel(frame); + label_loaded->setObjectName(QString::fromUtf8("label_loaded")); + label_loaded->setGeometry(QRect(10, 70, 357, 20)); + label_loaded->setFont(font1); + label_notLoaded = new QLabel(frame); + label_notLoaded->setObjectName(QString::fromUtf8("label_notLoaded")); + label_notLoaded->setGeometry(QRect(10, 170, 357, 20)); + label_notLoaded->setFont(font1); + line_module = new QLineEdit(frame); + line_module->setObjectName(QString::fromUtf8("line_module")); + line_module->setGeometry(QRect(10, 30, 357, 25)); + button_cancel = new QPushButton(frame); + button_cancel->setObjectName(QString::fromUtf8("button_cancel")); + button_cancel->setGeometry(QRect(410, 270, 71, 25)); + button_save = new QPushButton(frame); + button_save->setObjectName(QString::fromUtf8("button_save")); + button_save->setGeometry(QRect(490, 270, 71, 25)); + line_loaded = new QTextEdit(frame); + line_loaded->setObjectName(QString::fromUtf8("line_loaded")); + line_loaded->setGeometry(QRect(10, 90, 511, 71)); + line_notLoaded = new QTextEdit(frame); + line_notLoaded->setObjectName(QString::fromUtf8("line_notLoaded")); + line_notLoaded->setGeometry(QRect(10, 190, 511, 71)); + label_module->raise(); + label_loaded->raise(); + label_notLoaded->raise(); + button_save->raise(); + button_cancel->raise(); + line_module->raise(); + line_loaded->raise(); + line_notLoaded->raise(); + + retranslateUi(osmodules); + //QObject::connect(buttonBox, SIGNAL(accepted()), osmodules, SLOT(accept())); + QObject::connect(buttonBox, SIGNAL(rejected()), osmodules, SLOT(reject())); + + QMetaObject::connectSlotsByName(osmodules); + } // setupUi + + void retranslateUi(QDialog *osmodules) + { + osmodules->setWindowTitle(QCoreApplication::translate("osmodules", "Modules", nullptr)); + button_add->setText(QCoreApplication::translate("osmodules", "Add New", nullptr)); + button_remove->setText(QCoreApplication::translate("osmodules", "Remove", nullptr)); + label_module->setText(QCoreApplication::translate("osmodules", "Module", nullptr)); + label_loaded->setText(QCoreApplication::translate("osmodules", "Command if Module is Loaded", nullptr)); + label_notLoaded->setText(QCoreApplication::translate("osmodules", "Command if Module is NOT Loaded", nullptr)); +#if QT_CONFIG(tooltip) + line_module->setToolTip(QCoreApplication::translate("osmodules", "

Name of OpenSpace module related to this profile

", nullptr)); +#endif // QT_CONFIG(tooltip) +#if QT_CONFIG(tooltip) + button_cancel->setToolTip(QCoreApplication::translate("osmodules", "

Cancel adding this module to the above list

", nullptr)); +#endif // QT_CONFIG(tooltip) + button_cancel->setText(QCoreApplication::translate("osmodules", "Cancel", nullptr)); +#if QT_CONFIG(tooltip) + button_save->setToolTip(QCoreApplication::translate("osmodules", "

Save module changes to the above list

", nullptr)); +#endif // QT_CONFIG(tooltip) + button_save->setText(QCoreApplication::translate("osmodules", "Save", nullptr)); +#if QT_CONFIG(tooltip) + line_loaded->setToolTip(QCoreApplication::translate("osmodules", "

[OPTIONAL] Lua command(s) to execute if the module is present in the OpenSpace application

", nullptr)); +#endif // QT_CONFIG(tooltip) +#if QT_CONFIG(tooltip) + line_notLoaded->setToolTip(QCoreApplication::translate("osmodules", "

[OPTIONAL] Lua command(s) to execute if the module is not present in the OpenSpace application (for example steps to account for a missing module)

", nullptr)); +#endif // QT_CONFIG(tooltip) + } // retranslateUi + +}; + +namespace Ui { + class osmodules: public Ui_osmodules {}; +} // namespace Ui + +QT_END_NAMESPACE + +#endif // UI_OSMODULES_H diff --git a/apps/OpenSpace/ext/launcher/src/osmodules.cpp b/apps/OpenSpace/ext/launcher/src/osmodules.cpp new file mode 100644 index 0000000000..c0242a9c2c --- /dev/null +++ b/apps/OpenSpace/ext/launcher/src/osmodules.cpp @@ -0,0 +1,156 @@ +#include "osmodules.h" +#include "./ui_osmodules.h" +#include + +osmodules::osmodules(std::vector& imported, QWidget *parent) + : QDialog(parent) + , ui(new Ui::osmodules) + , _imported(imported) + , _data(imported) +{ + ui->setupUi(this); + + for (size_t i = 0; i < _data.size(); ++i) { + _modulesListItems.push_back(new QListWidgetItem(createOneLineSummary(_data[i]))); + ui->list->addItem(_modulesListItems[i]); + } + + connect(ui->list, SIGNAL(itemSelectionChanged()), this, SLOT(listItemSelected())); + connect(ui->button_add, SIGNAL(clicked()), this, SLOT(listItemAdded())); + connect(ui->button_save, SIGNAL(clicked()), this, SLOT(listItemSave())); + connect(ui->button_cancel, SIGNAL(clicked()), this, SLOT(listItemCancelSave())); + connect(ui->button_remove, SIGNAL(clicked()), this, SLOT(listItemRemove())); + connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(parseSelections())); + + transitionFromEditMode(); +} + +QString osmodules::createOneLineSummary(Module m) { + QString summary = QString(m.name.c_str()); + bool hasCommandForLoaded = (m.loadedInstruction.length() > 0); + bool hasCommandForNotLoaded = (m.notLoadedInstruction.length() > 0); + + if (hasCommandForLoaded && hasCommandForNotLoaded) { + summary += " (commands set for both loaded & not-loaded conditions)"; + } + else if (hasCommandForLoaded) { + summary += " (command set only for loaded condition)"; + } + else if (hasCommandForNotLoaded) { + summary += " (command set only for NOT loaded condition)"; + } + else { + summary += " (no commands set)"; + } + return summary; +} + +void osmodules::listItemSelected(void) { + QListWidgetItem *item = ui->list->currentItem(); + int index = ui->list->row(item); + + Module& m = _data[index]; + ui->line_module->setText(QString(m.name.c_str())); + ui->line_loaded->setText(QString(m.loadedInstruction.c_str())); + ui->line_notLoaded->setText(QString(m.notLoadedInstruction.c_str())); + transitionToEditMode(); +} + +void osmodules::listItemAdded(void) { + //Add new line at bottom of props list + _data.push_back({"", "", ""}); + _modulesListItems.push_back(new QListWidgetItem(" (Enter details below and click 'Save')")); + ui->list->addItem(_modulesListItems.back()); + + //Scroll down to that blank line highlighted + ui->list->setCurrentItem(_modulesListItems.back()); + + //Blank-out the 2 text fields, set combo box to index 0 + ui->line_module->setText(QString(_data.back().name.c_str())); + ui->line_loaded->setText(QString(_data.back().loadedInstruction.c_str())); + ui->line_notLoaded->setText(QString(_data.back().notLoadedInstruction.c_str())); + _editModeNewItem = true; +} + +void osmodules::listItemSave(void) { + if (ui->line_module->text().length() == 0) { + ui->label_module->setText("Module"); + return; + } + + QListWidgetItem *item = ui->list->currentItem(); + int index = ui->list->row(item); + + _data[index].name = ui->line_module->text().toUtf8().constData(); + _data[index].loadedInstruction = ui->line_loaded->toPlainText().toUtf8().constData(); + _data[index].notLoadedInstruction = ui->line_notLoaded->toPlainText().toUtf8().constData(); + + _modulesListItems.at(index)->setText(createOneLineSummary(_data[index])); + transitionFromEditMode(); + _editModeNewItem = false; +} + +void osmodules::listItemCancelSave(void) { + listItemSelected(); + transitionFromEditMode(); + if (_editModeNewItem) { + if(_data.back().name.length() == 0) { + listItemRemove(); + } + } + _editModeNewItem = false; +} + +void osmodules::listItemRemove(void) { + QListWidgetItem *item = ui->list->currentItem(); + int index = ui->list->row(item); + + ui->list->takeItem(index); + _data.erase(_data.begin() + index); + _modulesListItems.erase(_modulesListItems.begin() + index); + transitionFromEditMode(); +} + +void osmodules::transitionToEditMode(void) { + ui->list->setDisabled(true); + ui->button_add->setDisabled(true); + ui->button_remove->setDisabled(true); + + editBoxDisabled(false); +} + +void osmodules::transitionFromEditMode(void) { + ui->list->setDisabled(false); + ui->button_add->setDisabled(false); + ui->button_remove->setDisabled(false); + + editBoxDisabled(true); + ui->label_module->setText("Module"); +} + +void osmodules::editBoxDisabled(bool disabled) { + ui->label_module->setDisabled(disabled); + ui->line_module->setDisabled(disabled); + ui->label_loaded->setDisabled(disabled); + ui->line_loaded->setDisabled(disabled); + ui->label_notLoaded->setDisabled(disabled); + ui->line_notLoaded->setDisabled(disabled); + ui->button_cancel->setDisabled(disabled); + ui->button_save->setDisabled(disabled); +} + +//osmodules::save() { +// +//} + +void osmodules::parseSelections() { + _imported = _data; + accept(); +} + +osmodules::~osmodules() { + for (auto p : _modulesListItems) { + delete p; + } + delete ui; +} diff --git a/apps/OpenSpace/ext/launcher/src/osmodules.ui b/apps/OpenSpace/ext/launcher/src/osmodules.ui new file mode 100644 index 0000000000..345fe1c791 --- /dev/null +++ b/apps/OpenSpace/ext/launcher/src/osmodules.ui @@ -0,0 +1,288 @@ + + + osmodules + + + + 0 + 0 + 591 + 559 + + + + Modules + + + + + 240 + 520 + 341 + 32 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + 10 + 10 + 571 + 120 + + + + + 0 + 0 + + + + + 0 + 50 + + + + + 16777215 + 120 + + + + + Arial + + + + true + + + QListView::Free + + + QListView::Adjust + + + + + + 10 + 140 + 111 + 25 + + + + Add New + + + + + + 160 + 140 + 111 + 25 + + + + Remove + + + + + + 10 + 190 + 571 + 311 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + 10 + 10 + 357 + 20 + + + + + Arial + 12 + + + + Module + + + + + + 10 + 70 + 357 + 20 + + + + + Arial + 12 + + + + Command if Module is Loaded + + + + + + 10 + 170 + 357 + 20 + + + + + Arial + 12 + + + + Command if Module is NOT Loaded + + + + + + 10 + 30 + 357 + 25 + + + + <html><head/><body><p>Name of OpenSpace module related to this profile</p></body></html> + + + + + + 410 + 270 + 71 + 25 + + + + <html><head/><body><p>Cancel adding this module to the above list</p></body></html> + + + Cancel + + + + + + 490 + 270 + 71 + 25 + + + + <html><head/><body><p>Save module changes to the above list</p></body></html> + + + Save + + + + + + 10 + 90 + 511 + 71 + + + + <html><head/><body><p>[OPTIONAL] Lua command(s) to execute if the module is present in the OpenSpace application</p></body></html> + + + + + + 10 + 190 + 511 + 71 + + + + <html><head/><body><p>[OPTIONAL] Lua command(s) to execute if the module is <span style=" font-style:italic;">not </span>present in the OpenSpace application (for example steps to account for a missing module)</p></body></html> + + + label_module + label_loaded + label_notLoaded + button_save + button_cancel + line_module + line_loaded + line_notLoaded + + + + + + buttonBox + accepted() + osmodules + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + osmodules + reject() + + + 316 + 260 + + + 286 + 274 + + + + +