mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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());
|
}, lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PhotoEditor::handleKeyPress(not_null<QKeyEvent*> e) {
|
||||||
|
_content->handleKeyPress(e) || _controls->handleKeyPress(e);
|
||||||
|
}
|
||||||
|
|
||||||
void PhotoEditor::save() {
|
void PhotoEditor::save() {
|
||||||
_content->save(_modifications);
|
_content->save(_modifications);
|
||||||
_done.fire_copy(_modifications);
|
_done.fire_copy(_modifications);
|
||||||
|
|
|
@ -37,6 +37,8 @@ public:
|
||||||
rpl::producer<PhotoModifications> doneRequests() const;
|
rpl::producer<PhotoModifications> doneRequests() const;
|
||||||
rpl::producer<> cancelRequests() const;
|
rpl::producer<> cancelRequests() const;
|
||||||
|
|
||||||
|
void handleKeyPress(not_null<QKeyEvent*> e);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
PhotoModifications _modifications;
|
PhotoModifications _modifications;
|
||||||
|
|
|
@ -129,4 +129,8 @@ void PhotoEditorContent::applyBrush(const Brush &brush) {
|
||||||
_paint->applyBrush(brush);
|
_paint->applyBrush(brush);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PhotoEditorContent::handleKeyPress(not_null<QKeyEvent*> e) const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Editor
|
} // namespace Editor
|
||||||
|
|
|
@ -32,6 +32,8 @@ public:
|
||||||
void applyBrush(const Brush &brush);
|
void applyBrush(const Brush &brush);
|
||||||
void save(PhotoModifications &modifications);
|
void save(PhotoModifications &modifications);
|
||||||
|
|
||||||
|
bool handleKeyPress(not_null<QKeyEvent*> e) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
const QSize _photoSize;
|
const QSize _photoSize;
|
||||||
|
@ -40,6 +42,7 @@ private:
|
||||||
const std::shared_ptr<Image> _photo;
|
const std::shared_ptr<Image> _photo;
|
||||||
|
|
||||||
rpl::variable<PhotoModifications> _modifications;
|
rpl::variable<PhotoModifications> _modifications;
|
||||||
|
rpl::event_stream<int> _keyPresses;
|
||||||
|
|
||||||
QRect _imageRect;
|
QRect _imageRect;
|
||||||
QMatrix _imageMatrix;
|
QMatrix _imageMatrix;
|
||||||
|
|
|
@ -363,13 +363,23 @@ rpl::producer<> PhotoEditorControls::paintModeRequests() const {
|
||||||
rpl::producer<> PhotoEditorControls::doneRequests() const {
|
rpl::producer<> PhotoEditorControls::doneRequests() const {
|
||||||
return rpl::merge(
|
return rpl::merge(
|
||||||
_transformDone->clicks() | rpl::to_empty,
|
_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 {
|
rpl::producer<> PhotoEditorControls::cancelRequests() const {
|
||||||
return rpl::merge(
|
return rpl::merge(
|
||||||
_transformCancel->clicks() | rpl::to_empty,
|
_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 {
|
int PhotoEditorControls::bottomButtonsTop() const {
|
||||||
|
@ -465,4 +475,13 @@ rpl::producer<bool> PhotoEditorControls::colorLineShownValue() const {
|
||||||
return _paintTopButtons->shownValue();
|
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
|
} // namespace Editor
|
||||||
|
|
|
@ -38,6 +38,10 @@ public:
|
||||||
[[nodiscard]] rpl::producer<QPoint> colorLinePositionValue() const;
|
[[nodiscard]] rpl::producer<QPoint> colorLinePositionValue() const;
|
||||||
[[nodiscard]] rpl::producer<bool> colorLineShownValue() const;
|
[[nodiscard]] rpl::producer<bool> colorLineShownValue() const;
|
||||||
|
|
||||||
|
[[nodiscard]] bool animating() const;
|
||||||
|
|
||||||
|
bool handleKeyPress(not_null<QKeyEvent*> e) const;
|
||||||
|
|
||||||
void applyMode(const PhotoEditorMode &mode);
|
void applyMode(const PhotoEditorMode &mode);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -71,6 +75,7 @@ private:
|
||||||
Ui::Animations::Simple _toggledBarAnimation;
|
Ui::Animations::Simple _toggledBarAnimation;
|
||||||
|
|
||||||
rpl::variable<PhotoEditorMode> _mode;
|
rpl::variable<PhotoEditorMode> _mode;
|
||||||
|
rpl::event_stream<int> _keyPresses;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -174,6 +174,10 @@ void LayerWidget::parentResized() {
|
||||||
resizeToWidth(parentWidget()->width());
|
resizeToWidth(parentWidget()->width());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LayerWidget::keyPressEvent(QKeyEvent *e) {
|
||||||
|
_content->handleKeyPress(e);
|
||||||
|
}
|
||||||
|
|
||||||
int LayerWidget::resizeGetHeight(int newWidth) {
|
int LayerWidget::resizeGetHeight(int newWidth) {
|
||||||
return parentWidget()->height();
|
return parentWidget()->height();
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,7 @@ public:
|
||||||
bool closeByOutsideClick() const override;
|
bool closeByOutsideClick() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void keyPressEvent(QKeyEvent *e) override;
|
||||||
int resizeGetHeight(int newWidth) override;
|
int resizeGetHeight(int newWidth) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Add table
Reference in a new issue