~ubuntu-branches/ubuntu/quantal/psi/quantal

« back to all changes in this revision

Viewing changes to src/tools/advwidget/advwidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-04-14 18:57:30 UTC
  • mfrom: (2.1.9 hardy)
  • Revision ID: james.westby@ubuntu.com-20080414185730-528re3zp0m2hdlhi
Tags: 0.11-8
* added CONFIG -= link_prl to .pro files and removed dependencies
  which are made unnecessary by this change
* Fix segfault when closing last chat tab with qt4.4
  (This is from upstream svn, rev. 1101) (Closes: Bug#476122)

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
#include "advwidget.h"
22
22
 
23
 
#include <qapplication.h>
24
 
#include <qwidgetlist.h>
25
 
#include <qtimer.h>
 
23
#include <QApplication>
 
24
#include <QWidget>
 
25
#include <QTimer>
 
26
#include <QDesktopWidget>
26
27
 
27
28
#ifdef Q_OS_WIN
28
29
#include <windows.h>
74
75
        bool flashing();
75
76
        void doFlash(bool on);
76
77
        void posChanging(int *x, int *y, int *width, int *height);
 
78
        void moveEvent(QMoveEvent *e);
77
79
 
78
80
private:
79
81
        QTimer *flashTimer;
80
82
        int flashCount;
 
83
        QRect newGeometry;
81
84
 
82
85
private slots:
83
86
        void flashAnimate();
 
87
        void updateGeometry();
84
88
};
85
89
 
86
90
int  GAdvancedWidget::Private::stickAt        = 5;
104
108
            !stickEnabled                    ||
105
109
            !parentWidget->isTopLevel()      ||
106
110
             parentWidget->isMaximized()     ||
107
 
            !parentWidget->isUpdatesEnabled() )
 
111
            !parentWidget->updatesEnabled() )
108
112
        {
109
113
                return;
110
114
        }
116
120
 
117
121
        bool resizing = p->frameSize() != QSize(*width, *height);
118
122
 
119
 
        QWidget *w;
120
123
        QDesktopWidget *desktop = qApp->desktop();
121
 
        QWidgetList *list;
 
124
        QWidgetList list;
122
125
 
123
126
        if ( stickToWindows )
124
127
                list = QApplication::topLevelWidgets();
125
 
        else
126
 
                list = new QWidgetList();
127
 
        list->append( desktop );
128
128
 
129
 
        QWidgetListIt it( *list );
130
 
        for ( ; (w = it.current()); ++it ) {
 
129
        foreach(QWidget *w, list) {
131
130
                QRect rect;
132
131
                bool dockWidget = false;
133
132
 
134
 
                if ( w->isDesktop() )
 
133
                if ( w->windowType() == Qt::Desktop )
135
134
                        rect = ((QDesktopWidget *)w)->availableGeometry((QWidget *)parent());
136
135
                else {
137
136
                        if ( w == p ||
195
194
                        }
196
195
                }
197
196
        }
198
 
 
199
 
        delete list;
200
197
}
201
198
 
202
199
void GAdvancedWidget::Private::doFlash(bool yes)
235
232
 
236
233
bool GAdvancedWidget::Private::flashing()
237
234
{
238
 
        bool on = false;
239
 
        if ( flashTimer )
240
 
                on = flashCount & 1;
241
 
 
242
 
        return on;
 
235
        return flashTimer && flashCount & 1;
 
236
}
 
237
 
 
238
void GAdvancedWidget::Private::moveEvent(QMoveEvent *)
 
239
{
 
240
        if (!parentWidget->isTopLevel())
 
241
                return;
 
242
#ifdef Q_WS_MAC
 
243
        QRect r = qApp->desktop()->availableGeometry(parentWidget);
 
244
        QRect g = parentWidget->frameGeometry();
 
245
 
 
246
        int margin = 5;
 
247
 
 
248
        if (g.top() < r.top())
 
249
                g.moveTo(g.x(), r.top());
 
250
 
 
251
        if (g.right() < r.left() + margin)
 
252
                g.moveTo(r.left() + margin - g.width(), g.y());
 
253
 
 
254
        if (g.left() > r.right() - margin)
 
255
                g.moveTo(r.right() - margin, g.y());
 
256
 
 
257
        if (g.top() > r.bottom() - margin)
 
258
                g.moveTo(g.x(), r.bottom() - margin);
 
259
 
 
260
        newGeometry = g;
 
261
        QTimer::singleShot(0, this, SLOT(updateGeometry()));
 
262
#endif
 
263
}
 
264
 
 
265
void GAdvancedWidget::Private::updateGeometry()
 
266
{
 
267
        QWidget *w = (QWidget *)parent();
 
268
        w->move(newGeometry.topLeft());
243
269
}
244
270
 
245
271
//----------------------------------------------------------------------------
246
272
// GAdvancedWidget
247
273
//----------------------------------------------------------------------------
248
274
 
249
 
GAdvancedWidget::GAdvancedWidget(QWidget *parent, const char *name)
250
 
        : QObject(parent, name)
 
275
GAdvancedWidget::GAdvancedWidget(QWidget *parent)
 
276
        : QObject(parent)
251
277
{
252
278
        d = new Private(parent);
253
279
}
254
280
 
255
 
GAdvancedWidget::~GAdvancedWidget()
256
 
{
257
 
        delete d;
258
 
}
259
 
 
260
281
#ifdef Q_OS_WIN
261
282
bool GAdvancedWidget::winEvent(MSG *msg)
262
283
{
288
309
#endif
289
310
}
290
311
 
 
312
void GAdvancedWidget::restoreSavedGeometry(QRect savedGeometry)
 
313
{
 
314
        QRect geom = savedGeometry;
 
315
        QDesktopWidget *pdesktop = QApplication::desktop();
 
316
        int nscreen = pdesktop->screenNumber(geom.topLeft());
 
317
        QRect r = pdesktop->screenGeometry(nscreen);
 
318
 
 
319
        // if the coordinates are out of the desktop bounds, reset to the top left
 
320
        int pad = 10;
 
321
        if((geom.width() + pad * 2) > r.width())
 
322
                geom.setWidth(r.width() - pad * 2);
 
323
        if((geom.height() + pad * 2) > r.height())
 
324
                geom.setHeight(r.height() - pad * 2);
 
325
        if(geom.left() < r.left())
 
326
                geom.moveLeft(r.left());
 
327
        if(geom.right() >= r.right())
 
328
                geom.moveRight(r.right() - 1);
 
329
        if(geom.top() < r.top())
 
330
                geom.moveTop(r.top());
 
331
        if(geom.bottom() >= r.bottom())
 
332
                geom.moveBottom(r.bottom() - 1);
 
333
 
 
334
        d->parentWidget->move(geom.topLeft());
 
335
        d->parentWidget->resize(geom.size());
 
336
}
 
337
 
291
338
void GAdvancedWidget::doFlash(bool on)
292
339
{
293
340
        d->doFlash( on );
295
342
 
296
343
void GAdvancedWidget::windowActivationChange(bool oldstate)
297
344
{
 
345
        Q_UNUSED(oldstate);
298
346
        if ( d->parentWidget->isActiveWindow() ) {
299
347
                d->doFlash(false);
300
348
        }
330
378
        Private::stickEnabled = val;
331
379
}
332
380
 
 
381
void GAdvancedWidget::moveEvent(QMoveEvent *e)
 
382
{
 
383
        d->moveEvent(e);
 
384
}
 
385
 
333
386
#include "advwidget.moc"