2
* advwidget.cpp - AdvancedWidget template class
3
* Copyright (C) 2005 Michail Pishchagin
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2.1 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
#include "advwidget.h"
23
#include <qapplication.h>
24
#include <qwidgetlist.h>
32
// TODO: Make use of KDE taskbar flashing support
33
// TODO: Use FlashWindowEx instead of FlashWindow!
35
//----------------------------------------------------------------------------
36
// AdvancedWidgetShared
37
//----------------------------------------------------------------------------
39
class AdvancedWidgetShared : public QObject
43
AdvancedWidgetShared();
44
~AdvancedWidgetShared();
47
AdvancedWidgetShared::AdvancedWidgetShared()
52
AdvancedWidgetShared::~AdvancedWidgetShared()
56
static AdvancedWidgetShared *advancedWidgetShared = 0;
58
//----------------------------------------------------------------------------
59
// GAdvancedWidget::Private
60
//----------------------------------------------------------------------------
62
class GAdvancedWidget::Private : public QObject
66
Private(QWidget *parent);
69
static bool stickToWindows;
70
static bool stickEnabled;
72
QWidget *parentWidget;
75
void doFlash(bool on);
76
void posChanging(int *x, int *y, int *width, int *height);
86
int GAdvancedWidget::Private::stickAt = 5;
87
bool GAdvancedWidget::Private::stickToWindows = true;
88
bool GAdvancedWidget::Private::stickEnabled = true;
90
GAdvancedWidget::Private::Private(QWidget *parent)
93
if ( !advancedWidgetShared )
94
advancedWidgetShared = new AdvancedWidgetShared();
96
parentWidget = parent;
101
void GAdvancedWidget::Private::posChanging(int *x, int *y, int *width, int *height)
105
!parentWidget->isTopLevel() ||
106
parentWidget->isMaximized() ||
107
!parentWidget->isUpdatesEnabled() )
112
QWidget *p = parentWidget;
113
if ( p->pos() == QPoint(*x, *y) &&
114
p->frameSize() == QSize(*width, *height) )
117
bool resizing = p->frameSize() != QSize(*width, *height);
120
QDesktopWidget *desktop = qApp->desktop();
123
if ( stickToWindows )
124
list = QApplication::topLevelWidgets();
126
list = new QWidgetList();
127
list->append( desktop );
129
QWidgetListIt it( *list );
130
for ( ; (w = it.current()); ++it ) {
132
bool dockWidget = false;
134
if ( w->isDesktop() )
135
rect = ((QDesktopWidget *)w)->availableGeometry((QWidget *)parent());
138
desktop->screenNumber(p) != desktop->screenNumber(w) )
141
if ( !w->isVisible() )
144
// we want for widget to stick to outer edges of another widget, so
145
// we'll change the rect to what it'll snap
146
rect = QRect(w->frameGeometry().bottomRight(), w->frameGeometry().topLeft());
151
if ( *x <= rect.left() + stickAt &&
152
*x > rect.left() - stickAt ) {
154
(p->frameGeometry().bottom() >= rect.bottom() &&
155
p->frameGeometry().top() <= rect.top()) ) {
158
*width = p->frameSize().width() + p->x() - *x;
162
if ( *x + *width >= rect.right() - stickAt &&
163
*x + *width <= rect.right() + stickAt ) {
165
(p->frameGeometry().bottom() >= rect.bottom() &&
166
p->frameGeometry().top() <= rect.top()) ) {
168
*width = rect.right() - *x + 1;
170
*x = rect.right() - *width + 1;
175
if ( *y <= rect.top() + stickAt &&
176
*y > rect.top() - stickAt ) {
178
(p->frameGeometry().right() >= rect.right() &&
179
p->frameGeometry().left() <= rect.left()) ) {
182
*height = p->frameSize().height() + p->y() - *y;
186
if ( *y + *height >= rect.bottom() - stickAt &&
187
*y + *height <= rect.bottom() + stickAt ) {
189
(p->frameGeometry().right() >= rect.right() &&
190
p->frameGeometry().left() <= rect.left()) ) {
192
*height = rect.bottom() - *y + 1;
194
*y = rect.bottom() - *height + 1;
202
void GAdvancedWidget::Private::doFlash(bool yes)
208
flashTimer = new QTimer(this);
209
connect(flashTimer, SIGNAL(timeout()), SLOT(flashAnimate()));
211
flashAnimate(); // kick the first one immediately
212
flashTimer->start(500);
218
// comment this out to fix titlebar repaint on Windows??
219
//FlashWindow(winId(), false);
227
void GAdvancedWidget::Private::flashAnimate()
230
FlashWindow( parentWidget->winId(), true );
231
if ( ++flashCount == 5 )
236
bool GAdvancedWidget::Private::flashing()
245
//----------------------------------------------------------------------------
247
//----------------------------------------------------------------------------
249
GAdvancedWidget::GAdvancedWidget(QWidget *parent, const char *name)
250
: QObject(parent, name)
252
d = new Private(parent);
255
GAdvancedWidget::~GAdvancedWidget()
261
bool GAdvancedWidget::winEvent(MSG *msg)
263
if ( msg->message == WM_WINDOWPOSCHANGING ) {
264
WINDOWPOS *wpos = (WINDOWPOS *)msg->lParam;
266
d->posChanging(&wpos->x, &wpos->y, &wpos->cx, &wpos->cy);
275
void GAdvancedWidget::preSetCaption()
279
FlashWindow( d->parentWidget->winId(), true );
283
void GAdvancedWidget::postSetCaption()
287
FlashWindow( d->parentWidget->winId(), true );
291
void GAdvancedWidget::doFlash(bool on)
296
void GAdvancedWidget::windowActivationChange(bool oldstate)
298
if ( d->parentWidget->isActiveWindow() ) {
303
int GAdvancedWidget::stickAt()
305
return Private::stickAt;
308
void GAdvancedWidget::setStickAt(int val)
310
Private::stickAt = val;
313
bool GAdvancedWidget::stickToWindows()
315
return Private::stickToWindows;
318
void GAdvancedWidget::setStickToWindows(bool val)
320
Private::stickToWindows = val;
323
bool GAdvancedWidget::stickEnabled()
325
return Private::stickEnabled;
328
void GAdvancedWidget::setStickEnabled(bool val)
330
Private::stickEnabled = val;
333
#include "advwidget.moc"