Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TimeLineCells rewrite part 1 #1880

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
9dda124
TimeLine rewrite: WIP
MrStevns Aug 25, 2024
16acdd9
Introduce TimeLineBaseCell for reuse-ability
MrStevns Aug 27, 2024
1260b3d
Re-implement ability to select layer
MrStevns Aug 31, 2024
c44daff
Implement layer list widget
MrStevns Sep 1, 2024
c80529a
Layer cell: preload asset on init rather than paint
MrStevns Sep 3, 2024
3926283
Layer list: Enable high DPI for the overall pixmap
MrStevns Sep 3, 2024
f404c2b
Layer list: clean up a lot of unnecessary state
MrStevns Sep 3, 2024
79b068b
Layer list: Rework cell dragging
MrStevns Sep 7, 2024
c24c2e3
Layer list: fix crash when moving layers around
MrStevns Sep 7, 2024
f91be18
Layer list: Update dragging based on layer cell top
MrStevns Sep 7, 2024
578f7fb
Track list: preparations (WIP)
MrStevns Sep 7, 2024
07ad6ff
Track list: Separate header and list
MrStevns Sep 8, 2024
a494131
Layer list: fix being able to drag cell while changing visibility state
MrStevns Sep 8, 2024
ce314bd
Layer cell: refactoring
MrStevns Sep 8, 2024
6c72962
Layer list: refactor double click event
MrStevns Sep 8, 2024
80592ee
Tweak layer dragging
MrStevns Sep 8, 2024
4c971aa
Fix crash when deleting cells while we're still in event loop
MrStevns Sep 8, 2024
bf6ba4c
Layer list: improve event logic
MrStevns Sep 8, 2024
495eea8
Layer list: improve dragging visuals
MrStevns Sep 8, 2024
44bfeaa
Merge branch 'master' into timeline-rewrite-v2
MrStevns Sep 8, 2024
99f8a20
Cleanup
MrStevns Sep 8, 2024
9eb6c32
Roll back some changes to fix tests
MrStevns Sep 8, 2024
701b11d
Fix cases where dragging could initiate a swap from the same layer
MrStevns Sep 10, 2024
e706f9e
Introduce an editor widget for the layer cell
MrStevns Sep 18, 2024
beb7e68
Re-implement cell drag gutter as a widget
MrStevns Sep 19, 2024
bb3d5d6
Implement new layer cell with qboxlayout
MrStevns Sep 22, 2024
287c3dc
Implement double-click to edit layer name
MrStevns Sep 22, 2024
83386c7
Remove QSvgWidget import
MrStevns Sep 23, 2024
a255cd5
Cleanup TimeLineLayerList
MrStevns Sep 23, 2024
e81831f
Implement better dragging UI/UX
MrStevns Sep 24, 2024
66eab40
LayerList: Cleanup obsolete code
MrStevns Sep 25, 2024
d299e99
Tracklist: remove TIMELINE_CELL_TYPE
MrStevns Sep 25, 2024
055226b
TimeLineLayerCellEditorWidget: Remove focus when about to drag
MrStevns Sep 25, 2024
cb91c1e
Add missing licenses
MrStevns Sep 25, 2024
d8c5290
Rollback some changes not meant for this PR
MrStevns Sep 25, 2024
3c930cf
TimeLineLayerList: Change QMap to QList
MrStevns Sep 26, 2024
83dedd5
More cleanup of obsolete code
MrStevns Sep 26, 2024
a407f92
Remove input dialog to input layer name
MrStevns Sep 26, 2024
54d35f2
LineEditView: Remove qDebug statement
MrStevns Sep 26, 2024
be8bdb0
Merge branch 'master' into timeline-rewrite-v2
MrStevns Oct 19, 2024
41d2ad5
LineEditView: Accept some events
MrStevns Nov 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions app/app.pro
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ HEADERS += \
src/importlayersdialog.h \
src/importpositiondialog.h \
src/layeropacitydialog.h \
src/layervisibilitybutton.h \
src/lineeditwidget.h \
src/mainwindow2.h \
src/onionskinwidget.h \
src/predefinedsetmodel.h \
Expand All @@ -88,15 +90,22 @@ HEADERS += \
src/filespage.h \
src/generalpage.h \
src/shortcutspage.h \
src/timelinebasecell.h \
src/timelinelayercell.h \
src/timelinelayercelleditorwidget.h \
src/timelinelayercellgutterwidget.h \
src/timelinelayerheaderwidget.h \
src/timelinelayerlist.h \
src/timelinepage.h \
src/timelinetrackheaderwidget.h \
src/timelinetracklist.h \
src/toolspage.h \
src/basedockwidget.h \
src/colorbox.h \
src/colorinspector.h \
src/colorpalettewidget.h \
src/colorwheel.h \
src/timeline.h \
src/timelinecells.h \
src/timecontrols.h \
src/cameracontextmenu.h \
src/camerapropertiesdialog.h \
Expand Down Expand Up @@ -128,6 +137,8 @@ SOURCES += \
src/importlayersdialog.cpp \
src/importpositiondialog.cpp \
src/layeropacitydialog.cpp \
src/layervisibilitybutton.cpp \
src/lineeditwidget.cpp \
src/main.cpp \
src/mainwindow2.cpp \
src/onionskinwidget.cpp \
Expand All @@ -139,15 +150,22 @@ SOURCES += \
src/filespage.cpp \
src/generalpage.cpp \
src/shortcutspage.cpp \
src/timelinebasecell.cpp \
src/timelinelayercell.cpp \
src/timelinelayercelleditorwidget.cpp \
src/timelinelayercellgutterwidget.cpp \
src/timelinelayerheaderwidget.cpp \
src/timelinelayerlist.cpp \
src/timelinepage.cpp \
src/timelinetrackheaderwidget.cpp \
src/timelinetracklist.cpp \
src/toolspage.cpp \
src/basedockwidget.cpp \
src/colorbox.cpp \
src/colorinspector.cpp \
src/colorpalettewidget.cpp \
src/colorwheel.cpp \
src/timeline.cpp \
src/timelinecells.cpp \
src/timecontrols.cpp \
src/cameracontextmenu.cpp \
src/camerapropertiesdialog.cpp \
Expand Down
37 changes: 4 additions & 33 deletions app/src/actioncommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -842,54 +842,25 @@ void ActionCommands::moveFrameBackward()

Status ActionCommands::addNewBitmapLayer()
{
bool ok;
QString text = QInputDialog::getText(nullptr, tr("Layer Properties"),
tr("Layer name:"), QLineEdit::Normal,
mEditor->layers()->nameSuggestLayer(tr("Bitmap Layer")), &ok);
if (ok && !text.isEmpty())
{
mEditor->layers()->createBitmapLayer(text);
}
mEditor->layers()->createBitmapLayer(mEditor->layers()->nameSuggestLayer(tr("Bitmap Layer")));
return Status::OK;
}

Status ActionCommands::addNewVectorLayer()
{
bool ok;
QString text = QInputDialog::getText(nullptr, tr("Layer Properties"),
tr("Layer name:"), QLineEdit::Normal,
mEditor->layers()->nameSuggestLayer(tr("Vector Layer")), &ok);
if (ok && !text.isEmpty())
{
mEditor->layers()->createVectorLayer(text);
}
mEditor->layers()->createVectorLayer(mEditor->layers()->nameSuggestLayer(tr("Vector Layer")));
return Status::OK;
}

Status ActionCommands::addNewCameraLayer()
{
bool ok;
QString text = QInputDialog::getText(nullptr, tr("Layer Properties", "A popup when creating a new layer"),
tr("Layer name:"), QLineEdit::Normal,
mEditor->layers()->nameSuggestLayer(tr("Camera Layer")), &ok);
if (ok && !text.isEmpty())
{
mEditor->layers()->createCameraLayer(text);
}
mEditor->layers()->createCameraLayer(mEditor->layers()->nameSuggestLayer(tr("Camera Layer")));
return Status::OK;
}

Status ActionCommands::addNewSoundLayer()
{
bool ok = false;
QString strLayerName = QInputDialog::getText(nullptr, tr("Layer Properties"),
tr("Layer name:"), QLineEdit::Normal,
mEditor->layers()->nameSuggestLayer(tr("Sound Layer")), &ok);
if (ok && !strLayerName.isEmpty())
{
Layer* layer = mEditor->layers()->createSoundLayer(strLayerName);
mEditor->layers()->setCurrentLayer(layer);
}
mEditor->layers()->createSoundLayer(mEditor->layers()->nameSuggestLayer(tr("Sound Layer")));
return Status::OK;
}

Expand Down
149 changes: 149 additions & 0 deletions app/src/layervisibilitybutton.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
Pencil2D - Traditional Animation Software
Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
Copyright (C) 2008-2009 Mj Mendoza IV
Copyright (C) 2012-2020 Matthew Chiawen Chang
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include "layervisibilitybutton.h"

#include "layer.h"
#include "editor.h"
#include "layermanager.h"

#include <QIcon>
#include <QPainter>
#include <QApplication>
#include <QDebug>
#include <QMouseEvent>

LayerVisibilityButton::LayerVisibilityButton(QWidget* parent,
const LayerVisibilityContext& visibilityContext,
Layer* layer,
Editor* editor)
: QWidget(parent),
mLayer(layer),
mEditor(editor),
mVisibilityContext(visibilityContext)
{
}

QSize LayerVisibilityButton::sizeHint() const
{
return QSize(22,22);
}

void LayerVisibilityButton::paintEvent(QPaintEvent* event)
{
QPainter painter(this);

const QPalette& palette = QApplication::palette();

switch (mVisibilityContext) {
case LayerVisibilityContext::LOCAL:
paintLocalVisibilityState(painter, palette);
break;
case LayerVisibilityContext::GLOBAL:
paintGlobalVisibilityState(painter, palette);
break;
}

painter.setRenderHint(QPainter::Antialiasing, true);
painter.drawEllipse(rect().center().x() - (mVisibilityCircleSize.width() * 0.5) + painter.pen().width(),
rect().center().y() - (mVisibilityCircleSize.height() * 0.5) + painter.pen().width(),
mVisibilityCircleSize.width(), mVisibilityCircleSize.height());
painter.setRenderHint(QPainter::Antialiasing, false);

mIconValid = true;
}

void LayerVisibilityButton::paintLocalVisibilityState(QPainter& painter, const QPalette& palette)
{
int isSelected = mLayer->id() == mEditor->layers()->currentLayer()->id();

const LayerVisibility& visibility = mEditor->layerVisibility();
QColor penColor = painter.pen().color();

if (mEditor->layers()->currentLayer()->id() == mLayer->id())
{
penColor = palette.color(QPalette::HighlightedText);
}
else
{
penColor = palette.color(QPalette::Text);
}

if (!mLayer->visible())
{
if (visibility == LayerVisibility::CURRENTONLY && !isSelected) {
penColor.setAlphaF(0.5);
}
painter.setPen(penColor);
painter.setBrush(palette.color(QPalette::Base));
}
else
{
if ((visibility == LayerVisibility::ALL) || isSelected)
{
painter.setBrush(palette.color(QPalette::Text));
}
else if (visibility == LayerVisibility::CURRENTONLY)
{
painter.setBrush(palette.color(QPalette::Base));
}
else if (visibility == LayerVisibility::RELATED)
{
QColor color = palette.color(QPalette::Text);
color.setAlpha(128);
painter.setBrush(color);
}
}

painter.setPen(penColor);
}

void LayerVisibilityButton::paintGlobalVisibilityState(QPainter &painter, const QPalette& palette)
{
// --- draw circle
painter.setPen(palette.color(QPalette::Text));
if (mEditor->layerVisibility() == LayerVisibility::CURRENTONLY)
{
painter.setBrush(palette.color(QPalette::Base));
}
else if (mEditor->layerVisibility() == LayerVisibility::RELATED)
{
QColor color = palette.color(QPalette::Text);
color.setAlpha(128);
painter.setBrush(color);
}
else if (mEditor->layerVisibility() == LayerVisibility::ALL)
{
painter.setBrush(palette.brush(QPalette::Text));
}
}

void LayerVisibilityButton::mousePressEvent(QMouseEvent* event)
{
switch (mVisibilityContext) {
case LayerVisibilityContext::GLOBAL: {
if (event->buttons() & Qt::LeftButton) {
mEditor->increaseLayerVisibilityIndex();
} else if (event->buttons() & Qt::RightButton) {
mEditor->decreaseLayerVisibilityIndex();
}
break;
}
case LayerVisibilityContext::LOCAL:
{
mLayer->switchVisibility();
}
}

emit visibilityChanged();
}
65 changes: 65 additions & 0 deletions app/src/layervisibilitybutton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
Pencil2D - Traditional Animation Software
Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
Copyright (C) 2008-2009 Mj Mendoza IV
Copyright (C) 2012-2020 Matthew Chiawen Chang
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#ifndef LAYERVISIBILITYBUTTON_H
#define LAYERVISIBILITYBUTTON_H

#include <QObject>
#include <QWidget>

class Layer;
class QIcon;
class QToolButton;
class Editor;
class QPixmap;

enum class LayerVisibilityContext
{
LOCAL,
GLOBAL
};

class LayerVisibilityButton : public QWidget
{
Q_OBJECT
public:
LayerVisibilityButton(QWidget* parent,
const LayerVisibilityContext& visibilityContext,
Layer* layer,
Editor* editor);

void paintEvent(QPaintEvent* event) override;

void paintLocalVisibilityState(QPainter& painter, const QPalette& palette);
void paintGlobalVisibilityState(QPainter& painter, const QPalette& palette);

void mousePressEvent(QMouseEvent* event) override;

QSize sizeHint() const override;

signals:
void visibilityChanged();

private:

Layer* mLayer = nullptr;
Editor* mEditor = nullptr;
QSize mVisibilityCircleSize = QSize(10,10);

bool mIconValid = false;

const LayerVisibilityContext mVisibilityContext;

};

#endif // LAYERVISIBILITYBUTTON_H
Loading
Loading