Skip to content

Commit

Permalink
Merge branch 'preset'
Browse files Browse the repository at this point in the history
  • Loading branch information
chchwy committed Jan 7, 2020
2 parents a7813fd + 4b38d1d commit 3469949
Show file tree
Hide file tree
Showing 19 changed files with 581 additions and 79 deletions.
9 changes: 6 additions & 3 deletions app/app.pro
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ HEADERS += \
src/spinslider.h \
src/doubleprogressdialog.h \
src/colorslider.h \
src/checkupdatesdialog.h
src/checkupdatesdialog.h \
src/presetdialog.h

SOURCES += \
src/importlayersdialog.cpp \
Expand Down Expand Up @@ -101,7 +102,8 @@ SOURCES += \
src/spinslider.cpp \
src/doubleprogressdialog.cpp \
src/colorslider.cpp \
src/checkupdatesdialog.cpp
src/checkupdatesdialog.cpp \
src/presetdialog.cpp

FORMS += \
ui/importimageseqpreview.ui \
Expand All @@ -127,7 +129,8 @@ FORMS += \
ui/timelinepage.ui \
ui/filespage.ui \
ui/toolspage.ui \
ui/toolboxwidget.ui
ui/toolboxwidget.ui \
ui/presetdialog.ui



Expand Down
7 changes: 5 additions & 2 deletions app/src/colorpalettewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,24 @@ void ColorPaletteWidget::initUI()
connect(ui->colorDialogButton, &QPushButton::clicked, this, &ColorPaletteWidget::clickColorDialogButton);
connect(ui->removeColorButton, &QPushButton::clicked, this, &ColorPaletteWidget::clickRemoveColorButton);
connect(ui->colorListWidget, &QListWidget::customContextMenuRequested, this, &ColorPaletteWidget::showContextMenu);

connect(editor(), &Editor::objectLoaded, this, &ColorPaletteWidget::updateUI);
}

void ColorPaletteWidget::updateUI()
{
mObject = mEditor->object();
refreshColorList();
updateGridUI();
}

void ColorPaletteWidget::setCore(Editor *editor)
void ColorPaletteWidget::setCore(Editor* editor)
{
mEditor = editor;
mObject = mEditor->object();
}

void ColorPaletteWidget::showContextMenu(const QPoint &pos)
void ColorPaletteWidget::showContextMenu(const QPoint& pos)
{
QPoint globalPos = ui->colorListWidget->mapToGlobal(pos);

Expand Down
1 change: 0 additions & 1 deletion app/src/colorpalettewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ private slots:

Editor* mEditor = nullptr;
Object* mObject = nullptr;

};

#endif
Expand Down
120 changes: 82 additions & 38 deletions app/src/mainwindow2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ GNU General Public License for more details.
#include "playbackmanager.h"
#include "soundmanager.h"
#include "viewmanager.h"
#include "selectionmanager.h"

#include "actioncommands.h"
#include "fileformat.h" //contains constants used by Pencil File Format
Expand All @@ -69,6 +68,7 @@ GNU General Public License for more details.
#include "recentfilemenu.h"
#include "shortcutfilter.h"
#include "app_util.h"
#include "presetdialog.h"

#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
Expand All @@ -88,22 +88,19 @@ GNU General Public License for more details.



MainWindow2::MainWindow2(QWidget *parent) :
MainWindow2::MainWindow2(QWidget* parent) :
QMainWindow(parent),
ui(new Ui::MainWindow2)
{
ui->setupUi(this);

// Initialize order
// 1. object 2. editor 3. scribble area 4. other widgets
Object* object = new Object();
object->init();
object->createDefaultLayers();

// 1. editor 2. object 3. scribble area 4. other widgets
mEditor = new Editor(this);
mEditor->setScribbleArea(ui->scribbleArea);
mEditor->init();
mEditor->setObject(object);

newObject();

ui->scribbleArea->setEditor(mEditor);
ui->scribbleArea->init();
Expand All @@ -128,9 +125,10 @@ MainWindow2::MainWindow2(QWidget *parent) :

mEditor->tools()->setDefaultTool();
ui->background->init(mEditor->preference());
mEditor->updateObject();

setWindowTitle(PENCIL_WINDOW_TITLE);

showPresetDialog();
}

MainWindow2::~MainWindow2()
Expand Down Expand Up @@ -491,23 +489,28 @@ void MainWindow2::tabletEvent(QTabletEvent* event)

void MainWindow2::newDocument(bool force)
{
if (force || maybeSave())
if (force)
{
Object* object = new Object();
object->init();
object->createDefaultLayers();
mEditor->setObject(object);
mEditor->scrubTo(0);
mEditor->view()->resetView();
mEditor->select()->resetSelectionProperties();

// Refresh the palette
mColorPalette->refreshColorList();
mEditor->color()->setColorNumber(0);
newObject();

setWindowTitle(PENCIL_WINDOW_TITLE);
updateSaveState();
}
else if (maybeSave())
{
if (mEditor->preference()->isOn(SETTING::ASK_FOR_PRESET))
{
showPresetDialog();
}
else
{
int defaultPreset = mEditor->preference()->getInt(SETTING::DEFAULT_PRESET);
newObjectFromPresets(defaultPreset);

setWindowTitle(PENCIL_WINDOW_TITLE);
updateSaveState();
}
}
}

void MainWindow2::openDocument()
Expand All @@ -516,17 +519,10 @@ void MainWindow2::openDocument()
{
FileDialog fileDialog(this);
QString fileName = fileDialog.openFile(FileType::ANIMATION);
if (fileName.isEmpty())
if (!fileName.isEmpty())
{
return;
openObject(fileName);
}
QFileInfo fileInfo(fileName);
if (fileInfo.isDir())
{
return;
}

openObject(fileName, false);
}
}

Expand All @@ -543,13 +539,14 @@ bool MainWindow2::saveAsNewDocument()

void MainWindow2::openFile(QString filename)
{
openObject(filename, true);
if (maybeSave())
{
openObject(filename);
}
}

bool MainWindow2::openObject(QString strFilePath, bool checkForChanges)
bool MainWindow2::openObject(QString strFilePath)
{
if(checkForChanges && !maybeSave()) return false; // Open cancelled by user

// Check for potential issues with the file
QFileInfo fileInfo(strFilePath);
if (fileInfo.isDir())
Expand Down Expand Up @@ -653,10 +650,6 @@ bool MainWindow2::openObject(QString strFilePath, bool checkForChanges)

progress.setValue(progress.value() + 1);

mEditor->select()->resetSelectionProperties();

// Refresh the Palette
mColorPalette->refreshColorList();
mEditor->layers()->notifyAnimationLengthChanged();

progress.setValue(progress.maximum());
Expand Down Expand Up @@ -688,6 +681,7 @@ bool MainWindow2::saveObject(QString strSavedFileName)

Status st = fm.save(mEditor->object(), strSavedFileName);


if (!st.ok())
{
#if QT_VERSION >= 0x050400
Expand Down Expand Up @@ -717,6 +711,9 @@ bool MainWindow2::saveObject(QString strSavedFileName)
return false;
}

mEditor->object()->setFilePath(strSavedFileName);
mEditor->object()->setModified(false);

QSettings settings(PENCIL2D, PENCIL2D);
settings.setValue(LAST_PCLX_PATH, strSavedFileName);

Expand Down Expand Up @@ -1018,6 +1015,53 @@ void MainWindow2::resetAndDockAllSubWidgets()
}
}

bool MainWindow2::newObject()
{
Object* object = nullptr;
object = new Object();
object->init();
mEditor->setObject(object);
return true;
}

bool MainWindow2::newObjectFromPresets(int presetIndex)
{
Object* object = nullptr;
QString presetFilePath = (presetIndex > 0) ? PresetDialog::getPresetPath(presetIndex) : "";
if (!presetFilePath.isEmpty())
{
FileManager fm(this);
object = fm.load(presetFilePath);
if (fm.error().ok() == false) object = nullptr;
}
if (object == nullptr)
{
object = new Object();
object->init();
}
mEditor->setObject(object);
return true;
}

void MainWindow2::showPresetDialog()
{
if (mEditor->preference()->isOn(SETTING::ASK_FOR_PRESET))
{
PresetDialog* presetDialog = new PresetDialog(mEditor->preference(), this);
presetDialog->setAttribute(Qt::WA_DeleteOnClose);
connect(presetDialog, &PresetDialog::finished, [=](int result)
{
if (result == QDialog::Accepted)
{
int presetIndex = presetDialog->getPresetIndex();
newObjectFromPresets(presetIndex);
qDebug() << "Accepted!";
}
});
presetDialog->open();
}
}

void MainWindow2::readSettings()
{
QSettings settings(PENCIL2D, PENCIL2D);
Expand Down
14 changes: 8 additions & 6 deletions app/src/mainwindow2.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class MainWindow2 : public QMainWindow

Editor* mEditor = nullptr;

public slots:
public slots:
void undoActSetText();
void undoActSetEnabled();
void updateSaveState();
Expand All @@ -71,7 +71,6 @@ class MainWindow2 : public QMainWindow
void currentLayerChanged();

public:
void setOpacity(int opacity);
void newDocument(bool force = false);
void openDocument();
bool saveDocument();
Expand All @@ -83,15 +82,15 @@ class MainWindow2 : public QMainWindow
void importImage();
void importImageSequence();
void importPredefinedImageSet();
void importImageSequenceNumbered();
void importLayers();
void importMovie();
void importGIF();

void lockWidgets(bool shouldLock);

void setOpacity(int opacity);
void preferences();

void openFile(QString filename);

PreferencesDialog* getPrefDialog() { return mPrefDialog; }
Expand All @@ -110,7 +109,9 @@ private slots:
void resetAndDockAllSubWidgets();

private:
bool openObject(QString strFilename, bool checkForChanges);
bool newObject();
bool newObjectFromPresets(int presetIndex);
bool openObject(QString strFilename);
bool saveObject(QString strFileName);

void createDockWidgets();
Expand All @@ -119,6 +120,7 @@ private slots:
void setupKeyboardShortcuts();
void clearKeyboardShortcuts();
void updateZoomLabel();
void showPresetDialog();

void openPalette();
void importPalette();
Expand Down Expand Up @@ -160,7 +162,7 @@ private slots:

private:
ActionCommands* mCommands = nullptr;
QList< BaseDockWidget* > mDockWidgets;
QList<BaseDockWidget*> mDockWidgets;

QIcon mStartIcon;
QIcon mStopIcon;
Expand Down
Loading

0 comments on commit 3469949

Please sign in to comment.