Serenity Operating System
at master 50 lines 1.4 kB view raw
1/* 2 * Copyright (c) 2020, Hüseyin Aslıtürk <asliturk@hotmail.com> 3 * Copyright (c) 2022, the SerenityOS developers. 4 * 5 * SPDX-License-Identifier: BSD-2-Clause 6 */ 7 8#pragma once 9 10#include <AK/Function.h> 11#include <LibGUI/TextEditor.h> 12 13namespace GUI { 14 15class ColorInput final : public TextEditor { 16 C_OBJECT(ColorInput); 17 18public: 19 virtual ~ColorInput() override = default; 20 21 bool has_alpha_channel() const { return m_color_has_alpha_channel; } 22 void set_color_has_alpha_channel(bool has_alpha) { m_color_has_alpha_channel = has_alpha; } 23 24 void set_color(Color, AllowCallback = AllowCallback::Yes); 25 Color color() { return m_color; } 26 27 void set_color_picker_title(DeprecatedString title) { m_color_picker_title = move(title); } 28 DeprecatedString color_picker_title() { return m_color_picker_title; } 29 30 Function<void()> on_change; 31 32protected: 33 virtual void mousedown_event(MouseEvent&) override; 34 virtual void mouseup_event(MouseEvent&) override; 35 virtual void mousemove_event(MouseEvent&) override; 36 virtual void paint_event(PaintEvent&) override; 37 38private: 39 ColorInput(); 40 41 Gfx::IntRect color_rect() const; 42 void set_color_internal(Color, AllowCallback, bool change_text); 43 44 Color m_color; 45 DeprecatedString m_color_picker_title { "Select color" }; 46 bool m_color_has_alpha_channel { true }; 47 bool m_may_be_color_rect_click { false }; 48}; 49 50}