872
872
m_boundingRect.setHeight(qRound(m_boundingRect.height()));
875
ThumbnailItem::ThumbnailItem(Model::Page* page, int index, QGraphicsItem* parent) : PageItem(page, index, false, parent)
875
ThumbnailItem::ThumbnailItem(Model::Page* page, int index, QGraphicsItem* parent) : PageItem(page, index, false, parent),
876
#if QT_VERSION >= QT_VERSION_CHECK(4,7,0)
877
m_text(QString::number(index + 1)),
877
881
setAcceptHoverEvents(false);
879
const QFontMetrics fontMetrics = QFontMetrics(QFont());
881
m_textWidth = fontMetrics.width(QString::number(index + 1));
882
m_textHeight = fontMetrics.height();
887
884
QRectF ThumbnailItem::boundingRect() const
889
return PageItem::boundingRect().adjusted(0.0, 0.0, 0.0, 2.0 * m_textHeight);
886
#if QT_VERSION >= QT_VERSION_CHECK(4,7,0)
888
return PageItem::boundingRect().adjusted(0.0, 0.0, 0.0, 2.0 * m_text.size().height());
892
return PageItem::boundingRect().adjusted(0.0, 0.0, 0.0, 2.0 * QFontMetrics(QFont()).height());
892
897
void ThumbnailItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
896
901
const QRectF boundingRect = PageItem::boundingRect();
898
QPointF pos = boundingRect.bottomLeft();
899
pos.rx() += 0.5 * (boundingRect.width() - m_textWidth);
900
pos.ry() += m_textHeight;
902
painter->drawText(pos, QString::number(index() + 1));
903
#if QT_VERSION >= QT_VERSION_CHECK(4,7,0)
905
const QSizeF textSize = m_text.size();
907
QPointF pos = boundingRect.bottomLeft();
908
pos.rx() += 0.5 * (boundingRect.width() - textSize.width());
909
pos.ry() += 0.5 * textSize.height();
911
painter->drawStaticText(pos, m_text);
915
const QString text = QString::number(index() + 1);
916
const QFontMetrics fontMetrics = QFontMetrics(QFont());
918
QPointF pos = boundingRect.bottomLeft();
919
pos.rx() += 0.5 * (boundingRect.width() - fontMetrics.width(text));
920
pos.ry() += fontMetrics.height();
922
painter->drawText(pos, text);
908
930
painter->setCompositionMode(QPainter::CompositionMode_Multiply);
910
931
painter->fillRect(boundingRect, widget->palette().highlight());
912
933
painter->restore();
952
973
void ThumbnailItem::loadInteractiveElements()
975
const qreal width = size().width() / 72.0 * 25.4;
976
const qreal height = size().height() / 72.0 * 25.4;
978
const qreal longEdge = qMax(width, height);
979
const qreal shortEdge = qMin(width, height);
983
if(qAbs(longEdge - 279.4) <= 1.0 && qAbs(shortEdge - 215.9) <= 1.0)
985
paperSize = QLatin1String(" (Letter)");
989
qreal longEdgeA = 1189.0;
990
qreal shortEdgeA = 841.0;
992
qreal longEdgeB = 1414.0;
993
qreal shortEdgeB = 1000.0;
995
for(int i = 0; i <= 10; ++i)
997
if(qAbs(longEdge - longEdgeA) <= 1.0 && qAbs(shortEdge - shortEdgeA) <= 1.0)
999
paperSize = QString(" (A%1)").arg(i);
1002
else if(qAbs(longEdge - longEdgeB) <= 1.0 && qAbs(shortEdge - shortEdgeB) <= 1.0)
1004
paperSize = QString(" (B%1)").arg(i);
1008
longEdgeA = shortEdgeA;
1009
shortEdgeA /= qSqrt(2.0);
1011
longEdgeB = shortEdgeB;
1012
shortEdgeB /= qSqrt(2.0);
1016
setToolTip(QString("%1 mm x %2 mm%3").arg(width, 0, 'f', 1).arg(height, 0, 'f', 1).arg(paperSize));