From c58c848684c4d1d58e59ca0d8112530bc451175c Mon Sep 17 00:00:00 2001 From: John Smith Date: Thu, 27 Sep 2012 11:58:05 +0900 Subject: Fix for 171177 : Border in palette swatches (bzr r11706) --- src/ui/previewholder.cpp | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'src/ui/previewholder.cpp') diff --git a/src/ui/previewholder.cpp b/src/ui/previewholder.cpp index e1c2c718a..0dac18665 100644 --- a/src/ui/previewholder.cpp +++ b/src/ui/previewholder.cpp @@ -12,6 +12,7 @@ #include "previewholder.h" +#include "preferences.h" #include #include @@ -38,7 +39,8 @@ PreviewHolder::PreviewHolder() : _baseSize(PREVIEW_SIZE_SMALL), _ratio(100), _view(VIEW_TYPE_LIST), - _wrap(false) + _wrap(false), + _border(BORDER_NONE) { _scroller = manage(new Gtk::ScrolledWindow()); _insides = manage(new Gtk::Table( 1, 2 )); @@ -77,13 +79,13 @@ 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)); - Gtk::Widget* thing = manage(preview->getPreview(PREVIEW_STYLE_PREVIEW, VIEW_TYPE_LIST, _baseSize, _ratio)); + 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)); + Gtk::Widget* thing = manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, VIEW_TYPE_GRID, _baseSize, _ratio, _border)); int width = 1; int height = 1; @@ -129,12 +131,13 @@ void PreviewHolder::thawUpdates() rebuildUI(); } -void PreviewHolder::setStyle( ::PreviewSize size, ViewType view, guint ratio ) +void PreviewHolder::setStyle( ::PreviewSize size, ViewType view, guint ratio, ::BorderStyle border ) { - if ( size != _baseSize || view != _view || ratio != _ratio ) { + if ( size != _baseSize || view != _view || ratio != _ratio || border != _border ) { _baseSize = size; _view = view; _ratio = ratio; + _border = border; // Kludge to restore scrollbars if ( !_wrap && (_view != VIEW_TYPE_LIST) && (_anchor == SP_ANCHOR_NORTH || _anchor == SP_ANCHOR_SOUTH) ) { dynamic_cast(_scroller)->set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_NEVER ); @@ -304,12 +307,15 @@ void PreviewHolder::rebuildUI() 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 ); + } for ( unsigned int i = 0; i < items.size(); i++ ) { - Gtk::Widget* label = manage(items[i]->getPreview(PREVIEW_STYLE_BLURB, _view, _baseSize, _ratio)); + Gtk::Widget* label = manage(items[i]->getPreview(PREVIEW_STYLE_BLURB, _view, _baseSize, _ratio, _border)); //label->set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER); - Gtk::Widget* thing = manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, _view, _baseSize, _ratio)); + Gtk::Widget* thing = manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, _view, _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 ); @@ -322,11 +328,18 @@ void PreviewHolder::rebuildUI() int height = 1; for ( unsigned int i = 0; i < items.size(); i++ ) { - Gtk::Widget* thing = manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, _view, _baseSize, _ratio)); + + // 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 ); _insides = manage(new Gtk::Table( height, width )); + if (_border == BORDER_WIDE) { + _insides->set_col_spacings( 1 ); + _insides->set_row_spacings( 1 ); + } } _insides->attach( *thing, col, col+1, row, row+1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND ); -- cgit v1.2.3 From e64e134d847ae7b741bf94839bd1b2c308984062 Mon Sep 17 00:00:00 2001 From: John Smith Date: Sun, 14 Oct 2012 17:00:27 +0900 Subject: Fix for 171221 : color panel improvements (bzr r11793) --- src/ui/previewholder.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/ui/previewholder.cpp') diff --git a/src/ui/previewholder.cpp b/src/ui/previewholder.cpp index 0dac18665..24049d2f9 100644 --- a/src/ui/previewholder.cpp +++ b/src/ui/previewholder.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #define COLUMNS_FOR_SMALL 16 #define COLUMNS_FOR_LARGE 8 @@ -56,9 +57,25 @@ PreviewHolder::PreviewHolder() : PreviewHolder::~PreviewHolder() { + } +bool PreviewHolder::on_scroll_event(GdkEventScroll *event) +{ + // Scroll horizontally by page on mouse wheel + Gtk::Adjustment *adj = dynamic_cast(_scroller)->get_hadjustment(); + if (!adj) { + return FALSE; + } + + int move = (event->direction == GDK_SCROLL_DOWN) ? adj->get_page_size() : -adj->get_page_size(); + double value = std::min(adj->get_upper() - move, adj->get_value() + move ); + + adj->set_value(value); + + return FALSE; +} void PreviewHolder::clear() { -- cgit v1.2.3 From 07c44d98ba749d6fc9cf5c7dd7a2f73220da5460 Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Sun, 14 Oct 2012 11:03:51 +0100 Subject: Fix build with new color palette features (bzr r11796) --- src/ui/previewholder.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/ui/previewholder.cpp') diff --git a/src/ui/previewholder.cpp b/src/ui/previewholder.cpp index 24049d2f9..0b280ccb9 100644 --- a/src/ui/previewholder.cpp +++ b/src/ui/previewholder.cpp @@ -63,7 +63,12 @@ PreviewHolder::~PreviewHolder() bool PreviewHolder::on_scroll_event(GdkEventScroll *event) { // Scroll horizontally by page on mouse wheel +#if WITH_GTKMM_3_0 + Glib::RefPtr adj = dynamic_cast(_scroller)->get_hadjustment(); +#else Gtk::Adjustment *adj = dynamic_cast(_scroller)->get_hadjustment(); +#endif + if (!adj) { return FALSE; } -- cgit v1.2.3 From 0c7f8357aeb104034b81e6bbb68231713c78ff1f Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Sat, 9 Mar 2013 13:24:32 +0000 Subject: Use Gtk::Grid in PreviewHolder. Fixes color preview in RegisteredColorPicker Fixed bugs: - https://launchpad.net/bugs/1094504 (bzr r12185) --- src/ui/previewholder.cpp | 270 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 197 insertions(+), 73 deletions(-) (limited to 'src/ui/previewholder.cpp') 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 #include +#if WITH_GTKMM_3_0 +# include +#else +# include +#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::vectorkids = _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 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::vectorkids = _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 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(); -- cgit v1.2.3