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

📄 qwidget.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************** 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 "qapplication.h"#include "qapplication_p.h"#include "qbrush.h"#include "qcursor.h"#include "qdesktopwidget.h"#include "qevent.h"#include "qhash.h"#include "qlayout.h"#include "qmenu.h"#include "qmetaobject.h"#include "qpixmap.h"#include "qpointer.h"#include "qstack.h"#include "qstyle.h"#include "qstylefactory.h"#include "qvariant.h"#include "qwidget.h"#include "qstyleoption.h"#ifndef QT_NO_ACCESSIBILITY# include "qaccessible.h"#endif#if defined(Q_WS_WIN)# include "qt_windows.h"#endif#ifdef Q_WS_MAC# include "qt_mac_p.h"#endif#if defined(Q_WS_QWS)# include "qwsmanager_qws.h"# include "qpaintengine.h" // for PorterDuff# include "private/qwindowsurface_qws_p.h"#endif#include "qpainter.h"#include "qtooltip.h"#include "qwhatsthis.h"#include "qdebug.h"#include "private/qstylesheetstyle_p.h"#include "private/qstyle_p.h"#include "qinputcontext.h"#ifdef Q_WS_WIN# include <private/qwininputcontext_p.h>#endif#if defined(Q_WS_X11)# include <private/qpaintengine_x11_p.h># include "qx11info_x11.h"#endif#include <private/qwindowsurface_p.h>#ifndef Q_WS_MAC# include <private/qbackingstore_p.h>#else# include <private/qpaintengine_mac_p.h>#endif#include "qwidget_p.h"#include "qaction_p.h"#include "qlayout_p.h"// widget/widget data creation count//#define QWIDGET_EXTRA_DEBUGQWidgetPrivate::QWidgetPrivate(int version) :        QObjectPrivate(version), extra(0), focus_child(0)        ,layout(0)        ,leftmargin(0), topmargin(0), rightmargin(0), bottommargin(0)        ,leftLayoutItemMargin(0), topLayoutItemMargin(0), rightLayoutItemMargin(0)        ,bottomLayoutItemMargin(0)        ,fg_role(QPalette::NoRole)        ,bg_role(QPalette::NoRole)        ,hd(0)#ifdef Q_RATE_LIMIT_PAINTING        ,timerId(-1)#endif#if defined(Q_WS_X11)        ,picture(0)#endif#ifdef Q_WS_MAC        ,isGLWidget(0)#endif        ,polished(0)        , size_policy(QSizePolicy::Preferred, QSizePolicy::Preferred){    if (!qApp) {        qFatal("QWidget: Must construct a QApplication before a QPaintDevice");        return;    }    if (version != QObjectPrivateVersion)        qFatal("Cannot mix incompatible Qt libraries");#ifdef Q_WIDGET_CACHE_OPAQUEREGIONS    dirtyOpaqueChildren = true;#endif    isWidget = true;    memset(high_attributes, 0, sizeof(high_attributes));#ifdef QWIDGET_EXTRA_DEBUG    static int count = 0;    qDebug() << "widgets" << ++count;#endif}QWidgetPrivate::~QWidgetPrivate(){#ifdef Q_WIDGET_USE_DIRTYLIST    if (!dirty.isEmpty()) {        Q_Q(QWidget);        QWidgetBackingStore *bs = maybeBackingStore();        if (bs)            bs->removeDirtyWidget(q);    }#endif    if (extra)        deleteExtra();}/*!    \internal    This is an internal function, you should never call this.    This function is called to focus associated input context. The    code intends to eliminate duplicate focus for the context even if    the context is shared between widgets    \sa QInputContext::setFocus() */void QWidgetPrivate::focusInputContext(){#ifndef QT_NO_IM    Q_Q(QWidget);    QInputContext *qic = q->inputContext();    if (qic) {        if(qic->focusWidget() != q)            qic->setFocusWidget(q);    }#endif // QT_NO_IM}/*!    \internal*/void QWidgetPrivate::scrollChildren(int dx, int dy){    Q_Q(QWidget);    if (q->children().size() > 0) {        // scroll children        QPoint pd(dx, dy);        QObjectList childObjects = q->children();        for (int i = 0; i < childObjects.size(); ++i) { // move all children            QWidget *w = qobject_cast<QWidget*>(childObjects.at(i));            if (w && !w->isWindow()) {                QPoint oldp = w->pos();                QRect  r(w->pos() + pd, w->size());                w->data->crect = r;#ifndef Q_WS_QWS                if (w->testAttribute(Qt::WA_WState_Created))                    w->d_func()->setWSGeometry();#endif                QMoveEvent e(r.topLeft(), oldp);                QApplication::sendEvent(w, &e);            }        }    }}/*!    This function returns the QInputContext for this widget. By    default the input context is inherited from the widgets    parent. For toplevels it is inherited from QApplication.    You can override this and set a special input context for this    widget by using the setInputContext() method.    \sa setInputContext()*/QInputContext *QWidget::inputContext(){    Q_D(QWidget);    if (!testAttribute(Qt::WA_InputMethodEnabled))        return 0;#ifndef QT_NO_IM    if (d->ic)        return d->ic;#endif    return qApp->inputContext();}/*!  This function sets the input context \a context  on this widget.  \sa inputContext()*/void QWidget::setInputContext(QInputContext *context){    Q_D(QWidget);    if (!testAttribute(Qt::WA_InputMethodEnabled))        return;#ifndef QT_NO_IM    if (d->ic)        delete d->ic;    d->ic = context;#endif}/*!    This function can be called on the widget that currently has focus    to reset the input method operating on it.    \sa QInputContext, QInputContext::reset()*/void QWidget::resetInputContext(){    if (!hasFocus())        return;#ifndef QT_NO_IM    QInputContext *qic = this->inputContext();    if( qic )        qic->reset();#endif // QT_NO_IM}#ifdef QT_KEYPAD_NAVIGATIONQPointer<QWidget> QWidgetPrivate::editingWidget;/*!    Returns true if this widget currently has edit focus; otherwise false.    This feature is available in Qtopia Core only.    \sa setEditFocus(), QApplication::keypadNavigationEnabled()*/bool QWidget::hasEditFocus() const{    const QWidget* w = this;    while (w->d_func()->extra && w->d_func()->extra->focus_proxy)        w = w->d_func()->extra->focus_proxy;    return QWidgetPrivate::editingWidget == w;}/*!    \fn void QWidget::setEditFocus(bool enable)    If \a enable is true, make this widget have edit focus, in which    case Qt::Key_Up and Qt::Key_Down will be delivered to the widget    normally; otherwise, Qt::Key_Up and Qt::Key_Down are used to    change focus.    This feature is available in Qtopia Core only.    \sa hasEditFocus(), QApplication::keypadNavigationEnabled()*/void QWidget::setEditFocus(bool on){    QWidget *f = this;    while (f->d_func()->extra && f->d_func()->extra->focus_proxy)        f = f->d_func()->extra->focus_proxy;    if (QWidgetPrivate::editingWidget && QWidgetPrivate::editingWidget != f)        QWidgetPrivate::editingWidget->setEditFocus(false);    if (on && !f->hasFocus())        f->setFocus();    if ((!on && !QWidgetPrivate::editingWidget)        || (on && QWidgetPrivate::editingWidget == f)) {        return;    }    if (!on && QWidgetPrivate::editingWidget == f) {        QWidgetPrivate::editingWidget = 0;        QEvent event(QEvent::LeaveEditFocus);        QApplication::sendEvent(f, &event);        QApplication::sendEvent(f->style(), &event);    } else if (on) {        QWidgetPrivate::editingWidget = f;        QEvent event(QEvent::EnterEditFocus);        QApplication::sendEvent(f, &event);        QApplication::sendEvent(f->style(), &event);    }}#endif/*!    \property QWidget::autoFillBackground    \brief whether the widget background is filled automatically    \since 4.1    If enabled, this will cause Qt to fill the background    using the widget's background role before invoking    the paint event. The background role is defined by the widget's    \l{palette}.    In addition, Windows are always filled with QPalette::Window,    unless the WA_OpaquePaintEvent or WA_NoSystemBackground    attributes are set.    \warning Do not set this property when using \l{Qt Style Sheets}.    When using style sheets, the widget is always filled with the "background"    property. The "border-radius" property may be used to clip the background.    \sa Qt::WA_OpaquePaintEvent, Qt::WA_NoSystemBackground*/bool QWidget::autoFillBackground() const{    Q_D(const QWidget);    return d->extra && d->extra->autoFillBackground;}void QWidget::setAutoFillBackground(bool enabled){    Q_D(QWidget);    if (!d->extra)        d->createExtra();    if (d->extra->autoFillBackground == enabled)        return;    d->extra->autoFillBackground = enabled;    d->updateIsOpaque();    update();    d->updateIsOpaque();}/*!    \class QWidget    \brief The QWidget class is the base class of all user interface objects.    \ingroup basicwidgets    \mainclass    The widget is the atom of the user interface: it receives mouse,    keyboard and other events from the window system, and paints a    representation of itself on the screen. Every widget is    rectangular, and they are sorted in a Z-order. A widget is    clipped by its parent and by the widgets in front of it.    A widget that isn't embedded in a parent widget is called a    window. Usually, windows have a frame and a title bar, although    it is also possible to create windows without such decoration using    suitable \l{Qt::WindowFlags}{window flags}). In Qt,    QMainWindow and the various subclasses of QDialog are the most    common window types.    Every widget's constructor accepts one or two standard arguments:    \list 1    \i \c{QWidget *parent = 0} is the parent of the new widget.    If it is 0 (the default), the new widget will be a window.    If not, it will be a child of \e parent, and be constrained by \e    parent's geometry (unless you specify Qt::Window as    window flag).    \i \c{Qt::WindowFlags f = 0} (where available) sets the window flags; the    default is suitable for almost all widgets, but to get, for    example, a window without a window system frame, you    must use special flags.    \endlist    QWidget has many member functions, but some of them have little    direct functionality; for example, QWidget has a font property,    but never uses this itself. There are many subclasses which    provide real functionality, such as QLabel, QPushButton, QListWidget,    and QTabWidget.    \section1 Top-Level and Child Widgets    A widget without a parent widget is always an independent window    (top-level widget). For these widgets, setWindowTitle() and    setWindowIcon() set the title bar and icon respectively.    Non-window widgets are child widgets, and are displayed within

⌨️ 快捷键说明

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