We now have a current svn snapshot of libqxt in our contrib dir, and
[quassel.git] / src / contrib / libqxt-2007-10-24 / src / gui / qxtdesktopwidget.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) Qxt Foundation. Some rights reserved.
4 **
5 ** This file is part of the QxtGui module of the Qt eXTension library
6 **
7 ** This library is free software; you can redistribute it and/or modify it
8 ** under the terms of th Common Public License, version 1.0, as published by
9 ** IBM.
10 **
11 ** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
12 ** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
13 ** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
14 ** FITNESS FOR A PARTICULAR PURPOSE.
15 **
16 ** You should have received a copy of the CPL along with this file.
17 ** See the LICENSE file and the cpl1.0.txt file included with the source
18 ** distribution for more information. If you did not receive a copy of the
19 ** license, contact the Qxt Foundation.
20 **
21 ** <http://libqxt.sourceforge.net>  <foundation@libqxt.org>
22 **
23 ****************************************************************************/
24 #include "qxtdesktopwidget.h"
25 #include <QStringList>
26
27 /*!
28     \class QxtDesktopWidget QxtDesktopWidget
29     \ingroup QxtGui
30     \brief QxtDesktopWidget provides means for accessing native windows.
31
32     \note QxtDesktopWidget is portable in principle, but be careful while
33     using it since you are probably about to do something non-portable.
34
35     <P>Advanced example usage:
36     \code
37     class NativeWindow : public QWidget {
38         public:
39             NativeWindow(WId wid) {
40                 QWidget::create(wid, false, false); // window, initializeWindow, destroyOldWindow
41             }
42             ~NativeWindow() {
43                 QWidget::destroy(false, false); // destroyWindow, destroySubWindows
44             }
45     };
46     \endcode
47
48     \code
49     WindowList windows = QxtDesktopWidget::windows();
50     QStringList titles = QxtDesktopWidget::windowTitles();
51     bool ok = false;
52     QString title = QInputDialog::getItem(0, "Choose Window", "Choose a window to be hid:", titles, 0, false, &ok);
53     if (ok)
54     {
55         int index = titles.indexOf(title);
56         if (index != -1)
57         {
58             NativeWindow window(windows.at(index));
59             window.hide();
60         }
61     }
62     \endcode
63
64     \note Currently supported platforms are \b X11 and \b Windows.
65  */
66
67 /*!
68     \fn QxtDesktopWidget::windows()
69
70     Returns the list of native window system identifiers.
71
72     \note The windows are not necessarily QWidgets.
73
74     \sa QApplication::topLevelWidgets(), windowTitles()
75  */
76
77
78 /*!
79     \fn QxtDesktopWidget::activeWindow()
80
81     Returns the native window system identifier of the active window if any.
82
83     Example usage:
84     \code
85     WId wid = QxtDesktopWidget::activeWindow();
86     QString title = QxtDesktopWidget::windowTitle(wid);
87     qDebug() << "Currently active window is:" << title;
88     \endcode
89
90     \note The window is not necessarily a QWidget.
91
92     \sa QApplication::activeWindow()
93  */
94
95 /*!
96     \fn QxtDesktopWidget::findWindow(const QString& title)
97
98     Returns the native window system identifier of the window if any with given \a title.
99
100     Example usage:
101     \code
102     WId wid = QxtDesktopWidget::findWindow("Mail - Kontact");
103     QPixmap screenshot = QPixmap::grabWindow(wid);
104     \endcode
105
106     \note The window is not necessarily a QWidget.
107
108     \sa QWidget::find()
109  */
110
111 /*!
112     \fn QxtDesktopWidget::windowAt(const QPoint& pos)
113
114     Returns the native window system identifier of the window if any at \a pos.
115
116     Example usage:
117     \code
118     QPoint point = // a mouse press or something
119     WId wid = QxtDesktopWidget::windowAt(point);
120     QPixmap screenshot = QPixmap::grabWindow(wid);
121     \endcode
122
123     \note The window is not necessarily a QWidget.
124
125     \sa QApplication::widgetAt()
126  */
127
128 /*!
129     \fn QxtDesktopWidget::windowTitle(WId window)
130
131     Returns the title of the native \a window.
132
133     Example usage:
134     \code
135     WId wid = QxtDesktopWidget::activeWindow();
136     QString title = QxtDesktopWidget::windowTitle(wid);
137     qDebug() << "Currently active window is:" << title;
138     \endcode
139
140     \sa QWidget::windowTitle(), windowTitles()
141  */
142
143 /*!
144     \fn QxtDesktopWidget::windowTitles()
145
146     Returns a list of native window titles.
147
148     Example usage:
149     \code
150     qDebug() << "Windows:";
151     foreach (QString title, QxtDesktopWidget::windowTitles())
152        qDebug() << title;
153     \endcode
154
155     \sa QWidget::windowTitle(), windowTitle(), windows()
156  */
157
158 /*!
159     \fn QxtDesktopWidget::windowGeometry(WId window)
160
161     Returns the geometry of the native \a window.
162
163     Example usage:
164     \code
165     WId wid = QxtDesktopWidget::activeWindow();
166     QRect geometry = QxtDesktopWidget::windowGeometry(wid);
167     qDebug() << "Geometry of the active window is:" << geometry;
168     \endcode
169
170     \sa QWidget::frameGeometry()
171  */
172
173 QStringList QxtDesktopWidget::windowTitles()
174 {
175     WindowList windows = QxtDesktopWidget::windows();
176     QStringList titles;
177     foreach (WId window, windows)
178     titles += QxtDesktopWidget::windowTitle(window);
179     return titles;
180 }