mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:07:35 +00:00
ImageViewer: Inherit from AbstractZoomPanWidget
This commit is contained in:
parent
5d7f2086b0
commit
b21d128075
2 changed files with 21 additions and 117 deletions
|
@ -2,6 +2,7 @@
|
|||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2021, Mohsan Ali <mohsan0073@gmail.com>
|
||||
* Copyright (c) 2022, Mustafa Quraish <mustafa@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -9,14 +10,13 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibCore/Timer.h>
|
||||
#include <LibGUI/Frame.h>
|
||||
#include <LibGUI/AbstractZoomPanWidget.h>
|
||||
#include <LibGUI/Painter.h>
|
||||
#include <LibGfx/Point.h>
|
||||
#include <LibImageDecoderClient/Client.h>
|
||||
|
||||
namespace ImageViewer {
|
||||
|
||||
class ViewWidget final : public GUI::Frame {
|
||||
class ViewWidget final : public GUI::AbstractZoomPanWidget {
|
||||
C_OBJECT(ViewWidget)
|
||||
public:
|
||||
enum Directions {
|
||||
|
@ -30,8 +30,6 @@ public:
|
|||
|
||||
const Gfx::Bitmap* bitmap() const { return m_bitmap.ptr(); }
|
||||
const String& path() const { return m_path; }
|
||||
void set_scale(float);
|
||||
float scale() { return m_scale; }
|
||||
void set_toolbar_height(int height) { m_toolbar_height = height; }
|
||||
int toolbar_height() { return m_toolbar_height; }
|
||||
bool scaled_for_first_image() { return m_scaled_for_first_image; }
|
||||
|
@ -49,7 +47,6 @@ public:
|
|||
void navigate(Directions);
|
||||
void load_from_file(const String&);
|
||||
|
||||
Function<void(float)> on_scale_change;
|
||||
Function<void()> on_doubleclick;
|
||||
Function<void(const GUI::DropEvent&)> on_drop;
|
||||
Function<void(const Gfx::Bitmap*)> on_image_change;
|
||||
|
@ -58,34 +55,24 @@ private:
|
|||
ViewWidget();
|
||||
virtual void doubleclick_event(GUI::MouseEvent&) override;
|
||||
virtual void paint_event(GUI::PaintEvent&) override;
|
||||
virtual void resize_event(GUI::ResizeEvent&) override;
|
||||
virtual void mousedown_event(GUI::MouseEvent&) override;
|
||||
virtual void mouseup_event(GUI::MouseEvent&) override;
|
||||
virtual void mousemove_event(GUI::MouseEvent&) override;
|
||||
virtual void mousewheel_event(GUI::MouseEvent&) override;
|
||||
virtual void drop_event(GUI::DropEvent&) override;
|
||||
|
||||
void set_bitmap(const Gfx::Bitmap* bitmap);
|
||||
void relayout();
|
||||
void reset_view();
|
||||
void animate();
|
||||
Vector<String> load_files_from_directory(const String& path) const;
|
||||
|
||||
String m_path;
|
||||
RefPtr<Gfx::Bitmap> m_bitmap;
|
||||
Gfx::IntRect m_bitmap_rect;
|
||||
Optional<ImageDecoderClient::DecodedImage> m_decoded_image;
|
||||
|
||||
size_t m_current_frame_index { 0 };
|
||||
size_t m_loops_completed { 0 };
|
||||
NonnullRefPtr<Core::Timer> m_timer;
|
||||
|
||||
float m_scale { -1 };
|
||||
int m_toolbar_height { 28 };
|
||||
bool m_scaled_for_first_image { false };
|
||||
Gfx::FloatPoint m_pan_origin;
|
||||
Gfx::IntPoint m_click_position;
|
||||
Gfx::FloatPoint m_saved_pan_origin;
|
||||
Vector<String> m_files_in_same_dir;
|
||||
Optional<size_t> m_current_index;
|
||||
Gfx::Painter::ScalingMode m_scaling_mode { Gfx::Painter::ScalingMode::NearestNeighbor };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue