5 #include <yui/Libyui_config.h>
8 #include "ygtkbargraph.h"
10 #include "YBarGraph.h"
17 ,
YGWidget (
this, parent, YGTK_TYPE_BAR_GRAPH, NULL)
21 virtual void doUpdate()
24 ygtk_bar_graph_create_entries (graph, segments());
25 for (
int i = 0; i < segments(); i++) {
26 const YBarGraphSegment &s = segment (i);
27 ygtk_bar_graph_setup_entry (graph, i, s.label().c_str(), s.value());
28 if (s.hasSegmentColor()) {
29 GdkRGBA color = ycolorToGdk (s.segmentColor());
30 ygtk_bar_graph_customize_bg (graph, i, &color);
32 if (s.hasTextColor()) {
33 GdkRGBA color = ycolorToGdk (s.textColor());
34 ygtk_bar_graph_customize_fg (graph, i, &color);
39 static GdkRGBA ycolorToGdk (
const YColor &ycolor)
42 static_cast<gdouble
> ( guint16(ycolor.red() << 8 ) ),
43 static_cast<gdouble
> ( guint16(ycolor.green() << 8 ) ),
44 static_cast<gdouble
> ( guint16(ycolor.blue() << 8 ) )
49 virtual unsigned int getMinSize (YUIDimension dim)
50 {
return dim == YD_HORIZ ? 80 : 30; }
52 YGWIDGET_IMPL_COMMON (YBarGraph)
55 YBarGraph *YGOptionalWidgetFactory::createBarGraph (YWidget *parent)
60 #include "YPartitionSplitter.h"
66 GtkWidget *m_scale, *m_free_spin, *m_new_spin;
69 int minNewPartSize,
int minFreeSize,
const std::string &usedLabel,
const std::string &freeLabel,
70 const std::string &newPartLabel,
const std::string &freeFieldLabel,
const std::string &newPartFieldLabel)
71 : YPartitionSplitter (NULL, usedSize, totalFreeSize, newPartSize, minNewPartSize,
72 minFreeSize, usedLabel, freeLabel, newPartLabel, freeFieldLabel, newPartFieldLabel)
73 ,
YGWidget (
this, parent, GTK_TYPE_VBOX, NULL)
76 GtkWidget *graph = ygtk_bar_graph_new();
77 m_barGraph = YGTK_BAR_GRAPH (graph);
78 ygtk_bar_graph_create_entries (m_barGraph, 3);
79 ygtk_bar_graph_setup_entry (m_barGraph, 0, usedLabel.c_str(), usedSize);
82 GtkWidget *labels_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
83 gtk_box_set_homogeneous (GTK_BOX (labels_box), FALSE);
84 gtk_box_pack_start (GTK_BOX (labels_box),
85 gtk_label_new (freeFieldLabel.c_str()), FALSE, TRUE, 0);
86 gtk_box_pack_start (GTK_BOX (labels_box), gtk_label_new (NULL), TRUE, TRUE, 0);
87 gtk_box_pack_start (GTK_BOX (labels_box),
88 gtk_label_new (newPartFieldLabel.c_str()), FALSE, TRUE, 0);
91 GtkWidget *slider_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
92 gtk_box_set_homogeneous (GTK_BOX (slider_box), FALSE);
93 m_scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL, (gdouble) minFreeSize, maxFreeSize(), 1);
94 gtk_scale_set_draw_value (GTK_SCALE (m_scale), FALSE);
95 m_free_spin = gtk_spin_button_new_with_range
96 (minFreeSize, maxFreeSize(), 1);
97 m_new_spin = gtk_spin_button_new_with_range
98 (minNewPartSize, maxNewPartSize(), 1);
101 gtk_widget_set_direction (labels_box, GTK_TEXT_DIR_LTR);
102 gtk_widget_set_direction (slider_box, GTK_TEXT_DIR_LTR);
104 gtk_box_pack_start (GTK_BOX (slider_box), m_free_spin, FALSE, FALSE, 0);
105 gtk_box_pack_start (GTK_BOX (slider_box), m_scale, TRUE, TRUE, 0);
106 gtk_box_pack_start (GTK_BOX (slider_box), m_new_spin, FALSE, FALSE, 0);
108 connect (m_scale,
"value-changed", G_CALLBACK (scale_changed_cb),
this);
109 connect (m_free_spin,
"value-changed", G_CALLBACK (free_spin_changed_cb),
this);
110 connect (m_new_spin,
"value-changed", G_CALLBACK (new_spin_changed_cb),
this);
113 gtk_box_pack_start (GTK_BOX (getWidget()), graph, TRUE, TRUE, 6);
114 gtk_box_pack_start (GTK_BOX (getWidget()), labels_box, FALSE, TRUE, 2);
115 gtk_box_pack_start (GTK_BOX (getWidget()), slider_box, FALSE, TRUE, 2);
117 setValue (newPartSize);
118 gtk_widget_show_all (getWidget());
124 return gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (m_new_spin));
127 virtual void setValue (
int newValue)
130 gtk_spin_button_set_value (GTK_SPIN_BUTTON (m_new_spin), newValue);
131 int freeSize = totalFreeSize() - newValue;
132 gtk_spin_button_set_value (GTK_SPIN_BUTTON (m_free_spin), freeSize);
133 gtk_range_set_value (GTK_RANGE (m_scale), freeSize);
135 gtk_spin_button_set_value (GTK_SPIN_BUTTON (m_free_spin), freeSize);
136 gtk_spin_button_set_value (GTK_SPIN_BUTTON (m_new_spin), newValue);
138 ygtk_bar_graph_setup_entry (m_barGraph, 1, freeLabel().c_str(), freeSize);
139 ygtk_bar_graph_setup_entry (m_barGraph, 2, newPartLabel().c_str(), newValue);
144 int newFreeSize = (int) gtk_range_get_value (range);
145 int newPartSize = pThis->totalFreeSize() - newFreeSize;
147 pThis->setValue (newPartSize);
148 pThis->emitEvent (YEvent::ValueChanged);
153 int newFreeSize = gtk_spin_button_get_value_as_int (spin);
154 int newPartSize = pThis->totalFreeSize() - newFreeSize;
155 pThis->setValue (newPartSize);
156 pThis->emitEvent (YEvent::ValueChanged);
161 pThis->setValue (gtk_spin_button_get_value_as_int (spin));
162 pThis->emitEvent (YEvent::ValueChanged);
165 YGWIDGET_IMPL_COMMON (YPartitionSplitter)
168 YPartitionSplitter *YGOptionalWidgetFactory::createPartitionSplitter (YWidget *parent,
169 int usedSize,
int totalFreeSize,
int newPartSize,
int minNewPartSize,
170 int minFreeSize,
const std::string &usedLabel,
const std::string &freeLabel,
171 const std::string &newPartLabel,
const std::string &freeFieldLabel,
172 const std::string &newPartFieldLabel)
175 minNewPartSize, minFreeSize, usedLabel, freeLabel, newPartLabel, freeFieldLabel,