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