added colorsupport to mklabel in Util.h and replaced self-made widget with UTF-8 block in VBox_VisualDisk.cc/.h

This commit is contained in:
Bart Hakvoort 2004-10-07 14:12:34 +00:00
parent bd3152788f
commit 4d47390878
4 changed files with 49 additions and 52 deletions

View File

@ -1,3 +1,9 @@
2004-10-07 Bart Hakvoort <gparted@users.sf.net>
* include/Utils.h: added support for colored text to mk_label
* include/VBox_VisualDisk.h,
include/VBox_VisualDisk.cc: use UTF-8 character ██ instead of some self-forged widget.
2004-10-06 Bart Hakvoort <gparted@users.sf.net> 2004-10-06 Bart Hakvoort <gparted@users.sf.net>
* implemented mk_label wherever possible (means less code, improved readability) * implemented mk_label wherever possible (means less code, improved readability)

View File

@ -63,7 +63,7 @@ inline Sector Abs( Sector sectors )
return sectors < 0 ? sectors - 2*sectors : sectors ; return sectors < 0 ? sectors - 2*sectors : sectors ;
} }
inline Gtk::Label * mk_label( const Glib::ustring & text, bool use_markup = true, bool align_left = true, bool wrap = false ) inline Gtk::Label * mk_label( const Glib::ustring & text, bool use_markup = true, bool align_left = true, bool wrap = false, const Glib::ustring & text_color = "black" )
{ {
Gtk::Label * label = manage( new Gtk::Label( text ) ) ; Gtk::Label * label = manage( new Gtk::Label( text ) ) ;
@ -74,6 +74,12 @@ inline Gtk::Label * mk_label( const Glib::ustring & text, bool use_markup = true
label ->set_line_wrap( wrap ) ; label ->set_line_wrap( wrap ) ;
if ( text_color != "black" )
{
Gdk::Color color( text_color ) ;
label ->modify_fg( label ->get_state(), color ) ;
}
return label ; return label ;
} }

View File

@ -25,8 +25,6 @@
#include <gtkmm/frame.h> #include <gtkmm/frame.h>
#include <gtkmm/eventbox.h> #include <gtkmm/eventbox.h>
#include <gtkmm/tooltips.h> #include <gtkmm/tooltips.h>
#include <gtkmm/label.h>
#include <gtkmm/entry.h>
#include <gtkmm/checkbutton.h> #include <gtkmm/checkbutton.h>
#include <gtkmm/drawingarea.h> #include <gtkmm/drawingarea.h>
@ -67,7 +65,6 @@ public:
private: private:
void Build_Visual_Disk( int ) ; //i still dream of some fully resizeable visualdisk.... void Build_Visual_Disk( int ) ; //i still dream of some fully resizeable visualdisk....
void Build_Legend( ) ; void Build_Legend( ) ;
void Add_Legend_Item( const Glib::ustring & filesystem, const Gdk::Color & color );
//signal handlers //signal handlers
void drawingarea_on_realize( Visual_Partition * ); void drawingarea_on_realize( Visual_Partition * );
@ -90,7 +87,6 @@ private:
Glib::ustring str_temp ; Glib::ustring str_temp ;
int temp,selected_partition; int temp,selected_partition;
Gtk::Entry *entry_temp;
}; };
} //GParted } //GParted

View File

@ -95,7 +95,7 @@ void VBox_VisualDisk::Build_Visual_Disk( int SCREEN_WIDTH )
visual_partitions.back() ->length = 0 ; //keeps total_length clean visual_partitions.back() ->length = 0 ; //keeps total_length clean
eventbox_extended = manage( new Gtk::EventBox() ) ; eventbox_extended = manage( new Gtk::EventBox() ) ;
eventbox_extended ->set_size_request( -1 , 60 ); eventbox_extended ->set_size_request( -1, 60 );
eventbox_extended ->modify_bg( eventbox_extended ->get_state(), partitions[i].color ); eventbox_extended ->modify_bg( eventbox_extended ->get_state(), partitions[i].color );
hbox_disk ->pack_start( *eventbox_extended, Gtk::PACK_SHRINK ) ; hbox_disk ->pack_start( *eventbox_extended, Gtk::PACK_SHRINK ) ;
@ -111,7 +111,7 @@ void VBox_VisualDisk::Build_Visual_Disk( int SCREEN_WIDTH )
partitions[i] .type == GParted::UNALLOCATED ? visual_partitions.back() ->length = 15 : visual_partitions.back() ->length = 20 ; partitions[i] .type == GParted::UNALLOCATED ? visual_partitions.back() ->length = 15 : visual_partitions.back() ->length = 20 ;
if ( partitions[i].inside_extended ) if ( partitions[i].inside_extended )
{ visual_partitions.back() ->height = 34 ; visual_partitions.back() ->text_y = 10 ; } { visual_partitions.back() ->height = 34 ; visual_partitions.back() ->text_y = 9 ; }
else else
{ visual_partitions.back() ->height = 44 ;visual_partitions.back() ->text_y = 15 ; } { visual_partitions.back() ->height = 44 ;visual_partitions.back() ->text_y = 15 ; }
@ -121,11 +121,11 @@ void VBox_VisualDisk::Build_Visual_Disk( int SCREEN_WIDTH )
visual_partitions.back() ->used = (int) ( (visual_partitions.back() ->length - (BORDER *2)) / (double) ( ( partitions[i].sector_end - partitions[i].sector_start) / (double)partitions[i].sectors_used ) ) ; visual_partitions.back() ->used = (int) ( (visual_partitions.back() ->length - (BORDER *2)) / (double) ( ( partitions[i].sector_end - partitions[i].sector_start) / (double)partitions[i].sectors_used ) ) ;
visual_partitions.back() ->color_fs = partitions[i].color; visual_partitions.back() ->color_fs = partitions[i] .color;
this ->get_colormap() ->alloc_color(visual_partitions.back() ->color_fs); this ->get_colormap() ->alloc_color(visual_partitions.back() ->color_fs);
visual_partitions.back() ->drawingarea = manage( new Gtk::DrawingArea() ) ; visual_partitions.back() ->drawingarea = manage( new Gtk::DrawingArea() ) ;
visual_partitions.back() ->drawingarea ->set_size_request( visual_partitions.back() ->length+1 ,60 ); visual_partitions.back() ->drawingarea ->set_size_request( visual_partitions.back() ->length +1, 60 );
visual_partitions.back() ->drawingarea ->set_events(Gdk::BUTTON_PRESS_MASK); visual_partitions.back() ->drawingarea ->set_events(Gdk::BUTTON_PRESS_MASK);
//connect signal handlers //connect signal handlers
@ -168,30 +168,30 @@ void VBox_VisualDisk::Build_Legend( )
hbox_legend = manage( new Gtk::HBox() ); hbox_legend = manage( new Gtk::HBox() );
frame_disk_legend ->add( *hbox_legend ) ; frame_disk_legend ->add( *hbox_legend ) ;
this->pack_start( hbox_legend_main ); this ->pack_start( hbox_legend_main );
std::vector<Glib::ustring> legende; std::vector<Glib::ustring> legende;
bool legende_allow = true, only_unallocated = true; bool only_unallocated = true;
for ( unsigned int i=0;i<partitions.size();i++ ) for ( unsigned int i=0;i<partitions.size();i++ )
{ {
if ( partitions[i].type != GParted::UNALLOCATED && partitions[i].type != GParted::EXTENDED ) if ( partitions[i].type != GParted::UNALLOCATED && partitions[i].type != GParted::EXTENDED )
only_unallocated = false; only_unallocated = false;
//check if filesystem is already in legende if ( std::find( legende .begin(), legende .end(), partitions[i] .filesystem ) == legende .end() )
for ( unsigned int t=0;t<legende.size();t++) //not very nice, but very effective :P
if ( partitions[i].filesystem == legende[t] )
{ legende_allow = false; break; }
if ( legende_allow )
{ {
Add_Legend_Item( partitions[ i ] .filesystem + " " , partitions[ i ] .color ) ; if ( legende .size() )
hbox_legend ->pack_start( * mk_label( " " ), Gtk::PACK_SHRINK );
else
hbox_legend ->pack_start( * mk_label( " " ), Gtk::PACK_SHRINK );
//make sure this color isn't added to the legende again. hbox_legend ->pack_start( * mk_label( "██ ", false, false, false, partitions[i] .color_string ), Gtk::PACK_SHRINK );
legende.push_back( partitions[i].filesystem ); hbox_legend ->pack_start( * mk_label( partitions[i] .filesystem + " " ), Gtk::PACK_SHRINK );
//make sure this color isn't added to the legend again.
legende .push_back( partitions[i] .filesystem );
} }
legende_allow = true;
} }
//if there are any partitions add used/unused //if there are any partitions add used/unused
@ -203,25 +203,14 @@ void VBox_VisualDisk::Build_Legend( )
hbox_legend = manage( new Gtk::HBox() ); hbox_legend = manage( new Gtk::HBox() );
frame_disk_legend ->add( *hbox_legend ); frame_disk_legend ->add( *hbox_legend );
Add_Legend_Item( (Glib::ustring) _( "used" ) + " ", color_used ) ; hbox_legend ->pack_start( * mk_label( " ██ ", false, false, false, "#F8F8BA" ), Gtk::PACK_SHRINK );
Add_Legend_Item( (Glib::ustring) _( "unused") + " ", color_unused ) ; hbox_legend ->pack_start( * mk_label( "used " ), Gtk::PACK_SHRINK );
hbox_legend ->pack_start( * mk_label( "██ ", false, false, false, "white" ), Gtk::PACK_SHRINK );
hbox_legend ->pack_start( * mk_label( "unused " ), Gtk::PACK_SHRINK );
} }
} }
void VBox_VisualDisk::Add_Legend_Item( const Glib::ustring & filesystem, const Gdk::Color & color )
{
//the colored square
entry_temp = manage ( new Gtk::Entry() );
entry_temp ->set_sensitive( false );
entry_temp ->set_size_request( 15,15);
entry_temp ->modify_base( entry_temp->get_state(), color );
hbox_legend ->pack_start( *entry_temp, Gtk::PACK_SHRINK );
//and the label
hbox_legend ->pack_start( * mk_label( " " + filesystem, false, false ), Gtk::PACK_SHRINK );
}
void VBox_VisualDisk::Set_Selected( const Partition & partition ) void VBox_VisualDisk::Set_Selected( const Partition & partition )
{ {
//clean previously selected one //clean previously selected one
@ -235,7 +224,7 @@ void VBox_VisualDisk::Set_Selected( const Partition & partition )
return; //extended can not be selected in visualdisk (yet ) return; //extended can not be selected in visualdisk (yet )
//now set new selected one //now set new selected one
for ( unsigned int t=0;t< visual_partitions.size() ; t++ ) for ( unsigned int t = 0;t < visual_partitions.size() ; t++ )
{ {
if ( visual_partitions[t] ->sector_start == partition.sector_start && visual_partitions[t] ->drawingarea != NULL ) if ( visual_partitions[t] ->sector_start == partition.sector_start && visual_partitions[t] ->drawingarea != NULL )
{ {
@ -255,8 +244,8 @@ void VBox_VisualDisk::drawingarea_on_realize( Visual_Partition* vp )
vp ->drawingarea ->get_window() ->set_background( vp ->color_fs ); vp ->drawingarea ->get_window() ->set_background( vp ->color_fs );
//eventmasks necessary for tooltips //eventmasks necessary for tooltips
vp ->drawingarea ->add_events(Gdk::ENTER_NOTIFY_MASK ); vp ->drawingarea ->add_events( Gdk::ENTER_NOTIFY_MASK );
vp ->drawingarea ->add_events(Gdk::LEAVE_NOTIFY_MASK ); vp ->drawingarea ->add_events( Gdk::LEAVE_NOTIFY_MASK );
} }
@ -267,7 +256,7 @@ bool VBox_VisualDisk::drawingarea_on_expose( GdkEventExpose * ev, Visual_Partiti
if ( vp ->used != -1 ) //if not unknown or unallocated if ( vp ->used != -1 ) //if not unknown or unallocated
{ {
vp ->gc ->set_foreground( color_used ); vp ->gc ->set_foreground( color_used );
vp ->drawingarea ->get_window() ->draw_rectangle( vp ->gc, true, BORDER,BORDER,vp ->used , vp ->height ); vp ->drawingarea ->get_window() ->draw_rectangle( vp ->gc, true, BORDER,BORDER, vp ->used, vp ->height );
vp ->gc ->set_foreground( color_unused ); vp ->gc ->set_foreground( color_unused );
vp ->drawingarea ->get_window() ->draw_rectangle( vp ->gc, true, BORDER + vp ->used, BORDER, vp ->length - vp ->used - BORDER *2 , vp ->height ); vp ->drawingarea ->get_window() ->draw_rectangle( vp ->gc, true, BORDER + vp ->used, BORDER, vp ->length - vp ->used - BORDER *2 , vp ->height );
@ -296,7 +285,7 @@ VBox_VisualDisk::~VBox_VisualDisk()
{ {
for ( unsigned int t=0;t< visual_partitions.size() ; t++ ) for ( unsigned int t=0;t< visual_partitions.size() ; t++ )
{ {
this ->get_colormap() ->free_colors( visual_partitions[t] ->color_fs , 1 ) ; this ->get_colormap() ->free_colors( visual_partitions[t] ->color_fs, 1 ) ;
delete visual_partitions[t] ; delete visual_partitions[t] ;
} }