5 #include <yui/Libyui_config.h> 8 #include "ygtkbargraph.h" 10 #include "YBarGraph.h" 19 ,
YGWidget (
this, parent, YGTK_TYPE_BAR_GRAPH, NULL)
23 virtual void doUpdate()
26 ygtk_bar_graph_create_entries (graph, segments());
27 for (
int i = 0; i < segments(); i++) {
28 const YBarGraphSegment &s = segment (i);
29 ygtk_bar_graph_setup_entry (graph, i, s.label().c_str(), s.value());
30 if (s.hasSegmentColor()) {
31 GdkRGBA color = ycolorToGdk (s.segmentColor());
32 ygtk_bar_graph_customize_bg (graph, i, &color);
34 if (s.hasTextColor()) {
35 GdkRGBA color = ycolorToGdk (s.textColor());
36 ygtk_bar_graph_customize_fg (graph, i, &color);
41 static GdkRGBA ycolorToGdk (
const YColor &ycolor)
44 static_cast<gdouble
> ( guint16(ycolor.red() << 8 ) ),
45 static_cast<gdouble
> ( guint16(ycolor.green() << 8 ) ),
46 static_cast<gdouble
> ( guint16(ycolor.blue() << 8 ) )
51 virtual unsigned int getMinSize (YUIDimension dim)
52 {
return dim == YD_HORIZ ? 80 : 30; }
54 YGWIDGET_IMPL_COMMON (YBarGraph)
57 YBarGraph *YGOptionalWidgetFactory::createBarGraph (YWidget *parent)
62 #include "YPartitionSplitter.h" 68 GtkWidget *m_scale, *m_free_spin, *m_new_spin;
71 int minNewPartSize,
int minFreeSize,
const std::string &usedLabel,
const std::string &freeLabel,
72 const std::string &newPartLabel,
const std::string &freeFieldLabel,
const std::string &newPartFieldLabel)
73 : YPartitionSplitter (NULL, usedSize, totalFreeSize, newPartSize, minNewPartSize,
74 minFreeSize, usedLabel, freeLabel, newPartLabel, freeFieldLabel, newPartFieldLabel)
75 ,
YGWidget (
this, parent, YGTK_VBOX_NEW(0), NULL)
78 GtkWidget *graph = ygtk_bar_graph_new();
79 m_barGraph = YGTK_BAR_GRAPH (graph);
80 ygtk_bar_graph_create_entries (m_barGraph, 3);
81 ygtk_bar_graph_setup_entry (m_barGraph, 0, usedLabel.c_str(), usedSize);
84 GtkWidget *labels_box = YGTK_HBOX_NEW(0);
85 gtk_box_set_homogeneous (GTK_BOX (labels_box), FALSE);
86 gtk_box_pack_start (GTK_BOX (labels_box),
87 gtk_label_new (freeFieldLabel.c_str()), FALSE, TRUE, 0);
88 gtk_box_pack_start (GTK_BOX (labels_box), gtk_label_new (NULL), TRUE, TRUE, 0);
89 gtk_box_pack_start (GTK_BOX (labels_box),
90 gtk_label_new (newPartFieldLabel.c_str()), FALSE, TRUE, 0);
93 GtkWidget *slider_box = YGTK_HBOX_NEW(0);
94 gtk_box_set_homogeneous (GTK_BOX (slider_box), FALSE);
95 m_scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL, (gdouble) minFreeSize, maxFreeSize(), 1);
96 gtk_scale_set_draw_value (GTK_SCALE (m_scale), FALSE);
97 m_free_spin = gtk_spin_button_new_with_range
98 (minFreeSize, maxFreeSize(), 1);
99 m_new_spin = gtk_spin_button_new_with_range
100 (minNewPartSize, maxNewPartSize(), 1);
103 gtk_widget_set_direction (labels_box, GTK_TEXT_DIR_LTR);
104 gtk_widget_set_direction (slider_box, GTK_TEXT_DIR_LTR);
106 gtk_box_pack_start (GTK_BOX (slider_box), m_free_spin, FALSE, FALSE, 0);
107 gtk_box_pack_start (GTK_BOX (slider_box), m_scale, TRUE, TRUE, 0);
108 gtk_box_pack_start (GTK_BOX (slider_box), m_new_spin, FALSE, FALSE, 0);
110 connect (m_scale,
"value-changed", G_CALLBACK (scale_changed_cb),
this);
111 connect (m_free_spin,
"value-changed", G_CALLBACK (free_spin_changed_cb),
this);
112 connect (m_new_spin,
"value-changed", G_CALLBACK (new_spin_changed_cb),
this);
115 gtk_box_pack_start (GTK_BOX (getWidget()), graph, TRUE, TRUE, 6);
116 gtk_box_pack_start (GTK_BOX (getWidget()), labels_box, FALSE, TRUE, 2);
117 gtk_box_pack_start (GTK_BOX (getWidget()), slider_box, FALSE, TRUE, 2);
119 setValue (newPartSize);
120 gtk_widget_show_all (getWidget());
126 return gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (m_new_spin));
129 virtual void setValue (
int newValue)
132 gtk_spin_button_set_value (GTK_SPIN_BUTTON (m_new_spin), newValue);
133 int freeSize = totalFreeSize() - newValue;
134 gtk_spin_button_set_value (GTK_SPIN_BUTTON (m_free_spin), freeSize);
135 gtk_range_set_value (GTK_RANGE (m_scale), freeSize);
137 gtk_spin_button_set_value (GTK_SPIN_BUTTON (m_free_spin), freeSize);
138 gtk_spin_button_set_value (GTK_SPIN_BUTTON (m_new_spin), newValue);
140 ygtk_bar_graph_setup_entry (m_barGraph, 1, freeLabel().c_str(), freeSize);
141 ygtk_bar_graph_setup_entry (m_barGraph, 2, newPartLabel().c_str(), newValue);
146 int newFreeSize = (int) gtk_range_get_value (range);
147 int newPartSize = pThis->totalFreeSize() - newFreeSize;
149 pThis->setValue (newPartSize);
150 pThis->emitEvent (YEvent::ValueChanged);
155 int newFreeSize = gtk_spin_button_get_value_as_int (spin);
156 int newPartSize = pThis->totalFreeSize() - newFreeSize;
157 pThis->setValue (newPartSize);
158 pThis->emitEvent (YEvent::ValueChanged);
163 pThis->setValue (gtk_spin_button_get_value_as_int (spin));
164 pThis->emitEvent (YEvent::ValueChanged);
167 YGWIDGET_IMPL_COMMON (YPartitionSplitter)
170 YPartitionSplitter *YGOptionalWidgetFactory::createPartitionSplitter (YWidget *parent,
171 int usedSize,
int totalFreeSize,
int newPartSize,
int minNewPartSize,
172 int minFreeSize,
const std::string &usedLabel,
const std::string &freeLabel,
173 const std::string &newPartLabel,
const std::string &freeFieldLabel,
174 const std::string &newPartFieldLabel)
177 minNewPartSize, minFreeSize, usedLabel, freeLabel, newPartLabel, freeFieldLabel,