diff --git a/Telegram/SourceFiles/editor/photo_editor.cpp b/Telegram/SourceFiles/editor/photo_editor.cpp index 5d29d7413..420488d24 100644 --- a/Telegram/SourceFiles/editor/photo_editor.cpp +++ b/Telegram/SourceFiles/editor/photo_editor.cpp @@ -164,6 +164,10 @@ PhotoEditor::PhotoEditor( }, lifetime()); } +void PhotoEditor::handleKeyPress(not_null e) { + _content->handleKeyPress(e) || _controls->handleKeyPress(e); +} + void PhotoEditor::save() { _content->save(_modifications); _done.fire_copy(_modifications); diff --git a/Telegram/SourceFiles/editor/photo_editor.h b/Telegram/SourceFiles/editor/photo_editor.h index dc05d80f5..f16abac32 100644 --- a/Telegram/SourceFiles/editor/photo_editor.h +++ b/Telegram/SourceFiles/editor/photo_editor.h @@ -37,6 +37,8 @@ public: rpl::producer doneRequests() const; rpl::producer<> cancelRequests() const; + void handleKeyPress(not_null e); + private: PhotoModifications _modifications; diff --git a/Telegram/SourceFiles/editor/photo_editor_content.cpp b/Telegram/SourceFiles/editor/photo_editor_content.cpp index 3be425a74..45da5b5d2 100644 --- a/Telegram/SourceFiles/editor/photo_editor_content.cpp +++ b/Telegram/SourceFiles/editor/photo_editor_content.cpp @@ -129,4 +129,8 @@ void PhotoEditorContent::applyBrush(const Brush &brush) { _paint->applyBrush(brush); } +bool PhotoEditorContent::handleKeyPress(not_null e) const { + return false; +} + } // namespace Editor diff --git a/Telegram/SourceFiles/editor/photo_editor_content.h b/Telegram/SourceFiles/editor/photo_editor_content.h index 310f99dff..46ca580e1 100644 --- a/Telegram/SourceFiles/editor/photo_editor_content.h +++ b/Telegram/SourceFiles/editor/photo_editor_content.h @@ -32,6 +32,8 @@ public: void applyBrush(const Brush &brush); void save(PhotoModifications &modifications); + bool handleKeyPress(not_null e) const; + private: const QSize _photoSize; @@ -40,6 +42,7 @@ private: const std::shared_ptr _photo; rpl::variable _modifications; + rpl::event_stream _keyPresses; QRect _imageRect; QMatrix _imageMatrix; diff --git a/Telegram/SourceFiles/editor/photo_editor_controls.cpp b/Telegram/SourceFiles/editor/photo_editor_controls.cpp index d948bfd9e..035f3cbbb 100644 --- a/Telegram/SourceFiles/editor/photo_editor_controls.cpp +++ b/Telegram/SourceFiles/editor/photo_editor_controls.cpp @@ -363,13 +363,23 @@ rpl::producer<> PhotoEditorControls::paintModeRequests() const { rpl::producer<> PhotoEditorControls::doneRequests() const { return rpl::merge( _transformDone->clicks() | rpl::to_empty, - _paintDone->clicks() | rpl::to_empty); + _paintDone->clicks() | rpl::to_empty, + _keyPresses.events( + ) | rpl::filter([=](int key) { + return ((key == Qt::Key_Enter) || (key == Qt::Key_Return)) + && !_toggledBarAnimation.animating(); + }) | rpl::to_empty); } rpl::producer<> PhotoEditorControls::cancelRequests() const { return rpl::merge( _transformCancel->clicks() | rpl::to_empty, - _paintCancel->clicks() | rpl::to_empty); + _paintCancel->clicks() | rpl::to_empty, + _keyPresses.events( + ) | rpl::filter([=](int key) { + return (key == Qt::Key_Escape) + && !_toggledBarAnimation.animating(); + }) | rpl::to_empty); } int PhotoEditorControls::bottomButtonsTop() const { @@ -465,4 +475,13 @@ rpl::producer PhotoEditorControls::colorLineShownValue() const { return _paintTopButtons->shownValue(); } +bool PhotoEditorControls::handleKeyPress(not_null e) const { + _keyPresses.fire(e->key()); + return true; +} + +bool PhotoEditorControls::animating() const { + return _toggledBarAnimation.animating(); +} + } // namespace Editor diff --git a/Telegram/SourceFiles/editor/photo_editor_controls.h b/Telegram/SourceFiles/editor/photo_editor_controls.h index fac27dadc..9b018f0c5 100644 --- a/Telegram/SourceFiles/editor/photo_editor_controls.h +++ b/Telegram/SourceFiles/editor/photo_editor_controls.h @@ -38,6 +38,10 @@ public: [[nodiscard]] rpl::producer colorLinePositionValue() const; [[nodiscard]] rpl::producer colorLineShownValue() const; + [[nodiscard]] bool animating() const; + + bool handleKeyPress(not_null e) const; + void applyMode(const PhotoEditorMode &mode); private: @@ -71,6 +75,7 @@ private: Ui::Animations::Simple _toggledBarAnimation; rpl::variable _mode; + rpl::event_stream _keyPresses; }; diff --git a/Telegram/SourceFiles/editor/photo_editor_layer_widget.cpp b/Telegram/SourceFiles/editor/photo_editor_layer_widget.cpp index 864bc0c55..8bb077673 100644 --- a/Telegram/SourceFiles/editor/photo_editor_layer_widget.cpp +++ b/Telegram/SourceFiles/editor/photo_editor_layer_widget.cpp @@ -174,6 +174,10 @@ void LayerWidget::parentResized() { resizeToWidth(parentWidget()->width()); } +void LayerWidget::keyPressEvent(QKeyEvent *e) { + _content->handleKeyPress(e); +} + int LayerWidget::resizeGetHeight(int newWidth) { return parentWidget()->height(); } diff --git a/Telegram/SourceFiles/editor/photo_editor_layer_widget.h b/Telegram/SourceFiles/editor/photo_editor_layer_widget.h index e1c0b2b89..3a278afb5 100644 --- a/Telegram/SourceFiles/editor/photo_editor_layer_widget.h +++ b/Telegram/SourceFiles/editor/photo_editor_layer_widget.h @@ -52,6 +52,7 @@ public: bool closeByOutsideClick() const override; protected: + void keyPressEvent(QKeyEvent *e) override; int resizeGetHeight(int newWidth) override; private: