From 270730d9b36c8fc3a221da7e565632c1432d41c6 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Sun, 5 Jun 2022 21:41:57 -0400 Subject: start attachments (image paste and upload) --- src/components/chatinput.hpp | 89 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 4 deletions(-) (limited to 'src/components/chatinput.hpp') diff --git a/src/components/chatinput.hpp b/src/components/chatinput.hpp index ad7f0b1..a6b2a31 100644 --- a/src/components/chatinput.hpp +++ b/src/components/chatinput.hpp @@ -1,9 +1,57 @@ #pragma once #include -class ChatInput : public Gtk::ScrolledWindow { +class ChatInputAttachmentItem : public Gtk::EventBox { public: - ChatInput(); + ChatInputAttachmentItem(std::string path, const Glib::RefPtr &pb); + + [[nodiscard]] std::string GetPath() const; + +private: + void SetupMenu(); + + Gtk::Menu m_menu; + Gtk::MenuItem m_menu_remove; + + Gtk::Box m_box; + Gtk::Image *m_img = nullptr; + + std::string m_path; + +private: + using type_signal_remove = sigc::signal; + + type_signal_remove m_signal_remove; + +public: + type_signal_remove signal_remove(); +}; + +class ChatInputAttachmentContainer : public Gtk::ScrolledWindow { +public: + ChatInputAttachmentContainer(); + + void Clear(); + bool AddImage(const Glib::RefPtr &pb, const std::string &path); + [[nodiscard]] std::vector GetFilePaths() const; + +private: + std::set m_attachments; + + Gtk::Box m_box; + +private: + using type_signal_emptied = sigc::signal; + + type_signal_emptied m_signal_emptied; + +public: + type_signal_emptied signal_emptied(); +}; + +class ChatInputText : public Gtk::ScrolledWindow { +public: + ChatInputText(); void InsertText(const Glib::ustring &text); Glib::RefPtr GetBuffer(); @@ -15,9 +63,42 @@ protected: private: Gtk::TextView m_textview; + bool CheckHandleClipboardPaste(); + void HandleNewPastedImage(const Glib::RefPtr &pb, const std::string &filename); + +public: + using type_signal_submit = sigc::signal; + using type_signal_escape = sigc::signal; + using type_signal_image_paste = sigc::signal, std::string>; + + type_signal_submit signal_submit(); + type_signal_escape signal_escape(); + type_signal_image_paste signal_image_paste(); + +private: + type_signal_submit m_signal_submit; + type_signal_escape m_signal_escape; + type_signal_image_paste m_signal_image_paste; +}; + +class ChatInput : public Gtk::Box { +public: + ChatInput(); + + void InsertText(const Glib::ustring &text); + Glib::RefPtr GetBuffer(); + bool ProcessKeyPress(GdkEventKey *event); + +private: + Gtk::Revealer m_attachments_revealer; + ChatInputAttachmentContainer m_attachments; + ChatInputText m_input; + public: - typedef sigc::signal type_signal_submit; - typedef sigc::signal type_signal_escape; + // text, attachments -> request sent + // maybe this should be reduced to a single struct, its bound to get more complicated (application commands?) + using type_signal_submit = sigc::signal>; + using type_signal_escape = sigc::signal; type_signal_submit signal_submit(); type_signal_escape signal_escape(); -- cgit v1.2.3