Skip to content

Commit

Permalink
Merge branch 'master' into timeline-rewrite-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
MrStevns committed Sep 8, 2024
2 parents 495eea8 + 3d0a148 commit 44bfeaa
Show file tree
Hide file tree
Showing 40 changed files with 1,602 additions and 486 deletions.
90 changes: 90 additions & 0 deletions app/src/generalpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ GeneralPage::GeneralPage() : ui(new Ui::GeneralPage)
ui->backgroundButtons->setId(ui->dotsBackgroundButton, 4);
ui->backgroundButtons->setId(ui->weaveBackgroundButton, 5);

ui->undoRedoGroupApplyButton->setDisabled(true);
ui->undoRedoGroupCancelButton->setDisabled(true);

auto buttonClicked = static_cast<void (QButtonGroup::*)(QAbstractButton*)>(&QButtonGroup::buttonClicked);
auto curIndexChanged = static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged);
auto spinValueChanged = static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged);
Expand All @@ -122,6 +125,10 @@ GeneralPage::GeneralPage() : ui(new Ui::GeneralPage)
connect(ui->gridCheckBox, &QCheckBox::stateChanged, this, &GeneralPage::gridCheckBoxStateChanged);
connect(ui->framePoolSizeSpin, spinValueChanged, this, &GeneralPage::frameCacheNumberChanged);
connect(ui->invertScrollDirectionBox, &QCheckBox::stateChanged, this, &GeneralPage::invertScrollDirectionBoxStateChanged);
connect(ui->newUndoRedoCheckBox, &QCheckBox::stateChanged, this, &GeneralPage::newUndoRedoCheckBoxStateChanged);
connect(ui->undoStepsBox, spinValueChanged, this, &GeneralPage::undoRedoMaxStepsChanged);
connect(ui->undoRedoGroupApplyButton, &QPushButton::clicked, this, &GeneralPage::undoRedoApplyButtonPressed);
connect(ui->undoRedoGroupCancelButton, &QPushButton::clicked, this, &GeneralPage::undoRedoCancelButtonPressed);
}

GeneralPage::~GeneralPage()
Expand Down Expand Up @@ -181,6 +188,12 @@ void GeneralPage::updateValues()
QSignalBlocker b12(ui->framePoolSizeSpin);
ui->framePoolSizeSpin->setValue(mManager->getInt(SETTING::FRAME_POOL_SIZE));

QSignalBlocker bNewUndoRedoCheckBox(ui->newUndoRedoCheckBox);
ui->newUndoRedoCheckBox->setChecked(mManager->isOn(SETTING::NEW_UNDO_REDO_SYSTEM_ON));

QSignalBlocker bUndoRedoLimitSpinBox(ui->undoStepsBox);
ui->undoStepsBox->setValue(mManager->getInt(SETTING::UNDO_REDO_MAX_STEPS));

int buttonIdx = 1;
if (bgName == "checkerboard") buttonIdx = 1;
else if (bgName == "white") buttonIdx = 2;
Expand Down Expand Up @@ -318,3 +331,80 @@ void GeneralPage::invertScrollDirectionBoxStateChanged(int b)
{
mManager->set(SETTING::INVERT_SCROLL_ZOOM_DIRECTION, b != Qt::Unchecked);
}

void GeneralPage::newUndoRedoCheckBoxStateChanged()
{
ui->undoRedoGroupApplyButton->setEnabled(canApplyOrCancelUndoRedoChanges());
ui->undoRedoGroupCancelButton->setEnabled(canApplyOrCancelUndoRedoChanges());
}

void GeneralPage::undoRedoMaxStepsChanged()
{
ui->undoRedoGroupApplyButton->setEnabled(canApplyOrCancelUndoRedoChanges());
ui->undoRedoGroupCancelButton->setEnabled(canApplyOrCancelUndoRedoChanges());
}

bool GeneralPage::canApplyOrCancelUndoRedoChanges() const
{
const bool newSystemIsOnCurrent = mManager->isOn(SETTING::NEW_UNDO_REDO_SYSTEM_ON);
const int maxUndoRedoStepNumCurrent = mManager->getInt(SETTING::UNDO_REDO_MAX_STEPS);

if (newSystemIsOnCurrent != ui->newUndoRedoCheckBox->isChecked()
|| maxUndoRedoStepNumCurrent != ui->undoStepsBox->value()) {
return true;
} else {
return false;
}
}

void GeneralPage::undoRedoApplyButtonPressed()
{
if (ui->undoStepsBox->value() != mManager->getInt(SETTING::UNDO_REDO_MAX_STEPS)) {
QMessageBox messageBox(this);
messageBox.setIcon(QMessageBox::Warning);
messageBox.setText(tr("Resets your current undo history"));
messageBox.setInformativeText(tr("Changing the maximum number of undo/redo steps resets your current undo/redo history. \n\nAre you sure you want to proceed?"));
messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);

if (messageBox.exec() == QMessageBox::Yes) {
mManager->set(SETTING::UNDO_REDO_MAX_STEPS, ui->undoStepsBox->value());
} else {
ui->undoStepsBox->setValue(mManager->getInt(SETTING::UNDO_REDO_MAX_STEPS));
}
}

const bool systemIsOn = mManager->isOn(SETTING::NEW_UNDO_REDO_SYSTEM_ON);
if (ui->newUndoRedoCheckBox->isChecked() != systemIsOn) {
if (ui->newUndoRedoCheckBox->isChecked()) {
QMessageBox messageBox(this);
messageBox.setIcon(QMessageBox::Warning);
messageBox.setText(tr("Experimental feature!"));
messageBox.setInformativeText(tr("This feature is work in progress and may not currently allow for the same features as the current undo/redo system. Once enabled, you'll need to restart the application to start using it. \n\nDo you still want to try?"));
messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);

if (messageBox.exec() == QMessageBox::Yes) {
mManager->set(SETTING::NEW_UNDO_REDO_SYSTEM_ON, true);
} else {
ui->newUndoRedoCheckBox->setCheckState(Qt::Unchecked);
mManager->set(SETTING::NEW_UNDO_REDO_SYSTEM_ON, false);
}
} else {
QMessageBox messageBox(this);
messageBox.setIcon(QMessageBox::Information);
messageBox.setText(tr("The undo/redo system will be changed on the next launch of the application"));
messageBox.exec();
mManager->set(SETTING::NEW_UNDO_REDO_SYSTEM_ON, false);
}
}

ui->undoRedoGroupCancelButton->setDisabled(true);
ui->undoRedoGroupApplyButton->setDisabled(true);
}

void GeneralPage::undoRedoCancelButtonPressed()
{
ui->undoStepsBox->setValue(mManager->getInt(SETTING::UNDO_REDO_MAX_STEPS));
ui->newUndoRedoCheckBox->setCheckState(mManager->isOn(SETTING::NEW_UNDO_REDO_SYSTEM_ON) ? Qt::Checked : Qt::Unchecked);
ui->undoRedoGroupCancelButton->setDisabled(true);
ui->undoRedoGroupApplyButton->setDisabled(true);
}
6 changes: 6 additions & 0 deletions app/src/generalpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@ private slots:
void backgroundChanged(QAbstractButton* button);
void frameCacheNumberChanged(int value);
void invertScrollDirectionBoxStateChanged(int b);
void newUndoRedoCheckBoxStateChanged();
void undoRedoMaxStepsChanged();

void undoRedoApplyButtonPressed();
void undoRedoCancelButtonPressed();

private:

bool canApplyOrCancelUndoRedoChanges() const;
void updateSafeHelperTextEnabledState();

Ui::GeneralPage* ui = nullptr;
Expand Down
71 changes: 29 additions & 42 deletions app/src/mainwindow2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ GNU General Public License for more details.
#include "soundmanager.h"
#include "viewmanager.h"
#include "selectionmanager.h"
#include "undoredomanager.h"

#include "actioncommands.h"
#include "fileformat.h" //contains constants used by Pencil File Format
#include "util.h"
#include "backupelement.h"
#include "undoredocommand.h"

// app headers
#include "colorbox.h"
Expand Down Expand Up @@ -263,10 +264,8 @@ void MainWindow2::createMenus()
connect(ui->actionImport_Replace_Palette, &QAction::triggered, this, &MainWindow2::openPalette);

//--- Edit Menu ---
connect(mEditor, &Editor::updateBackup, this, &MainWindow2::undoActSetText);
connect(ui->actionUndo, &QAction::triggered, mEditor, &Editor::undo);
replaceUndoRedoActions();
connect(ui->actionRemoveLastPolylineSegment, &QAction::triggered, static_cast<PolylineTool*>(mEditor->tools()->getTool(POLYLINE)), &PolylineTool::removeLastPolylineSegment);
connect(ui->actionRedo, &QAction::triggered, mEditor, &Editor::redo);
connect(ui->actionCut, &QAction::triggered, mEditor, &Editor::copyAndCut);
connect(ui->actionCopy, &QAction::triggered, mEditor, &Editor::copy);
connect(ui->actionPaste_Previous, &QAction::triggered, mEditor, &Editor::pasteFromPreviousFrame);
Expand Down Expand Up @@ -465,6 +464,16 @@ void MainWindow2::createMenus()
connect(mRecentFileMenu, &RecentFileMenu::loadRecentFile, this, &MainWindow2::openFile);
}

void MainWindow2::replaceUndoRedoActions()
{
ui->menuEdit->removeAction(ui->actionUndo);
ui->menuEdit->removeAction(ui->actionRedo);
ui->actionUndo = mEditor->undoRedo()->createUndoAction(this, ui->actionUndo->icon());
ui->actionRedo = mEditor->undoRedo()->createRedoAction(this, ui->actionRedo->icon());
ui->menuEdit->insertAction(ui->actionCut, ui->actionUndo);
ui->menuEdit->insertAction(ui->actionCut, ui->actionRedo);
}

void MainWindow2::setOpacity(int opacity)
{
mEditor->preference()->set(SETTING::WINDOW_OPACITY, 100 - opacity);
Expand All @@ -473,11 +482,17 @@ void MainWindow2::setOpacity(int opacity)

void MainWindow2::updateSaveState()
{
const bool hasUnsavedChanges = mEditor->currentBackup() != mBackupAtSave;
const bool hasUnsavedChanges = mEditor->undoRedo()->hasUnsavedChanges();
setWindowModified(hasUnsavedChanges);
ui->statusBar->updateModifiedStatus(hasUnsavedChanges);
}

void MainWindow2::updateBackupActionState()
{
mEditor->undoRedo()->updateUndoAction(ui->actionUndo);
mEditor->undoRedo()->updateRedoAction(ui->actionRedo);
}

void MainWindow2::openPegAlignDialog()
{
if (mPegAlign != nullptr)
Expand Down Expand Up @@ -698,7 +713,7 @@ bool MainWindow2::openObject(const QString& strFilePath)
progress.setValue(progress.maximum());

updateSaveState();
undoActSetText();
updateBackupActionState();

if (!QFileInfo(strFilePath).isWritable())
{
Expand Down Expand Up @@ -779,7 +794,6 @@ bool MainWindow2::saveObject(QString strSavedFileName)
mTimeLine->updateContent();

setWindowTitle(strSavedFileName.prepend("[*]"));
mBackupAtSave = mEditor->currentBackup();
updateSaveState();

progress.setValue(progress.maximum());
Expand All @@ -799,7 +813,7 @@ bool MainWindow2::saveDocument()

bool MainWindow2::maybeSave()
{
if (mEditor->currentBackup() == mBackupAtSave)
if (!mEditor->undoRedo()->hasUnsavedChanges())
{
return true;
}
Expand Down Expand Up @@ -1046,7 +1060,8 @@ void MainWindow2::newObject()
closeDialogs();

setWindowTitle(PENCIL_WINDOW_TITLE);
undoActSetText();

updateBackupActionState();
}

bool MainWindow2::newObjectFromPresets(int presetIndex)
Expand All @@ -1071,7 +1086,7 @@ bool MainWindow2::newObjectFromPresets(int presetIndex)

setWindowTitle(PENCIL_WINDOW_TITLE);
updateSaveState();
undoActSetText();
updateBackupActionState();

return true;
}
Expand Down Expand Up @@ -1322,35 +1337,6 @@ void MainWindow2::clearKeyboardShortcuts()
}
}

void MainWindow2::undoActSetText()
{
if (mEditor->mBackupIndex < 0)
{
ui->actionUndo->setText(tr("Undo", "Menu item text"));
ui->actionUndo->setEnabled(false);
}
else
{
ui->actionUndo->setText(QString("%1 %2 %3").arg(tr("Undo", "Menu item text"))
.arg(mEditor->mBackupIndex + 1)
.arg(mEditor->mBackupList.at(mEditor->mBackupIndex)->undoText));
ui->actionUndo->setEnabled(true);
}

if (mEditor->mBackupIndex + 2 < mEditor->mBackupList.size())
{
ui->actionRedo->setText(QString("%1 %2 %3").arg(tr("Redo", "Menu item text"))
.arg(mEditor->mBackupIndex + 2)
.arg(mEditor->mBackupList.at(mEditor->mBackupIndex + 1)->undoText));
ui->actionRedo->setEnabled(true);
}
else
{
ui->actionRedo->setText(tr("Redo", "Menu item text"));
ui->actionRedo->setEnabled(false);
}
}

void MainWindow2::exportPalette()
{
QString filePath = FileDialog::getSaveFileName(this, FileType::PALETTE);
Expand Down Expand Up @@ -1406,7 +1392,8 @@ void MainWindow2::openPalette()

void MainWindow2::makeConnections(Editor* editor)
{
connect(editor, &Editor::updateBackup, this, &MainWindow2::updateSaveState);
connect(editor->undoRedo(), &UndoRedoManager::didUpdateUndoStack, this, &MainWindow2::updateSaveState);
connect(editor->undoRedo(), &UndoRedoManager::didUpdateUndoStack, this, &MainWindow2::updateBackupActionState);
connect(editor, &Editor::needDisplayInfo, this, &MainWindow2::displayMessageBox);
connect(editor, &Editor::needDisplayInfoNoTitle, this, &MainWindow2::displayMessageBoxNoTitle);
connect(editor->layers(), &LayerManager::currentLayerChanged, this, &MainWindow2::currentLayerChanged);
Expand Down Expand Up @@ -1634,7 +1621,7 @@ void MainWindow2::startProjectRecovery(int result)
Q_ASSERT(o);
mEditor->setObject(o);
updateSaveState();
undoActSetText();
updateBackupActionState();

const QString title = tr("Recovery Succeeded!");
const QString text = tr("Please save your work immediately to prevent loss of data");
Expand Down Expand Up @@ -1682,7 +1669,7 @@ void MainWindow2::createToolbars()
mOverlayToolbar->setIconSize(QSize(22,22));
mViewToolbar->setIconSize(QSize(22,22));
mMainToolbar->setIconSize(QSize(22,22));

QToolButton* perspectiveLinesAngleButton = new QToolButton(this);
perspectiveLinesAngleButton->setDefaultAction(ui->menuPerspectiveLinesAngle->menuAction());
perspectiveLinesAngleButton->setPopupMode(QToolButton::InstantPopup);
Expand Down
8 changes: 3 additions & 5 deletions app/src/mainwindow2.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ColorInspector;
class RecentFileMenu;
class ActionCommands;
class ImportImageSeqDialog;
class BackupElement;
class UndoRedoCommand;
class LayerOpacityDialog;
class PegBarAlignmentDialog;
class RepositionFramesDialog;
Expand All @@ -65,7 +65,7 @@ class MainWindow2 : public QMainWindow
Editor* mEditor = nullptr;

public slots:
void undoActSetText();
void updateBackupActionState();
void updateSaveState();
void openPegAlignDialog();
void openRepositionDialog();
Expand Down Expand Up @@ -124,6 +124,7 @@ private slots:

void createDockWidgets();
void createMenus();
void replaceUndoRedoActions();
void setupKeyboardShortcuts();
void clearKeyboardShortcuts();
bool loadMostRecent();
Expand Down Expand Up @@ -167,9 +168,6 @@ private slots:
QToolBar* mViewToolbar = nullptr;
QToolBar* mOverlayToolbar = nullptr;

// backup
BackupElement* mBackupAtSave = nullptr;

PegBarAlignmentDialog* mPegAlign = nullptr;
RepositionFramesDialog* mReposDialog = nullptr;
LayerOpacityDialog* mLayerOpacityDialog = nullptr;
Expand Down
Loading

0 comments on commit 44bfeaa

Please sign in to comment.