Skip to content

Commit

Permalink
Re-implement cell drag gutter as a widget
Browse files Browse the repository at this point in the history
  • Loading branch information
MrStevns committed Sep 19, 2024
1 parent e706f9e commit beb7e68
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 55 deletions.
2 changes: 2 additions & 0 deletions app/app.pro
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ HEADERS += \
src/timelinedef.h \
src/timelinelayercell.h \
src/timelinelayercelleditorwidget.h \
src/timelinelayercellgutterwidget.h \
src/timelinelayerheaderwidget.h \
src/timelinelayerlist.h \
src/timelinepage.h \
Expand Down Expand Up @@ -149,6 +150,7 @@ SOURCES += \
src/timelinebasecell.cpp \
src/timelinelayercell.cpp \
src/timelinelayercelleditorwidget.cpp \
src/timelinelayercellgutterwidget.cpp \
src/timelinelayerheaderwidget.cpp \
src/timelinelayerlist.cpp \
src/timelinepage.cpp \
Expand Down
16 changes: 1 addition & 15 deletions app/src/timelinebasecell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,13 @@

TimeLineBaseCell::TimeLineBaseCell(TimeLine* timeline,
QWidget* parent,
Editor* editor,
const QPoint& origin,
int width,
int height) : QObject(parent)
Editor* editor) : QObject(parent)
{
mTimeLine = timeline;
mEditor = editor;
mPrefs = mEditor->preference();
mGlobalBounds = QRect(origin, QSize(width,height));
}

TimeLineBaseCell::~TimeLineBaseCell()
{
}

bool TimeLineBaseCell::contains(const QPoint& point) const
{
return mGlobalBounds.contains(point);
}

void TimeLineBaseCell::move(int x, int y)
{
mGlobalBounds.translate(x, y);
}
13 changes: 2 additions & 11 deletions app/src/timelinebasecell.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,17 @@ class TimeLineBaseCell: public QObject {
public:
TimeLineBaseCell(TimeLine* timeline,
QWidget* parent,
Editor* editor,
const QPoint& origin,
int width,
int height);
Editor* editor);
virtual ~TimeLineBaseCell();

virtual TimeLineCellType type() const { return TimeLineCellType::INVALID; }

bool contains(const QPoint& point) const;
void move(int x, int y);
virtual void setSize(const QSize& size) { mGlobalBounds.setSize(size); }
const QSize size() const { return mGlobalBounds.size(); }
const QPoint topLeft() const { return mGlobalBounds.topLeft(); }
virtual void setSize(const QSize& size) = 0;

Editor* mEditor = nullptr;
TimeLine* mTimeLine = nullptr;
PreferenceManager* mPrefs = nullptr;

QRect mGlobalBounds = QRect();

private:
};

Expand Down
11 changes: 7 additions & 4 deletions app/src/timelinelayercell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ TimeLineLayerCell::TimeLineLayerCell(TimeLine* timeline,
Editor* editor,
Layer* layer,
const QPoint& origin, int width, int height)
: TimeLineBaseCell(timeline, parent, editor, origin, width, height)
: TimeLineBaseCell(timeline, parent, editor)
{
// mOldBounds = mGlobalBounds;

mEditorWidget = new TimeLineLayerCellEditorWidget(parent, editor, layer);
mEditorWidget->setGeometry(mGlobalBounds);
mEditorWidget->setGeometry(QRect(origin, QSize(width, height)));
mEditorWidget->show();
}

Expand All @@ -36,3 +34,8 @@ TimeLineLayerCell::~TimeLineLayerCell()
mEditorWidget->deleteLater();
}

void TimeLineLayerCell::setSize(const QSize& size)
{
mEditorWidget->resize(size);
}

2 changes: 2 additions & 0 deletions app/src/timelinelayercell.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class TimeLineLayerCell : public TimeLineBaseCell

TimeLineLayerCellEditorWidget* editorWidget() const { return mEditorWidget; }

void setSize(const QSize& size) override;

private:
TimeLineLayerCellEditorWidget* mEditorWidget = nullptr;
};
Expand Down
7 changes: 4 additions & 3 deletions app/src/timelinelayercelleditorwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,13 @@ void TimeLineLayerCellEditorWidget::handleDragging(QMouseEvent* event)

void TimeLineLayerCellEditorWidget::handleDragEnded(QMouseEvent*)
{
if (mDidDetach) {
if (mIsDraggable) {
emit drag(DragEvent::ENDED, this, 0, y());

mIsDraggable = false;
mDragFromY = y();
mDidDetach = false;
}
mIsDraggable = false;
mDragFromY = y();
}

int TimeLineLayerCellEditorWidget::getLayerNumber(int posY) const
Expand Down
25 changes: 25 additions & 0 deletions app/src/timelinelayercellgutterwidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "timelinelayercellgutterwidget.h"

#include <QPainter>
#include <QApplication>

TimeLineLayerCellGutterWidget::TimeLineLayerCellGutterWidget(int width, QWidget* parent)
: QWidget(parent)
{

setGeometry(0, 0, width, 2);
}

void TimeLineLayerCellGutterWidget::paintEvent(QPaintEvent* event)
{
QPainter painter(this);
QPalette palette = QApplication::palette();

painter.setPen(palette.color(QPalette::HighlightedText));
painter.drawRect(0, rect().bottom(), rect().width(), 2);
}

void TimeLineLayerCellGutterWidget::updateWidth(int width)
{
resize(width, height());
}
15 changes: 15 additions & 0 deletions app/src/timelinelayercellgutterwidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef TIMELINELAYERCELLGUTTERWIDGET_H
#define TIMELINELAYERCELLGUTTERWIDGET_H

#include <QWidget>

class TimeLineLayerCellGutterWidget : public QWidget
{
public:
TimeLineLayerCellGutterWidget(int width, QWidget* parent = nullptr);

void paintEvent(QPaintEvent* event) override;
void updateWidth(int width);
};

#endif // TIMELINELAYERCELLGUTTERWIDGET_H
42 changes: 20 additions & 22 deletions app/src/timelinelayerlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "timelinelayercell.h"
#include "timelinelayercelleditorwidget.h"
#include "timelinelayercellgutterwidget.h"

TimeLineLayerList::TimeLineLayerList(TimeLine* parent, Editor* editor) : QWidget(parent)
{
Expand All @@ -23,6 +24,9 @@ TimeLineLayerList::TimeLineLayerList(TimeLine* parent, Editor* editor) : QWidget
setMouseTracking(true);

connect(mPrefs, &PreferenceManager::optionChanged, this, &TimeLineLayerList::loadSetting);


mGutterWidget = new TimeLineLayerCellGutterWidget(width(), this);
}

TimeLineLayerList::~TimeLineLayerList()
Expand Down Expand Up @@ -97,19 +101,6 @@ void TimeLineLayerList::drawContent()
// }
// }

int selectedLayerId = mEditor->layers()->selectedLayerId();

const auto cell = getCell(selectedLayerId);

if (cell) {
qDebug() << "cell";
// cell->paint(painter, palette);

if (cell->editorWidget()->didDetach()) {
qDebug() << "paint layer gutter";
paintLayerGutter(painter, palette);
}
}
mRedrawContent = false;
}

Expand Down Expand Up @@ -148,6 +139,8 @@ void TimeLineLayerList::resizeEvent(QResizeEvent* event)
cell->setSize(QSize(event->size().width(), mLayerHeight));
}

mGutterWidget->updateWidth(event->size().width());

updateContent();
event->accept();

Expand Down Expand Up @@ -251,22 +244,26 @@ void TimeLineLayerList::onScrollingVerticallyStopped()

void TimeLineLayerList::onCellDragged(const DragEvent& event, TimeLineLayerCellEditorWidget* editorWidget, int x, int y)
{
// QPoint mapped = mapToParent(QPoint(x,y));
qDebug() << "mapped point: " << y;
int newY = y;
switch (event)
{
case DragEvent::STARTED: {
mGutterPositionY = getLayerGutterYPosition(newY);
mFromLayer = getLayerNumber(newY);
mGutterPositionY = getLayerGutterYPosition(y);
mFromLayer = getLayerNumber(y);
editorWidget->raise();
emit cellDraggedY(event, newY);
mGutterWidget->hide();
mGutterWidget->raise();
emit cellDraggedY(event, y);
break;
}
case DragEvent::DRAGGING: {
editorWidget->move(0, newY);
mGutterPositionY = getLayerGutterYPosition(newY);
emit cellDraggedY(event, newY);
editorWidget->move(0, y);
mGutterPositionY = getLayerGutterYPosition(y);

if (editorWidget->didDetach()) {
mGutterWidget->show();
}
mGutterWidget->move(0, mGutterPositionY);
emit cellDraggedY(event, y);
break;
}
case DragEvent::ENDED: {
Expand Down Expand Up @@ -297,6 +294,7 @@ void TimeLineLayerList::onCellDragged(const DragEvent& event, TimeLineLayerCellE
}
}
}
mGutterWidget->hide();
editorWidget->move(0, fromLayerDragY);
emit cellDraggedY(event, y);
mGutterPositionY = -1;
Expand Down
2 changes: 2 additions & 0 deletions app/src/timelinelayerlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class QPaintEvent;
class QMouseEvent;
class QResizeEvent;
class QListWidget;
class TimeLineLayerCellGutterWidget;

class TimeLineLayerList : public QWidget
{
Expand Down Expand Up @@ -88,6 +89,7 @@ private slots:
const static int mLayerDetachThreshold = 5;

QMap<int, TimeLineLayerCell*> mLayerCells;
TimeLineLayerCellGutterWidget* mGutterWidget = nullptr;
};

#endif // TIMELINELAYERLIST_H

0 comments on commit beb7e68

Please sign in to comment.