File indexing completed on 2024-04-21 07:27:51

0001 /***************************************************************************
0002  *   Copyright (C) 2004-2005 by Albert Astals Cid                          *
0003  *   aacid@kde.org                                                         *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  ***************************************************************************/
0010 
0011 #include "mypopup.h"
0012 
0013 #include <KIconLoader>
0014 #include <KLocalizedString>
0015 
0016 #include <QEvent>
0017 #include <QIcon>
0018 #include <QLabel>
0019 #include <QLayout>
0020 #include <QImage>
0021 #include <QDesktopServices>
0022 #include <QUrl>
0023 
0024 myPopup::myPopup(QWidget *parent, const QString &text, const QString &wikiLink, const QString &text2, const QString &flagFile) : QFrame(parent, Qt::FramelessWindowHint)
0025 {
0026     wikipedia = wikiLink;
0027     QHBoxLayout *lay = new QHBoxLayout(this);
0028     lay -> setContentsMargins(4, 4, 4, 4);
0029     lay -> setSpacing(4);
0030     
0031     if (!wikiLink.isEmpty())
0032     {
0033         wiki = new QLabel(this);
0034         lay -> addWidget(wiki);
0035         wiki -> setPixmap(QIcon::fromTheme( QStringLiteral("dialog-information") ).pixmap(KIconLoader::SizeSmall));
0036         wiki -> setToolTip(i18n("Wikipedia page"));
0037         wiki -> setAlignment(Qt::AlignCenter);
0038         wiki -> installEventFilter(this);
0039     }
0040     
0041     QWidget *vbox = new QWidget(this);
0042     lay -> addWidget(vbox);
0043     
0044     QVBoxLayout *vboxLayout = new QVBoxLayout(vbox);
0045     vboxLayout -> setContentsMargins(0, 0, 0, 0);
0046     vboxLayout -> setSpacing(0);
0047     QLabel *l = new QLabel(text, vbox);
0048     vboxLayout -> addWidget(l);
0049     
0050     if (!text2.isNull())
0051     {
0052         QLabel *l2 = new QLabel(text2, vbox);
0053         l2 -> setAlignment(Qt::AlignCenter);
0054         vboxLayout -> addWidget(l2);
0055     }
0056     
0057     if (!flagFile.isNull())
0058     {
0059         QLabel *flag = new QLabel(this);
0060         lay -> addWidget(flag);
0061         QImage flagImg(flagFile);
0062         flag -> setPixmap(QPixmap::fromImage(flagImg.scaled(flagImg.width() / 5, flagImg. height() / 5, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)));
0063         flag -> setAlignment(Qt::AlignCenter);
0064     }
0065     
0066     l -> setAlignment(Qt::AlignCenter);
0067     QFont f = l -> font();
0068     f.setBold(true);
0069     l -> setFont(f);
0070     
0071     
0072     setFrameStyle(QFrame::Box | QFrame::Plain);
0073     setLineWidth(2);
0074     
0075     setFixedSize(sizeHint());
0076     setAutoFillBackground(true);
0077 }
0078 
0079 void myPopup::mousePressEvent(QMouseEvent *)
0080 {
0081     Q_EMIT deleteMe();
0082 }
0083 
0084 bool myPopup::eventFilter(QObject *obj, QEvent *event)
0085 {
0086     if (obj == wiki)
0087     {
0088         
0089         if (event -> type() == QEvent::MouseButtonPress)
0090         {
0091             QDesktopServices::openUrl(QUrl(wikipedia));
0092             return true;
0093         }
0094         else
0095         {
0096             return false;
0097         }
0098     }
0099     Q_EMIT deleteMe();
0100 
0101     return false;
0102 }
0103 
0104 #include "moc_mypopup.cpp"