⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qsizegrip.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************** Copyright (C) 1992-2007 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://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** 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"#include <QDesktopWidget>#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>#include <QtGui/qabstractscrollarea.h>#define SZ_SIZEBOTTOMRIGHT  0xf008#define SZ_SIZEBOTTOMLEFT   0xf007#define SZ_SIZETOPLEFT      0xf004#define SZ_SIZETOPRIGHT     0xf005static QWidget *qt_sizegrip_topLevelWidget(QWidget* w){    while (w && !w->isWindow() && w->windowType() != Qt::SubWindow)        w = w->parentWidget();    return w;}class QSizeGripPrivate : public QWidgetPrivate{    Q_DECLARE_PUBLIC(QSizeGrip)public:    void init();    QPoint p;    QRect r;    int d;    int dxMax;    int dyMax;    bool hiddenByUser;    Qt::Corner m_corner;    bool gotMousePress;#ifdef Q_WS_MAC    void updateMacSizer(bool hide) const;#endif    Qt::Corner corner() const;    inline bool atBottom() const    {        return m_corner == Qt::BottomRightCorner || m_corner == Qt::BottomLeftCorner;    }    inline bool atLeft() const    {        return m_corner == Qt::BottomLeftCorner || m_corner == Qt::TopLeftCorner;    }};#ifdef Q_WS_MACvoid QSizeGripPrivate::updateMacSizer(bool hide) const{    Q_Q(const QSizeGrip);    if (QApplication::closingDown() || !q->parentWidget())        return;    QWidget *topLevelWindow = qt_sizegrip_topLevelWidget(const_cast<QSizeGrip *>(q));    if(topLevelWindow && topLevelWindow->isWindow())        QWidgetPrivate::qt_mac_update_sizer(topLevelWindow, hide ? -1 : 1);}#endifQt::Corner QSizeGripPrivate::corner() const{    Q_Q(const QSizeGrip);    QWidget *tlw = qt_sizegrip_topLevelWidget(const_cast<QSizeGrip *>(q));    const QPoint sizeGripPos = q->mapTo(tlw, QPoint(0, 0));    const QPoint globalPos = tlw->mapFromGlobal(q->mapToGlobal(QPoint(0, 0)));    bool isAtBottom = sizeGripPos.y() >= tlw->height() / 2;    bool isAtLeft = sizeGripPos.x() <= tlw->width() / 2;    if (isAtLeft)        return isAtBottom ? Qt::BottomLeftCorner : Qt::TopLeftCorner;    else        return isAtBottom ? Qt::BottomRightCorner : Qt::TopRightCorner;}/*!    \class QSizeGrip    \brief The QSizeGrip class provides a resize handle for resizing top-level windows.    \ingroup application    \ingroup basicwidgets    \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 if the X11 window manager does not    support necessary modern post-ICCCM specifications.    Put this widget anywhere in a widget tree and the user can use it    to resize the top-level window or any widget with the Qt::SubWindow    flag set. 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 size grip 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    size grip 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();}#endifvoid QSizeGripPrivate::init(){    Q_Q(QSizeGrip);    dxMax = 0;    dyMax = 0;    hiddenByUser = false;    m_corner = corner();    gotMousePress = false;#if !defined(QT_NO_CURSOR) && !defined(Q_WS_MAC)    q->setCursor(m_corner == Qt::TopLeftCorner || m_corner == Qt::BottomRightCorner                 ? Qt::SizeFDiagCursor : Qt::SizeBDiagCursor);#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);    QPainter painter(this);    QStyleOptionSizeGrip opt;    opt.init(this);    opt.corner = d->m_corner;    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){    if (e->button() != Qt::LeftButton) {        QWidget::mousePressEvent(e);        return;    }    Q_D(QSizeGrip);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -