diff options
| author | Alex Valavanis <valavanisalex@gmail.com> | 2013-03-09 13:24:32 +0000 |
|---|---|---|
| committer | Alex Valavanis <valavanisalex@gmail.com> | 2013-03-09 13:24:32 +0000 |
| commit | 0c7f8357aeb104034b81e6bbb68231713c78ff1f (patch) | |
| tree | 599b6c2938e92ca5352ad76ea165c3fcc7d7e411 /src | |
| parent | Preparation to merge /dom/io and /io code (bug #1120585 ) (diff) | |
| download | inkscape-0c7f8357aeb104034b81e6bbb68231713c78ff1f.tar.gz inkscape-0c7f8357aeb104034b81e6bbb68231713c78ff1f.zip | |
Use Gtk::Grid in PreviewHolder. Fixes color preview in RegisteredColorPicker
Fixed bugs:
- https://launchpad.net/bugs/1094504
(bzr r12185)
Diffstat (limited to 'src')
| -rw-r--r-- | src/ui/dialog/swatches.cpp | 3 | ||||
| -rw-r--r-- | src/ui/previewholder.cpp | 270 | ||||
| -rw-r--r-- | src/ui/previewholder.h | 19 | ||||
| -rw-r--r-- | src/ui/widget/selected-style.cpp | 27 | ||||
| -rw-r--r-- | src/ui/widget/selected-style.h | 16 | ||||
| -rw-r--r-- | src/widgets/desktop-widget.cpp | 5 |
6 files changed, 261 insertions, 79 deletions
diff --git a/src/ui/dialog/swatches.cpp b/src/ui/dialog/swatches.cpp index 71fee342a..90cb1cdc9 100644 --- a/src/ui/dialog/swatches.cpp +++ b/src/ui/dialog/swatches.cpp @@ -1179,9 +1179,6 @@ void SwatchesPanel::_rebuild() _holder->thawUpdates(); } - - - } //namespace Dialogs } //namespace UI } //namespace Inkscape diff --git a/src/ui/previewholder.cpp b/src/ui/previewholder.cpp index 0b280ccb9..b5a1a29a8 100644 --- a/src/ui/previewholder.cpp +++ b/src/ui/previewholder.cpp @@ -19,6 +19,12 @@ #include <gtkmm/scrollbar.h> #include <gtkmm/adjustment.h> +#if WITH_GTKMM_3_0 +# include <gtkmm/grid.h> +#else +# include <gtkmm/table.h> +#endif + #define COLUMNS_FOR_SMALL 16 #define COLUMNS_FOR_LARGE 8 //#define COLUMNS_FOR_SMALL 48 @@ -44,13 +50,31 @@ PreviewHolder::PreviewHolder() : _border(BORDER_NONE) { _scroller = manage(new Gtk::ScrolledWindow()); + +#if WITH_GTKMM_3_0 + _insides = manage(new Gtk::Grid()); + _insides->set_column_spacing(8); + + // Add a container with the scroller and a spacer + Gtk::Grid* spaceHolder = manage(new Gtk::Grid()); + + _scroller->set_hexpand(); + _scroller->set_vexpand(); +#else _insides = manage(new Gtk::Table( 1, 2 )); _insides->set_col_spacings( 8 ); - + // Add a container with the scroller and a spacer Gtk::Table* spaceHolder = manage( new Gtk::Table(1, 2) ); +#endif + _scroller->add( *_insides ); + +#if WITH_GTKMM_3_0 + spaceHolder->attach( *_scroller, 0, 0, 1, 1); +#else spaceHolder->attach( *_scroller, 0, 1, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND ); +#endif pack_start(*spaceHolder, Gtk::PACK_EXPAND_WIDGET); } @@ -93,6 +117,11 @@ void PreviewHolder::clear() rebuildUI(); } +/** + * Add a Previewable item to the PreviewHolder + * + * \param[in] preview The Previewable item to add + */ void PreviewHolder::addPreview( Previewable* preview ) { items.push_back(preview); @@ -100,41 +129,78 @@ void PreviewHolder::addPreview( Previewable* preview ) { int i = items.size() - 1; - if ( _view == VIEW_TYPE_LIST ) { - Gtk::Widget* label = manage(preview->getPreview(PREVIEW_STYLE_BLURB, VIEW_TYPE_LIST, _baseSize, _ratio, _border)); - Gtk::Widget* thing = manage(preview->getPreview(PREVIEW_STYLE_PREVIEW, VIEW_TYPE_LIST, _baseSize, _ratio, _border)); + switch(_view) { + case VIEW_TYPE_LIST: + { + Gtk::Widget* label = manage(preview->getPreview(PREVIEW_STYLE_BLURB, VIEW_TYPE_LIST, _baseSize, _ratio, _border)); + Gtk::Widget* thing = manage(preview->getPreview(PREVIEW_STYLE_PREVIEW, VIEW_TYPE_LIST, _baseSize, _ratio, _border)); - _insides->attach( *thing, 0, 1, i, i+1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND ); - _insides->attach( *label, 1, 2, i, i+1, Gtk::FILL|Gtk::EXPAND, Gtk::SHRINK ); - } else { - Gtk::Widget* thing = manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, VIEW_TYPE_GRID, _baseSize, _ratio, _border)); - - int width = 1; - int height = 1; - calcGridSize( thing, items.size(), width, height ); - int col = i % width; - int row = i / width; - - if ( _insides && width > (int)_insides->property_n_columns() ) { - std::vector<Gtk::Widget*>kids = _insides->get_children(); - int oldWidth = (int)_insides->property_n_columns(); - int childCount = (int)kids.size(); -// g_message(" %3d resize from %d to %d (r:%d, c:%d) with %d children", i, oldWidth, width, row, col, childCount ); - _insides->resize( height, width ); - - for ( int j = oldWidth; j < childCount; j++ ) { - Gtk::Widget* target = kids[childCount - (j + 1)]; - int col2 = j % width; - int row2 = j / width; - Glib::RefPtr<Gtk::Widget> handle(target); - _insides->remove( *target ); - _insides->attach( *target, col2, col2+1, row2, row2+1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND ); +#if WITH_GTKMM_3_0 + thing->set_hexpand(); + thing->set_vexpand(); + _insides->attach(*thing, 0, i, 1, 1); + + label->set_hexpand(); + label->set_valign(Gtk::ALIGN_CENTER); + _insides->attach(*label, 1, i, 1, 1); +#else + _insides->attach( *thing, 0, 1, i, i+1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND ); + _insides->attach( *label, 1, 2, i, i+1, Gtk::FILL|Gtk::EXPAND, Gtk::SHRINK ); +#endif + } + + break; + case VIEW_TYPE_GRID: + { + Gtk::Widget* thing = manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, VIEW_TYPE_GRID, _baseSize, _ratio, _border)); + + int width = 1; + int height = 1; + calcGridSize( thing, items.size(), width, height ); + + // Column and row for the new widget + int col = i % width; + int row = i / width; + +#if !WITH_GTKMM_3_0 + // If the existing grid isn't wide enough, we need to resize + // it and re-pack the existing widgets + if ( _insides && width > (int)_insides->property_n_columns() ) { + _insides->resize( height, width ); +#endif + std::vector<Gtk::Widget*>kids = _insides->get_children(); + int childCount = (int)kids.size(); + // g_message(" %3d resize from %d to %d (r:%d, c:%d) with %d children", i, oldWidth, width, row, col, childCount ); + + // Loop through the existing widgets and move them to new location + for ( int j = 1; j < childCount; j++ ) { + Gtk::Widget* target = kids[childCount - (j + 1)]; + int col2 = j % width; + int row2 = j / width; + Glib::RefPtr<Gtk::Widget> handle(target); + _insides->remove( *target ); + +#if WITH_GTKMM_3_0 + target->set_hexpand(); + target->set_vexpand(); + _insides->attach( *target, col2, row2, 1, 1); +#else + _insides->attach( *target, col2, col2+1, row2, row2+1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND ); +#endif + } +#if WITH_GTKMM_3_0 + thing->set_hexpand(); + thing->set_vexpand(); + _insides->attach(*thing, col, row, 1, 1); +#else + } else if ( col == 0 ) { + // we just started a new row + _insides->resize( row + 1, width ); + } + + _insides->attach( *thing, col, col+1, row, row+1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND ); +#endif } - } else if ( col == 0 ) { - // we just started a new row - _insides->resize( row + 1, width ); - } - _insides->attach( *thing, col, col+1, row, row+1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND ); } _scroller->show_all_children(); @@ -258,8 +324,17 @@ void PreviewHolder::on_size_allocate( Gtk::Allocation& allocation ) // g_message(" items:%d", (int)items.size()); //} +/** + * Calculate the grid side of a preview holder + * + * \param[in] thing + * \param[in] itemCount The number of items to pack into the grid + * \param[out] width The width of the grid + * \param[out] height The height of the grid + */ void PreviewHolder::calcGridSize( const Gtk::Widget* thing, int itemCount, int& width, int& height ) { + // Initially set all items in a horizontal row width = itemCount; height = 1; @@ -326,55 +401,104 @@ void PreviewHolder::rebuildUI() _scroller->remove(); _insides = 0; // remove() call should have deleted the Gtk::Table. - if ( _view == VIEW_TYPE_LIST ) { - _insides = manage(new Gtk::Table( 1, 2 )); - _insides->set_col_spacings( 8 ); - if (_border == BORDER_WIDE) { - _insides->set_row_spacings( 1 ); - } + switch(_view) { + case VIEW_TYPE_LIST: + { - for ( unsigned int i = 0; i < items.size(); i++ ) { - Gtk::Widget* label = manage(items[i]->getPreview(PREVIEW_STYLE_BLURB, _view, _baseSize, _ratio, _border)); - //label->set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER); +#if WITH_GTKMM_3_0 + _insides = manage(new Gtk::Grid()); + _insides->set_column_spacing(8); +#else + _insides = manage(new Gtk::Table( 1, 2 )); + _insides->set_col_spacings( 8 ); +#endif - Gtk::Widget* thing = manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, _view, _baseSize, _ratio, _border)); + if (_border == BORDER_WIDE) { +#if WITH_GTKMM_3_0 + _insides->set_row_spacing(1); +#else + _insides->set_row_spacings( 1 ); +#endif + } - _insides->attach( *thing, 0, 1, i, i+1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND ); - _insides->attach( *label, 1, 2, i, i+1, Gtk::FILL|Gtk::EXPAND, Gtk::SHRINK ); - } - _scroller->add( *_insides ); - } else { - int col = 0; - int row = 0; - int width = 2; - int height = 1; + for ( unsigned int i = 0; i < items.size(); i++ ) { + Gtk::Widget* label = manage(items[i]->getPreview(PREVIEW_STYLE_BLURB, _view, _baseSize, _ratio, _border)); + //label->set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER); - for ( unsigned int i = 0; i < items.size(); i++ ) { + Gtk::Widget* thing = manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, _view, _baseSize, _ratio, _border)); - // If this is the last row, flag so the previews can draw a bottom - ::BorderStyle border = ((row == height -1) && (_border == BORDER_SOLID)) ? BORDER_SOLID_LAST_ROW : _border; - Gtk::Widget* thing = manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, _view, _baseSize, _ratio, border)); +#if WITH_GTKMM_3_0 + thing->set_hexpand(); + thing->set_vexpand(); + _insides->attach(*thing, 0, i, 1, 1); - if ( !_insides ) { - calcGridSize( thing, items.size(), width, height ); - _insides = manage(new Gtk::Table( height, width )); - if (_border == BORDER_WIDE) { - _insides->set_col_spacings( 1 ); - _insides->set_row_spacings( 1 ); + label->set_hexpand(); + label->set_valign(Gtk::ALIGN_CENTER); + _insides->attach(*label, 1, i, 1, 1); +#else + _insides->attach( *thing, 0, 1, i, i+1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND ); + _insides->attach( *label, 1, 2, i, i+1, Gtk::FILL|Gtk::EXPAND, Gtk::SHRINK ); +#endif } - } - _insides->attach( *thing, col, col+1, row, row+1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND ); - if ( ++col >= width ) { - col = 0; - row++; + _scroller->add( *_insides ); } - } - if ( !_insides ) { - _insides = manage(new Gtk::Table( 1, 2 )); - } + break; - _scroller->add( *_insides ); + case VIEW_TYPE_GRID: + { + int col = 0; + int row = 0; + int width = 2; + int height = 1; + + for ( unsigned int i = 0; i < items.size(); i++ ) { + + // If this is the last row, flag so the previews can draw a bottom + ::BorderStyle border = ((row == height -1) && (_border == BORDER_SOLID)) ? BORDER_SOLID_LAST_ROW : _border; + Gtk::Widget* thing = manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, _view, _baseSize, _ratio, border)); + + if ( !_insides ) { + calcGridSize( thing, items.size(), width, height ); + +#if WITH_GTKMM_3_0 + _insides = manage(new Gtk::Grid()); + if (_border == BORDER_WIDE) { + _insides->set_column_spacing(1); + _insides->set_row_spacing(1); + } +#else + _insides = manage(new Gtk::Table( height, width )); + if (_border == BORDER_WIDE) { + _insides->set_col_spacings( 1 ); + _insides->set_row_spacings( 1 ); + } +#endif + } + +#if WITH_GTKMM_3_0 + thing->set_hexpand(); + thing->set_vexpand(); + _insides->attach( *thing, col, row, 1, 1); +#else + _insides->attach( *thing, col, col+1, row, row+1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND ); +#endif + + if ( ++col >= width ) { + col = 0; + row++; + } + } + if ( !_insides ) { +#if WITH_GTKMM_3_0 + _insides = manage(new Gtk::Grid()); +#else + _insides = manage(new Gtk::Table( 1, 2 )); +#endif + } + + _scroller->add( *_insides ); + } } _scroller->show_all_children(); diff --git a/src/ui/previewholder.h b/src/ui/previewholder.h index 4c591bfaf..f6d1985cc 100644 --- a/src/ui/previewholder.h +++ b/src/ui/previewholder.h @@ -12,10 +12,21 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#if HAVE_CONFIG_H +# include "config.h" +#endif #include <gtkmm/box.h> #include <gtkmm/bin.h> -#include <gtkmm/table.h> + +namespace Gtk { +#if WITH_GTKMM_3_0 +class Grid; +#else +class Table; +#endif +} + #include "previewfillable.h" #include "../widgets/eek-preview.h" #include "enums.h" @@ -56,7 +67,13 @@ private: std::vector<Previewable*> items; Gtk::Bin *_scroller; + +#if WITH_GTKMM_3_0 + Gtk::Grid *_insides; +#else Gtk::Table *_insides; +#endif + int _prefCols; bool _updatesFrozen; SPAnchorType _anchor; diff --git a/src/ui/widget/selected-style.cpp b/src/ui/widget/selected-style.cpp index 41d7c8be2..18dbb984b 100644 --- a/src/ui/widget/selected-style.cpp +++ b/src/ui/widget/selected-style.cpp @@ -119,8 +119,11 @@ SelectedStyle::SelectedStyle(bool /*layout*/) current_stroke_width(0), _desktop (NULL), - +#if WITH_GTKMM_3_0 + _table(), +#else _table(2, 6), +#endif _fill_label (_("Fill:")), _stroke_label (_("Stroke:")), _opacity_label (_("O:")), @@ -158,8 +161,13 @@ SelectedStyle::SelectedStyle(bool /*layout*/) _opacity_label.set_alignment(0.0, 0.5); _opacity_label.set_padding(0, 0); +#if WITH_GTKMM_3_0 + _table.set_column_spacing(2); + _table.set_row_spacing(0); +#else _table.set_col_spacings (2); _table.set_row_spacings (0); +#endif for (int i = SS_FILL; i <= SS_STROKE; i++) { @@ -361,6 +369,16 @@ SelectedStyle::SelectedStyle(bool /*layout*/) _opacity_sb.set_size_request (SELECTED_STYLE_SB_WIDTH, -1); _opacity_sb.set_sensitive (false); +#if WITH_GTKMM_3_0 + _table.attach(_fill_label, 0, 0, 1, 1); + _table.attach(_stroke_label, 0, 1, 1, 1); + + _table.attach(_fill_flag_place, 1, 0, 1, 1); + _table.attach(_stroke_flag_place, 1, 1, 1, 1); + + _table.attach(_fill_place, 2, 0, 1, 1); + _table.attach(_stroke, 2, 1, 1, 1); +#else _table.attach(_fill_label, 0,1, 0,1, Gtk::FILL, Gtk::SHRINK); _table.attach(_stroke_label, 0,1, 1,2, Gtk::FILL, Gtk::SHRINK); @@ -369,10 +387,17 @@ SelectedStyle::SelectedStyle(bool /*layout*/) _table.attach(_fill_place, 2,3, 0,1); _table.attach(_stroke, 2,3, 1,2); +#endif _opacity_place.add(_opacity_label); + +#if WITH_GTKMM_3_0 + _table.attach(_opacity_place, 4, 0, 1, 2); + _table.attach(_opacity_sb, 5, 0, 1, 2); +#else _table.attach(_opacity_place, 4,5, 0,2, Gtk::SHRINK, Gtk::SHRINK); _table.attach(_opacity_sb, 5,6, 0,2, Gtk::SHRINK, Gtk::SHRINK); +#endif pack_start(_table, true, true, 2); diff --git a/src/ui/widget/selected-style.h b/src/ui/widget/selected-style.h index fac4f22e6..6d5222429 100644 --- a/src/ui/widget/selected-style.h +++ b/src/ui/widget/selected-style.h @@ -11,8 +11,18 @@ #ifndef INKSCAPE_UI_CURRENT_STYLE_H #define INKSCAPE_UI_CURRENT_STYLE_H +#if HAVE_CONFIG_H +# include "config.h" +#endif + #include <gtkmm/box.h> -#include <gtkmm/table.h> + +#if WITH_GTKMM_3_0 +# include <gtkmm/grid.h> +#else +# include <gtkmm/table.h> +#endif + #include <gtkmm/label.h> #include <gtkmm/eventbox.h> #include <gtkmm/enums.h> @@ -127,7 +137,11 @@ public: protected: SPDesktop *_desktop; +#if WITH_GTKMM_3_0 + Gtk::Grid _table; +#else Gtk::Table _table; +#endif Gtk::Label _fill_label; Gtk::Label _stroke_label; diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index b0d8d974e..4af7c0795 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -357,6 +357,11 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) dtw->panels = new SwatchesPanel("/embedded/swatches"); dtw->panels->setOrientation(SP_ANCHOR_SOUTH); + +#if GTK_CHECK_VERSION(3,0,0) + dtw->panels->set_vexpand(false); +#endif + gtk_box_pack_end( GTK_BOX( dtw->vbox ), GTK_WIDGET(dtw->panels->gobj()), FALSE, TRUE, 0 ); } |
