mypopup.cpp 2.74 KB
Newer Older
Albert Astals Cid's avatar
Albert Astals Cid committed
1
/***************************************************************************
2
 *   Copyright (C) 2004-2005 by Albert Astals Cid                          *
3
 *   aacid@kde.org                                                         *
Albert Astals Cid's avatar
Albert Astals Cid committed
4
5
6
7
8
9
10
 *                                                                         *
 *   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.                                   *
 ***************************************************************************/

Albert Astals Cid's avatar
Albert Astals Cid committed
11
12
#include "mypopup.h"

13
#include <kiconloader.h>
David Gil's avatar
David Gil committed
14
#include <klocalizedstring.h>
15
16

#include <qevent.h>
Albert Astals Cid's avatar
Albert Astals Cid committed
17
#include <qicon.h>
Albert Astals Cid's avatar
Albert Astals Cid committed
18
#include <qlabel.h>
19
#include <qlayout.h>
20
#include <qimage.h>
21
#include <qdesktopservices.h>
Albert Astals Cid's avatar
Albert Astals Cid committed
22

23
myPopup::myPopup(QWidget *parent, const QString &text, const QString &wikiLink, const QString &text2, const QString &flagFile) : QFrame(parent, Qt::FramelessWindowHint)
Pino Toscano's avatar
Pino Toscano committed
24
{
25
	wikipedia = wikiLink;
26
	QHBoxLayout *lay = new QHBoxLayout(this);
Laurent Montel's avatar
Laurent Montel committed
27
	lay -> setContentsMargins(4, 4, 4, 4);
28
	lay -> setSpacing(4);
29
	
30
31
32
33
	if (!wikiLink.isEmpty())
	{
		wiki = new QLabel(this);
		lay -> addWidget(wiki);
Albert Astals Cid's avatar
Albert Astals Cid committed
34
		wiki -> setPixmap(QIcon::fromTheme( QStringLiteral("dialog-information") ).pixmap(KIconLoader::SizeSmall));
35
36
37
38
39
		wiki -> setToolTip(i18n("Wikipedia page"));
		wiki -> setAlignment(Qt::AlignCenter);
		wiki -> installEventFilter(this);
	}
	
40
41
	QWidget *vbox = new QWidget(this);
	lay -> addWidget(vbox);
42
	
43
	QVBoxLayout *vboxLayout = new QVBoxLayout(vbox);
Laurent Montel's avatar
Laurent Montel committed
44
	vboxLayout -> setContentsMargins(0, 0, 0, 0);
45
	vboxLayout -> setSpacing(0);
46
	QLabel *l = new QLabel(text, vbox);
47
	vboxLayout -> addWidget(l);
48
	
49
50
51
52
	if (!text2.isNull())
	{
		QLabel *l2 = new QLabel(text2, vbox);
		l2 -> setAlignment(Qt::AlignCenter);
53
		vboxLayout -> addWidget(l2);
54
55
56
57
58
	}
	
	if (!flagFile.isNull())
	{
		QLabel *flag = new QLabel(this);
59
		lay -> addWidget(flag);
60
		QImage flagImg(flagFile);
61
		flag -> setPixmap(QPixmap::fromImage(flagImg.scaled(flagImg.width() / 5, flagImg. height() / 5, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)));
62
63
64
		flag -> setAlignment(Qt::AlignCenter);
	}
	
65
66
67
68
	l -> setAlignment(Qt::AlignCenter);
	QFont f = l -> font();
	f.setBold(true);
	l -> setFont(f);
69
	
70
71
72
73
	
	setFrameStyle(QFrame::Box | QFrame::Plain);
	setLineWidth(2);
	
74
	setFixedSize(sizeHint());
75
	setAutoFillBackground(true);
Albert Astals Cid's avatar
Albert Astals Cid committed
76
77
}

78
void myPopup::mousePressEvent(QMouseEvent *)
Albert Astals Cid's avatar
Albert Astals Cid committed
79
{
80
	emit deleteMe();
Albert Astals Cid's avatar
Albert Astals Cid committed
81
}
82

83
84
85
86
87
88
89
bool myPopup::eventFilter(QObject *obj, QEvent *event)
{
	if (obj == wiki)
	{
		
		if (event -> type() == QEvent::MouseButtonPress)
		{
90
			QDesktopServices::openUrl(QUrl(wikipedia));
91
92
93
94
95
96
97
98
99
100
101
			return true;
		}
		else
		{
			return false;
		}
	}
	emit deleteMe();

	return false;
}
102