From b5d1cfef585b5102472fc05061912fbbecb2d5f4 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 11 Apr 2019 06:08:06 +0200 Subject: [PATCH] VisualBuilder: Add icons to the toolbox, and support for GProgressBar. --- Applications/VisualBuilder/VBWidget.cpp | 8 +++++++ Applications/VisualBuilder/VBWidget.h | 1 + Applications/VisualBuilder/main.cpp | 16 ++++++++++--- Base/res/icons/vbwidgets/button.png | Bin 0 -> 266 bytes Base/res/icons/vbwidgets/progressbar.png | Bin 0 -> 186 bytes Base/res/icons/vbwidgets/spinbox.png | Bin 0 -> 261 bytes Base/res/icons/vbwidgets/textbox.png | Bin 0 -> 243 bytes LibGUI/GProgressBar.cpp | 29 +++++++++++++---------- LibGUI/GProgressBar.h | 2 +- 9 files changed, 40 insertions(+), 16 deletions(-) create mode 100644 Base/res/icons/vbwidgets/button.png create mode 100644 Base/res/icons/vbwidgets/progressbar.png create mode 100644 Base/res/icons/vbwidgets/spinbox.png create mode 100644 Base/res/icons/vbwidgets/textbox.png diff --git a/Applications/VisualBuilder/VBWidget.cpp b/Applications/VisualBuilder/VBWidget.cpp index 2c1040b4c1..be7b966986 100644 --- a/Applications/VisualBuilder/VBWidget.cpp +++ b/Applications/VisualBuilder/VBWidget.cpp @@ -5,6 +5,7 @@ #include #include #include +#include static GWidget* build_gwidget(WidgetType type, GWidget* parent) { @@ -22,6 +23,13 @@ static GWidget* build_gwidget(WidgetType type, GWidget* parent) editor->set_ruler_visible(false); return editor; } + case WidgetType::GProgressBar: { + auto* bar = new GProgressBar(parent); + bar->set_format(GProgressBar::Format::NoText); + bar->set_range(0, 100); + bar->set_value(50); + return bar; + } default: ASSERT_NOT_REACHED(); return nullptr; diff --git a/Applications/VisualBuilder/VBWidget.h b/Applications/VisualBuilder/VBWidget.h index 0e13c1f8c4..d0576bdf0c 100644 --- a/Applications/VisualBuilder/VBWidget.h +++ b/Applications/VisualBuilder/VBWidget.h @@ -30,6 +30,7 @@ enum class WidgetType { GLabel, GSpinBox, GTextEditor, + GProgressBar, }; class VBWidget : public Retainable, public Weakable { diff --git a/Applications/VisualBuilder/main.cpp b/Applications/VisualBuilder/main.cpp index 17b5455a86..5926a57352 100644 --- a/Applications/VisualBuilder/main.cpp +++ b/Applications/VisualBuilder/main.cpp @@ -67,22 +67,32 @@ GWindow* make_toolbox_window() window->set_main_widget(widget); auto* button_button = new GButton(widget); - button_button->set_caption("Button"); + button_button->set_tooltip("GButton"); + button_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/vbwidgets/button.png")); button_button->on_click = [] (GButton&) { if (auto* form = VBForm::current()) form->insert_widget(WidgetType::GButton); }; auto* spinbox_button = new GButton(widget); - spinbox_button->set_caption("SpinBox"); + spinbox_button->set_tooltip("GSpinBox"); + spinbox_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/vbwidgets/spinbox.png")); spinbox_button->on_click = [] (GButton&) { if (auto* form = VBForm::current()) form->insert_widget(WidgetType::GSpinBox); }; auto* editor_button = new GButton(widget); - editor_button->set_caption("TextEditor"); + editor_button->set_tooltip("GTextEditor"); + editor_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/vbwidgets/textbox.png")); editor_button->on_click = [] (GButton&) { if (auto* form = VBForm::current()) form->insert_widget(WidgetType::GTextEditor); }; + auto* progress_bar_button = new GButton(widget); + progress_bar_button->set_tooltip("GProgressBar"); + progress_bar_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/vbwidgets/progressbar.png")); + progress_bar_button->on_click = [] (GButton&) { + if (auto* form = VBForm::current()) + form->insert_widget(WidgetType::GProgressBar); + }; return window; } diff --git a/Base/res/icons/vbwidgets/button.png b/Base/res/icons/vbwidgets/button.png new file mode 100644 index 0000000000000000000000000000000000000000..7d735c8e73240774b869b62f50a26f2b0534bbfd GIT binary patch literal 266 zcmeAS@N?(olHy`uVBq!ia0y~yV2}b~4mJh`hLv7E=NK3mE_%8+hIkx*8g`KPumX>b z`5!A5;S%<+hX5WL4Rq_=D#lMwO5#)-0SUe zh9|9V>O0|lE%k*J#mk}t_gi1Hwvr2|$coN6DZ2AokKwkjR>@};wXW&4yvaFX>$FKL zuT{m~|6Xuz>g+5(C#9&A7*n-v9y?qVxTnlk-*1|D*?;Lvn;@^Z#fx7*-NSu>H=HHv W!18|=85tND7(8A5T-G@yGywqGpln|N literal 0 HcmV?d00001 diff --git a/Base/res/icons/vbwidgets/progressbar.png b/Base/res/icons/vbwidgets/progressbar.png new file mode 100644 index 0000000000000000000000000000000000000000..a8c5e10a45afbc1bce19af87c6d43c2e0eaf6e0e GIT binary patch literal 186 zcmeAS@N?(olHy`uVBq!ia0y~yV2}b~4mJh`hLv7E=NK3m8a-VcLp+WrCrGd^P7n#; zl9*`8%gg(pbH)GeBWcH$Z`ikQUgN}xf_Zk_yPBBU`2ybjYHMTTF%-+;`YJa!<-wze zX%8Mf1>wX8ZI=p*zZ(fBUp&~%Zg^zI3sLvQViS2IIy?%>fJy3=E#GelF{r5}E)!Hb+|k literal 0 HcmV?d00001 diff --git a/Base/res/icons/vbwidgets/spinbox.png b/Base/res/icons/vbwidgets/spinbox.png new file mode 100644 index 0000000000000000000000000000000000000000..a81389690a15db1d3b33023c1e4e715111aeec48 GIT binary patch literal 261 zcmeAS@N?(olHy`uVBq!ia0y~yV2}b~4mJh`hLv7E=NK3m&Um^whIkx*8+uT%MM2=S z)i>2CNvan(mom&vP`%?W$>QfI8ULi6dG=hD-Av5P)*5ymnzic>IdKRCuCQM&-eb7l zbIFvO+jo`(X2bysH0^C+Ic!0=q= z-u-Cny^59r&ewG2Zrzr#ZRYBz6XNSMN z%RF=Z^HOysr4GY?-)BGA{dT@IYhvQV9{q!!snV}z=-V(bFfe$!`njxgN@xNAWT$7a literal 0 HcmV?d00001 diff --git a/LibGUI/GProgressBar.cpp b/LibGUI/GProgressBar.cpp index 89abea3580..1c60904cba 100644 --- a/LibGUI/GProgressBar.cpp +++ b/LibGUI/GProgressBar.cpp @@ -51,19 +51,22 @@ void GProgressBar::paint_event(GPaintEvent& event) float range_size = m_max - m_min; float progress = (m_value - m_min) / range_size; - // Then we draw the progress text over the gradient. - // We draw it twice, once offset (1, 1) for a drop shadow look. - StringBuilder builder; - builder.append(m_caption); - if (m_format == Format::Percentage) - builder.appendf("%d%%", (int)(progress * 100)); - else if (m_format == Format::ValueSlashMax) - builder.appendf("%d/%d", m_value, m_max); + String progress_text; + if (m_format != Format::NoText) { + // Then we draw the progress text over the gradient. + // We draw it twice, once offset (1, 1) for a drop shadow look. + StringBuilder builder; + builder.append(m_caption); + if (m_format == Format::Percentage) + builder.appendf("%d%%", (int)(progress * 100)); + else if (m_format == Format::ValueSlashMax) + builder.appendf("%d/%d", m_value, m_max); - auto progress_text = builder.to_string(); + progress_text = builder.to_string(); - painter.draw_text(rect.translated(1, 1), progress_text, TextAlignment::Center, Color::Black); - painter.draw_text(rect, progress_text, TextAlignment::Center, Color::White); + painter.draw_text(rect.translated(1, 1), progress_text, TextAlignment::Center, Color::Black); + painter.draw_text(rect, progress_text, TextAlignment::Center, Color::White); + } // Then we carve out a hole in the remaining part of the widget. // We draw the text a third time, clipped and inverse, for sharp contrast. @@ -71,5 +74,7 @@ void GProgressBar::paint_event(GPaintEvent& event) Rect hole_rect { (int)progress_width, 0, (int)(width() - progress_width), height() }; painter.add_clip_rect(hole_rect); painter.fill_rect(hole_rect, Color::White); - painter.draw_text(rect.translated(0, 0), progress_text, TextAlignment::Center, Color::Black); + + if (m_format != Format::NoText) + painter.draw_text(rect.translated(0, 0), progress_text, TextAlignment::Center, Color::Black); } diff --git a/LibGUI/GProgressBar.h b/LibGUI/GProgressBar.h index 82e0d07d31..c5ef4d7701 100644 --- a/LibGUI/GProgressBar.h +++ b/LibGUI/GProgressBar.h @@ -15,7 +15,7 @@ public: String caption() const { return m_caption; } void set_caption(const String& caption) { m_caption = caption; } - enum Format { Percentage, ValueSlashMax }; + enum Format { NoText, Percentage, ValueSlashMax }; Format format() const { return m_format; } void set_format(Format format) { m_format = format; }