blob: 9bc093a89f38364cfe7d31a4d2c5a0a38a57cc32 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibCore/Timer.h>
#include <LibGUI/Frame.h>
#include <LibGfx/Point.h>
#include <LibImageDecoderClient/Client.h>
namespace ImageViewer {
class ViewWidget final : public GUI::Frame {
C_OBJECT(ViewWidget)
public:
enum Directions {
First,
Back,
Forward,
Last
};
virtual ~ViewWidget() override;
const Gfx::Bitmap* bitmap() const { return m_bitmap.ptr(); }
const String& path() const { return m_path; }
void set_scale(int);
int scale() { return m_scale; }
void set_toolbar_height(int height) { m_toolbar_height = height; }
int toolbar_height() { return m_toolbar_height; }
void clear();
void flip(Gfx::Orientation);
void rotate(Gfx::RotationDirection);
void navigate(Directions);
void load_from_file(const String&);
Function<void(int, Gfx::IntRect)> on_scale_change;
Function<void()> on_doubleclick;
Function<void(const GUI::DropEvent&)> on_drop;
Function<void(const Gfx::Bitmap*)> on_image_change;
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 resize_window();
void reset_view();
void animate();
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;
int m_scale { -1 };
int m_toolbar_height { 28 };
Gfx::FloatPoint m_pan_origin;
Gfx::IntPoint m_click_position;
Gfx::FloatPoint m_saved_pan_origin;
Vector<String> m_files_in_same_dir;
};
}
|