BookTile.hpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #pragma once
  2. #include "Book.hpp"
  3. #include <gtkmm/box.h>
  4. #include <gtkmm/picture.h>
  5. #include <gtkmm/label.h>
  6. #include <gtkmm/overlay.h>
  7. #include <gtkmm/gestureclick.h>
  8. #include <gtkmm/eventcontrollermotion.h>
  9. /**
  10. * @brief Compact widget that renders a single Book cover and title.
  11. *
  12. * BookTile is used by @ref BookShelf's GridView factory; it presents the
  13. * cover art (texture if already loaded, otherwise lazy load from disk) and
  14. * a caption, and forwards click gestures via @ref signalActivated().
  15. */
  16. class BookTile : public Gtk::Box {
  17. public:
  18. BookTile(const Book& book, int coverSize = 128);
  19. void setBook(const Book& book); // for updates
  20. const Book& getBook() const noexcept { return m_book; }
  21. void setSelected(bool selected);
  22. /// Emitted when the tile is clicked (single click).
  23. sigc::signal<void(const Book&)>& signalActivated() { return m_signalActivated; }
  24. private:
  25. void rebuild();
  26. void onActivated();
  27. Book m_book;
  28. int m_coverSize = 128;
  29. Gtk::Overlay m_overlay;
  30. Gtk::Picture m_cover;
  31. Gtk::Label m_title;
  32. Glib::RefPtr<Gtk::GestureClick> m_click;
  33. Glib::RefPtr<Gtk::EventControllerMotion> m_hover;
  34. bool m_selected = false;
  35. sigc::signal<void(const Book&)> m_signalActivated;
  36. };