mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 22:27:20 +02:00
Added hotkeys for switching between modes in photo editor.
This commit is contained in:
parent
b4410c49b9
commit
3ee3919d50
8 changed files with 44 additions and 2 deletions
|
@ -164,6 +164,10 @@ PhotoEditor::PhotoEditor(
|
|||
}, lifetime());
|
||||
}
|
||||
|
||||
void PhotoEditor::handleKeyPress(not_null<QKeyEvent*> e) {
|
||||
_content->handleKeyPress(e) || _controls->handleKeyPress(e);
|
||||
}
|
||||
|
||||
void PhotoEditor::save() {
|
||||
_content->save(_modifications);
|
||||
_done.fire_copy(_modifications);
|
||||
|
|
|
@ -37,6 +37,8 @@ public:
|
|||
rpl::producer<PhotoModifications> doneRequests() const;
|
||||
rpl::producer<> cancelRequests() const;
|
||||
|
||||
void handleKeyPress(not_null<QKeyEvent*> e);
|
||||
|
||||
private:
|
||||
|
||||
PhotoModifications _modifications;
|
||||
|
|
|
@ -129,4 +129,8 @@ void PhotoEditorContent::applyBrush(const Brush &brush) {
|
|||
_paint->applyBrush(brush);
|
||||
}
|
||||
|
||||
bool PhotoEditorContent::handleKeyPress(not_null<QKeyEvent*> e) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace Editor
|
||||
|
|
|
@ -32,6 +32,8 @@ public:
|
|||
void applyBrush(const Brush &brush);
|
||||
void save(PhotoModifications &modifications);
|
||||
|
||||
bool handleKeyPress(not_null<QKeyEvent*> e) const;
|
||||
|
||||
private:
|
||||
|
||||
const QSize _photoSize;
|
||||
|
@ -40,6 +42,7 @@ private:
|
|||
const std::shared_ptr<Image> _photo;
|
||||
|
||||
rpl::variable<PhotoModifications> _modifications;
|
||||
rpl::event_stream<int> _keyPresses;
|
||||
|
||||
QRect _imageRect;
|
||||
QMatrix _imageMatrix;
|
||||
|
|
|
@ -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<bool> PhotoEditorControls::colorLineShownValue() const {
|
|||
return _paintTopButtons->shownValue();
|
||||
}
|
||||
|
||||
bool PhotoEditorControls::handleKeyPress(not_null<QKeyEvent*> e) const {
|
||||
_keyPresses.fire(e->key());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PhotoEditorControls::animating() const {
|
||||
return _toggledBarAnimation.animating();
|
||||
}
|
||||
|
||||
} // namespace Editor
|
||||
|
|
|
@ -38,6 +38,10 @@ public:
|
|||
[[nodiscard]] rpl::producer<QPoint> colorLinePositionValue() const;
|
||||
[[nodiscard]] rpl::producer<bool> colorLineShownValue() const;
|
||||
|
||||
[[nodiscard]] bool animating() const;
|
||||
|
||||
bool handleKeyPress(not_null<QKeyEvent*> e) const;
|
||||
|
||||
void applyMode(const PhotoEditorMode &mode);
|
||||
|
||||
private:
|
||||
|
@ -71,6 +75,7 @@ private:
|
|||
Ui::Animations::Simple _toggledBarAnimation;
|
||||
|
||||
rpl::variable<PhotoEditorMode> _mode;
|
||||
rpl::event_stream<int> _keyPresses;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ public:
|
|||
bool closeByOutsideClick() const override;
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent *e) override;
|
||||
int resizeGetHeight(int newWidth) override;
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Reference in a new issue