File leechcraft-monocle-gcc47.patch of Package leechcraft
diff --git a/src/plugins/monocle/annitem.cpp b/src/plugins/monocle/annitem.cpp
index 3c62097..9c9c9c9 100644
--- a/src/plugins/monocle/annitem.cpp
+++ b/src/plugins/monocle/annitem.cpp
@@ -63,88 +63,7 @@ namespace Monocle
AnnBaseItem* MakeItem (const IAnnotation_ptr& ann, QGraphicsItem *parent)
{
- switch (ann->GetAnnotationType ())
- {
- case AnnotationType::Text:
- return new TextAnnItem (std::dynamic_pointer_cast<ITextAnnotation> (ann), parent);
- case AnnotationType::Highlight:
- return new HighAnnItem (std::dynamic_pointer_cast<IHighlightAnnotation> (ann), parent);
- case AnnotationType::Link:
- return new LinkAnnItem (std::dynamic_pointer_cast<ILinkAnnotation> (ann), parent);
- case AnnotationType::Other:
- qWarning () << Q_FUNC_INFO
- << "unknown annotation type with contents"
- << ann->GetText ();
- return nullptr;
- }
-
- qWarning () << Q_FUNC_INFO
- << "unhandled annotation type "
- << static_cast<int> (ann->GetAnnotationType ())
- << "with contents"
- << ann->GetText ();
-
return nullptr;
}
-
- HighAnnItem::HighAnnItem (const IHighlightAnnotation_ptr& ann, QGraphicsItem *parent)
- : AnnBaseGraphicsItem { ann, parent }
- , Polys_ { ToPolyData (ann->GetPolygons ()) }
- {
- for (const auto& data : Polys_)
- {
- addToGroup (data.Item_);
- data.Item_->setPen (Qt::NoPen);
-
- Bounding_ |= data.Poly_.boundingRect ();
-
- data.Item_->setCursor (Qt::PointingHandCursor);
- }
- }
-
- void HighAnnItem::SetSelected (bool selected)
- {
- AnnBaseItem::SetSelected (selected);
-
- const auto& pen = selected ? QPen { QColor { 255, 234, 0 }, 2 } : Qt::NoPen;
- const auto& brush = selected ? QBrush { QColor { 255, 213, 0, 64 } } : QBrush {};
- for (const auto& data : Polys_)
- {
- data.Item_->setPen (pen);
- data.Item_->setBrush (brush);
- }
- }
-
- void HighAnnItem::UpdateRect (const QRectF& rect)
- {
- setPos (rect.topLeft ());
- for (auto data : Polys_)
- {
- auto poly = data.Poly_;
-
- if (!Bounding_.width () || !Bounding_.height ())
- continue;
-
- const auto xScale = rect.width () / Bounding_.width ();
- const auto yScale = rect.height () / Bounding_.height ();
- const auto xTran = rect.x () - Bounding_.x () * xScale - rect.left ();
- const auto yTran = rect.y () - Bounding_.y () * yScale - rect.top ();
-
- data.Item_->setPolygon (poly * QMatrix { xScale, 0, 0, yScale, xTran, yTran });
- }
- }
-
- QList<HighAnnItem::PolyData> HighAnnItem::ToPolyData (const QList<QPolygonF>& polys)
- {
- QList<PolyData> result;
- for (const auto& poly : polys)
- result.append ({ poly, new QGraphicsPolygonItem });
- return result;
- }
-
- LinkAnnItem::LinkAnnItem (const ILinkAnnotation_ptr& ann, QGraphicsItem *item)
- : AnnRectGraphicsItem { ann, ann->GetLink (), item }
- {
- }
}
}
diff --git a/src/plugins/monocle/annitem.h b/src/plugins/monocle/annitem.h
index adf81ce..9ea982c 100644
--- a/src/plugins/monocle/annitem.h
+++ b/src/plugins/monocle/annitem.h
@@ -63,84 +63,5 @@ namespace Monocle
AnnBaseItem* MakeItem (const IAnnotation_ptr&, QGraphicsItem*);
- template<typename T>
- class AnnBaseGraphicsItem : public AnnBaseItem
- , public T
- {
- QPointF PressedPos_;
- public:
- template<typename... TArgs>
- AnnBaseGraphicsItem (const IAnnotation_ptr& ann, TArgs... args)
- : AnnBaseItem { ann }
- , T { args... }
- {
- }
- protected:
- void mousePressEvent (QGraphicsSceneMouseEvent *event)
- {
- PressedPos_ = event->pos ();
- T::mousePressEvent (event);
- event->accept ();
- }
-
- void mouseReleaseEvent (QGraphicsSceneMouseEvent *event)
- {
- if (Handler_ &&
- (event->pos () - PressedPos_).manhattanLength () < 4)
- Handler_ (BaseAnn_);
-
- T::mouseReleaseEvent (event);
- }
- };
-
- template<typename T>
- class AnnRectGraphicsItem : public AnnBaseGraphicsItem<T>
- {
- public:
- using AnnBaseGraphicsItem<T>::AnnBaseGraphicsItem;
-
- void SetSelected (bool selected)
- {
- AnnBaseItem::SetSelected (selected);
- T::setPen (selected ? QPen { QColor { 255, 234, 0 }, 2 } : Qt::NoPen);
- }
-
- void UpdateRect (const QRectF& rect)
- {
- T::setRect (rect);
- }
- };
-
- class TextAnnItem : public AnnRectGraphicsItem<QGraphicsRectItem>
- {
- public:
- using AnnRectGraphicsItem<QGraphicsRectItem>::AnnRectGraphicsItem;
- };
-
- class HighAnnItem : public AnnBaseGraphicsItem<QGraphicsItemGroup>
- {
- struct PolyData
- {
- QPolygonF Poly_;
- QGraphicsPolygonItem *Item_;
- };
- const QList<PolyData> Polys_;
-
- QRectF Bounding_;
- public:
- HighAnnItem (const IHighlightAnnotation_ptr&, QGraphicsItem*);
-
- void SetSelected (bool);
-
- void UpdateRect (const QRectF& rect);
- private:
- static QList<PolyData> ToPolyData (const QList<QPolygonF>&);
- };
-
- class LinkAnnItem : public AnnRectGraphicsItem<LinkItem>
- {
- public:
- LinkAnnItem (const ILinkAnnotation_ptr&, QGraphicsItem*);
- };
}
}