mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added undo and redo shortcuts to photo editor.
This commit is contained in:
parent
799155279f
commit
889d7c0c15
2 changed files with 23 additions and 5 deletions
|
@ -293,7 +293,23 @@ PhotoEditorControls::PhotoEditorControls(
|
||||||
|
|
||||||
controllers->undoController->setPerformRequestChanges(rpl::merge(
|
controllers->undoController->setPerformRequestChanges(rpl::merge(
|
||||||
_undoButton->clicks() | rpl::map_to(Undo::Undo),
|
_undoButton->clicks() | rpl::map_to(Undo::Undo),
|
||||||
_redoButton->clicks() | rpl::map_to(Undo::Redo)));
|
_redoButton->clicks() | rpl::map_to(Undo::Redo),
|
||||||
|
_keyPresses.events(
|
||||||
|
) | rpl::filter([=](not_null<QKeyEvent*> e) {
|
||||||
|
using Mode = PhotoEditorMode::Mode;
|
||||||
|
return (e->matches(QKeySequence::Undo)
|
||||||
|
&& !_undoButton->isHidden()
|
||||||
|
&& !_undoButton->testAttribute(
|
||||||
|
Qt::WA_TransparentForMouseEvents)
|
||||||
|
&& (_mode.current().mode == Mode::Paint))
|
||||||
|
|| (e->matches(QKeySequence::Redo)
|
||||||
|
&& !_redoButton->isHidden()
|
||||||
|
&& !_redoButton->testAttribute(
|
||||||
|
Qt::WA_TransparentForMouseEvents)
|
||||||
|
&& (_mode.current().mode == Mode::Paint));
|
||||||
|
}) | rpl::map([=](not_null<QKeyEvent*> e) {
|
||||||
|
return e->matches(QKeySequence::Undo) ? Undo::Undo : Undo::Redo;
|
||||||
|
})));
|
||||||
|
|
||||||
controllers->undoController->canPerformChanges(
|
controllers->undoController->canPerformChanges(
|
||||||
) | rpl::start_with_next([=](const UndoController::EnableRequest &r) {
|
) | rpl::start_with_next([=](const UndoController::EnableRequest &r) {
|
||||||
|
@ -368,7 +384,8 @@ rpl::producer<> PhotoEditorControls::doneRequests() const {
|
||||||
_transformDone->clicks() | rpl::to_empty,
|
_transformDone->clicks() | rpl::to_empty,
|
||||||
_paintDone->clicks() | rpl::to_empty,
|
_paintDone->clicks() | rpl::to_empty,
|
||||||
_keyPresses.events(
|
_keyPresses.events(
|
||||||
) | rpl::filter([=](int key) {
|
) | rpl::filter([=](not_null<QKeyEvent*> e) {
|
||||||
|
const auto key = e->key();
|
||||||
return ((key == Qt::Key_Enter) || (key == Qt::Key_Return))
|
return ((key == Qt::Key_Enter) || (key == Qt::Key_Return))
|
||||||
&& !_toggledBarAnimation.animating();
|
&& !_toggledBarAnimation.animating();
|
||||||
}) | rpl::to_empty);
|
}) | rpl::to_empty);
|
||||||
|
@ -379,7 +396,8 @@ rpl::producer<> PhotoEditorControls::cancelRequests() const {
|
||||||
_transformCancel->clicks() | rpl::to_empty,
|
_transformCancel->clicks() | rpl::to_empty,
|
||||||
_paintCancel->clicks() | rpl::to_empty,
|
_paintCancel->clicks() | rpl::to_empty,
|
||||||
_keyPresses.events(
|
_keyPresses.events(
|
||||||
) | rpl::filter([=](int key) {
|
) | rpl::filter([=](not_null<QKeyEvent*> e) {
|
||||||
|
const auto key = e->key();
|
||||||
return (key == Qt::Key_Escape)
|
return (key == Qt::Key_Escape)
|
||||||
&& !_toggledBarAnimation.animating();
|
&& !_toggledBarAnimation.animating();
|
||||||
}) | rpl::to_empty);
|
}) | rpl::to_empty);
|
||||||
|
@ -478,7 +496,7 @@ rpl::producer<bool> PhotoEditorControls::colorLineShownValue() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PhotoEditorControls::handleKeyPress(not_null<QKeyEvent*> e) const {
|
bool PhotoEditorControls::handleKeyPress(not_null<QKeyEvent*> e) const {
|
||||||
_keyPresses.fire(e->key());
|
_keyPresses.fire(std::move(e));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ private:
|
||||||
Ui::Animations::Simple _toggledBarAnimation;
|
Ui::Animations::Simple _toggledBarAnimation;
|
||||||
|
|
||||||
rpl::variable<PhotoEditorMode> _mode;
|
rpl::variable<PhotoEditorMode> _mode;
|
||||||
rpl::event_stream<int> _keyPresses;
|
rpl::event_stream<not_null<QKeyEvent*>> _keyPresses;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue