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

📄 qwidget.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************** 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 "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"#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#endif#include "qpainter.h"#include "qtooltip.h"#include "qwhatsthis.h"#include "qdebug.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 "qwidget_p.h"#include "qaction_p.h"#include "qlayout_p.h"QWidgetPrivate::QWidgetPrivate(int version) :        QObjectPrivate(version), extra(0), focus_child(0)        ,layout(0)        ,leftmargin(0), topmargin(0), rightmargin(0), bottommargin(0)        ,fg_role(QPalette::NoRole)        ,bg_role(QPalette::NoRole)        ,hd(0)#if defined(Q_WS_X11)        ,picture(0)#elif defined(Q_WS_MAC)        ,cg_hd(0)#endif        ,polished(0){    if (!qApp) {        qFatal("QWidget: Must construct a QApplication before a QPaintDevice");        return;    }    if (version != QObjectPrivateVersion)        qFatal("Cannot mix incompatible Qt libraries");    isWidget = true;    memset(high_attributes, 0, sizeof(high_attributes));}QWidgetPrivate::~QWidgetPrivate(){    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                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;}/*!    Sets whether this widget has edit focus.  If a widget has edit focus    Qt::Key_Up and Qt::Key_Down will be delivered to the widget normally,    otherwise they 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)) {        update();        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);    }    update();}#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.    \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();}/*!    \class QWidget    \brief The QWidget class is the base class of all user interface objects.    \ingroup abstractwidgets    \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.    A widget without a parent widget is always an independent window.    Non-window widgets are child widgets. These are child windows    in their parent widgets. You cannot usually distinguish a child    widget from its parent visually. Most other widgets in Qt are    useful only as child widgets. (It is possible to make, say, a    button into a window, but most people prefer to put    their buttons inside other widgets, e.g. QDialog.)    If you want to use a QWidget to hold child widgets you will    probably want to add a layout to the parent QWidget. (See \link    layout.html Layouts\endlink.)    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 QPushButton, QListWidget and    QTabWidget, etc.    \section1 Groups of functions:    \table    \header \i Context \i Functions    \row \i Window functions \i        show(),        hide(),        raise(),        lower(),        close().    \row \i Top-level windows \i        isWindowModified(),        setWindowModified(),        windowTitle(),        setWindowTitle(),        windowIcon(),        setWindowIcon(),        windowIconText(),        setWindowIconText(),        isActiveWindow(),        activateWindow(),        showMinimized().        showMaximized(),        showFullScreen(),        showNormal().    \row \i Window contents \i        update(),        repaint(),        scroll().    \row \i Geometry \i        pos(),        size(),        rect(),        x(),        y(),        width(),        height(),        sizePolicy(),        setSizePolicy(),        sizeHint(),        updateGeometry(),        layout(),        move(),        resize(),        setGeometry(),        frameGeometry(),        geometry(),        childrenRect(),        adjustSize(),        mapFromGlobal(),        mapFromParent()        mapToGlobal(),        mapToParent(),        maximumSize(),        minimumSize(),        sizeIncrement(),        setMaximumSize(),        setMinimumSize(),        setSizeIncrement(),        setBaseSize(),        setFixedSize()    \row \i Mode \i        isVisible(),        isVisibleTo(),        isMinimized(),        isEnabled(),        isEnabledTo(),        isModal(),        isWindow(),        setEnabled(),        hasMouseTracking(),        setMouseTracking(),        updatesEnabled(),        setUpdatesEnabled(),        visibleRegion().    \row \i Look and feel \i        style(),        setStyle(),        cursor(),

⌨️ 快捷键说明

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