//添加槽 void HomePage::addSlot() { //获取图片 /* QStringList Stringlist = QFileDialog::getOpenFileNames(this,"Open file",QDir::currentPath(),tr("(*.png)")); if (Stringlist.size() == 0) { return; } */ //PItemData->BGKImage = Stringlist.at(i); PItemData->BGKImage = ":/image/2.png"; PItemData->ID = 0; emit sendUrl(*PItemData); QStandardItem *Item = new QStandardItem; Item->setSizeHint(QSize(60,60)); //设置Item大小为了美观 QVariant photoUrl(PItemData->BGKImage); Item->setData(photoUrl.toString(),Qt::UserRole); StandardItemModel->appendRow(Item); //追加Item }
void FlickrController::setup() { // const ci::Url url("https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=2c1dfa5a2a5487123799f3087a2dba93&text=birthday&sort=interestingness-desc&per_page=500&format=rest&api_sig=0121325a201b929e5455f4a112e8adac"); // load four pages worth of photos with "birthday" in the text std::vector<ci::Url> birthdayUrls; // search is for all pictures with the tag "birthday", page 1 const ci::Url urlp1("https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=fd591c6ac50b4a1dd197f6058ed4c1ee&text=birthday&min_upload_date=2014-01-01&per_page=500&format=json&nojsoncallback=1&api_sig=b4e1a313f75d789e13c0e51c82032a85"); // page 2 const ci::Url urlp2("https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=fd591c6ac50b4a1dd197f6058ed4c1ee&text=birthday&min_upload_date=2014-01-01&per_page=500&page=2&format=json&nojsoncallback=1&api_sig=0ce334b3df751e8cd556f96e72442c98"); // page 3 const ci::Url urlp3("https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=fd591c6ac50b4a1dd197f6058ed4c1ee&text=birthday&min_upload_date=2014-01-01&per_page=500&page=3&format=json&nojsoncallback=1&api_sig=bbcfd369e5d8b0e8528a9687bac03c2c"); // page 4 const ci::Url urlp4("https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=fd591c6ac50b4a1dd197f6058ed4c1ee&text=birthday&min_upload_date=2014-01-01&per_page=500&page=4&format=json&nojsoncallback=1&api_sig=eed5559f62bb829981f65c1b29dd3517"); birthdayUrls.push_back(urlp1); birthdayUrls.push_back(urlp2); birthdayUrls.push_back(urlp3); birthdayUrls.push_back(urlp4); // grab all the photos, one per owner for (int i = 0; i < birthdayUrls.size(); i++) { ci::JsonTree json(ci::loadUrl(birthdayUrls[i])); ci::app::console() << json << std::endl; ci::JsonTree photoInfo = json.getChild("photos").getChild(("photo")); std::string lastOwner = ""; for (ci::JsonTree::Iter photoData = photoInfo.begin(); photoData != photoInfo.end(); ++photoData) { ci::JsonTree eachPhoto = *photoData; //ci::app::console() << eachPhoto << std::endl; // get just one picture per owner std::string currentOwner = eachPhoto.getChild("owner").getValue<std::string>(); if (currentOwner == lastOwner) { continue; } else { lastOwner = currentOwner; } // if it's a new owner, create the URL std::string pictureUrl; pictureUrl = "https://farm" + eachPhoto.getChild("farm").getValue<std::string>() + ".staticflickr.com/" + eachPhoto.getChild("server").getValue<std::string>() + "/" + eachPhoto.getChild("id").getValue<std::string>() + "_" + eachPhoto.getChild("secret").getValue<std::string>() + ".jpg"; ci::app::console() << pictureUrl << std::endl; ci::Url photoUrl(pictureUrl); mUrls.push_back(photoUrl); } } ci::app::console() << "Number of URLs: " << mUrls.size() << std::endl; int count = 0; for (auto url : mUrls) { createTextureFromUrl(url); ci::app::console() << "Count: " << count << std::endl; count ++; // enough is enough if (count > 250) break; } mFadeOpacity = 0.f; }