diff options
author | Arno <am@disconnect.de> | 2010-05-24 14:14:00 +0200 |
---|---|---|
committer | Arno <am@disconnect.de> | 2010-05-24 14:14:00 +0200 |
commit | 199bf012a87ace47044627189012b854570e3970 (patch) | |
tree | 735966e8d8843c3f5beddaaff6c657d8c5bba030 /pictureviewerinfoitem.cpp | |
parent | f3b7e335c988cadd463063ca72790a638e44970e (diff) | |
download | SheMov-199bf012a87ace47044627189012b854570e3970.tar.gz SheMov-199bf012a87ace47044627189012b854570e3970.tar.bz2 SheMov-199bf012a87ace47044627189012b854570e3970.zip |
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.
Diffstat (limited to 'pictureviewerinfoitem.cpp')
-rw-r--r-- | pictureviewerinfoitem.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
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 <QApplication> +#include <QFont> +#include <QFontMetrics> +#include <QPen> +#include <QBrush> +#include <QPainter> + +#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(); +} |