libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GtkCRNScaleAction.cpp
Go to the documentation of this file.
1 /* Copyright 2010-2016 CoReNum, INSA-Lyon, ENS-Lyon
2  *
3  * This file is part of libgtkcrnmm.
4  *
5  * libgtkcrnmm is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * libgtkcrnmm is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with libgtkcrnmm. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * file: GtkCRNScaleAction.cpp
19  * \author Yann LEYDIER
20  */
21 
22 #include <GtkCRNScaleAction.h>
23 
24 #ifndef CRN_USING_GTKMM3
25 
26 #include <CRNIO/CRNIO.h>
27 #include <gtkmm/scalebutton.h>
28 #include <GtkCRNApp.h>
29 #include <CRNi18n.h>
30 
31 using namespace GtkCRN;
32 
35  Gtk::Action(),
36  adj(50, 0, 100)
37 {
38 }
39 
46 ScaleAction::ScaleAction(const Glib::ustring& name, const Gtk::StockID& stock_id, const Glib::ustring& label, const Glib::ustring& tooltip):
47  Gtk::Action(name, stock_id, label, tooltip),
48  adj(50, 0, 100),
49  lab(label)
50 {
51 }
52 
59 ScaleAction::ScaleAction(const Glib::ustring& name, const Glib::ustring& icon_name, const Glib::ustring& label, const Glib::ustring& tooltip):
60  Gtk::Action(name, icon_name, label, tooltip),
61  adj(50, 0, 100),
62  lab(label)
63 {
64 }
65 
69 void ScaleAction::set_icons(const Glib::StringArrayHandle& icons)
70 {
71  iconlist = icons;
72 }
73 
77 Glib::RefPtr<ScaleAction> ScaleAction::create()
78 {
79  return Glib::RefPtr<ScaleAction>(new ScaleAction());
80 }
81 
88 Glib::RefPtr<ScaleAction> ScaleAction::create(const Glib::ustring& name, const Glib::ustring& label, const Glib::ustring& tooltip)
89 {
90  return Glib::RefPtr<ScaleAction>(new ScaleAction(name, label, tooltip));
91 }
92 
100 Glib::RefPtr<ScaleAction> ScaleAction::create(const Glib::ustring& name, const Gtk::StockID& stock_id, const Glib::ustring& label, const Glib::ustring& tooltip)
101 {
102  return Glib::RefPtr<ScaleAction>(new ScaleAction(name, stock_id, label, tooltip));
103 }
104 
112 Glib::RefPtr<ScaleAction> ScaleAction::create_with_icon_name(const Glib::ustring& name, const Glib::ustring& icon_name, const Glib::ustring& label, const Glib::ustring& tooltip)
113 {
114  return Glib::RefPtr<ScaleAction>(new ScaleAction(name, icon_name, label, tooltip));
115 }
116 
118 {
119  //Gtk::MenuItem *it = (Gtk::MenuItem*)Action::create_menu_item_vfunc();
120  auto *it = Gtk::manage(new Gtk::MenuItem(lab));
121  it->signal_activate().connect(sigc::mem_fun(this, &ScaleAction::dialog));
122  return it;
123 }
124 
126 {
127  Gtk::ToolItem *it = new Gtk::ToolItem;
128  Gtk::ScaleButton *sb = Gtk::manage(new Gtk::ScaleButton(Gtk::ICON_SIZE_BUTTON, 0, 100, 10, iconlist));
129  sb->set_adjustment(adj);
130  sb->set_icons(iconlist);
131  sb->show();
132  it->add(*sb);
133  return it;
134 }
135 
137 {
138  Gtk::Dialog dial("", true);
139  Gtk::Window *mainwin = App::get_main_window();
140  if (mainwin)
141  {
142  dial.set_transient_for (*mainwin);
143  dial.set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
144  }
145  else
146  dial.set_position(Gtk::WIN_POS_CENTER);
147  dial.set_position(Gtk::WIN_POS_CENTER);
148  dial.add_button(Gtk::Stock::APPLY, Gtk::RESPONSE_ACCEPT);
149  dial.set_default_response(Gtk::RESPONSE_ACCEPT);
150  Gtk::HBox hbox;
151  dial.get_vbox()->pack_start(hbox, false, true, 0);
152  Gtk::Label label(lab, true);
153  hbox.pack_start(label, false, true, 2);
154  Gtk::HScale scale(adj);
155  scale.set_value_pos(Gtk::POS_LEFT);
156  scale.set_size_request(200);
157  hbox.pack_start(scale, true, true, 2);
158  hbox.show_all();
159  dial.show();
160  dial.run();
161 }
162 
163 #endif
164 
void set_icons(const Glib::StringArrayHandle &icons)
Sets the icons to display depending of the value of the scale.
static Glib::RefPtr< ScaleAction > create()
Creates a blank ScaleAction.
static Glib::RefPtr< ScaleAction > create_with_icon_name(const Glib::ustring &name, const Glib::ustring &icon_name, const Glib::ustring &label, const Glib::ustring &tooltip)
Creates a ScaleAction.
virtual Gtk::Widget * create_tool_item_vfunc() override
virtual Gtk::Widget * create_menu_item_vfunc() override
static Gtk::Window * get_main_window()
Gets a pointer to the main window.
Definition: GtkCRNApp.h:57
std::vector< Glib::ustring > iconlist
Gtk::Adjustment adj