Implemented actions widget and editing functionalities

This commit is contained in:
feedc0de committed 2022-01-14 21:21:17 +01:00
1 parent 8d45958d45
commit 0b4c275dfc
464 files changed
+36929 -439

No files matched your search

+146 -41
View File
@@ -3,19 +3,22 @@
#include <QDebug>
#include <QMessageBox>
#include <QInputDialog>
#include <QMenu>
#include "projectcontainer.h"
#include "projecttreemodel.h"
#include "timelinemomentsmodel.h"
#include "timelineactionsmodel.h"
#include <limits>
#include "models/projecttreemodel.h"
#include "models/timelinemomentsmodel.h"
#include "dialogs/deletemomentsdialog.h"
TimeLinePropertiesDialog::TimeLinePropertiesDialog(TimeLine &timeLine, ProjectTreeModel &projectModel, QWidget *parent) :
QDialog{parent},
m_ui{std::make_unique<Ui::TimeLinePropertiesDialog>()},
m_timeLine{timeLine},
m_projectModel{projectModel},
m_momentsModel{std::make_unique<TimelineMomentsModel>(this)},
m_actionsModel{std::make_unique<TimelineActionsModel>(this)}
m_moments{timeLine.moments},
m_momentsModel{std::make_unique<TimelineMomentsModel>(m_moments, this)}
{
m_ui->setupUi(this);
@@ -30,32 +33,51 @@ TimeLinePropertiesDialog::TimeLinePropertiesDialog(TimeLine &timeLine, ProjectTr
m_ui->listViewMoments->setModel(m_momentsModel.get());
m_ui->listViewActions->setModel(m_actionsModel.get());
connect(&m_projectModel, &ProjectTreeModel::timeLineNameChanged,
this, &TimeLinePropertiesDialog::timeLineNameChanged);
connect(m_momentsModel.get(), &QAbstractItemModel::modelReset,
this, &TimeLinePropertiesDialog::changed);
connect(m_momentsModel.get(), &QAbstractItemModel::rowsInserted,
this, &TimeLinePropertiesDialog::changed);
connect(m_momentsModel.get(), &QAbstractItemModel::dataChanged,
this, &TimeLinePropertiesDialog::changed);
connect(m_momentsModel.get(), &QAbstractItemModel::rowsRemoved,
this, &TimeLinePropertiesDialog::changed);
connect(m_ui->lineEditName, &QLineEdit::textChanged,
this, &TimeLinePropertiesDialog::changed);
connect(m_ui->pushButtonAdd, &QAbstractButton::clicked,
this, &TimeLinePropertiesDialog::add);
this, &TimeLinePropertiesDialog::addMoment);
connect(m_ui->pushButtonChange, &QAbstractButton::clicked,
this, &TimeLinePropertiesDialog::change);
this, &TimeLinePropertiesDialog::changeMoment);
connect(m_ui->pushButtonDelete, &QAbstractButton::clicked,
this, &TimeLinePropertiesDialog::delete_);
this, &TimeLinePropertiesDialog::deleteMoments);
connect(m_ui->pushButtonClear, &QAbstractButton::clicked,
this, &TimeLinePropertiesDialog::clear);
this, &TimeLinePropertiesDialog::clearMoments);
connect(m_ui->pushButtonShift, &QAbstractButton::clicked,
this, &TimeLinePropertiesDialog::shift);
this, &TimeLinePropertiesDialog::shiftMoments);
connect(m_ui->pushButtonDuplicate, &QAbstractButton::clicked,
this, &TimeLinePropertiesDialog::duplicate);
this, &TimeLinePropertiesDialog::duplicateMoments);
connect(m_ui->pushButtonSpread, &QAbstractButton::clicked,
this, &TimeLinePropertiesDialog::spread);
this, &TimeLinePropertiesDialog::spreadMoments);
connect(m_ui->pushButtonMerge, &QAbstractButton::clicked,
this, &TimeLinePropertiesDialog::merge);
this, &TimeLinePropertiesDialog::mergeMoments);
connect(m_ui->pushButtonShowInformation, &QAbstractButton::clicked,
this, &TimeLinePropertiesDialog::showInformation);
connect(m_ui->listViewMoments->selectionModel(), &QItemSelectionModel::currentChanged,
this, &TimeLinePropertiesDialog::currentMomentChanged);
connect(m_momentsModel.get(), &QAbstractItemModel::modelAboutToBeReset,
m_ui->listViewMoments, [listView=m_ui->listViewMoments](){
listView->setCurrentIndex(QModelIndex{});
});
connect(m_ui->listViewMoments, &QListView::customContextMenuRequested,
this, &TimeLinePropertiesDialog::momentsContextMenuRequested);
connect(m_ui->actionsWidget, &ActionsContainerWidget::changed,
this, &TimeLinePropertiesDialog::changed);
}
TimeLinePropertiesDialog::~TimeLinePropertiesDialog() = default;
@@ -77,7 +99,7 @@ void TimeLinePropertiesDialog::accept()
}
}
// TODO
m_timeLine.moments = m_moments;
QDialog::accept();
}
@@ -134,42 +156,92 @@ void TimeLinePropertiesDialog::timeLineNameChanged(const TimeLine &timeLine)
updateTitle();
}
void TimeLinePropertiesDialog::add()
void TimeLinePropertiesDialog::addMoment()
{
TimeLine::moment_key_t newMoment{};
for (const auto &moment : m_moments)
if (moment.first >= newMoment)
newMoment = moment.first + 1;
bool ok;
const auto moment = QInputDialog::getInt(this, tr("Adding a Moment"), tr("Indicate the moment:"), newMoment, 0, std::numeric_limits<TimeLine::moment_key_t>::max(), 1, &ok);
if (!ok)
return;
if (!m_momentsModel->addMoment(moment))
QMessageBox::warning(this, tr("Could not add Moment!"), tr("Could not add Moment!"));
}
void TimeLinePropertiesDialog::changeMoment()
{
const auto index = m_ui->listViewMoments->currentIndex();
if (!index.isValid())
return;
const auto moment = m_momentsModel->getMoment(index);
if (!moment)
return;
bool ok;
const auto newMoment = QInputDialog::getInt(this, tr("Changing a Moment"), tr("Indicate the moment:"), moment->first, 0, std::numeric_limits<TimeLine::moment_key_t>::max(), 1, &ok);
if (!ok)
return;
if (!m_momentsModel->changeMoment(moment->first, newMoment))
QMessageBox::warning(this, tr("Could not change Moment!"), tr("Could not change Moment!"));
}
void TimeLinePropertiesDialog::deleteMoments()
{
if (m_moments.empty())
return;
std::optional<TimeLine::moment_key_t> momentKey;
if (const auto index = m_ui->listViewMoments->currentIndex(); index.isValid())
if (const auto moment = m_momentsModel->getMoment(index); moment)
momentKey = moment->first;
DeleteMomentsDialog dialog = momentKey ? DeleteMomentsDialog{*momentKey, *momentKey, this} : DeleteMomentsDialog{this};
if (dialog.exec() == QDialog::Accepted)
{
if (dialog.fromMoment() > dialog.tillMoment())
{
QMessageBox::warning(this, tr("Invalid input!"), tr("Invalid input!") + "\n\n" + tr("From moment cannot be greater than Till moment!"));
return;
}
if (!m_momentsModel->removeRows(dialog.fromMoment(), dialog.tillMoment() - dialog.fromMoment() + 1))
QMessageBox::warning(this, tr("Could not remove Moments!"), tr("Could not remove Moments!"));
}
}
void TimeLinePropertiesDialog::clearMoments()
{
if (m_moments.empty())
return;
if (QMessageBox::question(this, tr("Confirm"), tr("Are you sure, that you really want to remove all Moments?")) != QMessageBox::Yes)
return;
if (!m_momentsModel->clearMoments())
QMessageBox::warning(this, tr("Could not clear Moments!"), tr("Could not clear Moments!"));
}
void TimeLinePropertiesDialog::shiftMoments()
{
QMessageBox::warning(this, tr("Not yet implemented"), tr("Not yet implemented"));
}
void TimeLinePropertiesDialog::change()
void TimeLinePropertiesDialog::duplicateMoments()
{
QMessageBox::warning(this, tr("Not yet implemented"), tr("Not yet implemented"));
}
void TimeLinePropertiesDialog::delete_()
void TimeLinePropertiesDialog::spreadMoments()
{
QMessageBox::warning(this, tr("Not yet implemented"), tr("Not yet implemented"));
}
void TimeLinePropertiesDialog::clear()
{
QMessageBox::warning(this, tr("Not yet implemented"), tr("Not yet implemented"));
}
void TimeLinePropertiesDialog::shift()
{
QMessageBox::warning(this, tr("Not yet implemented"), tr("Not yet implemented"));
}
void TimeLinePropertiesDialog::duplicate()
{
QMessageBox::warning(this, tr("Not yet implemented"), tr("Not yet implemented"));
}
void TimeLinePropertiesDialog::spread()
{
QMessageBox::warning(this, tr("Not yet implemented"), tr("Not yet implemented"));
}
void TimeLinePropertiesDialog::merge()
void TimeLinePropertiesDialog::mergeMoments()
{
QMessageBox::warning(this, tr("Not yet implemented"), tr("Not yet implemented"));
}
@@ -179,6 +251,39 @@ void TimeLinePropertiesDialog::showInformation()
QMessageBox::warning(this, tr("Not yet implemented"), tr("Not yet implemented"));
}
void TimeLinePropertiesDialog::currentMomentChanged(const QModelIndex &index)
{
qDebug() << index.isValid() << index.row();
if (index.isValid())
{
if (auto moment = m_momentsModel->getMoment(index))
m_ui->actionsWidget->setActionsContainer(&moment->second);
else
goto none;
}
else
{
none:
m_ui->actionsWidget->setActionsContainer(nullptr);
}
}
void TimeLinePropertiesDialog::momentsContextMenuRequested(const QPoint &pos)
{
const auto index = m_ui->listViewMoments->indexAt(pos);
auto moment = index.isValid() ? m_momentsModel->getMoment(index) : nullptr;
QMenu menu{this};
menu.addAction(tr("&Add Moment"), this, &TimeLinePropertiesDialog::addMoment);
menu.addAction(tr("&Change Moment"), this, &TimeLinePropertiesDialog::changeMoment)->setEnabled(moment);
menu.addAction(tr("&Delete Moment"), this, &TimeLinePropertiesDialog::deleteMoments)->setEnabled(moment);
menu.addSeparator();
menu.addAction(tr("&Shift Moments"), this, &TimeLinePropertiesDialog::shiftMoments)->setEnabled(moment);
menu.addAction(tr("&Merge Moments"), this, &TimeLinePropertiesDialog::mergeMoments)->setEnabled(moment);
menu.exec(m_ui->listViewMoments->viewport()->mapToGlobal(pos));
}
void TimeLinePropertiesDialog::updateTitle()
{
setWindowTitle(tr("Time Line Properties: %0%1")