mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-27 14:29:37 -05:00
added dialog for choosing scripts from the script log (#1539)
* added dialog for choosing scripts from the script log
This commit is contained in:
@@ -34,6 +34,7 @@ set(HEADER_FILES
|
||||
include/profile/cameradialog.h
|
||||
include/profile/deltatimesdialog.h
|
||||
include/profile/keybindingsdialog.h
|
||||
include/profile/scriptlogdialog.h
|
||||
include/profile/line.h
|
||||
include/profile/marknodesdialog.h
|
||||
include/profile/metadialog.h
|
||||
@@ -53,6 +54,7 @@ set(SOURCE_FILES
|
||||
src/profile/cameradialog.cpp
|
||||
src/profile/deltatimesdialog.cpp
|
||||
src/profile/keybindingsdialog.cpp
|
||||
src/profile/scriptlogdialog.cpp
|
||||
src/profile/line.cpp
|
||||
src/profile/marknodesdialog.cpp
|
||||
src/profile/metadialog.cpp
|
||||
@@ -74,6 +76,7 @@ qt5_wrap_cpp(
|
||||
include/profile/cameradialog.h
|
||||
include/profile/deltatimesdialog.h
|
||||
include/profile/keybindingsdialog.h
|
||||
include/profile/scriptlogdialog.h
|
||||
include/profile/marknodesdialog.h
|
||||
include/profile/metadialog.h
|
||||
include/profile/modulesdialog.h
|
||||
|
||||
@@ -58,6 +58,13 @@ public:
|
||||
*/
|
||||
virtual void keyPressEvent(QKeyEvent* evt) override;
|
||||
|
||||
/**
|
||||
* Adds scripts to the _scriptEdit from outside dialogs
|
||||
*
|
||||
* \param scripts #std::string scripts to be appended
|
||||
*/
|
||||
void appendScriptsToKeybind(const std::string& scripts);
|
||||
|
||||
private slots:
|
||||
void listItemSelected();
|
||||
void listItemAdded();
|
||||
@@ -66,6 +73,7 @@ private slots:
|
||||
void listItemCancelSave();
|
||||
void transitionToEditMode();
|
||||
void parseSelections();
|
||||
void chooseScripts();
|
||||
void keySelected(int index);
|
||||
|
||||
private:
|
||||
@@ -99,6 +107,7 @@ private:
|
||||
|
||||
QPushButton* _addButton = nullptr;
|
||||
QPushButton* _removeButton = nullptr;
|
||||
QPushButton* _chooseScriptsButton = nullptr;
|
||||
QPushButton* _saveButton = nullptr;
|
||||
QPushButton* _cancelButton = nullptr;
|
||||
QDialogButtonBox* _buttonBox = nullptr;
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2021 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __OPENSPACE_UI_LAUNCHER___SCRIPTLOG___H__
|
||||
#define __OPENSPACE_UI_LAUNCHER___SCRIPTLOG___H__
|
||||
|
||||
#include "profile/keybindingsdialog.h"
|
||||
#include <QDialog>
|
||||
#include <QListWidget>
|
||||
|
||||
class ScriptlogDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
/**
|
||||
* Constructor for ScriptlogDialog class
|
||||
*
|
||||
* \param bindingDialog keybindingDialog that openend this window.
|
||||
* \param parent Pointer to parent Qt widget
|
||||
*/
|
||||
ScriptlogDialog(KeybindingsDialog* bindingDialog, QWidget* parent);
|
||||
|
||||
private slots:
|
||||
void saveChosenScripts();
|
||||
|
||||
private:
|
||||
void createWidgets();
|
||||
|
||||
KeybindingsDialog* _bindingDialog = nullptr;
|
||||
QListWidget* _scriptlogList = nullptr;
|
||||
};
|
||||
|
||||
#endif // __OPENSPACE_UI_LAUNCHER___SCRIPTLOG___H__
|
||||
@@ -25,6 +25,8 @@
|
||||
#include "profile/keybindingsdialog.h"
|
||||
|
||||
#include "profile/line.h"
|
||||
#include "profile/scriptlogdialog.h"
|
||||
|
||||
#include <openspace/scene/profile.h>
|
||||
#include <openspace/util/keys.h>
|
||||
#include <qevent.h>
|
||||
@@ -106,6 +108,10 @@ KeybindingsDialog::KeybindingsDialog(Profile& profile, QWidget *parent)
|
||||
transitionFromEditMode();
|
||||
}
|
||||
|
||||
void KeybindingsDialog::appendScriptsToKeybind(const std::string& scripts) {
|
||||
_scriptEdit->append(QString::fromStdString(scripts));
|
||||
}
|
||||
|
||||
void KeybindingsDialog::createWidgets() {
|
||||
QBoxLayout* layout = new QVBoxLayout(this);
|
||||
{
|
||||
@@ -220,6 +226,14 @@ void KeybindingsDialog::createWidgets() {
|
||||
|
||||
_scriptLabel = new QLabel("Script");
|
||||
box->addWidget(_scriptLabel, 6, 0, 1, 2);
|
||||
|
||||
_chooseScriptsButton = new QPushButton("Choose Scripts");
|
||||
connect(
|
||||
_chooseScriptsButton, &QPushButton::clicked,
|
||||
this, &KeybindingsDialog::chooseScripts
|
||||
);
|
||||
box->addWidget(_chooseScriptsButton, 6, 1, 1, 1);
|
||||
|
||||
_scriptEdit = new QTextEdit;
|
||||
_scriptEdit->setAcceptRichText(false);
|
||||
_scriptEdit->setToolTip("Command(s) to execute at keypress event");
|
||||
@@ -497,6 +511,7 @@ void KeybindingsDialog::editBoxDisabled(bool disabled) {
|
||||
_scriptEdit->setDisabled(disabled);
|
||||
_cancelButton->setDisabled(disabled);
|
||||
_saveButton->setDisabled(disabled);
|
||||
_chooseScriptsButton->setDisabled(disabled);
|
||||
}
|
||||
|
||||
void KeybindingsDialog::parseSelections() {
|
||||
@@ -508,6 +523,11 @@ void KeybindingsDialog::parseSelections() {
|
||||
accept();
|
||||
}
|
||||
|
||||
void KeybindingsDialog::chooseScripts() {
|
||||
_errorMsg->clear();
|
||||
ScriptlogDialog(this, this).exec();
|
||||
}
|
||||
|
||||
void KeybindingsDialog::keyPressEvent(QKeyEvent* evt) {
|
||||
if (evt->key() == Qt::Key_Enter || evt->key() == Qt::Key_Return) {
|
||||
return;
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2021 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include "profile/scriptlogdialog.h"
|
||||
#include "profile/line.h"
|
||||
#include <openspace/engine/configuration.h>
|
||||
#include <openspace/scene/profile.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QLabel>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
ScriptlogDialog::ScriptlogDialog(KeybindingsDialog* bindingDialog,
|
||||
QWidget* parent)
|
||||
: QDialog(parent)
|
||||
, _bindingDialog(bindingDialog)
|
||||
{
|
||||
setWindowTitle("Scriptlog");
|
||||
createWidgets();
|
||||
|
||||
QFile file(QString::fromStdString(absPath("${LOGS}/scriptLog.txt")));
|
||||
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
QTextStream in(&file);
|
||||
while (!in.atEnd()) {
|
||||
QString line = in.readLine();
|
||||
// removing return from a few statments
|
||||
// these are usually generated by gui panels
|
||||
line.remove(QRegularExpression("^return "));
|
||||
if (!line.isEmpty()) {
|
||||
_scriptlogList->addItem(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptlogDialog::createWidgets() {
|
||||
QBoxLayout* layout = new QVBoxLayout(this);
|
||||
{
|
||||
QLabel* heading = new QLabel("Choose commands from log/scriptLog.txt");
|
||||
heading->setObjectName("heading");
|
||||
layout->addWidget(heading);
|
||||
}
|
||||
|
||||
_scriptlogList = new QListWidget;
|
||||
_scriptlogList->setSelectionMode(QAbstractItemView::SelectionMode::MultiSelection);
|
||||
layout->addWidget(_scriptlogList);
|
||||
|
||||
layout->addWidget(new Line);
|
||||
{
|
||||
QDialogButtonBox* buttons = new QDialogButtonBox;
|
||||
buttons->setStandardButtons(QDialogButtonBox::Save | QDialogButtonBox::Cancel);
|
||||
connect(
|
||||
buttons, &QDialogButtonBox::accepted,
|
||||
this, &ScriptlogDialog::saveChosenScripts
|
||||
);
|
||||
connect(
|
||||
buttons, &QDialogButtonBox::rejected,
|
||||
this, &ScriptlogDialog::reject
|
||||
);
|
||||
layout->addWidget(buttons);
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptlogDialog::saveChosenScripts() {
|
||||
std::string chosenScripts;
|
||||
QList<QListWidgetItem*> itemList = _scriptlogList->selectedItems();
|
||||
for (int i = 0; i < itemList.size(); ++i) {
|
||||
chosenScripts += itemList.at(i)->text().toStdString();
|
||||
if (i < itemList.size()) {
|
||||
chosenScripts += "\n";
|
||||
}
|
||||
}
|
||||
_bindingDialog->appendScriptsToKeybind(chosenScripts);
|
||||
|
||||
accept();
|
||||
}
|
||||
Reference in New Issue
Block a user