summaryrefslogtreecommitdiff
path: root/Applications
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-01-21 13:47:57 +0100
committerAndreas Kling <kling@serenityos.org>2020-01-21 13:47:57 +0100
commit1060d59ddd39c75b2fbbb4e2baa17dfaa223695b (patch)
tree83960a99807de0d7a4c4a2aaff1533c01fe036ed /Applications
parent07075cd0014b04660ac0d9d44267bdce72eefb5e (diff)
downloadserenity-1060d59ddd39c75b2fbbb4e2baa17dfaa223695b.zip
PaintBrush: Show which line thickness is selected in the tool menus
Put each tool's thickness altering actions into a GActionGroup and make them mutually exclusive so we get that nice radio button appearance. This all feel very clunky and we should move towards having something like a "tool settings" pane that gets populated by the currently active tool instead.
Diffstat (limited to 'Applications')
-rw-r--r--Applications/PaintBrush/EllipseTool.cpp27
-rw-r--r--Applications/PaintBrush/EllipseTool.h2
-rw-r--r--Applications/PaintBrush/EraseTool.cpp28
-rw-r--r--Applications/PaintBrush/EraseTool.h2
-rw-r--r--Applications/PaintBrush/LineTool.cpp27
-rw-r--r--Applications/PaintBrush/LineTool.h2
-rw-r--r--Applications/PaintBrush/PenTool.cpp27
-rw-r--r--Applications/PaintBrush/PenTool.h2
-rw-r--r--Applications/PaintBrush/SprayTool.cpp27
-rw-r--r--Applications/PaintBrush/SprayTool.h4
10 files changed, 87 insertions, 61 deletions
diff --git a/Applications/PaintBrush/EllipseTool.cpp b/Applications/PaintBrush/EllipseTool.cpp
index cbed5ebba6..1517c7065e 100644
--- a/Applications/PaintBrush/EllipseTool.cpp
+++ b/Applications/PaintBrush/EllipseTool.cpp
@@ -115,18 +115,21 @@ void EllipseTool::on_contextmenu(GContextMenuEvent& event)
m_mode = Mode::Outline;
}));
m_context_menu->add_separator();
- m_context_menu->add_action(GAction::create("1", [this](auto&) {
- m_thickness = 1;
- }));
- m_context_menu->add_action(GAction::create("2", [this](auto&) {
- m_thickness = 2;
- }));
- m_context_menu->add_action(GAction::create("3", [this](auto&) {
- m_thickness = 3;
- }));
- m_context_menu->add_action(GAction::create("4", [this](auto&) {
- m_thickness = 4;
- }));
+ m_thickness_actions.set_exclusive(true);
+ auto insert_action = [&](int size, bool checked = false) {
+ auto action = GAction::create(String::number(size), [this, size](auto& action) {
+ m_thickness = size;
+ action.set_checked(true);
+ });
+ action->set_checkable(true);
+ action->set_checked(checked);
+ m_thickness_actions.add_action(*action);
+ m_context_menu->add_action(move(action));
+ };
+ insert_action(1, true);
+ insert_action(2);
+ insert_action(3);
+ insert_action(4);
}
m_context_menu->popup(event.screen_position());
}
diff --git a/Applications/PaintBrush/EllipseTool.h b/Applications/PaintBrush/EllipseTool.h
index dfbd560ec0..09779566d8 100644
--- a/Applications/PaintBrush/EllipseTool.h
+++ b/Applications/PaintBrush/EllipseTool.h
@@ -28,6 +28,7 @@
#include "Tool.h"
#include <LibDraw/Point.h>
+#include <LibGUI/GActionGroup.h>
class GMenu;
class Painter;
@@ -58,5 +59,6 @@ private:
Point m_ellipse_end_position;
RefPtr<GMenu> m_context_menu;
int m_thickness { 1 };
+ GActionGroup m_thickness_actions;
Mode m_mode { Mode::Outline };
};
diff --git a/Applications/PaintBrush/EraseTool.cpp b/Applications/PaintBrush/EraseTool.cpp
index 76adad6630..cf9737b868 100644
--- a/Applications/PaintBrush/EraseTool.cpp
+++ b/Applications/PaintBrush/EraseTool.cpp
@@ -86,18 +86,22 @@ void EraseTool::on_contextmenu(GContextMenuEvent& event)
m_context_menu->add_action(eraser_color_toggler);
m_context_menu->add_separator();
- m_context_menu->add_action(GAction::create("1", [this](auto&) {
- m_thickness = 1;
- }));
- m_context_menu->add_action(GAction::create("2", [this](auto&) {
- m_thickness = 2;
- }));
- m_context_menu->add_action(GAction::create("3", [this](auto&) {
- m_thickness = 3;
- }));
- m_context_menu->add_action(GAction::create("4", [this](auto&) {
- m_thickness = 4;
- }));
+
+ m_thickness_actions.set_exclusive(true);
+ auto insert_action = [&](int size, bool checked = false) {
+ auto action = GAction::create(String::number(size), [this, size](auto& action) {
+ m_thickness = size;
+ action.set_checked(true);
+ });
+ action->set_checkable(true);
+ action->set_checked(checked);
+ m_thickness_actions.add_action(*action);
+ m_context_menu->add_action(move(action));
+ };
+ insert_action(1, true);
+ insert_action(2);
+ insert_action(3);
+ insert_action(4);
}
m_context_menu->popup(event.screen_position());
diff --git a/Applications/PaintBrush/EraseTool.h b/Applications/PaintBrush/EraseTool.h
index 76c1578c68..b7ca11ae8c 100644
--- a/Applications/PaintBrush/EraseTool.h
+++ b/Applications/PaintBrush/EraseTool.h
@@ -28,6 +28,7 @@
#include "Tool.h"
#include <LibDraw/Point.h>
+#include <LibGUI/GActionGroup.h>
class GMenu;
@@ -48,4 +49,5 @@ private:
bool m_use_secondary_color { true };
int m_thickness { 1 };
+ GActionGroup m_thickness_actions;
};
diff --git a/Applications/PaintBrush/LineTool.cpp b/Applications/PaintBrush/LineTool.cpp
index 40232a3753..8fcffb0d24 100644
--- a/Applications/PaintBrush/LineTool.cpp
+++ b/Applications/PaintBrush/LineTool.cpp
@@ -131,18 +131,21 @@ void LineTool::on_contextmenu(GContextMenuEvent& event)
{
if (!m_context_menu) {
m_context_menu = GMenu::construct();
- m_context_menu->add_action(GAction::create("1", [this](auto&) {
- m_thickness = 1;
- }));
- m_context_menu->add_action(GAction::create("2", [this](auto&) {
- m_thickness = 2;
- }));
- m_context_menu->add_action(GAction::create("3", [this](auto&) {
- m_thickness = 3;
- }));
- m_context_menu->add_action(GAction::create("4", [this](auto&) {
- m_thickness = 4;
- }));
+ m_thickness_actions.set_exclusive(true);
+ auto insert_action = [&](int size, bool checked = false) {
+ auto action = GAction::create(String::number(size), [this, size](auto& action) {
+ m_thickness = size;
+ action.set_checked(true);
+ });
+ action->set_checkable(true);
+ action->set_checked(checked);
+ m_thickness_actions.add_action(*action);
+ m_context_menu->add_action(move(action));
+ };
+ insert_action(1, true);
+ insert_action(2);
+ insert_action(3);
+ insert_action(4);
}
m_context_menu->popup(event.screen_position());
}
diff --git a/Applications/PaintBrush/LineTool.h b/Applications/PaintBrush/LineTool.h
index c34ab99a5f..b591ffeef5 100644
--- a/Applications/PaintBrush/LineTool.h
+++ b/Applications/PaintBrush/LineTool.h
@@ -28,6 +28,7 @@
#include "Tool.h"
#include <LibDraw/Point.h>
+#include <LibGUI/GActionGroup.h>
class GMenu;
@@ -51,6 +52,7 @@ private:
Point m_line_start_position;
Point m_line_end_position;
RefPtr<GMenu> m_context_menu;
+ GActionGroup m_thickness_actions;
int m_thickness { 1 };
bool m_constrain_angle { false };
};
diff --git a/Applications/PaintBrush/PenTool.cpp b/Applications/PaintBrush/PenTool.cpp
index 873f7ea46f..e670afa97f 100644
--- a/Applications/PaintBrush/PenTool.cpp
+++ b/Applications/PaintBrush/PenTool.cpp
@@ -77,18 +77,21 @@ void PenTool::on_contextmenu(GContextMenuEvent& event)
{
if (!m_context_menu) {
m_context_menu = GMenu::construct();
- m_context_menu->add_action(GAction::create("1", [this](auto&) {
- m_thickness = 1;
- }));
- m_context_menu->add_action(GAction::create("2", [this](auto&) {
- m_thickness = 2;
- }));
- m_context_menu->add_action(GAction::create("3", [this](auto&) {
- m_thickness = 3;
- }));
- m_context_menu->add_action(GAction::create("4", [this](auto&) {
- m_thickness = 4;
- }));
+ m_thickness_actions.set_exclusive(true);
+ auto insert_action = [&](int size, bool checked = false) {
+ auto action = GAction::create(String::number(size), [this, size](auto& action) {
+ m_thickness = size;
+ action.set_checked(true);
+ });
+ action->set_checkable(true);
+ action->set_checked(checked);
+ m_thickness_actions.add_action(*action);
+ m_context_menu->add_action(move(action));
+ };
+ insert_action(1, true);
+ insert_action(2);
+ insert_action(3);
+ insert_action(4);
}
m_context_menu->popup(event.screen_position());
}
diff --git a/Applications/PaintBrush/PenTool.h b/Applications/PaintBrush/PenTool.h
index 431325cf78..3495c23b2a 100644
--- a/Applications/PaintBrush/PenTool.h
+++ b/Applications/PaintBrush/PenTool.h
@@ -28,6 +28,7 @@
#include "Tool.h"
#include <LibDraw/Point.h>
+#include <LibGUI/GActionGroup.h>
class GMenu;
@@ -47,4 +48,5 @@ private:
Point m_last_drawing_event_position { -1, -1 };
RefPtr<GMenu> m_context_menu;
int m_thickness { 1 };
+ GActionGroup m_thickness_actions;
};
diff --git a/Applications/PaintBrush/SprayTool.cpp b/Applications/PaintBrush/SprayTool.cpp
index defc793022..1a9c9895a5 100644
--- a/Applications/PaintBrush/SprayTool.cpp
+++ b/Applications/PaintBrush/SprayTool.cpp
@@ -103,18 +103,21 @@ void SprayTool::on_contextmenu(GContextMenuEvent& event)
{
if (!m_context_menu) {
m_context_menu = GMenu::construct();
- m_context_menu->add_action(GAction::create("1", [this](auto&) {
- m_thickness = 1;
- }));
- m_context_menu->add_action(GAction::create("2", [this](auto&) {
- m_thickness = 2;
- }));
- m_context_menu->add_action(GAction::create("3", [this](auto&) {
- m_thickness = 3;
- }));
- m_context_menu->add_action(GAction::create("4", [this](auto&) {
- m_thickness = 4;
- }));
+ m_thickness_actions.set_exclusive(true);
+ auto insert_action = [&](int size, bool checked = false) {
+ auto action = GAction::create(String::number(size), [this, size](auto& action) {
+ m_thickness = size;
+ action.set_checked(true);
+ });
+ action->set_checkable(true);
+ action->set_checked(checked);
+ m_thickness_actions.add_action(*action);
+ m_context_menu->add_action(move(action));
+ };
+ insert_action(1, true);
+ insert_action(2);
+ insert_action(3);
+ insert_action(4);
}
m_context_menu->popup(event.screen_position());
}
diff --git a/Applications/PaintBrush/SprayTool.h b/Applications/PaintBrush/SprayTool.h
index fb0441ce1d..8eb13797c5 100644
--- a/Applications/PaintBrush/SprayTool.h
+++ b/Applications/PaintBrush/SprayTool.h
@@ -27,8 +27,9 @@
#pragma once
#include "Tool.h"
-#include <LibGUI/GPainter.h>
#include <LibCore/CTimer.h>
+#include <LibGUI/GActionGroup.h>
+#include <LibGUI/GPainter.h>
class GMenu;
@@ -49,5 +50,6 @@ private:
Point m_last_pos;
Color m_color;
RefPtr<GMenu> m_context_menu;
+ GActionGroup m_thickness_actions;
int m_thickness { 1 };
};