The expiration time for new job artifacts in CI/CD pipelines is now 30 days (GitLab default). Previously generated artifacts in already completed jobs will not be affected by the change. The latest artifacts for all jobs in the latest successful pipelines will be kept. More information: https://gitlab.lrz.de/help/user/admin_area/settings/continuous_integration.html#default-artifacts-expiration

scriptingwidget.cpp 4.26 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// ================================================================================================
// 
// This file is part of the CAMPVis Software Framework.
// 
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
//      Chair for Computer Aided Medical Procedures
//      Technische Universitaet Muenchen
//      Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
// 
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
// 
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 
// except in compliance with the License. You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software distributed under the 
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
// either express or implied. See the License for the specific language governing permissions 
// and limitations under the License.
// 
// ================================================================================================

#include "scriptingwidget.h"

27
28
#include <QKeyEvent>

29
30
31
32
namespace campvis {

    ScriptingWidget::ScriptingWidget(QWidget* parent)
        : QWidget(parent)
33
34
35
36
37
        , _consoleDisplay(nullptr)
        , _editCommand(nullptr)
        , _btnExecute(nullptr)
        , _btnClear(nullptr)
        , _currentPosition(-1)
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
    {
        setupGUI();
    }

    ScriptingWidget::~ScriptingWidget() {
    }

    void ScriptingWidget::setupGUI() {
        setWindowTitle(tr("Scripting Console"));

        QVBoxLayout* mainLayout = new QVBoxLayout(this);

        QHBoxLayout* controlsLayout = new QHBoxLayout();
        mainLayout->addLayout(controlsLayout);

        _consoleDisplay = new QTextEdit(this);
        _consoleDisplay->setReadOnly(true);
        mainLayout->addWidget(_consoleDisplay);

        // Use the system's default monospace font at the default size in the log viewer
        QFont monoFont = QFont("Monospace");
        monoFont.setStyleHint(QFont::TypeWriter);
        monoFont.setPointSize(QFont().pointSize() + 1);

        _consoleDisplay->document()->setDefaultFont(monoFont);
        _editCommand = new QLineEdit(this);
        _editCommand->setPlaceholderText(tr("Enter Lua commands here..."));
65
        _editCommand->installEventFilter(this);
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
        controlsLayout->addWidget(_editCommand);

        _btnExecute = new QPushButton(tr("&Execute"), this);
        controlsLayout->addWidget(_btnExecute);

        _btnClear = new QPushButton(tr("&Clear"), this);
        controlsLayout->addWidget(_btnClear);


        connect(_btnClear, SIGNAL(clicked()), this, SLOT(clearLog()));
        connect(_btnExecute, SIGNAL(clicked()), this, SLOT(execute()));
        connect(_editCommand, SIGNAL(returnPressed()), this, SLOT(execute()));
        connect(this, SIGNAL(s_commandExecuted(QString)), this, SLOT(appendMessage(const QString&)));
    }

    void ScriptingWidget::appendMessage(const QString& message) {
        _consoleDisplay->append(tr("> ") + message);
    }

    void ScriptingWidget::clearLog() {
        _consoleDisplay->clear();
    }

    void ScriptingWidget::execute() {
        QString command = _editCommand->text();
        emit s_commandExecuted(command);
92
93
        _history.push_front(command);
        _currentPosition = -1;
94
95
96
        _editCommand->clear();
    }

97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
    bool ScriptingWidget::eventFilter(QObject* obj, QEvent* event) {
        if (obj == _editCommand && event->type() == QEvent::KeyPress) {
            QKeyEvent* e = static_cast<QKeyEvent*>(event);
            if (e->key() == Qt::Key_Up && _currentPosition < static_cast<int>(_history.size())-1) {
                ++_currentPosition;
                _editCommand->setText(_history[_currentPosition]);
                return true;
            }
            if (e->key() == Qt::Key_Down && _currentPosition >= 0) {
                --_currentPosition;
                if (_currentPosition >= 0)
                    _editCommand->setText(_history[_currentPosition]);
                else
                    _editCommand->setText(tr(""));

                return true;
            }
        }

        return QObject::eventFilter(obj, event);
    }



121
}