LibGUI: Import GColorPicker from the PaintBrush application
This commit is contained in:
parent
30ad7953ca
commit
a14f08fcc9
Notes:
sideshowbarker
2024-07-19 09:54:40 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/a14f08fcc94
5 changed files with 30 additions and 28 deletions
|
@ -9,7 +9,6 @@ OBJS = \
|
|||
EllipseTool.o \
|
||||
EraseTool.o \
|
||||
BucketTool.o \
|
||||
ColorDialog.o \
|
||||
SprayTool.o \
|
||||
PickerTool.o \
|
||||
main.o
|
||||
|
|
|
@ -25,9 +25,9 @@
|
|||
*/
|
||||
|
||||
#include "PaletteWidget.h"
|
||||
#include "ColorDialog.h"
|
||||
#include "PaintableWidget.h"
|
||||
#include <LibGUI/GBoxLayout.h>
|
||||
#include <LibGUI/GColorPicker.h>
|
||||
|
||||
class ColorWidget : public GFrame {
|
||||
C_OBJECT(ColorWidget)
|
||||
|
@ -49,7 +49,7 @@ public:
|
|||
virtual void mousedown_event(GMouseEvent& event) override
|
||||
{
|
||||
if (event.modifiers() & KeyModifier::Mod_Ctrl && event.button() == GMouseButton::Left) {
|
||||
auto dialog = ColorDialog::construct(m_color, window());
|
||||
auto dialog = GColorPicker::construct(m_color, window());
|
||||
if (dialog->exec() == GDialog::ExecOK) {
|
||||
m_color = dialog->color();
|
||||
auto pal = palette();
|
||||
|
|
|
@ -24,14 +24,14 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "ColorDialog.h"
|
||||
#include <LibGUI/GBoxLayout.h>
|
||||
#include <LibGUI/GButton.h>
|
||||
#include <LibGUI/GColorPicker.h>
|
||||
#include <LibGUI/GFrame.h>
|
||||
#include <LibGUI/GSpinBox.h>
|
||||
#include <LibGUI/GWidget.h>
|
||||
|
||||
ColorDialog::ColorDialog(Color color, CObject* parent)
|
||||
GColorPicker::GColorPicker(Color color, CObject* parent)
|
||||
: GDialog(parent)
|
||||
, m_color(color)
|
||||
{
|
||||
|
@ -39,11 +39,11 @@ ColorDialog::ColorDialog(Color color, CObject* parent)
|
|||
build();
|
||||
}
|
||||
|
||||
ColorDialog::~ColorDialog()
|
||||
GColorPicker::~GColorPicker()
|
||||
{
|
||||
}
|
||||
|
||||
void ColorDialog::build()
|
||||
void GColorPicker::build()
|
||||
{
|
||||
auto horizontal_container = GWidget::construct();
|
||||
horizontal_container->set_fill_with_background_color(true);
|
||||
|
@ -58,7 +58,9 @@ void ColorDialog::build()
|
|||
right_vertical_container->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||
|
||||
enum RGBComponent {
|
||||
Red, Green, Blue
|
||||
Red,
|
||||
Green,
|
||||
Blue
|
||||
};
|
||||
|
||||
m_preview_widget = GFrame::construct(right_vertical_container);
|
||||
|
@ -81,27 +83,27 @@ void ColorDialog::build()
|
|||
};
|
||||
|
||||
auto make_spinbox = [&](RGBComponent component, int initial_value) {
|
||||
auto spinbox = GSpinBox::construct(left_vertical_container);
|
||||
spinbox->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
spinbox->set_preferred_size(0, 20);
|
||||
spinbox->set_min(0);
|
||||
spinbox->set_max(255);
|
||||
spinbox->set_value(initial_value);
|
||||
auto spinbox = GSpinBox::construct(left_vertical_container);
|
||||
spinbox->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
spinbox->set_preferred_size(0, 20);
|
||||
spinbox->set_min(0);
|
||||
spinbox->set_max(255);
|
||||
spinbox->set_value(initial_value);
|
||||
|
||||
spinbox->on_change = [this, component](auto value) {
|
||||
if (component == Red)
|
||||
spinbox->on_change = [this, component](auto value) {
|
||||
if (component == Red)
|
||||
m_color.set_red(value);
|
||||
if (component == Green)
|
||||
if (component == Green)
|
||||
m_color.set_green(value);
|
||||
if (component == Blue)
|
||||
if (component == Blue)
|
||||
m_color.set_blue(value);
|
||||
|
||||
auto pal = m_preview_widget->palette();
|
||||
pal.set_color(ColorRole::Background, m_color);
|
||||
m_preview_widget->set_palette(pal);
|
||||
m_preview_widget->update();
|
||||
};
|
||||
return spinbox;
|
||||
auto pal = m_preview_widget->palette();
|
||||
pal.set_color(ColorRole::Background, m_color);
|
||||
m_preview_widget->set_palette(pal);
|
||||
m_preview_widget->update();
|
||||
};
|
||||
return spinbox;
|
||||
};
|
||||
|
||||
make_spinbox(Red, m_color.red());
|
|
@ -30,15 +30,15 @@
|
|||
|
||||
class GFrame;
|
||||
|
||||
class ColorDialog final : public GDialog {
|
||||
C_OBJECT(ColorDialog)
|
||||
class GColorPicker final : public GDialog {
|
||||
C_OBJECT(GColorPicker)
|
||||
public:
|
||||
virtual ~ColorDialog() override;
|
||||
virtual ~GColorPicker() override;
|
||||
|
||||
Color color() const { return m_color; }
|
||||
|
||||
private:
|
||||
explicit ColorDialog(Color, CObject* parent = nullptr);
|
||||
explicit GColorPicker(Color, CObject* parent = nullptr);
|
||||
|
||||
void build();
|
||||
|
|
@ -10,6 +10,7 @@ OBJS = \
|
|||
GWidget.o \
|
||||
GLayout.o \
|
||||
GBoxLayout.o \
|
||||
GColorPicker.o \
|
||||
GMenuBar.o \
|
||||
GMenu.o \
|
||||
GMenuItem.o \
|
||||
|
|
Loading…
Add table
Reference in a new issue