mirror of
https://github.com/RGBCube/serenity
synced 2025-05-18 17:55:07 +00:00
QuickShow: Rotate image left and right, flip vertical and horizontal
This commit is contained in:
parent
2689fdf1d8
commit
d79c81a179
3 changed files with 65 additions and 0 deletions
|
@ -42,6 +42,22 @@ QSWidget::~QSWidget()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QSWidget::flip(Gfx::Orientation orientation)
|
||||||
|
{
|
||||||
|
m_bitmap = m_bitmap->flipped(orientation);
|
||||||
|
set_scale(m_scale);
|
||||||
|
|
||||||
|
resize_window();
|
||||||
|
}
|
||||||
|
|
||||||
|
void QSWidget::rotate(Gfx::RotationDirection rotation_direction)
|
||||||
|
{
|
||||||
|
m_bitmap = m_bitmap->rotated(rotation_direction);
|
||||||
|
set_scale(m_scale);
|
||||||
|
|
||||||
|
resize_window();
|
||||||
|
}
|
||||||
|
|
||||||
void QSWidget::navigate(Directions direction)
|
void QSWidget::navigate(Directions direction)
|
||||||
{
|
{
|
||||||
if (m_path == nullptr)
|
if (m_path == nullptr)
|
||||||
|
@ -211,3 +227,22 @@ void QSWidget::drop_event(GUI::DropEvent& event)
|
||||||
if (on_drop)
|
if (on_drop)
|
||||||
on_drop(event);
|
on_drop(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QSWidget::resize_window()
|
||||||
|
{
|
||||||
|
if (window()->is_fullscreen())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!m_bitmap)
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto new_size = m_bitmap->size();
|
||||||
|
|
||||||
|
if (new_size.width() < 300)
|
||||||
|
new_size.set_width(300);
|
||||||
|
if (new_size.height() < 200)
|
||||||
|
new_size.set_height(200);
|
||||||
|
|
||||||
|
new_size.set_height(new_size.height());
|
||||||
|
window()->resize(new_size);
|
||||||
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <LibGUI/Frame.h>
|
#include <LibGUI/Frame.h>
|
||||||
|
#include <LibGfx/Bitmap.h>
|
||||||
#include <LibGfx/FloatPoint.h>
|
#include <LibGfx/FloatPoint.h>
|
||||||
|
|
||||||
class QSLabel;
|
class QSLabel;
|
||||||
|
@ -46,6 +47,8 @@ public:
|
||||||
const Gfx::Bitmap* bitmap() const { return m_bitmap.ptr(); }
|
const Gfx::Bitmap* bitmap() const { return m_bitmap.ptr(); }
|
||||||
const String& path() const { return m_path; }
|
const String& path() const { return m_path; }
|
||||||
|
|
||||||
|
void flip(Gfx::Orientation);
|
||||||
|
void rotate(Gfx::RotationDirection);
|
||||||
void navigate(Directions);
|
void navigate(Directions);
|
||||||
void load_from_file(const String&);
|
void load_from_file(const String&);
|
||||||
|
|
||||||
|
@ -63,6 +66,7 @@ private:
|
||||||
virtual void drop_event(GUI::DropEvent&) override;
|
virtual void drop_event(GUI::DropEvent&) override;
|
||||||
|
|
||||||
void relayout();
|
void relayout();
|
||||||
|
void resize_window();
|
||||||
|
|
||||||
String m_path;
|
String m_path;
|
||||||
RefPtr<Gfx::Bitmap> m_bitmap;
|
RefPtr<Gfx::Bitmap> m_bitmap;
|
||||||
|
|
|
@ -103,6 +103,26 @@ int main(int argc, char** argv)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
|
auto rotate_left_action = GUI::Action::create("Rotate Left", { Mod_None, Key_L },
|
||||||
|
[&](auto&) {
|
||||||
|
widget.rotate(Gfx::RotationDirection::Left);
|
||||||
|
});
|
||||||
|
|
||||||
|
auto rotate_right_action = GUI::Action::create("Rotate Right", { Mod_None, Key_R },
|
||||||
|
[&](auto&) {
|
||||||
|
widget.rotate(Gfx::RotationDirection::Right);
|
||||||
|
});
|
||||||
|
|
||||||
|
auto vertical_flip_action = GUI::Action::create("Vertical Flip", { Mod_None, Key_V },
|
||||||
|
[&](auto&) {
|
||||||
|
widget.flip(Gfx::Orientation::Vertical);
|
||||||
|
});
|
||||||
|
|
||||||
|
auto horizontal_flip_action = GUI::Action::create("Horizontal Flip", { Mod_None, Key_H },
|
||||||
|
[&](auto&) {
|
||||||
|
widget.flip(Gfx::Orientation::Horizontal);
|
||||||
|
});
|
||||||
|
|
||||||
auto go_first_action = GUI::Action::create("First", { Mod_None, Key_Home }, Gfx::Bitmap::load_from_file("/res/icons/16x16/go-first.png"),
|
auto go_first_action = GUI::Action::create("First", { Mod_None, Key_Home }, Gfx::Bitmap::load_from_file("/res/icons/16x16/go-first.png"),
|
||||||
[&](auto&) {
|
[&](auto&) {
|
||||||
widget.navigate(QSWidget::Directions::First);
|
widget.navigate(QSWidget::Directions::First);
|
||||||
|
@ -137,6 +157,12 @@ int main(int argc, char** argv)
|
||||||
app.quit();
|
app.quit();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
auto& image_menu = menubar->add_menu("Image");
|
||||||
|
image_menu.add_action(rotate_left_action);
|
||||||
|
image_menu.add_action(rotate_right_action);
|
||||||
|
image_menu.add_action(vertical_flip_action);
|
||||||
|
image_menu.add_action(horizontal_flip_action);
|
||||||
|
|
||||||
auto& navigate_menu = menubar->add_menu("Navigate");
|
auto& navigate_menu = menubar->add_menu("Navigate");
|
||||||
navigate_menu.add_action(go_first_action);
|
navigate_menu.add_action(go_first_action);
|
||||||
navigate_menu.add_action(go_back_action);
|
navigate_menu.add_action(go_back_action);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue