~ben-kietzman/ubuntu/quantal/mountmanager/fix-for-598070

« back to all changes in this revision

Viewing changes to sources/gui/popupwindow.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fabrice Coutadeur
  • Date: 2008-08-20 10:22:14 UTC
  • Revision ID: james.westby@ubuntu.com-20080820102214-fv93myu0ncb1503r
Tags: upstream-0.2.4
ImportĀ upstreamĀ versionĀ 0.2.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//MountManager - the program for easy mounting of storage devices in Linux
 
2
//Copyright (C) 2007-2008 Tikhonov Sergey
 
3
//
 
4
//This file is part of MountManager Gui
 
5
//
 
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.
 
10
//
 
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.
 
15
//
 
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>
 
23
#include <QLabel>
 
24
#include <QVBoxLayout>
 
25
#include <QHBoxLayout>
 
26
#include <QCursor>
 
27
#include "popupwindow.h"
 
28
#include "const.h"
 
29
 
 
30
PopupWindow::PopupWindow(QWidget *parent) : QDialog(parent) {
 
31
 
 
32
        setWindowFlags(Qt::Popup);
 
33
 
 
34
        header = new QLabel;
 
35
 
 
36
        browser = new QTextBrowser;
 
37
 
 
38
        cursor = new QCursor();
 
39
        
 
40
        closeButton = new QToolButton;
 
41
        closeButton->setIcon(QIcon(ICONS_PATH"close_popup.png"));
 
42
        connect(closeButton,SIGNAL(clicked()),this,SLOT(hide()));
 
43
 
 
44
        
 
45
        QHBoxLayout *topLayout = new QHBoxLayout;
 
46
        topLayout->addWidget(header);
 
47
        topLayout->addStretch();
 
48
        topLayout->addWidget(closeButton);
 
49
        
 
50
        QVBoxLayout *mainLayout = new QVBoxLayout;
 
51
        mainLayout->addLayout(topLayout);
 
52
        mainLayout->addWidget(browser);
 
53
        mainLayout->setMargin(3);
 
54
        mainLayout->setSpacing(3);
 
55
 
 
56
        setLayout(mainLayout);
 
57
        resize(300,200);
 
58
}
 
59
 
 
60
PopupWindow::~PopupWindow() {
 
61
        delete browser;
 
62
        delete closeButton;
 
63
        delete header;
 
64
        delete cursor;
 
65
}
 
66
 
 
67
void PopupWindow::setText(const QString &text) {
 
68
        browser->setHtml(text);
 
69
}
 
70
 
 
71
void PopupWindow::setHeaderText(const QString &headerText) {
 
72
        header->setText("<b>" + headerText + "</b>");
 
73
}
 
74
 
 
75
void PopupWindow::showPopup() {
 
76
        int x = 0;
 
77
        int y = 0;
 
78
        x = cursor->pos().x();
 
79
        y = cursor->pos().y();
 
80
        if (x < 0) x = 0;
 
81
        if (y < 0) y = 0;
 
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;
 
86
        move(QPoint(x,y));
 
87
        show();
 
88
}
 
89