130 lines
3.0 KiB
C++
Executable File
130 lines
3.0 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* Base Class of Topic Editor for the Script Editor (not the Script Player)
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*
|
|
* Created by Mike Wille, SLSE, 2017-04-27
|
|
*/
|
|
|
|
#include "topic_editor_base.h"
|
|
#include "topic_preview_widget.h"
|
|
|
|
#include <LtsWidgets/lts_dialog.h>
|
|
|
|
#include <QMessageBox>
|
|
#include <QDebug>
|
|
|
|
|
|
namespace TopicEditorBase
|
|
{
|
|
|
|
TopicEditor::TopicEditor(QWidget *parent)
|
|
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::OkApplyCancel)
|
|
, m_previewWidget(nullptr)
|
|
{
|
|
m_buttonBox->getButton(LtsWidgets::DialogButton::Ok)->hide();
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// PUBLIC
|
|
|
|
void TopicEditor::setTopicData(const TopicEditorBase::TopicData &data)
|
|
{
|
|
m_topicData = data;
|
|
m_topicDuration = data.duration;
|
|
|
|
if (m_previewWidget == nullptr)
|
|
{
|
|
QMessageBox::critical(
|
|
nullptr, QStringLiteral("An den Entwickler!"),
|
|
QStringLiteral("!! STOP !! - Dieser Topic Editor hatte 'init()' vorher nicht aufgerufen!")
|
|
);
|
|
// qWarning() << "TopicEditor: base was not initialized !! call init() first !";
|
|
return;
|
|
}
|
|
|
|
m_previewWidget->setTopicData(m_topicData);
|
|
|
|
bool isAlreadyUnchangeable = unchangeable();
|
|
if (!isAlreadyUnchangeable) // NOTE: every topic EDITOR should be EDITable
|
|
setUnchangeable(true);
|
|
|
|
updateInternalData();
|
|
|
|
if (!isAlreadyUnchangeable)
|
|
setUnchangeable(false);
|
|
}
|
|
|
|
|
|
void TopicEditor::setDuration(int duration)
|
|
{
|
|
m_topicData.duration = duration;
|
|
updateInternalLength();
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// PROTECTED
|
|
|
|
void TopicEditor::init(TopicPreviewWidget *widget)
|
|
{
|
|
m_previewWidget = widget;
|
|
connect(m_previewWidget, &TopicPreviewWidget::deleteMe,
|
|
this, &TopicEditor::deleteLater);
|
|
|
|
// do not allow dragging before saving
|
|
m_previewWidget->setTopicEnabled(false);
|
|
connect(this, &TopicEditor::signalChangesMade, this, [this]()
|
|
{
|
|
m_previewWidget->setTopicEnabled(false);
|
|
});
|
|
}
|
|
|
|
|
|
void TopicEditor::setTopicDataProperty(const QString &key, const QJsonValue &value)
|
|
{
|
|
m_topicData.properties[key] = value;
|
|
emit signalChangesMade();
|
|
}
|
|
|
|
|
|
void TopicEditor::applied()
|
|
{
|
|
m_previewWidget->setTopicEnabled(true);
|
|
emit topicDataChanged();
|
|
}
|
|
|
|
void TopicEditor::setIsPlaying(bool isPlaying)
|
|
{
|
|
m_isPlaying = isPlaying;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// PRIVATE SLOTS
|
|
|
|
bool TopicEditor::apply()
|
|
{
|
|
if (m_previewWidget == nullptr)
|
|
{
|
|
QMessageBox::critical(
|
|
nullptr, QStringLiteral("An den Entwickler!"),
|
|
QStringLiteral("!! STOP !! - Dieser Topic Editor hatte 'init()' vorher nicht aufgerufen!")
|
|
);
|
|
// qWarning() << "TopicEditor: base was not initialized !! call init() first !";
|
|
return false;
|
|
}
|
|
if (m_isPlaying)
|
|
{
|
|
LtsWidgets::LtsMessageDialog::showMessage(this, tr("Please Stop Playback first"));
|
|
return false;
|
|
}
|
|
|
|
bool result = apply2();
|
|
if (result)
|
|
applied();
|
|
return result;
|
|
}
|
|
|
|
} // namespace TopicEditorBase
|