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