From 3a3aa74b2e82e3589fd5db4e274951729b1bdfa2 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 15 Mar 2019 23:24:40 +0100 Subject: [PATCH] IRCClient: Add a toolbar with some actions. --- Applications/IRCClient/IRCAppWindow.cpp | 29 ++++++++++++++++++--- Applications/IRCClient/IRCClient.cpp | 7 ++++- Applications/TextEditor/main.cpp | 2 +- Base/res/icons/16x16/.gitignore | 1 + Base/res/icons/16x16/irc-join.png | Bin 0 -> 424 bytes Base/res/icons/16x16/irc-join.rgb | Bin 0 -> 1024 bytes Base/res/icons/16x16/irc-part.png | Bin 0 -> 468 bytes Base/res/icons/16x16/irc-part.rgb | Bin 0 -> 1024 bytes LibGUI/GBoxLayout.cpp | 33 +++++++++++++++++++----- LibGUI/GStackWidget.cpp | 3 ++- LibGUI/GToolBar.cpp | 5 ++++ LibGUI/GWidget.cpp | 12 ++++++--- LibGUI/GWidget.h | 1 + 13 files changed, 76 insertions(+), 17 deletions(-) create mode 100644 Base/res/icons/16x16/.gitignore create mode 100644 Base/res/icons/16x16/irc-join.png create mode 100644 Base/res/icons/16x16/irc-join.rgb create mode 100644 Base/res/icons/16x16/irc-part.png create mode 100644 Base/res/icons/16x16/irc-part.rgb diff --git a/Applications/IRCClient/IRCAppWindow.cpp b/Applications/IRCClient/IRCAppWindow.cpp index c026bd074f..0595e7de45 100644 --- a/Applications/IRCClient/IRCAppWindow.cpp +++ b/Applications/IRCClient/IRCAppWindow.cpp @@ -4,6 +4,9 @@ #include #include #include +#include +#include +#include IRCAppWindow::IRCAppWindow() : GWindow() @@ -43,11 +46,28 @@ void IRCAppWindow::setup_client() void IRCAppWindow::setup_widgets() { auto* widget = new GWidget(nullptr); - widget->set_fill_with_background_color(true); set_main_widget(widget); - widget->set_layout(make(Orientation::Horizontal)); + widget->set_layout(make(Orientation::Vertical)); - auto* window_list = new GTableView(widget); + printf("main_widget: %s{%p}\n", widget->class_name(), widget); + + auto join_action = GAction::create("Join channel", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/irc-join.rgb", { 16, 16 }), [] (auto&) { + printf("FIXME: Implement join action\n"); + }); + + auto part_action = GAction::create("Part from channel", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/irc-part.rgb", { 16, 16 }), [] (auto&) { + printf("FIXME: Implement part action\n"); + }); + + auto* toolbar = new GToolBar(widget); + toolbar->add_action(join_action.copy_ref()); + toolbar->add_action(part_action.copy_ref()); + + auto* horizontal_container = new GWidget(widget); + printf("horizontal_widget: %s{%p}\n", horizontal_container->class_name(), horizontal_container); + horizontal_container->set_layout(make(Orientation::Horizontal)); + + auto* window_list = new GTableView(horizontal_container); window_list->set_headers_visible(false); window_list->set_alternating_row_colors(false); window_list->set_model(OwnPtr(m_client.client_window_list_model())); @@ -57,7 +77,8 @@ void IRCAppWindow::setup_widgets() m_container->set_active_widget(&window); }; - m_container = new GStackWidget(widget); + m_container = new GStackWidget(horizontal_container); + printf("m_container: %s{%p}\n", ((GWidget*)m_container)->class_name(), m_container); create_subwindow(IRCClientWindow::Server, "Server"); } diff --git a/Applications/IRCClient/IRCClient.cpp b/Applications/IRCClient/IRCClient.cpp index f27770cc6c..fd4ea8fe22 100644 --- a/Applications/IRCClient/IRCClient.cpp +++ b/Applications/IRCClient/IRCClient.cpp @@ -11,6 +11,8 @@ #include #include +//#define IRC_DEBUG + enum IRCNumeric { RPL_NAMREPLY = 353, RPL_ENDOFNAMES = 366, @@ -201,6 +203,7 @@ void IRCClient::join_channel(const String& channel_name) void IRCClient::handle(const Message& msg, const String&) { +#ifdef IRC_DEBUG printf("IRCClient::execute: prefix='%s', command='%s', arguments=%d\n", msg.prefix.characters(), msg.command.characters(), @@ -212,6 +215,7 @@ void IRCClient::handle(const Message& msg, const String&) printf(" [%d]: %s\n", i, arg.characters()); ++i; } +#endif bool is_numeric; int numeric = msg.command.to_uint(is_numeric); @@ -285,7 +289,9 @@ void IRCClient::handle_privmsg(const Message& msg) auto sender_nick = parts[0]; auto target = msg.arguments[0]; +#ifdef IRC_DEBUG printf("handle_privmsg: sender_nick='%s', target='%s'\n", sender_nick.characters(), target.characters()); +#endif if (sender_nick.is_empty()) return; @@ -353,7 +359,6 @@ void IRCClient::handle_join(const Message& msg) void IRCClient::handle_namreply(const Message& msg) { - printf("NAMREPLY:\n"); if (msg.arguments.size() < 4) return; diff --git a/Applications/TextEditor/main.cpp b/Applications/TextEditor/main.cpp index 78d9f16993..c7bddbe69d 100644 --- a/Applications/TextEditor/main.cpp +++ b/Applications/TextEditor/main.cpp @@ -22,7 +22,7 @@ int main(int argc, char** argv) widget->set_layout(make(Orientation::Vertical)); auto* toolbar = new GToolBar(widget); - auto* text_editor = new GTextEditor(widget); + auto* text_editor = new GTextEditor(GTextEditor::MultiLine, widget); auto* statusbar = new GStatusBar(widget); text_editor->on_cursor_change = [statusbar] (GTextEditor& editor) { diff --git a/Base/res/icons/16x16/.gitignore b/Base/res/icons/16x16/.gitignore new file mode 100644 index 0000000000..f9e8176423 --- /dev/null +++ b/Base/res/icons/16x16/.gitignore @@ -0,0 +1 @@ +*.data diff --git a/Base/res/icons/16x16/irc-join.png b/Base/res/icons/16x16/irc-join.png new file mode 100644 index 0000000000000000000000000000000000000000..3a8692780570fa2dd46ddab69b2a47950cf020b1 GIT binary patch literal 424 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4mJh`2Kmqb6B!s7*pj^6T^OtxRxtQw?hRVb zz`(#+;1OBOz@VoL!i*J5?aLS#7}!fZeO=ifGxLj>sm}WFdAk_ba}OH`)bf}z%|0+yTkpXE zolVW*6V*3{UF2iaVTx=BwF)N?IMjrMP*?v`1?%D2BZnQu2qWS)pPp5Q5 zGi7?#+%4$Z9(MZY)@ye%>>s2&jZ1&dtl`^xFj}wInwep4*)ox(+&T;v@(c>yhk6!^ zthIWhaCczCog;f@AR&RCY@*UlvDY>fqIp3usesQr+oXj~4 zhi5K({73IZ|C^cciB#OlnFu-~PdK>r3bZ a_7{wkwa&-*d}m-_VDNPHb6Mw<&;$StzNr%c literal 0 HcmV?d00001 diff --git a/Base/res/icons/16x16/irc-join.rgb b/Base/res/icons/16x16/irc-join.rgb new file mode 100644 index 0000000000000000000000000000000000000000..10773d09d3200689829eee6c320ca87ae787a009 GIT binary patch literal 1024 zcmZRe5-9LjXDIYnXDIMj|6k~@{vSlcj0UmM#b9zU8l-ncnKj6a|0~L@|A5pZ$zh1W zKgbLa2HB4;2GfsjFGw8{{sVFg5+B1Iq}UH~3k<{ThtcTn0I5Tg!>|`7 z2cw6Ae$xW=|0V_Me?S=KZc@Szq~CwJ^?wkJtRIwapm7X}FHl&)Fo^%hyg>aw3CeExAX(xXQR1ARo12+TF5KV?D>aVa}o5(|%6&s5l#aeqFlTXSq9(hh(qV zY@6?!Y^~4DYX)eO$5YtM7yxR2O^R44-xCiEZ=q8J^)x2Z~Qk)m+0RbRb-6 z!8RWEh*YkZG8GpBW-{G=+BwUnETAMsw$W2q`jJzFy6q9x literal 0 HcmV?d00001 diff --git a/Base/res/icons/16x16/irc-part.rgb b/Base/res/icons/16x16/irc-part.rgb new file mode 100644 index 0000000000000000000000000000000000000000..6440380486f904c15f7da63d53a32dc93f04dd49 GIT binary patch literal 1024 zcmZRe5-9LjXDIYnXDIMj|6k~@{vSlcj0UmM#b9zU8l-ncnKj6a|0~L@|A5pZ$zh1W zKgbLa2HB4;2GfsjFGw8{{sVFg5+B1Iq}UH~3k<{ThtcTn0I5Tg!>|`7 z2crkGeofQ-|Jr5+;B*0Vuexc$9}p%c{6PBc0+;^>(V%bv(bfSg;QB%71{%kp_yUC$ z41@R}47ML+2FM*Y0n7h`>;}1o82h1SgY5_D1=$bMi;O|$AiD$PPMAE1jchN>?J#)| o4bl&aLy%n{^&lD~4#FV&knIJz9h(^-wb(F7JqRPqf%qT{0O%Gh7ytkO literal 0 HcmV?d00001 diff --git a/LibGUI/GBoxLayout.cpp b/LibGUI/GBoxLayout.cpp index 75d7a05c4c..9abea5ed62 100644 --- a/LibGUI/GBoxLayout.cpp +++ b/LibGUI/GBoxLayout.cpp @@ -1,12 +1,9 @@ #include #include +#include //#define GBOXLAYOUT_DEBUG -#ifdef GBOXLAYOUT_DEBUG -#include -#endif - GBoxLayout::GBoxLayout(Orientation orientation) : m_orientation(orientation) { @@ -35,6 +32,12 @@ static Size compute_preferred_size(GLayout::Entry& entry) void GBoxLayout::run(GWidget& widget) { + bool should_log = false; +#ifdef GBOXLAYOUT_DEBUG + should_log = true; +#endif + if (should_log) + printf("GBoxLayout: running layout on %s{%p}\n", widget.class_name(), &widget); if (m_entries.is_empty()) return; @@ -43,20 +46,34 @@ void GBoxLayout::run(GWidget& widget) int number_of_visible_entries = 0; + if (should_log) + printf("GBoxLayout: Starting with available size: %s\n", available_size.to_string().characters()); + for (auto& entry : m_entries) { if (!entry.widget->is_visible()) continue; ++number_of_visible_entries; if (entry.widget && entry.widget->size_policy(orientation()) == SizePolicy::Fixed) { + if (should_log) { + printf("GBoxLayout: Subtracting for fixed %s{%p}, size: %s\n", entry.widget->class_name(), entry.widget.ptr(), entry.widget->preferred_size().to_string().characters()); + printf("GBoxLayout: Available size before: %s\n", available_size.to_string().characters()); + } + available_size -= entry.widget->preferred_size(); + if (should_log) + printf("GBoxLayout: Available size after: %s\n", available_size.to_string().characters()); ++number_of_entries_with_fixed_size; } } + if (should_log) + printf("GBoxLayout: Number of visible: %d/%d\n", number_of_visible_entries, m_entries.size()); + int number_of_entries_with_automatic_size = number_of_visible_entries - number_of_entries_with_fixed_size; #ifdef GBOXLAYOUT_DEBUG - printf("GBoxLayout: available_size=%s, fixed=%d, fill=%d\n", available_size.to_string().characters(), number_of_entries_with_fixed_size, number_of_entries_with_automatic_size); + if (should_log) + printf("GBoxLayout: available_size=%s, fixed=%d, fill=%d\n", available_size.to_string().characters(), number_of_entries_with_fixed_size, number_of_entries_with_automatic_size); #endif Size automatic_size; @@ -72,7 +89,8 @@ void GBoxLayout::run(GWidget& widget) } #ifdef GBOXLAYOUT_DEBUG - printf("GBoxLayout: automatic_size=%s\n", automatic_size.to_string().characters()); + if (should_log) + printf("GBoxLayout: automatic_size=%s\n", automatic_size.to_string().characters()); #endif int current_x = margins().left(); @@ -106,7 +124,8 @@ void GBoxLayout::run(GWidget& widget) } #ifdef GBOXLAYOUT_DEBUG - printf("GBoxLayout: apply, %s{%p} <- %s\n", entry.widget->class_name(), entry.widget.ptr(), rect.to_string().characters()); + if (should_log) + printf("GBoxLayout: apply, %s{%p} <- %s\n", entry.widget->class_name(), entry.widget.ptr(), rect.to_string().characters()); #endif entry.widget->set_relative_rect(rect); diff --git a/LibGUI/GStackWidget.cpp b/LibGUI/GStackWidget.cpp index fea58ab676..ba225a7547 100644 --- a/LibGUI/GStackWidget.cpp +++ b/LibGUI/GStackWidget.cpp @@ -34,7 +34,7 @@ void GStackWidget::resize_event(GResizeEvent& event) void GStackWidget::child_event(GChildEvent& event) { if (!event.child() || !event.child()->is_widget()) - return; + return GWidget::child_event(event); auto& child = static_cast(*event.child()); if (event.type() == GEvent::ChildAdded) { if (!m_active_widget) @@ -53,4 +53,5 @@ void GStackWidget::child_event(GChildEvent& event) set_active_widget(new_active_widget); } } + GWidget::child_event(event); } diff --git a/LibGUI/GToolBar.cpp b/LibGUI/GToolBar.cpp index 3024e218f8..992b7f867e 100644 --- a/LibGUI/GToolBar.cpp +++ b/LibGUI/GToolBar.cpp @@ -36,6 +36,8 @@ void GToolBar::add_action(Retained&& action) button->set_button_style(GButtonStyle::CoolBar); button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed); + ASSERT(button->size_policy(Orientation::Horizontal) == SizePolicy::Fixed); + ASSERT(button->size_policy(Orientation::Vertical) == SizePolicy::Fixed); button->set_preferred_size({ 24, 24 }); m_items.append(move(item)); @@ -60,6 +62,9 @@ public: painter.draw_line({ 0, 0 }, { 0, rect().bottom() }, Color::DarkGray); painter.draw_line({ 1, 0 }, { 1, rect().bottom() }, Color::White); } + +private: + virtual const char* class_name() const override { return "SeparatorWidget"; } }; void GToolBar::add_separator() diff --git a/LibGUI/GWidget.cpp b/LibGUI/GWidget.cpp index 15ee45de32..8303aad9c8 100644 --- a/LibGUI/GWidget.cpp +++ b/LibGUI/GWidget.cpp @@ -15,15 +15,21 @@ GWidget::GWidget(GWidget* parent) set_font(nullptr); m_background_color = Color::LightGray; m_foreground_color = Color::Black; - - if (parent && parent->layout()) - parent->layout()->add_widget(*this); } GWidget::~GWidget() { } +void GWidget::child_event(GChildEvent& event) +{ + if (event.type() == GEvent::ChildAdded) { + if (event.child() && event.child()->is_widget() && layout()) + layout()->add_widget(static_cast(*event.child())); + } + return GObject::child_event(event); +} + void GWidget::set_relative_rect(const Rect& rect) { if (rect == m_relative_rect) diff --git a/LibGUI/GWidget.h b/LibGUI/GWidget.h index b9a65598b2..d856e66420 100644 --- a/LibGUI/GWidget.h +++ b/LibGUI/GWidget.h @@ -47,6 +47,7 @@ public: virtual void focusout_event(GEvent&); virtual void enter_event(GEvent&); virtual void leave_event(GEvent&); + virtual void child_event(GChildEvent&) override; Rect relative_rect() const { return m_relative_rect; } Point relative_position() const { return m_relative_rect.location(); }