summaryrefslogtreecommitdiffstats
path: root/src/ui/widget/color-picker.h
blob: c7147ae7b3a3a5664b326d35ba6f413d817ed8be (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// SPDX-License-Identifier: GPL-2.0-or-later
/** @file
 * @brief Color picker button and window.
 */
/* Authors:
 *   Lauris Kaplinski <lauris@kaplinski.com>
 *   Ralf Stephan <ralf@ark.in-berlin.de>
 *
 * Copyright (C) Authors 2000-2005
 *
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

#ifndef __COLOR_PICKER_H__
#define __COLOR_PICKER_H__

#include "labelled.h"

#include <cstddef>

#include "ui/selected-color.h"
#include "ui/widget/color-preview.h"
#include <gtkmm/button.h>
#include <gtkmm/dialog.h>
#include <gtkmm/window.h>
#include <sigc++/sigc++.h>

struct SPColorSelector;

namespace Inkscape
{
namespace UI
{
namespace Widget
{


class ColorPicker : public Gtk::Button {
public:

    ColorPicker (const Glib::ustring& title,
                 const Glib::ustring& tip,
                 const guint32 rgba,
                 bool undo,
                 Gtk::Button* external_button = nullptr);

    ~ColorPicker() override;

    void setRgba32 (guint32 rgba);
    void setSensitive(bool sensitive);
    void open();
    void closeWindow();
    sigc::connection connectChanged (const sigc::slot<void,guint>& slot)
        { return _changed_signal.connect (slot); }
    void use_transparency(bool enable);

protected:

    void _onSelectedColorChanged();
    void on_clicked() override;
    virtual void on_changed (guint32);

    ColorPreview *_preview;

    /*const*/ Glib::ustring _title;
    sigc::signal<void,guint32> _changed_signal;
    guint32             _rgba;
    bool                _undo;
    bool                _updating;

    //Dialog
    void setupDialog(const Glib::ustring &title);
    //Inkscape::UI::Dialog::Dialog _colorSelectorDialog;
    Gtk::Dialog _colorSelectorDialog;
    SelectedColor _selected_color;

private:
    void set_preview(guint32 rgba);

    Gtk::Widget *_color_selector;
    bool _ignore_transparency = false;
};


class LabelledColorPicker : public Labelled {
public:

    LabelledColorPicker (const Glib::ustring& label,
                         const Glib::ustring& title,
                         const Glib::ustring& tip,
                         const guint32 rgba,
                         bool undo) : Labelled(label, tip, new ColorPicker(title, tip, rgba, undo)) {}

    void setRgba32 (guint32 rgba)
        { static_cast<ColorPicker*>(_widget)->setRgba32 (rgba); }

    void closeWindow()
        { static_cast<ColorPicker*>(_widget)->closeWindow (); }

    sigc::connection connectChanged (const sigc::slot<void,guint>& slot)
        { return static_cast<ColorPicker*>(_widget)->connectChanged(slot); }
};

}//namespace Widget
}//namespace UI
}//namespace Inkscape

#endif /* !__COLOR_PICKER_H__ */

/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :