2020-01-18 05:38:21 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
2021-04-22 17:51:19 -03:00
|
|
|
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
|
2021-09-03 15:36:13 -03:00
|
|
|
* Copyright (c) 2021, Mohsan Ali <mohsan0073@gmail.com>
|
2020-01-18 05:38:21 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2019-06-23 11:35:43 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
2021-03-16 19:37:44 -03:00
|
|
|
#include <LibCore/Timer.h>
|
2020-02-06 16:33:02 -03:00
|
|
|
#include <LibGUI/Frame.h>
|
2020-07-26 01:31:47 -03:00
|
|
|
#include <LibGfx/Point.h>
|
2021-05-14 14:54:31 -03:00
|
|
|
#include <LibImageDecoderClient/Client.h>
|
2019-06-23 11:35:43 -03:00
|
|
|
|
2021-05-14 13:37:08 -03:00
|
|
|
namespace ImageViewer {
|
|
|
|
|
|
|
|
|
|
class ViewWidget final : public GUI::Frame {
|
|
|
|
|
C_OBJECT(ViewWidget)
|
2019-06-23 11:35:43 -03:00
|
|
|
public:
|
2020-04-12 08:35:15 -03:00
|
|
|
enum Directions {
|
|
|
|
|
First,
|
|
|
|
|
Back,
|
|
|
|
|
Forward,
|
|
|
|
|
Last
|
|
|
|
|
};
|
|
|
|
|
|
2021-05-14 13:37:08 -03:00
|
|
|
virtual ~ViewWidget() override;
|
2019-06-23 11:35:43 -03:00
|
|
|
|
2020-02-06 07:56:38 -03:00
|
|
|
const Gfx::Bitmap* bitmap() const { return m_bitmap.ptr(); }
|
2019-12-19 16:39:11 -03:00
|
|
|
const String& path() const { return m_path; }
|
2020-04-12 10:24:31 -03:00
|
|
|
void set_scale(int);
|
|
|
|
|
int scale() { return m_scale; }
|
2020-04-12 11:40:34 -03:00
|
|
|
void set_toolbar_height(int height) { m_toolbar_height = height; }
|
2020-06-18 10:00:19 -03:00
|
|
|
int toolbar_height() { return m_toolbar_height; }
|
2021-07-08 19:57:42 -03:00
|
|
|
bool scaled_for_first_image() { return m_scaled_for_first_image; }
|
|
|
|
|
void set_scaled_for_first_image(bool val) { m_scaled_for_first_image = val; }
|
2021-09-03 15:36:13 -03:00
|
|
|
void set_path(const String& path);
|
2021-07-13 18:34:12 -03:00
|
|
|
void resize_window();
|
2019-06-23 11:35:43 -03:00
|
|
|
|
2021-09-03 15:36:13 -03:00
|
|
|
bool is_next_available() const;
|
|
|
|
|
bool is_previous_available() const;
|
|
|
|
|
|
2020-04-12 10:40:05 -03:00
|
|
|
void clear();
|
2020-04-12 10:03:31 -03:00
|
|
|
void flip(Gfx::Orientation);
|
|
|
|
|
void rotate(Gfx::RotationDirection);
|
2020-04-12 08:35:15 -03:00
|
|
|
void navigate(Directions);
|
2020-04-05 15:25:14 -03:00
|
|
|
void load_from_file(const String&);
|
|
|
|
|
|
2021-07-13 18:34:12 -03:00
|
|
|
Function<void(int)> on_scale_change;
|
2020-06-16 04:47:47 -03:00
|
|
|
Function<void()> on_doubleclick;
|
2020-04-05 15:25:14 -03:00
|
|
|
Function<void(const GUI::DropEvent&)> on_drop;
|
2021-05-16 05:01:29 -03:00
|
|
|
Function<void(const Gfx::Bitmap*)> on_image_change;
|
2019-06-23 11:35:43 -03:00
|
|
|
|
|
|
|
|
private:
|
2021-05-14 13:37:08 -03:00
|
|
|
ViewWidget();
|
2020-06-16 04:47:47 -03:00
|
|
|
virtual void doubleclick_event(GUI::MouseEvent&) override;
|
2020-02-02 11:07:41 -03:00
|
|
|
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;
|
2019-06-23 11:35:43 -03:00
|
|
|
|
2021-03-16 19:37:44 -03:00
|
|
|
void set_bitmap(const Gfx::Bitmap* bitmap);
|
2019-06-23 11:35:43 -03:00
|
|
|
void relayout();
|
2021-03-15 16:50:46 -03:00
|
|
|
void reset_view();
|
2021-03-16 19:37:44 -03:00
|
|
|
void animate();
|
2021-09-03 15:36:13 -03:00
|
|
|
Vector<String> load_files_from_directory(const String& path) const;
|
2019-06-23 11:35:43 -03:00
|
|
|
|
2020-04-05 15:25:14 -03:00
|
|
|
String m_path;
|
2020-02-06 07:56:38 -03:00
|
|
|
RefPtr<Gfx::Bitmap> m_bitmap;
|
2020-06-10 05:57:59 -03:00
|
|
|
Gfx::IntRect m_bitmap_rect;
|
2021-05-14 14:54:31 -03:00
|
|
|
Optional<ImageDecoderClient::DecodedImage> m_decoded_image;
|
2021-03-16 19:37:44 -03:00
|
|
|
|
|
|
|
|
size_t m_current_frame_index { 0 };
|
|
|
|
|
size_t m_loops_completed { 0 };
|
|
|
|
|
NonnullRefPtr<Core::Timer> m_timer;
|
|
|
|
|
|
2020-06-18 10:00:19 -03:00
|
|
|
int m_scale { -1 };
|
2021-03-16 19:37:44 -03:00
|
|
|
int m_toolbar_height { 28 };
|
2021-07-08 19:57:42 -03:00
|
|
|
bool m_scaled_for_first_image { false };
|
2020-04-05 15:25:14 -03:00
|
|
|
Gfx::FloatPoint m_pan_origin;
|
2020-06-10 05:57:59 -03:00
|
|
|
Gfx::IntPoint m_click_position;
|
2020-04-05 15:25:14 -03:00
|
|
|
Gfx::FloatPoint m_saved_pan_origin;
|
2020-04-12 08:35:15 -03:00
|
|
|
Vector<String> m_files_in_same_dir;
|
2021-09-03 15:36:13 -03:00
|
|
|
Optional<size_t> m_current_index;
|
2019-06-23 11:35:43 -03:00
|
|
|
};
|
2021-05-14 13:37:08 -03:00
|
|
|
|
|
|
|
|
}
|