Use gallery to display multiple images in Ubuntu scope

Source: Internet
Author: User

In this article, we'll show you how to use gallery Previewwidget to display multiple images in scope preview. More about previewwidget types can be found in the API.


First, let's download the Scopetemplate routine we talked about in our last lesson:


git clone https://gitcafe.com/ubuntu/scopetemplates_video.git


To be able to display multiple images, we have made the following changes to our program:


Query.cpp
  Add an array to show the gallary of it    Sc::variantarray arr;    for (const auto &datum:icons_) {        arr.push_back (Variant (datum.tostdstring ()));    }    r["array"] = Sc::variant (arr);

Here, we press our local image into a variantarray and write it into the "array" field.

Preview.cpp
    Result result = Previewquerybase::result ();    Previewwidget Listen ("tracks", "Audio");        {Variantbuilder Builder; Builder.add_tuple ({{"title", Variant ("This is the song title")}, {"Source", Variant (result["MUSICSO        Urce "].get_string (). C_STR ())});    Listen.add_attribute_value ("Tracks", Builder.end ());    } previewwidget Video ("Videos", "video");    Video.add_attribute_value ("Source", Variant (result["VideoSource"].get_string (). C_STR ()));    Video.add_attribute_value ("screenshot", Variant (result["screenshot"].get_string (). C_STR ()));    SC::P reviewwidget header_gal ("Gallery_header", "header");    Header_gal.add_attribute_value ("title", Variant ("Gallery files are:"));    Previewwidget Gallery ("Gallerys", "Gallery");    Gallery.add_attribute_value ("Sources", Variant (result["Array"]));    Previewwidgetlist Widgets ({image, header, description}); if (result["Musicsource"].get_string (). Length ()! = 0) {Widgets.emplace_back (Listen);    } if (result["VideoSource"].get_string (). Length ()! = 0) {widgets.emplace_back (video);        } if (result["array"].get_array (). Size ()! = 0) {widgets.emplace_back (Header_gal);    Widgets.emplace_back (gallery); } reply->push (widgets);

Here, we create a new header called Header_gal. It is used to cue a header to us, and we use it directly:
    Previewwidget Gallery ("Gallerys", "Gallery");    Gallery.add_attribute_value ("Sources", Variant (result["Array"]));

Or
    Previewwidget Gallery ("Gallerys", "Gallery");    Gallery.add_attribute_mapping ("Sources", "array");

Map the contents of the array field to sources so that the gallery can be displayed correctly:
To run our scope:


The source code for the entire project is: Git clone https://gitcafe.com/ubuntu/scopetemplates_gallery.git

Use gallery to display multiple images in Ubuntu scope

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.