这是indexloc提供的服务,不要输入任何密码
Skip to content
24 changes: 22 additions & 2 deletions app/src/mainwindow2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@ void MainWindow2::setupKeyboardShortcuts()
ui->actionFlip_inbetween->setShortcut(cmdKeySeq(CMD_FLIP_INBETWEEN));
ui->actionFlip_rolling->setShortcut(cmdKeySeq(CMD_FLIP_ROLLING));

ShortcutFilter* shortcutFilter = new ShortcutFilter(ui->scribbleArea, this);
ShortcutFilter* shortcutFilter = new ShortcutFilter(ui->scribbleArea, mEditor, this);
ui->actionMove->setShortcut(cmdKeySeq(CMD_TOOL_MOVE));
ui->actionSelect->setShortcut(cmdKeySeq(CMD_TOOL_SELECT));
ui->actionBrush->setShortcut(cmdKeySeq(CMD_TOOL_BRUSH));
Expand Down Expand Up @@ -1362,7 +1362,7 @@ void MainWindow2::makeConnections(Editor* editor)
ui->actionCut->setEnabled(canCopy);
});
connect(editor, &Editor::canPasteChanged, ui->actionPaste, &QAction::setEnabled);

connect(editor, &Editor::blockUI, this, &MainWindow2::onBlockUI);
}

void MainWindow2::makeConnections(Editor* editor, ColorBox* colorBox)
Expand Down Expand Up @@ -1504,6 +1504,26 @@ void MainWindow2::importMovieVideo()
mSuppressAutoSaveDialog = false;
}

void MainWindow2::onBlockUI(bool block) {

for (BaseDockWidget* widget : mDockWidgets) {
if (widget == nullptr) { continue; }
widget->blockUI(block);
}

if (block &&
(mEditor->tools()->currentTool()->type() == MOVE || mEditor->tools()->currentTool()->type() == SELECT)) {
// We explicitly enable the selection menu to allow transform modifications
ui->menuSelection->setEnabled(true);
}

ui->menuImport->setDisabled(block);
ui->menuAnimation->setDisabled(block);
ui->menuTools->setDisabled(block);
ui->menuLayer->setDisabled(block);
ui->menuEdit->setDisabled(block);
}

bool MainWindow2::event(QEvent* event)
{
if(event->type() == QEvent::WindowActivate) {
Expand Down
2 changes: 2 additions & 0 deletions app/src/mainwindow2.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public slots:
void displayMessageBox(const QString& title, const QString& body);
void displayMessageBoxNoTitle(const QString& body);

void onBlockUI(bool block);

signals:
void updateRecentFilesList(bool b);

Expand Down
12 changes: 11 additions & 1 deletion app/src/shortcutfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,24 @@ GNU General Public License for more details.

#include "shortcutfilter.h"

ShortcutFilter::ShortcutFilter(ScribbleArea* scribbleArea , QObject* parent) :
#include "scribblearea.h"
#include "editor.h"

ShortcutFilter::ShortcutFilter(ScribbleArea* scribbleArea, Editor* editor, QObject* parent) :
QObject(parent)
{
mScribbleArea = scribbleArea;
mEditor = editor;
}

bool ShortcutFilter::eventFilter(QObject* obj, QEvent* event)
{
if (mEditor->isUserActionRequired())
{
mEditor->requestUserActionIfNeeded();
return true;
}

if (mScribbleArea->isMouseInUse())
{
return true;
Expand Down
7 changes: 5 additions & 2 deletions app/src/shortcutfilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@ GNU General Public License for more details.
#define SHORTCUTFILTER_H

#include <QObject>
#include "scribblearea.h"

class ScribbleArea;
class Editor;

class ShortcutFilter : public QObject
{
Q_OBJECT

public:
ShortcutFilter(ScribbleArea* scribbleArea, QObject* parent);
ShortcutFilter(ScribbleArea* scribbleArea, Editor*, QObject* parent);
protected:
bool eventFilter(QObject* obj, QEvent* event) override;
ScribbleArea* mScribbleArea = nullptr;
Editor* mEditor = nullptr;
};

#endif
14 changes: 14 additions & 0 deletions app/src/toolbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,20 @@ void ToolBoxWidget::updateUI()
{
}

void ToolBoxWidget::blockUI(bool block)
{
blockWidget(block);
}

bool ToolBoxWidget::event(QEvent* event)
{
if (event->type() == QEvent::MouseButtonPress) {
editor()->requestUserActionIfNeeded();
}

return BaseDockWidget::event(event);
}

void ToolBoxWidget::onToolSetActive(ToolType toolType)
{
deselectAllTools();
Expand Down
2 changes: 2 additions & 0 deletions app/src/toolbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class ToolBoxWidget : public BaseDockWidget

void initUI() override;
void updateUI() override;
void blockUI(bool block) override;

public slots:
void onToolSetActive(ToolType toolType);
Expand All @@ -59,6 +60,7 @@ public slots:

protected:
int getMinHeightForWidth(int width) override;
bool event(QEvent* event) override;

signals:
void clearButtonClicked();
Expand Down
17 changes: 17 additions & 0 deletions core_lib/src/interface/basedockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ BaseDockWidget::BaseDockWidget(QWidget* pParent)
}
#endif

mBlockUIWidget = new QWidget(this);

mBlockUIWidget->setHidden(true);
layout()->addWidget(mBlockUIWidget);
}

BaseDockWidget::~BaseDockWidget()
Expand All @@ -45,6 +49,8 @@ void BaseDockWidget::resizeEvent(QResizeEvent *event)
{
QDockWidget::resizeEvent(event);

mBlockUIWidget->resize(event->size());

// Not sure where the -2 comes from, but the event width is always 2 more than what is passed to FlowLayout::setGeometry
int minHeight = getMinHeightForWidth(event->size().width() - 2);

Expand All @@ -63,3 +69,14 @@ int BaseDockWidget::getMinHeightForWidth(int width)
Q_UNUSED(width)
return -1;
}

void BaseDockWidget::blockWidget(bool block)
{
if (block) {
mBlockUIWidget->raise();
mBlockUIWidget->setHidden(false);
} else {
mBlockUIWidget->setHidden(true);
mBlockUIWidget->lower();
}
}
5 changes: 5 additions & 0 deletions core_lib/src/interface/basedockwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class BaseDockWidget : public QDockWidget
public:
virtual void initUI() = 0;
virtual void updateUI() = 0;
virtual void blockUI(bool block) { Q_UNUSED(block) };

void blockWidget(bool block);

Editor* editor() const { return mEditor; }
void setEditor( Editor* e ) { mEditor = e; }
Expand All @@ -43,6 +46,8 @@ class BaseDockWidget : public QDockWidget
virtual int getMinHeightForWidth(int width);

private:

QWidget* mBlockUIWidget = nullptr;
Editor* mEditor = nullptr;
};

Expand Down
18 changes: 17 additions & 1 deletion core_lib/src/interface/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ void Editor::selectAll() const
select()->setSelection(rect, false);
}

void Editor::deselectAll() const
void Editor::deselectAll()
{
select()->resetSelectionProperties();

Expand All @@ -990,12 +990,28 @@ void Editor::deselectAll() const
}
}

requireUserAction(false);

if (layer->hasAnySelectedFrames()) {
layer->deselectAll();
emit updateTimeLine();
}
}

void Editor::requireUserAction(bool b)
{
mActionRequired = b;

emit blockUI(b);
}

void Editor::requestUserActionIfNeeded()
{
if (mActionRequired) {
tools()->currentTool()->requestAction();
}
}

void Editor::updateFrame(int frameNumber)
{
mScribbleArea->updateFrame(frameNumber);
Expand Down
20 changes: 19 additions & 1 deletion core_lib/src/interface/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class Editor : public QObject
LayerVisibility layerVisibility();

qreal viewScaleInversed();
void deselectAll() const;
void deselectAll();
void selectAll() const;

void clipboardChanged();
Expand All @@ -124,6 +124,8 @@ class Editor : public QObject

signals:

void blockUI(bool b);

/** This should be emitted after scrubbing */
void scrubbed(int frameNumber);

Expand Down Expand Up @@ -215,6 +217,21 @@ class Editor : public QObject
bool autoSaveNeverAskAgain() const { return mAutosaveNeverAskAgain; }
void resetAutoSaveCounter();

/**
* Use this method to prevent user interaction until a certain action has been made.
* @param b True if user action should be required otherwise false
*/
void requireUserAction(bool b);

/** Use this for checking whether a user action is required to continue */
bool isUserActionRequired() { return mActionRequired; }

/**
* Notifies the current tool that the user needs to take action before proceeding
* Currently used by the move tool for applying transformations.
* Calling this method when `mActionRequired` is false does nothing */
void requestUserActionIfNeeded();

private:
bool importBitmapImage(const QString&, int space = 0);
bool importVectorImage(const QString&);
Expand Down Expand Up @@ -252,6 +269,7 @@ class Editor : public QObject
int mAutosaveNumber = 12;
int mAutosaveCounter = 0;
bool mAutosaveNeverAskAgain = false;
bool mActionRequired = false;

void makeConnections();
KeyFrame* addKeyFrame(int layerNumber, int frameNumber);
Expand Down
17 changes: 16 additions & 1 deletion core_lib/src/interface/timeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,20 @@ void TimeLine::updateUI()
updateContent();
}

void TimeLine::blockUI(bool block)
{
blockWidget(block);
}

bool TimeLine::event(QEvent* event)
{
if (event->type() == QEvent::MouseButtonPress) {
editor()->requestUserActionIfNeeded();
}

return BaseDockWidget::event(event);
}

int TimeLine::getLength()
{
return mTracks->getFrameLength();
Expand Down Expand Up @@ -275,8 +289,9 @@ void TimeLine::extendLength(int frame)
}
}

void TimeLine::resizeEvent(QResizeEvent*)
void TimeLine::resizeEvent(QResizeEvent* event)
{
BaseDockWidget::resizeEvent(event);
updateLayerView();
}

Expand Down
2 changes: 2 additions & 0 deletions core_lib/src/interface/timeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class TimeLine : public BaseDockWidget

void initUI() override;
void updateUI() override;
void blockUI(bool block) override;

void updateFrame( int frameNumber );
void updateLayerNumber( int number );
Expand Down Expand Up @@ -79,6 +80,7 @@ class TimeLine : public BaseDockWidget
protected:
void resizeEvent( QResizeEvent* event ) override;
void wheelEvent( QWheelEvent* ) override;
bool event(QEvent* event) override;

private:
void deleteCurrentLayer();
Expand Down
14 changes: 8 additions & 6 deletions core_lib/src/interface/timelinecells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -882,10 +882,13 @@ void TimeLineCells::resizeEvent(QResizeEvent* event)

bool TimeLineCells::event(QEvent* event)
{
if (event->type() == QEvent::Leave) {
onDidLeaveWidget();
if (event->type() == QEvent::Leave || event->type() == QEvent::Enter) {
// There's no guarantee that a release event is send after a press event...
// Therefore to avoid any weird states, we reset when leaving and entering the widget
onMouseFocusChange();
}


return QWidget::event(event);
}

Expand Down Expand Up @@ -915,9 +918,6 @@ void TimeLineCells::mousePressEvent(QMouseEvent* event)

primaryButton = event->button();

bool switchLayer = mEditor->tools()->currentTool()->switchingLayer();
if (!switchLayer) { return; }

switch (mType)
{
case TIMELINE_CELL_TYPE::Layers:
Expand Down Expand Up @@ -1310,9 +1310,11 @@ void TimeLineCells::trackScrubber()
}
}

void TimeLineCells::onDidLeaveWidget()
void TimeLineCells::onMouseFocusChange()
{
// Reset last known frame pos to avoid wrong UI states when leaving the widget
mFramePosMoveX = 0;
primaryButton = Qt::NoButton;
mTimeLine->scrubbing = false;
update();
}
3 changes: 1 addition & 2 deletions core_lib/src/interface/timelinecells.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private slots:
int getFrameX(int frameNumber) const;
int getFrameNumber(int x) const;

void onDidLeaveWidget();
void onMouseFocusChange();

void trackScrubber();
void drawContent();
Expand Down Expand Up @@ -129,7 +129,6 @@ private slots:
int mFrameLength = 1;
int mFrameSize = 0;
int mFontSize = 10;
bool mScrubbing = false;
int mLayerHeight = 20;
int mStartY = 0;
int mEndY = 0;
Expand Down
4 changes: 0 additions & 4 deletions core_lib/src/managers/playbackmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ void PlaybackManager::play()
updateStartFrame();
updateEndFrame();

// This is probably not the right place or function to be calling this, but it's the easiest thing to do right now that works
// TODO make a new tool function to handle playing (or perhaps generic scrubbing)
bool switchLayer = editor()->tools()->currentTool()->switchingLayer();
if (!switchLayer) return;

int frame = editor()->currentFrame();
if (frame >= mEndFrame || frame < mStartFrame)
Expand Down
Loading