File indexing completed on 2024-04-21 03:41:53

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 "popupmanager.h"
0012 
0013 #include "mypopup.h"
0014 
0015 popupManager::popupManager()
0016 {
0017     p_parent = nullptr;
0018     p_mp = nullptr;
0019 }
0020 
0021 void popupManager::setWidget(QWidget *w)
0022 {
0023     p_parent = w;
0024 }
0025 
0026 void popupManager::show(const QString &text, const QString &wikiLink, const QString &text2, const QPoint &p, const QString &flagFile)
0027 {
0028     delete p_mp;
0029 
0030     p_mp = new myPopup(p_parent, text, wikiLink, text2, flagFile);
0031     init(p);
0032 }
0033 
0034 void popupManager::show(const QString &text, const QString &wikiLink, const QString &text2, const QPoint &p)
0035 {
0036     delete p_mp;
0037     
0038     p_mp = new myPopup(p_parent, text, wikiLink, text2);
0039     init(p);
0040 }
0041 
0042 void popupManager::show(const QString &text, const QString &wikiLink, const QPoint &p)
0043 {
0044     delete p_mp;
0045     
0046     p_mp = new myPopup(p_parent, text, wikiLink);
0047     init(p);
0048 }
0049 
0050 void popupManager::clear()
0051 {
0052     if (p_mp)
0053     {
0054         p_mp -> deleteLater();
0055         p_mp = nullptr;
0056     }
0057 }
0058 
0059 void popupManager::init(const QPoint &p)
0060 {
0061     int x, y, maxX, maxY;
0062     maxX = p_parent -> width() - p_mp -> width();
0063     maxY = p_parent -> height() - p_mp -> height();
0064     if (p.x() < maxX) x = p.x();
0065     else x = maxX;
0066     if (p.y() < maxY) y = p.y();
0067     else y = maxY;
0068     p_mp -> move(x, y);
0069     p_mp -> show();
0070     connect(p_mp, &myPopup::deleteMe, this, &popupManager::clear);
0071 }
0072 
0073 #include "moc_popupmanager.cpp"