summaryrefslogtreecommitdiff
path: root/Userland/Applications/PixelPaint/PaletteWidget.h
blob: b90e5d8b426341dc900b6d036f12ea210b0258af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
 * Copyright (c) 2021, Felix Rauch <noreply@felixrau.ch>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/Result.h>
#include <AK/Vector.h>
#include <LibGUI/Frame.h>

namespace PixelPaint {

class ImageEditor;

class PaletteWidget final : public GUI::Frame {
    C_OBJECT(PaletteWidget);

public:
    virtual ~PaletteWidget() override;

    void set_primary_color(Color);
    void set_secondary_color(Color);

    void display_color_list(Vector<Color> const&);

    Vector<Color> colors();

    static Result<Vector<Color>, String> load_palette_fd_and_close(int);
    static Result<Vector<Color>, String> load_palette_path(String const&);
    static Result<void, String> save_palette_fd_and_close(Vector<Color>, int);
    static Vector<Color> fallback_colors();

    void set_image_editor(ImageEditor&);

private:
    static Result<Vector<Color>, String> load_palette_file(Core::File&);

    explicit PaletteWidget();

    ImageEditor* m_editor { nullptr };
    RefPtr<GUI::Frame> m_primary_color_widget;
    RefPtr<GUI::Frame> m_secondary_color_widget;
    RefPtr<GUI::Widget> m_color_container;
};

}