summaryrefslogtreecommitdiffstats
path: root/src/ui/toolbar/dropper-toolbar.cpp
blob: 83a18c37a28e3ce8e62b541b9bb361e9d9d11266 (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
// SPDX-License-Identifier: GPL-2.0-or-later
/**
 * @file
 * Dropper aux toolbar
 */
/* Authors:
 *   MenTaLguY <mental@rydia.net>
 *   Lauris Kaplinski <lauris@kaplinski.com>
 *   bulia byak <buliabyak@users.sf.net>
 *   Frank Felfe <innerspace@iname.com>
 *   John Cliff <simarilius@yahoo.com>
 *   David Turner <novalis@gnu.org>
 *   Josh Andler <scislac@scislac.com>
 *   Jon A. Cruz <jon@joncruz.org>
 *   Maximilian Albert <maximilian.albert@gmail.com>
 *   Tavmjong Bah <tavmjong@free.fr>
 *   Abhishek Sharma
 *   Kris De Gussem <Kris.DeGussem@gmail.com>
 *
 * Copyright (C) 2004 David Turner
 * Copyright (C) 2003 MenTaLguY
 * Copyright (C) 1999-2011 authors
 * Copyright (C) 2001-2002 Ximian, Inc.
 *
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

#include <glibmm/i18n.h>

#include "dropper-toolbar.h"
#include "document-undo.h"
#include "preferences.h"
#include "desktop.h"

#include "ui/widget/canvas.h" // Grab focus

namespace Inkscape {
namespace UI {
namespace Toolbar {

void DropperToolbar::on_pick_alpha_button_toggled()
{
    auto active = _pick_alpha_button->get_active();

    auto prefs = Inkscape::Preferences::get();
    prefs->setInt( "/tools/dropper/pick", active );

    _set_alpha_button->set_sensitive(active);
    _desktop->canvas->grab_focus();
}

void DropperToolbar::on_set_alpha_button_toggled()
{
    auto prefs = Inkscape::Preferences::get();
    prefs->setBool( "/tools/dropper/setalpha", _set_alpha_button->get_active( ) );
    _desktop->canvas->grab_focus();
}

/*
 * TODO: Would like to add swatch of current color.
 * TODO: Add queue of last 5 or so colors selected with new swatches so that
 *       can drag and drop places. Will provide a nice mixing palette.
 */
DropperToolbar::DropperToolbar(SPDesktop *desktop)
    : Toolbar(desktop)
{
    // Add widgets to toolbar
    add_label(_("Opacity:"));
    _pick_alpha_button = add_toggle_button(_("Pick"),
                                           _("Pick both the color and the alpha (transparency) under cursor; "
                                             "otherwise, pick only the visible color premultiplied by alpha"));
    _set_alpha_button = add_toggle_button(_("Assign"),
                                          _("If alpha was picked, assign it to selection "
                                            "as fill or stroke transparency"));

    Inkscape::Preferences *prefs = Inkscape::Preferences::get();

    // Set initial state of widgets
    auto pickAlpha = prefs->getInt( "/tools/dropper/pick", 1 );
    auto setAlpha  = prefs->getBool( "/tools/dropper/setalpha", true);

    _pick_alpha_button->set_active(pickAlpha);
    _set_alpha_button->set_active(setAlpha);

    // Make sure the set-alpha button is disabled if we're not picking alpha
    _set_alpha_button->set_sensitive(pickAlpha);

    // Connect signal handlers
    auto pick_alpha_button_toggled_cb = sigc::mem_fun(*this, &DropperToolbar::on_pick_alpha_button_toggled);
    auto set_alpha_button_toggled_cb  = sigc::mem_fun(*this, &DropperToolbar::on_set_alpha_button_toggled);

    _pick_alpha_button->signal_toggled().connect(pick_alpha_button_toggled_cb);
    _set_alpha_button->signal_toggled().connect(set_alpha_button_toggled_cb);

    show_all();
}

GtkWidget *
DropperToolbar::create(SPDesktop *desktop)
{
    auto toolbar = Gtk::manage(new DropperToolbar(desktop));
    return GTK_WIDGET(toolbar->gobj());
}
}
}
}

/*
  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 :