Code

1d99f406cf4ef5824066e0807e464de7078413de
[inkscape.git] / src / ui / widget / random.cpp
1 /**\r
2  * \brief Scalar Widget - A labelled text box, with spin buttons and optional\r
3  *        icon or suffix, for entering arbitrary number values. It adds an extra\r
4  *       number called "startseed", that is not UI edittable, but should be put in SVG.\r
5  *      This does NOT generate a random number, but provides merely the saving of \r
6  *      the startseed value.\r
7  *\r
8  * Authors:\r
9  *   Carl Hetherington <inkscape@carlh.net>\r
10  *   Derek P. Moore <derekm@hackunix.org>\r
11  *   Bryce Harrington <bryce@bryceharrington.org>\r
12  *\r
13  * Copyright (C) 2004 Carl Hetherington\r
14  *\r
15  * Released under GNU GPL.  Read the file 'COPYING' for more information.\r
16  */\r
17 \r
18 #ifdef HAVE_CONFIG_H\r
19 # include <config.h>\r
20 #endif\r
21 \r
22 \r
23 #include "random.h"\r
24 #include "widgets/icon.h"\r
25 \r
26 #include <glibmm/i18n.h>\r
27 \r
28 namespace Inkscape {\r
29 namespace UI {\r
30 namespace Widget {\r
31 \r
32 /**\r
33  * Construct a Random scalar Widget.\r
34  *\r
35  * \param label     Label.\r
36  * \param suffix    Suffix, placed after the widget (defaults to "").\r
37  * \param icon      Icon filename, placed before the label (defaults to "").\r
38  * \param mnemonic  Mnemonic toggle; if true, an underscore (_) in the label\r
39  *                  indicates the next character should be used for the\r
40  *                  mnemonic accelerator key (defaults to false).\r
41  */\r
42 Random::Random(Glib::ustring const &label, Glib::ustring const &tooltip,\r
43                Glib::ustring const &suffix,\r
44                Glib::ustring const &icon,\r
45                bool mnemonic)\r
46     : Scalar(label, tooltip, suffix, icon, mnemonic)\r
47 {\r
48     startseed = 0;\r
49     addReseedButton();\r
50 }\r
51 \r
52 /**\r
53  * Construct a  Random Scalar Widget.\r
54  *\r
55  * \param label     Label.\r
56  * \param digits    Number of decimal digits to display.\r
57  * \param suffix    Suffix, placed after the widget (defaults to "").\r
58  * \param icon      Icon filename, placed before the label (defaults to "").\r
59  * \param mnemonic  Mnemonic toggle; if true, an underscore (_) in the label\r
60  *                  indicates the next character should be used for the\r
61  *                  mnemonic accelerator key (defaults to false).\r
62  */\r
63 Random::Random(Glib::ustring const &label, Glib::ustring const &tooltip,\r
64                unsigned digits,\r
65                Glib::ustring const &suffix,\r
66                Glib::ustring const &icon,\r
67                bool mnemonic)\r
68     : Scalar(label, tooltip, digits, suffix, icon, mnemonic)\r
69 {\r
70     startseed = 0;\r
71     addReseedButton();\r
72 }\r
73 \r
74 /**\r
75  * Construct a Random Scalar Widget.\r
76  *\r
77  * \param label     Label.\r
78  * \param adjust    Adjustment to use for the SpinButton.\r
79  * \param digits    Number of decimal digits to display (defaults to 0).\r
80  * \param suffix    Suffix, placed after the widget (defaults to "").\r
81  * \param icon      Icon filename, placed before the label (defaults to "").\r
82  * \param mnemonic  Mnemonic toggle; if true, an underscore (_) in the label\r
83  *                  indicates the next character should be used for the\r
84  *                  mnemonic accelerator key (defaults to true).\r
85  */\r
86 Random::Random(Glib::ustring const &label, Glib::ustring const &tooltip,\r
87                Gtk::Adjustment &adjust,\r
88                unsigned digits,\r
89                Glib::ustring const &suffix,\r
90                Glib::ustring const &icon,\r
91                bool mnemonic)\r
92     : Scalar(label, tooltip, adjust, digits, suffix, icon, mnemonic)\r
93 {\r
94     startseed = 0;\r
95     addReseedButton();\r
96 }\r
97 \r
98 /** Gets the startseed  */\r
99 long\r
100 Random::getStartSeed() const\r
101 {\r
102     return startseed;\r
103 }\r
104 \r
105 /** Sets the startseed number */\r
106 void\r
107 Random::setStartSeed(long newseed)\r
108 {\r
109     startseed = newseed;\r
110 }\r
111 \r
112 /** Add reseed button to the widget */\r
113 void\r
114 Random::addReseedButton()\r
115 {\r
116     Gtk::Widget*  pIcon = Gtk::manage( sp_icon_get_icon( "draw_spiral", Inkscape::ICON_SIZE_BUTTON) );\r
117     Gtk::Button * pButton = Gtk::manage(new Gtk::Button());\r
118     pButton->set_relief(Gtk::RELIEF_NONE);\r
119     pIcon->show();\r
120     pButton->add(*pIcon);\r
121     pButton->show();\r
122     pButton->signal_clicked().connect(sigc::mem_fun(*this, &Random::onReseedButtonClick));\r
123     _tooltips.set_tip(*pButton, _("Reseed the random number generator; this creates a different sequence of random numbers."));\r
124 \r
125     pack_start(*pButton, Gtk::PACK_SHRINK, 0);\r
126 }\r
127 \r
128 void\r
129 Random::onReseedButtonClick()\r
130 {\r
131     startseed = g_random_int();\r
132     signal_reseeded.emit();\r
133 }\r
134 \r
135 } // namespace Widget\r
136 } // namespace UI\r
137 } // namespace Inkscape\r
138 \r
139 /*\r
140   Local Variables:\r
141   mode:c++\r
142   c-file-style:"stroustrup"\r
143   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))\r
144   indent-tabs-mode:nil\r
145   fill-column:99\r
146   End:\r
147 */\r
148 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :\r