void ContactDropFilter::CollectDataFilters (QStringList& choiceItems, QList<std::function<void ()>>& functions, const QImage& image) { const auto& imageVar = QVariant::fromValue (image); const auto& entity = Util::MakeEntity (imageVar, {}, TaskParameter::NoParameters, "x-leechcraft/data-filter-request"); auto prevChoices = choiceItems; choiceItems.clear (); auto prevFunctions = functions; functions.clear (); auto em = Core::Instance ().GetProxy ()->GetEntityManager (); for (const auto obj : em->GetPossibleHandlers (entity)) { const auto idf = qobject_cast<IDataFilter*> (obj); const auto& verb = idf->GetFilterVerb (); for (const auto& var : idf->GetFilterVariants (imageVar)) { auto thisEnt = entity; thisEnt.Additional_ ["DataFilter"] = var.Name_; choiceItems << verb + ": " + var.Name_; thisEnt.Additional_ ["DataFilterCallback"] = QVariant::fromValue<DataFilterCallback_f> ( [this] (const QVariant& var) { const auto& url = var.toUrl (); if (url.isEmpty ()) return; ChatTab_->insertMessageText (url.toEncoded ()); }); functions.append ([thisEnt, obj] { qobject_cast<IEntityHandler*> (obj)->Handle (thisEnt); }); } } choiceItems << prevChoices; functions << prevFunctions; }
StdDataFilterMenuCreator::StdDataFilterMenuCreator (const QVariant& dataVar, IEntityManager *em, QMenu *menu) : QObject (menu) , EntityMgr_ (em) { auto entity = MakeEntity (dataVar, QString (), FromUserInitiated | OnlyHandle, "x-leechcraft/data-filter-request"); for (auto plugin : em->GetPossibleHandlers (entity)) { auto ii = qobject_cast<IInfo*> (plugin); auto idf = qobject_cast<IDataFilter*> (plugin); if (!idf) continue; const auto& vars = idf->GetFilterVariants (dataVar); if (vars.isEmpty ()) continue; const auto actor = [this, entity, plugin] (const IDataFilter::FilterVariant& var) mutable { entity.Additional_ ["DataFilter"] = var.ID_; EntityMgr_->HandleEntity (entity, plugin); ChosenPlugin_ = qobject_cast<IInfo*> (plugin)->GetUniqueID (); ChosenVariant_ = var.ID_; }; if (vars.size () == 1) AddDatafilterMenuItem (vars.value (0), menu, actor); else { auto searchMenu = menu->addMenu (ii->GetIcon (), idf->GetFilterVerb ()); for (const auto& var : vars) AddDatafilterMenuItem (var, searchMenu, actor); } } }
EntityTestHandleResult Plugin::CouldHandle (const Entity& e) const { if (e.Mime_ != "x-leechcraft/data-filter-request" || !e.Entity_.canConvert<QString> ()) return EntityTestHandleResult (); if (e.Additional_.contains ("DataFilter")) { const auto& rawCat = e.Additional_ ["DataFilter"].toByteArray (); const auto& catStr = QString::fromUtf8 (rawCat.data ()); const auto& vars = GetFilterVariants (); if (std::find_if (vars.begin (), vars.end (), [&catStr] (decltype (vars.front ()) var) { return var.ID_ == catStr; }) == vars.end ()) return EntityTestHandleResult (); } const auto& str = e.Entity_.toString (); return str.size () < 200 && str.count ("\n") < 3 ? EntityTestHandleResult (EntityTestHandleResult::PIdeal) : EntityTestHandleResult (); }
ScreenShotSaveDialog::ScreenShotSaveDialog (const QPixmap& source, QWidget *parent) : QDialog (parent) , Source_ (source) , PixmapHolder_ (new QLabel ()) , RenderScheduled_ (false) { PixmapHolder_->setAlignment (Qt::AlignTop | Qt::AlignLeft); Ui_.setupUi (this); QList<QByteArray> formats = QImageWriter::supportedImageFormats (); formats.removeAll ("ico"); if (formats.contains ("jpg")) formats.removeAll ("jpeg"); std::sort (formats.begin (), formats.end ()); for (QList<QByteArray>::const_iterator i = formats.begin (), end = formats.end (); i != end; ++i) Ui_.FormatCombobox_->addItem (i->toUpper ()); if (formats.contains ("png")) Ui_.FormatCombobox_->setCurrentIndex (formats.indexOf ("png")); Ui_.Scroller_->setWidget (PixmapHolder_); auto proxy = Core::Instance ().GetProxy (); const auto& dfs = Util::GetDataFilters (QVariant::fromValue (Source_.toImage ()), proxy->GetEntityManager ()); for (auto df : dfs) { auto idf = qobject_cast<IDataFilter*> (df); for (const auto& var : idf->GetFilterVariants ()) { Ui_.ActionBox_->addItem (var.Icon_, var.Name_); Filters_.append ({ df, var.ID_ }); } } Ui_.ActionBox_->addItem (proxy->GetIcon ("document-save"), tr ("Save")); }
void ShooterDialog::SetScreenshot (const QPixmap& px) { CurrentScreenshot_ = px; RescaleLabel (); Ui_.ActionBox_->clear (); Filters_.clear (); const auto& image = px.toImage (); const auto& filters = Util::GetDataFilters (image, Proxy_->GetEntityManager ()); for (auto filter : filters) { auto idf = qobject_cast<IDataFilter*> (filter); const auto& verb = idf->GetFilterVerb (); for (const auto& var : idf->GetFilterVariants ()) { Filters_.append ({ filter, var.ID_ }); Ui_.ActionBox_->addItem (QString ("%1: %2").arg (verb).arg (var.Name_)); } } Ui_.ActionBox_->addItem (tr ("save")); }