ViewWidget.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
  4. * Copyright (c) 2021, Mohsan Ali <mohsan0073@gmail.com>
  5. * Copyright (c) 2022, Mustafa Quraish <mustafa@serenityos.org>
  6. * Copyright (c) 2022, the SerenityOS developers.
  7. *
  8. * SPDX-License-Identifier: BSD-2-Clause
  9. */
  10. #pragma once
  11. #include <LibCore/Timer.h>
  12. #include <LibGUI/AbstractZoomPanWidget.h>
  13. #include <LibGUI/Painter.h>
  14. #include <LibImageDecoderClient/Client.h>
  15. namespace ImageViewer {
  16. class ViewWidget final : public GUI::AbstractZoomPanWidget {
  17. C_OBJECT(ViewWidget)
  18. public:
  19. enum Directions {
  20. First,
  21. Back,
  22. Forward,
  23. Last
  24. };
  25. virtual ~ViewWidget() override = default;
  26. Gfx::Bitmap const* bitmap() const { return m_bitmap.ptr(); }
  27. DeprecatedString const& path() const { return m_path; }
  28. void set_toolbar_height(int height) { m_toolbar_height = height; }
  29. int toolbar_height() { return m_toolbar_height; }
  30. bool scaled_for_first_image() { return m_scaled_for_first_image; }
  31. void set_scaled_for_first_image(bool val) { m_scaled_for_first_image = val; }
  32. void set_path(DeprecatedString const& path);
  33. void resize_window();
  34. void set_scaling_mode(Gfx::Painter::ScalingMode);
  35. bool is_next_available() const;
  36. bool is_previous_available() const;
  37. void clear();
  38. void flip(Gfx::Orientation);
  39. void rotate(Gfx::RotationDirection);
  40. void navigate(Directions);
  41. void load_from_file(DeprecatedString const&);
  42. Function<void()> on_doubleclick;
  43. Function<void(const GUI::DropEvent&)> on_drop;
  44. Function<void(Gfx::Bitmap const*)> on_image_change;
  45. private:
  46. ViewWidget();
  47. virtual void doubleclick_event(GUI::MouseEvent&) override;
  48. virtual void paint_event(GUI::PaintEvent&) override;
  49. virtual void mousedown_event(GUI::MouseEvent&) override;
  50. virtual void mouseup_event(GUI::MouseEvent&) override;
  51. virtual void drag_enter_event(GUI::DragEvent&) override;
  52. virtual void drop_event(GUI::DropEvent&) override;
  53. void set_bitmap(Gfx::Bitmap const* bitmap);
  54. void animate();
  55. Vector<DeprecatedString> load_files_from_directory(DeprecatedString const& path) const;
  56. DeprecatedString m_path;
  57. RefPtr<Gfx::Bitmap const> m_bitmap;
  58. Optional<ImageDecoderClient::DecodedImage> m_decoded_image;
  59. size_t m_current_frame_index { 0 };
  60. size_t m_loops_completed { 0 };
  61. NonnullRefPtr<Core::Timer> m_timer;
  62. int m_toolbar_height { 28 };
  63. bool m_scaled_for_first_image { false };
  64. Vector<DeprecatedString> m_files_in_same_dir;
  65. Optional<size_t> m_current_index;
  66. Gfx::Painter::ScalingMode m_scaling_mode { Gfx::Painter::ScalingMode::NearestNeighbor };
  67. };
  68. }