- SignalConvertTypePtr on_finish;
- on_finish.reset(new SignalConvertType);
- cc_ = on_finish->connect(SigC::slot(this, &GCacheItem::imageConverted));
-
- GConverter & graphics_converter = GConverter::get();
- graphics_converter.convert(filename, to_file_base, from, to, on_finish);
-}
-
-
-ModifiedItem::ModifiedItem(InsetGraphics const & new_inset,
- GParams const & new_params,
- ImagePtr const & new_image)
- : status_(ScalingEtc)
-{
- p_.reset(new GParams(new_params));
- insets.push_back(&new_inset);
- modify(new_image);
-}
-
-
-void ModifiedItem::add(InsetGraphics const & inset)
-{
- insets.push_back(&inset);
- insets.sort();
-}
-
-
-void ModifiedItem::remove(InsetGraphics const & inset)
-{
- ListType::iterator begin = insets.begin();
- ListType::iterator end = insets.end();
- ListType::iterator it = std::remove(begin, end, &inset);
- insets.erase(it, end);
-}
-
-
-bool ModifiedItem::referencedBy(InsetGraphics const & inset) const
-{
- ListType::const_iterator begin = insets.begin();
- ListType::const_iterator end = insets.end();
- return std::find(begin, end, &inset) != end;
-}
-
-
-ImagePtr const ModifiedItem::image() const
-{
- if (modified_image_.get())
- return modified_image_;
-
- return original_image_;
-}
-
-
-void ModifiedItem::modify(ImagePtr const & new_image)
-{
- if (!new_image.get())
- return;
-
- original_image_ = new_image;
- modified_image_.reset(original_image_->clone());
-
- if (params().display == GParams::NONE) {
- setStatus(Loaded);
- return;
- }
-
- setStatus(ScalingEtc);
- modified_image_->clip(params());
- modified_image_->rotate(params());
- modified_image_->scale(params());
- setPixmap();
-}
-
-
-void ModifiedItem::setPixmap()
-{
- if (!modified_image_.get())
- return;
-
- if (params().display == GParams::NONE) {
- setStatus(Loaded);
- return;
- }
-
- bool const success = modified_image_->setPixmap(params());
-
- if (success) {
- setStatus(Loaded);
- } else {
- modified_image_.reset();
- setStatus(ErrorScalingEtc);
- }
-}
-
-
-void ModifiedItem::setStatus(ImageStatus new_status)
-{
- status_ = new_status;
-
- // Tell the BufferView that the inset has changed.
- // Very, Very Ugly!!
- ListType::const_iterator it = insets.begin();
- ListType::const_iterator end = insets.end();
- for (; it != end; ++it) {
- InsetGraphics * inset = const_cast<InsetGraphics *>(*it);
- current_view->updateInset(inset, false);
- }
-}
-
-
-namespace {
-
-struct Params_Changed {
-
- Params_Changed(GParams const & p) : p_(p) {}
-
- bool operator()(InsetGraphics const * inset)
- {
- string const path = OnlyPath(p_.filename);
- return GParams(inset->params(), path) != p_;
- }
-
-private:
- GParams p_;
-};
-
-} // namespace anon
-
-// changeDisplay returns an initialised ModifiedItem if any of the insets
-// have display == DEFAULT and if that DEFAULT value has changed.
-// If this occurs, then (this) has these insets removed.
-ModifiedItemPtr ModifiedItem::changeDisplay()
-{
- // Loop over the list of insets. Compare the updated params for each
- // with params(). If different, move into a new list.
- ListType::iterator begin = insets.begin();
- ListType::iterator end = insets.end();
- ListType::iterator it =
- std::remove_if(begin, end, Params_Changed(params()));
-
- if (it == end) {
- // No insets have changed params
- return ModifiedItemPtr();
- }
-
- // it -> end have params that are changed. Move to the new list.
- ListType new_insets;
- new_insets.insert(new_insets.begin(), it, end);
- insets.erase(it, end);
-
- // Create a new ModifiedItem with these new params. Note that
- // the only params that have changed are the display ones,
- // so we don't need to crop, rotate, scale.
- string const path = OnlyPath(p_->filename);
-
- ModifiedItemPtr new_item(new ModifiedItem(*this));
- new_item->insets = new_insets;
- *(new_item->p_) = GParams((*new_insets.begin())->params(), path);
-
- new_item->setPixmap();
- return new_item;