From 625c4435399d3b80902b9cdbd2be3071ca527f77 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sun, 29 Oct 2017 11:18:24 +0100 Subject: Add overlay widgets --- src/ui/dialog/symbols.cpp | 197 +++++++++++++++++++++++++++++++++++++--------- src/ui/dialog/symbols.h | 12 ++- 2 files changed, 167 insertions(+), 42 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index e0aa4cb23..ec1345257 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -108,7 +108,6 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : preview_document(0), instanceConns() { - /******************** Table *************************/ table = new Gtk::Grid(); table->set_margin_left(3); @@ -155,9 +154,10 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : search->set_margin_bottom(6); search->signal_search_changed().connect(sigc::mem_fun(*this, &SymbolsDialog::clearSearch)); table->attach(*Gtk::manage(search),0,row,2,1); + search_str = ""; ++row; - + /********************* Icon View **************************/ SymbolColumns* columns = getColumns(); @@ -192,7 +192,7 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : overlay->set_vexpand(); overlay->add(* scroller); table->attach(*Gtk::manage(overlay),0,row,2,1); - + ++row; /******************** Progress *******************************/ @@ -305,20 +305,47 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : ++row; - /**********************************************************/ sensitive = true; - search_str = ""; + current_desktop = SP_ACTIVE_DESKTOP; current_document = current_desktop->getDocument(); - preview_document = symbolsPreviewDoc(); /* Template to render symbols in */ preview_document->ensureUpToDate(); /* Necessary? */ - key = SPItem::display_key_new(1); renderDrawing.setRoot(preview_document->getRoot()->invoke_show(renderDrawing, key, SP_ITEM_SHOW_DISPLAY )); // This might need to be a global variable so setTargetDesktop can modify it SPDefs *defs = current_document->getDefs(); + + /*************************Overlays******************************/ + //Loading + overlay_opacity = new Gtk::Image(getStockPixbuf("overlay", 1000)); + overlay_opacity->set_halign(Gtk::ALIGN_START ); + overlay_opacity->set_valign(Gtk::ALIGN_START ); + //No results + noresults_icon = getStockPixbuf("noresults", 90); + search_icon = getStockPixbuf("search", 90); + overlay_icon = new Gtk::Image(noresults_icon); + overlay_icon->set_halign(Gtk::ALIGN_CENTER ); + overlay_icon->set_valign(Gtk::ALIGN_START ); + overlay_icon->set_margin_top(45); + overlay_title = new Gtk::Label(); + overlay_title->set_halign(Gtk::ALIGN_CENTER ); + overlay_title->set_valign(Gtk::ALIGN_START ); + overlay_title->set_justify(Gtk::JUSTIFY_CENTER); + overlay_title->set_margin_top(155); + overlay_title->set_markup(Glib::ustring("") + Glib::ustring(_("No results found")) + Glib::ustring("")); + overlay_desc = new Gtk::Label(); + overlay_desc->set_halign(Gtk::ALIGN_CENTER ); + overlay_desc->set_valign(Gtk::ALIGN_START ); + overlay_desc->set_margin_top(180); + overlay_desc->set_justify(Gtk::JUSTIFY_CENTER); + overlay_desc->set_markup(Glib::ustring("") + Glib::ustring(_("Try a another search or select other set")) + Glib::ustring("")); + overlay->add_overlay(* overlay_opacity); + overlay->add_overlay(* overlay_icon); + overlay->add_overlay(* overlay_title); + overlay->add_overlay(* overlay_desc); + sigc::connection defsModifiedConn = defs->connectModified(sigc::mem_fun(*this, &SymbolsDialog::defsModified)); instanceConns.push_back(defsModifiedConn); @@ -796,7 +823,9 @@ SymbolsDialog::symbolsInDoc( SPDocument* symbol_document, Glib::ustring doc_titl { std::vector > l; - symbolsInDocRecursive (symbol_document->getRoot(), l , doc_title); + if (symbol_document) { + symbolsInDocRecursive (symbol_document->getRoot(), l , doc_title); + } return l; } @@ -893,9 +922,42 @@ void SymbolsDialog::unsensitive(GdkEventKey* evt) bool SymbolsDialog::callbackSymbols(){ Glib::ustring current = symbol_set->get_active_text(); + if (current == _("All symbols sets") && + search->get_text() != _("Loading documents...")) + { + if (!all_docs_processed) { + overlay_opacity->show(); + overlay_icon->set(noresults_icon); + overlay_icon->show(); + overlay_title->show(); + overlay_desc->show(); + overlay_title->set_markup(Glib::ustring("") + Glib::ustring(_("Search over all symbols sets")) + Glib::ustring("")); + overlay_desc->set_markup(Glib::ustring("") + Glib::ustring(_("This process is slow first time.\nFuture searches dont need this process.\nKeep waiting!")) + Glib::ustring("")); + } + } + if (current == _("Current Document") && !icons_found) { + if (!all_docs_processed) { + overlay_icon->set(noresults_icon); + overlay_opacity->show(); + overlay_icon->show(); + overlay_title->show(); + overlay_desc->show(); + overlay_title->set_markup(Glib::ustring("") + Glib::ustring(_("No icons in current document")) + Glib::ustring("")); + overlay_desc->set_markup(Glib::ustring("") + Glib::ustring(_("You can fill me if you want\nUse add and remove buttons.\nOr drag symbols from other sets")) + Glib::ustring("")); + } + } if (current == _("All symbols sets") && search->get_text() == _("Loading documents...") ) { + overlay_opacity->show(); + if (!all_docs_processed) { + overlay_title->set_markup(Glib::ustring("") + Glib::ustring(_("Processing all symbols sets")) + Glib::ustring("")); + overlay_desc->set_markup(Glib::ustring("") + Glib::ustring(_("This process is slow first time.\nFuture searches dont need this process.\nKeep waiting!")) + Glib::ustring("")); + overlay_icon->show(); + overlay_title->show(); + overlay_icon->set(search_icon); + overlay_desc->show(); + } size_t counter = 0; for(auto const &symbol_document_map : symbol_sets) { ++counter; @@ -911,12 +973,16 @@ bool SymbolsDialog::callbackSymbols(){ progress_bar->set_fraction(((100.0/number_docs) * counter)/100.0); return true; } + overlay_icon->hide(); + overlay_title->hide(); + overlay_desc->hide(); progress_bar->set_fraction(1.0); all_docs_processed = true; addSymbols(); search->set_text("Documents done, searchig inside..."); return true; } else if (l.size()) { + overlay_opacity->show(); for (auto symbol_data = l.begin(); symbol_data != l.end();) { Glib::ustring doc_title = symbol_data->first; SPSymbol * symbol = symbol_data->second; @@ -952,20 +1018,17 @@ bool SymbolsDialog::callbackSymbols(){ } } if (!icons_found && !search_str.empty()) { - Gtk::Image* no_results_icon = new Gtk::Image(getSearchPixbuf()); - no_results_icon->set_halign(Gtk::ALIGN_CENTER ); - no_results_icon->set_valign(Gtk::ALIGN_CENTER ); - Gtk::Label* no_results = new Gtk::Label(); - no_results->set_halign(Gtk::ALIGN_CENTER ); - no_results->set_valign(Gtk::ALIGN_CENTER ); - no_results->set_markup(Glib::ustring("") + Glib::ustring(_("No results found")) + Glib::ustring("")); - Gtk::Label* different = new Gtk::Label(); - different->set_halign(Gtk::ALIGN_CENTER ); - different->set_valign(Gtk::ALIGN_CENTER ); - different->set_markup(Glib::ustring("") + Glib::ustring(_("Try a different search")) + Glib::ustring("")); - overlay->add_overlay(* no_results_icon); - overlay->add_overlay(* no_results); - overlay->add_overlay(* different); + overlay_title->set_markup(Glib::ustring("") + Glib::ustring(_("No results found")) + Glib::ustring("")); + overlay_desc->set_markup(Glib::ustring("") + Glib::ustring(_("Try a another search or select other set")) + Glib::ustring("")); + overlay_icon->set(noresults_icon); + overlay_icon->show(); + overlay_title->show(); + overlay_desc->show(); + } else { + overlay_opacity->hide(); + overlay_icon->hide(); + overlay_title->hide(); + overlay_desc->hide(); } sensitive = false; search->set_text(search_str); @@ -995,6 +1058,16 @@ void SymbolsDialog::addSymbolsInDoc(SPDocument* symbol_document) { number_symbols = container_symbols_tmp.size(); l = container_symbols_tmp; container_symbols_tmp.clear(); + if (!number_symbols) { + overlay_icon->set(noresults_icon); + overlay_icon->show(); + overlay_title->show(); + overlay_desc->show(); + sensitive = false; + search->set_text(search_str); + sensitive = true; + enableWidgets(true); + } } void SymbolsDialog::addSymbols() { @@ -1016,6 +1089,16 @@ void SymbolsDialog::addSymbols() { number_symbols = container_symbols.size(); l = container_symbols; container_symbols.clear(); + if (!number_symbols) { + overlay_icon->set(noresults_icon); + overlay_icon->show(); + overlay_title->show(); + overlay_desc->show(); + sensitive = false; + search->set_text(search_str); + sensitive = true; + enableWidgets(true); + } } void SymbolsDialog::addSymbol( SPObject* symbol, Glib::ustring doc_title) { @@ -1055,7 +1138,7 @@ void SymbolsDialog::addSymbol( SPObject* symbol, Glib::ustring doc_title) { * the temporary document is rendered. */ Glib::RefPtr -SymbolsDialog::drawSymbol(SPObject *symbol) +SymbolsDialog::drawSymbol(SPObject *symbol, unsigned force_psize) { // Create a copy repr of the symbol with id="the_symbol" Inkscape::XML::Document *xml_doc = preview_document->getReprDoc(); @@ -1128,12 +1211,16 @@ SymbolsDialog::drawSymbol(SPObject *symbol) if( width == 0.0 ) width = 1.0; if( height == 0.0 ) height = 1.0; - if( fit_symbol->get_active() ) { - scale = psize / ceil(std::max(width, height)); - } + if( fit_symbol->get_active() ) + scale = psize / ceil(std::max(width, height)); else scale = pow( 2.0, scale_factor/2.0 ) * psize / 32.0; + if (force_psize > 0) { + psize = force_psize; + scale = psize / ceil(std::max(width, height)); + } + pixbuf = Glib::wrap(render_pixbuf(renderDrawing, scale, *dbox, psize)); } @@ -1165,32 +1252,64 @@ SPDocument* SymbolsDialog::symbolsPreviewDoc() * Return search symbol pixbuf */ Glib::RefPtr -SymbolsDialog::getSearchPixbuf() +SymbolsDialog::getStockPixbuf(gchar const * symbol_title, unsigned psize) { - // BUG: must be inside gchar const *buffer = "" +" Inkscape " " " " " +" id=\"search\">" " Search Taiga Icon" +" id=\"search_title\">Search" +" From Taiga Icon Set" " " +" style=\"fill:#dddddd;stroke:none\"" +" d=\"m 296.87191,139.51013 c -42.96864,0 -77.93812,28.58932 -77.93812,63.7203 0,35.13101 34.96894,63.72102 77.93812,63.72102 18.73068,0 35.93889,-5.43504 49.39552,-14.4736 l 50.71196,41.46091 8.86813,-7.2504 -50.55612,-41.33356 c 12.13855,-11.23867 19.51775,-25.99037 19.51775,-42.12437 0,-35.13098 -34.96854,-63.7203 -77.93724,-63.7203 z m 0,10.25413 c 36.19119,0 65.3962,23.87692 65.3962,53.46617 0,29.58969 -29.20519,53.46706 -65.3962,53.46706 -36.19149,0 -65.39616,-23.87737 -65.39616,-53.46706 0,-29.58939 29.20467,-53.46685 65.39616,-53.46685 z\"" +" id=\"search_shape_1\" />" +" " +" " +" Overlay" +" Overlay Square" +" " +" " +" " +" No Results" +" No results" +" " " " " " ""; SPDocument* doc = SPDocument::createNewDocFromMem( buffer, strlen(buffer), FALSE ); - std::vector > l = symbolsInDoc(doc, "Search Taiga Icon"); - int prev_scale_factor = scale_factor; - scale_factor = 10; - Glib::RefPtr pb = drawSymbol(l[0].second); - scale_factor = prev_scale_factor; - return pb; + std::vector > symbols_data = symbolsInDoc(doc, "Search Taiga Icon"); + Glib::RefPtr pixbuf(NULL); + for(auto data:symbols_data) { + Glib::ustring doc_title = data.first; + SPSymbol * symbol = data.second; + if (!strcmp(symbol->getId(),symbol_title)) { + pixbuf = drawSymbol(symbol, psize); + return pixbuf; + } + } + //Fallback if errors + return pixbuf; } void SymbolsDialog::setTargetDesktop(SPDesktop *desktop) diff --git a/src/ui/dialog/symbols.h b/src/ui/dialog/symbols.h index a77a265b5..3a007aba8 100644 --- a/src/ui/dialog/symbols.h +++ b/src/ui/dialog/symbols.h @@ -99,12 +99,14 @@ private: void enableWidgets(bool enable); Glib::ustring ellipsize(Glib::ustring data, size_t limit = 40); gchar const* styleFromUse( gchar const* id, SPDocument* document); - Glib::RefPtr drawSymbol(SPObject *symbol); - Glib::RefPtr getSearchPixbuf(); + Glib::RefPtr drawSymbol(SPObject *symbol, unsigned force_psize = 0); + Glib::RefPtr getStockPixbuf(gchar const * symbol_title, unsigned psize); /* Keep track of all symbol template documents */ std::map symbol_sets; std::vector > l; // Index into sizes which is selected + Glib::RefPtr noresults_icon; + Glib::RefPtr search_icon; int pack_size; // Scale factor int scale_factor; @@ -128,10 +130,14 @@ private: Gtk::Button* more; Gtk::Button* fewer; Gtk::HBox* tools; + Gtk::Overlay* overlay; + Gtk::Image* overlay_icon; + Gtk::Image* overlay_opacity; + Gtk::Label* overlay_title; + Gtk::Label* overlay_desc; Gtk::Grid* table; Gtk::ScrolledWindow *scroller; Gtk::ToggleButton* fit_symbol; - Gtk::Overlay* overlay; void setTargetDesktop(SPDesktop *desktop); SPDesktop* current_desktop; -- cgit v1.2.3