/* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. */ #include #include #include #include #include #include #include "pictureviewerinfoitem.h" PictureviewerInfoItem::PictureviewerInfoItem(const QString &fileName, QGraphicsItem *parent) : QGraphicsItem(parent), mFileName(fileName){ setZValue(1); } QRectF PictureviewerInfoItem::boundingRect() const { QSize size = qApp->fontMetrics().size(Qt::TextSingleLine, mFileName); size += QSize(2, 2); QRectF retval; retval.setWidth(size.width()); retval.setHeight(size.height()); return retval; } void PictureviewerInfoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){ Q_UNUSED(option); Q_UNUSED(widget); painter->save(); painter->setRenderHint(QPainter::Antialiasing, false); painter->setRenderHint(QPainter::TextAntialiasing, true); QRectF boundRect = boundingRect(); QColor backgroundColor(Qt::white); backgroundColor.setAlpha(70); QBrush brush(backgroundColor); painter->setPen(QPen(Qt::NoPen)); painter->setBrush(brush); painter->drawRect(boundRect); QPen pen(Qt:: black); painter->setPen(pen); QPoint start(1, qApp->fontMetrics().ascent() + 1); painter->drawText(start, mFileName); painter->restore(); }