~engelmarkus/inkscape/cppify

« back to all changes in this revision

Viewing changes to src/ui/widget/anchor-selector.cpp

  • Committer: Markus Engel
  • Date: 2014-07-17 20:26:50 UTC
  • mfrom: (11608.7.1169 inkscape)
  • Revision ID: markus.engel@tum.de-20140717202650-8ov45e3cj8ktk89e
Merged from trunk (r13454).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * anchor-selector.cpp
 
3
 *
 
4
 *  Created on: Mar 22, 2012
 
5
 *      Author: denis
 
6
 *
 
7
 * Released under GNU GPL.  Read the file 'COPYING' for more information.
 
8
 */
 
9
 
 
10
#include "ui/widget/anchor-selector.h"
 
11
#include <iostream>
 
12
#include "widgets/icon.h"
 
13
#include "ui/icon-names.h"
 
14
 
 
15
namespace Inkscape {
 
16
namespace UI {
 
17
namespace Widget {
 
18
 
 
19
void AnchorSelector::setupButton(const Glib::ustring& icon, Gtk::ToggleButton& button) {
 
20
        Gtk::Widget*  buttonIcon = Gtk::manage(sp_icon_get_icon(icon, Inkscape::ICON_SIZE_SMALL_TOOLBAR));
 
21
        buttonIcon->show();
 
22
 
 
23
        button.set_relief(Gtk::RELIEF_NONE);
 
24
        button.show();
 
25
        button.add(*buttonIcon);
 
26
        button.set_can_focus(false);
 
27
}
 
28
 
 
29
AnchorSelector::AnchorSelector()
 
30
        : Gtk::Alignment(0.5, 0, 0, 0),
 
31
          _container(3, 3, true)
 
32
{
 
33
        setupButton(INKSCAPE_ICON("boundingbox_top_left"),     _buttons[0]);
 
34
        setupButton(INKSCAPE_ICON("boundingbox_top"),          _buttons[1]);
 
35
        setupButton(INKSCAPE_ICON("boundingbox_top_right"),    _buttons[2]);
 
36
        setupButton(INKSCAPE_ICON("boundingbox_left"),         _buttons[3]);
 
37
        setupButton(INKSCAPE_ICON("boundingbox_center"),       _buttons[4]);
 
38
        setupButton(INKSCAPE_ICON("boundingbox_right"),        _buttons[5]);
 
39
        setupButton(INKSCAPE_ICON("boundingbox_bottom_left"),  _buttons[6]);
 
40
        setupButton(INKSCAPE_ICON("boundingbox_bottom"),       _buttons[7]);
 
41
        setupButton(INKSCAPE_ICON("boundingbox_bottom_right"), _buttons[8]);
 
42
 
 
43
        for(int i = 0; i < 9; ++i) {
 
44
                _buttons[i].signal_clicked().connect(
 
45
                                sigc::bind(sigc::mem_fun(*this, &AnchorSelector::btn_activated), i));
 
46
                _container.attach(_buttons[i], i % 3, i % 3+1, i / 3, i / 3+1, Gtk::FILL, Gtk::FILL);
 
47
        }
 
48
        _selection = 4;
 
49
        _buttons[4].set_active();
 
50
 
 
51
        this->add(_container);
 
52
}
 
53
 
 
54
AnchorSelector::~AnchorSelector()
 
55
{
 
56
        // TODO Auto-generated destructor stub
 
57
}
 
58
 
 
59
void AnchorSelector::btn_activated(int index)
 
60
{
 
61
 
 
62
        if(_selection == index && _buttons[index].get_active() == false)
 
63
        {
 
64
                _buttons[index].set_active(true);
 
65
        }
 
66
        else if(_selection != index && _buttons[index].get_active())
 
67
        {
 
68
                int old_selection = _selection;
 
69
                _selection = index;
 
70
                _buttons[old_selection].set_active(false);
 
71
                _selectionChanged.emit();
 
72
        }
 
73
}
 
74
 
 
75
void AnchorSelector::setAlignment(int horizontal, int vertical)
 
76
{
 
77
        int index = 3 * vertical + horizontal;
 
78
        if(index >= 0 && index < 9)
 
79
        {
 
80
                _buttons[index].set_active(!_buttons[index].get_active());
 
81
        }
 
82
}
 
83
 
 
84
} // namespace Widget
 
85
} // namespace UI
 
86
} // namespace Inkscape
 
87
 
 
88
/*
 
89
  Local Variables:
 
90
  mode:c++
 
91
  c-file-style:"stroustrup"
 
92
  c-file-offsets:((innamespace . 0)(inline-open . 0))
 
93
  indent-tabs-mode:nil
 
94
  fill-column:99
 
95
  End:
 
96
*/
 
97
// vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :