A
download qsizegrip.cpp
Language: C++
License: GPL
Copyright: (C) 1992-2006 Trolltech ASA. All rights reserved.
LOC: 206
Project Info
qt-copy
Server: KDE Repo
Type: svn
...py\qt‑copy\src\gui\widgets\
   qabstractbutton.cpp
   qabstractbutton.h
   qabstractbutton_p.h
   qabstractscrollarea.cpp
   qabstractscrollarea.h
   qabstractscrollarea_p.h
   qabstractslider.cpp
   qabstractslider.h
   qabstractslider_p.h
   qabstractspinbox.cpp
   qabstractspinbox.h
   qabstractspinbox_p.h
   qbuttongroup.cpp
   qbuttongroup.h
   qcalendarwidget.cpp
   qcalendarwidget.h
   qcheckbox.cpp
   qcheckbox.h
   qcombobox.cpp
   qcombobox.h
   qcombobox_p.h
   qdatetimeedit.cpp
   qdatetimeedit.h
   qdatetimeedit_p.h
   qdial.cpp
   qdial.h
   qdialogbuttonbox.cpp
   qdialogbuttonbox.h
   qdockwidget.cpp
   qdockwidget.h
   qdockwidget_p.h
   qdockwidgetlayout.cpp
   qdockwidgetlayout_p.h
   qeffects.cpp
   qeffects_p.h
   qfocusframe.cpp
   qfocusframe.h
   qfontcombobox.cpp
   qfontcombobox.h
   qframe.cpp
   qframe.h
   qframe_p.h
   qgroupbox.cpp
   qgroupbox.h
   qlabel.cpp
   qlabel.h
   qlabel_p.h
   qlcdnumber.cpp
   qlcdnumber.h
   qlineedit.cpp
   qlineedit.h
   qlineedit_p.h
   qmainwindow.cpp
   qmainwindow.h
   qmainwindowlayout.cpp
   qmainwindowlayout_p.h
   qmenu.cpp
   qmenu.h
   qmenu_p.h
   qmenubar.cpp
   qmenubar.h
   qmenubar_p.h
   qmenudata.cpp
   qmenudata.h
   qprogressbar.cpp
   qprogressbar.h
   qpushbutton.cpp
   qpushbutton.h
   qradiobutton.cpp
   qradiobutton.h
   qrubberband.cpp
   qrubberband.h
   qscrollarea.cpp
   qscrollarea.h
   qscrollarea_p.h
   qscrollbar.cpp
   qscrollbar.h
   qsizegrip.cpp
   qsizegrip.h
   qslider.cpp
   qslider.h
   qspinbox.cpp
   qspinbox.h
   qsplashscreen.cpp
   qsplashscreen.h
   qsplitter.cpp
   qsplitter.h
   qsplitter_p.h
   qstackedwidget.cpp
   qstackedwidget.h
   qstatusbar.cpp
   qstatusbar.h
   qtabbar.cpp
   qtabbar.h
   qtabbar_p.h
   qtabwidget.cpp
   qtabwidget.h
   qtextbrowser.cpp
   qtextbrowser.h
   qtextedit.cpp
   qtextedit.h
   qtextedit_p.h
   qtoolbar.cpp
   qtoolbar.h
   qtoolbar_p.h
   qtoolbarextension.cpp
   qtoolbarextension_p.h
   qtoolbarhandle.cpp
   qtoolbarhandle_p.h
   qtoolbarseparator.cpp
   qtoolbarseparator_p.h
   qtoolbox.cpp
   qtoolbox.h
   qtoolbutton.cpp
   qtoolbutton.h
   qvalidator.cpp
   qvalidator.h
   qwidgetanimator.cpp
   qwidgetanimator_p.h
   qwidgetresizehandler.cpp
   qwidgetresizehandler_p.h
   qworkspace.cpp
   qworkspace.h
   widgets.pri

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
/****************************************************************************
**
** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** This file may be used under the terms of the GNU General Public
** License version 2.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file.  Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
** http://www.trolltech.com/products/qt/opensource.html
**
** If you are unsure which license is appropriate for your use, please
** review the following information:
** http://www.trolltech.com/products/qt/licensing.html or contact the
** sales department at sales@trolltech.com.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/

#include "qsizegrip.h"

#ifndef QT_NO_SIZEGRIP

#include "qapplication.h"
#include "qevent.h"
#include "qpainter.h"
#include "qstyle.h"
#include "qstyleoption.h"
#include "qdebug.h"

#if defined(Q_WS_X11)
#include <private/qt_x11_p.h>
#elif defined (Q_WS_WIN)
#include "qt_windows.h"
#endif
#ifdef Q_WS_MAC
#include <private/qt_mac_p.h>
#endif

#include <private/qwidget_p.h>

class QSizeGripPrivate : public QWidgetPrivate
{
    Q_DECLARE_PUBLIC(QSizeGrip)
public:
    void init();
    QPoint p;
    QRect r;
    int d;
    bool hiddenByUser;
    bool atBottom;
    bool gotMousePress;
};

static QWidget *qt_sizegrip_topLevelWidget(QWidget* w)
{
    while (!w->isWindow() && !(w->parentWidget()->windowType() == Qt::SubWindow))
        w = w->parentWidget();
    return w;
}

static bool qt_sizegrip_atBottom(QWidget* sg)
{
    QWidget *tlw = qt_sizegrip_topLevelWidget(sg);
    return tlw->mapFromGlobal(sg->mapToGlobal(QPoint(0, 0))).y() >= (tlw->height() / 2);
}

/*!
    \class QSizeGrip

    \brief The QSizeGrip class provides a corner-grip for resizing a top-level window.

    \ingroup application
    \ingroup basic
    \ingroup appearance

    This widget works like the standard Windows resize handle. In the
    X11 version this resize handle generally works differently from
    the one provided by the system; we hope to reduce this difference
    in the future.

    Put this widget anywhere in a widget tree and the user can use it
    to resize the top-level window. Generally, this should be in the
    lower right-hand corner. Note that QStatusBar already uses this
    widget, so if you have a status bar (e.g. you are using
    QMainWindow), then you don't need to use this widget explicitly.

    On some platforms the sizegrip automatically hides itself when the
    window is shown full screen or maximised.

    \table 50%
    \row \o \inlineimage plastique-sizegrip.png Screenshot of a Plastique style size grip
    \o A size grip widget at the bottom-right corner of a main window, shown in the
    \l{Plastique Style Widget Gallery}{Plastique widget style}.
    \endtable

    The QSizeGrip class inherits QWidget and reimplements the \l
    {QWidget::mousePressEvent()}{mousePressEvent()} and \l
    {QWidget::mouseMoveEvent()}{mouseMoveEvent()} functions to feature
    the resize functionality, and the \l
    {QWidget::paintEvent()}{paintEvent()} function to render the
    sizegrip widget.

    \sa QStatusBar QWidget::windowState()
*/


/*!
    Constructs a resize corner as a child widget of  the given \a
    parent.
*/
QSizeGrip::QSizeGrip(QWidget * parent)
    : QWidget(*new QSizeGripPrivate, parent, 0)
{
    Q_D(QSizeGrip);
    d->init();
}

#ifdef QT3_SUPPORT
/*!
    \obsolete

    Constructs a resize corner with the given \a name, as a child
    widget of the given \a parent.
*/
QSizeGrip::QSizeGrip(QWidget * parent, const char* name)
    : QWidget(*new QSizeGripPrivate, parent, 0)
{
    Q_D(QSizeGrip);
    setObjectName(QString::fromAscii(name));
    d->init();
}
#endif

void QSizeGripPrivate::init()
{
    Q_Q(QSizeGrip);
    hiddenByUser = false;
    atBottom = qt_sizegrip_atBottom(q);
    gotMousePress = false;

#ifndef QT_NO_CURSOR
#ifndef Q_WS_MAC
    q->setCursor(q->isRightToLeft() ^ atBottom ? Qt::SizeFDiagCursor : Qt::SizeBDiagCursor);
#endif
#endif
    q->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed));
    QWidget *tlw = qt_sizegrip_topLevelWidget(q);
    tlw->installEventFilter(q);
}


/*!
    Destroys this size grip.
*/
QSizeGrip::~QSizeGrip()
{
}

/*!
  \reimp
*/
QSize QSizeGrip::sizeHint() const
{
    QStyleOption opt(0);
    opt.init(this);
    return (style()->sizeFromContents(QStyle::CT_SizeGrip, &opt, QSize(13, 13), this).
            expandedTo(QApplication::globalStrut()));
}

/*!
    Paints the resize grip.

    Resize grips are usually rendered as small diagonal textured lines
    in the lower-right corner. The paint event is passed in the \a
    event parameter.
*/
void QSizeGrip::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);
    Q_D(QSizeGrip);
    if (d->p.isNull()) { // update "bottomness" unless we are resizing
#ifndef QT_NO_CURSOR
#ifndef Q_WS_MAC
        if (qt_sizegrip_atBottom(this) != d->atBottom) {
            d->atBottom = !d->atBottom;
            setCursor(isRightToLeft() ^ d->atBottom ? Qt::SizeFDiagCursor : Qt::SizeBDiagCursor);
        }
#endif
#endif
    }
    QPainter painter(this);
    QStyleOptionSizeGrip opt;
    opt.init(this);
    if (isRightToLeft())
        opt.corner = d->atBottom ? Qt::BottomLeftCorner : Qt::TopLeftCorner;
    else
        opt.corner = d->atBottom ? Qt::BottomRightCorner : Qt::TopRightCorner;
    style()->drawControl(QStyle::CE_SizeGrip, &opt, &painter, this);
}

/*!
    \fn void QSizeGrip::mousePressEvent(QMouseEvent * event)

    Receives the mouse press events for the widget, and primes the
    resize operation. The mouse press event is passed in the \a event
    parameter.
*/
void QSizeGrip::mousePressEvent(QMouseEvent * e)
{
    Q_D(QSizeGrip);
    d->gotMousePress = true;
    d->p = e->globalPos();
    d->r = qt_sizegrip_topLevelWidget(this)->geometry();
}


/*!
    \fn void QSizeGrip::mouseMoveEvent(QMouseEvent * event)
    Resizes the top-level widget containing this widget. The mouse
    move event is passed in the \a event parameter.
*/
void QSizeGrip::mouseMoveEvent(QMouseEvent * e)
{
    if (e->buttons() != Qt::LeftButton)
        return;

    Q_D(QSizeGrip);
    if (d->gotMousePress == false)
        return;

    QWidget* tlw = qt_sizegrip_topLevelWidget(this);
    if (tlw->testAttribute(Qt::WA_WState_ConfigPending))
        return;

    QPoint np(e->globalPos());

    if (!tlw->isWindow()) {
        QWidget* ws = tlw->parentWidget()->parentWidget();
        QPoint tmp(ws->mapFromGlobal(np));
        if (tmp.x() > ws->width())
            tmp.setX(ws->width());
        if (tmp.y() > ws->height())
            tmp.setY(ws->height());
        np = ws->mapToGlobal(tmp);
    }

    QSize ns;
    if (d->atBottom)
        ns.rheight() = np.y() - d->p.y() + d->r.height();
    else
        ns.rheight() = d->r.height() - (np.y() - d->p.y());

    if (isRightToLeft())
        ns.rwidth() = d->r.width() - (np.x() - d->p.x());
    else
        ns.rwidth() = np.x() - d->p.x() + d->r.width();

    ns = ns.expandedTo(tlw->minimumSize()).expandedTo(tlw->minimumSizeHint()).boundedTo(tlw->maximumSize());

    QPoint p;
    QRect nr(p, ns);
    if (d->atBottom) {
        if (isRightToLeft())
            nr.moveTopRight(d->r.topRight());
        else
            nr.moveTopLeft(d->r.topLeft());
    } else {
        if (isRightToLeft())
            nr.moveBottomRight(d->r.bottomRight());
        else
            nr.moveBottomLeft(d->r.bottomLeft());
    }

    tlw->setGeometry(nr);

#ifdef Q_WS_WIN
    MSG msg;
    while(PeekMessage(&msg, winId(), WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE))
      ;
#endif
}

/*! \reimp */
void QSizeGrip::setVisible(bool visible)
{
    Q_D(QSizeGrip);
    d->hiddenByUser = !visible;
    QWidget::setVisible(visible);
}


/*! \reimp */
bool QSizeGrip::eventFilter(QObject *o, QEvent *e)
{
    Q_D(QSizeGrip);
    QWidget *tlw = qt_sizegrip_topLevelWidget(this);
    if (!d->hiddenByUser && e->type() == QEvent::WindowStateChange && o == tlw) {
        QWidget::setVisible((tlw->windowState() &
                             (Qt::WindowFullScreen
#ifndef Q_WS_MAC
                              | Qt::WindowMaximized
#endif
                              ))==0);
    }
    return false;
}

/*! \reimp */
bool QSizeGrip::event(QEvent *e)
{
    Q_D(QSizeGrip);
    switch(e->type()) {
#if defined(Q_WS_MAC)
    case QEvent::Hide:
    case QEvent::Show:
        d->atBottom = qt_sizegrip_atBottom(this);
        if(!QApplication::closingDown() && parentWidget()) {
            if(QWidget *w = qt_sizegrip_topLevelWidget(this)) {
                if(w->isWindow())
                    QWidgetPrivate::qt_mac_update_sizer(w, e->type() == QEvent::Hide ? -1 : 1);
            }
        }
        break;
#endif
    case QEvent::MouseButtonRelease:
        d->gotMousePress = false;
        d->p = QPoint();
        break;
    default:
        break;
    }
    return QWidget::event(e);
}

#endif //QT_NO_SIZEGRIP

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us