summaryrefslogtreecommitdiffstats
path: root/pictureviewerinfoitem.cpp
blob: e80e8c6ec6cdf55d699f252b83c896e1c7788849 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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();
}