]> cloud.milkyroute.net Git - dolphin.git/blob - src/tooltips/ktooltip.cpp
Restore the "Edit->Selection" menu from Konqueror 3 for file
[dolphin.git] / src / tooltips / ktooltip.cpp
1 /***************************************************************************
2 * Copyright (C) 2008 by Fredrik Höglund <fredrik@kde.org> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #include "ktooltip.h"
21 #include "ktooltipwindow_p.h"
22 #include <QLabel>
23 #include <QPoint>
24 #include <QWidget>
25
26 class KToolTipManager
27 {
28 public:
29 ~KToolTipManager();
30
31 static KToolTipManager* instance();
32
33 void showTip(const QPoint& pos, QWidget* content);
34 void hideTip();
35
36 private:
37 KToolTipManager();
38
39 KToolTipWindow* m_window;
40 static KToolTipManager *s_instance;
41 };
42
43 KToolTipManager *KToolTipManager::s_instance = 0;
44
45 KToolTipManager::KToolTipManager() :
46 m_window(0)
47 {
48 }
49
50 KToolTipManager::~KToolTipManager()
51 {
52 delete m_window;
53 m_window = 0;
54 }
55
56 KToolTipManager* KToolTipManager::instance()
57 {
58 if (s_instance == 0) {
59 s_instance = new KToolTipManager();
60 }
61
62 return s_instance;
63 }
64
65 void KToolTipManager::showTip(const QPoint& pos, QWidget* content)
66 {
67 hideTip();
68 Q_ASSERT(m_window == 0);
69 m_window = new KToolTipWindow(content);
70 m_window->move(pos);
71 m_window->show();
72 }
73
74 void KToolTipManager::hideTip()
75 {
76 if (m_window != 0) {
77 m_window->hide();
78 delete m_window;
79 m_window = 0;
80 }
81 }
82
83 namespace KToolTip
84 {
85 void showText(const QPoint& pos, const QString& text)
86 {
87 QLabel* label = new QLabel(text);
88 label->setForegroundRole(QPalette::ToolTipText);
89 showTip(pos, label);
90 }
91
92 void showTip(const QPoint& pos, QWidget* content)
93 {
94 KToolTipManager::instance()->showTip(pos, content);
95 }
96
97 void hideTip()
98 {
99 KToolTipManager::instance()->hideTip();
100 }
101 }
102