1
//MountManager - the program for easy mounting of storage devices in Linux
2
//Copyright (C) 2007-2008 Tikhonov Sergey
4
//This file is part of MountManager Gui
6
//This program is free software; you can redistribute it and/or
7
//modify it under the terms of the GNU General Public License
8
//as published by the Free Software Foundation; either version 2
9
//of the License, or (at your option) any later version.
11
//This program is distributed in the hope that it will be useful,
12
//but WITHOUT ANY WARRANTY; without even the implied warranty of
13
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
//GNU General Public License for more details.
16
//You should have received a copy of the GNU General Public License
17
//along with this program; if not, write to the Free Software
18
//Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
#include <QToolButton>
20
#include <QApplication>
21
#include <QDesktopWidget>
22
#include <QTextBrowser>
24
#include <QVBoxLayout>
25
#include <QHBoxLayout>
27
#include "popupwindow.h"
30
PopupWindow::PopupWindow(QWidget *parent) : QDialog(parent) {
32
setWindowFlags(Qt::Popup);
36
browser = new QTextBrowser;
38
cursor = new QCursor();
40
closeButton = new QToolButton;
41
closeButton->setIcon(QIcon(ICONS_PATH"close_popup.png"));
42
connect(closeButton,SIGNAL(clicked()),this,SLOT(hide()));
45
QHBoxLayout *topLayout = new QHBoxLayout;
46
topLayout->addWidget(header);
47
topLayout->addStretch();
48
topLayout->addWidget(closeButton);
50
QVBoxLayout *mainLayout = new QVBoxLayout;
51
mainLayout->addLayout(topLayout);
52
mainLayout->addWidget(browser);
53
mainLayout->setMargin(3);
54
mainLayout->setSpacing(3);
56
setLayout(mainLayout);
60
PopupWindow::~PopupWindow() {
67
void PopupWindow::setText(const QString &text) {
68
browser->setHtml(text);
71
void PopupWindow::setHeaderText(const QString &headerText) {
72
header->setText("<b>" + headerText + "</b>");
75
void PopupWindow::showPopup() {
78
x = cursor->pos().x();
79
y = cursor->pos().y();
82
if (x + width() > QApplication::desktop()->width())
83
x = QApplication::desktop()->width() - width() - 10;
84
if (y + height() > QApplication::desktop()->height())
85
y = QApplication::desktop()->height() - height() - 10;