From 199bf012a87ace47044627189012b854570e3970 Mon Sep 17 00:00:00 2001 From: Arno Date: Mon, 24 May 2010 14:14:00 +0200 Subject: Implemented PictureViewer class Don't call an external program for showing a picture. When an image is doubleclicked a new windows shows the picture. Pictures can still be opened in an exteral program by using the "Open with..." context menu item. --- pictureviewerinfoitem.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 pictureviewerinfoitem.cpp (limited to 'pictureviewerinfoitem.cpp') diff --git a/pictureviewerinfoitem.cpp b/pictureviewerinfoitem.cpp new file mode 100644 index 0000000..e80e8c6 --- /dev/null +++ b/pictureviewerinfoitem.cpp @@ -0,0 +1,48 @@ +/* + 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(); +} -- cgit v1.2.3-70-g09d2