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

📄 qwidget_x11.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    // set X11 event mask    if (desktop) {//         QWidget* main_desktop = find(id);//         if (main_desktop->testWFlags(Qt::WPaintDesktop))//             XSelectInput(dpy, id, stdDesktopEventMask | ExposureMask);//         else        XSelectInput(dpy, id, stdDesktopEventMask);    } else {        XSelectInput(dpy, id, stdWidgetEventMask);#if !defined (QT_NO_TABLET)        QTabletDeviceDataList *tablet_list = qt_tablet_devices();        for (int i = 0; i < tablet_list->size(); ++i) {            QTabletDeviceData tablet = tablet_list->at(i);            XSelectExtensionEvent(dpy, id, reinterpret_cast<XEventClass*>(tablet.eventList),                                  tablet.eventCount);        }#endif    }    if (desktop) {        q->setAttribute(Qt::WA_WState_Visible);    } else if (topLevel) {                        // set X cursor        if (initializeWindow) {            qt_x11_enforce_cursor(q);            if (QTLWExtra *topData = maybeTopData())                setWindowTitle_helper(topData->caption);            //always enable dnd: it's not worth the effort to maintain the state            // NOTE: this always creates topData()            X11->dndEnable(q, true);            if (maybeTopData() && maybeTopData()->opacity != 255)                q->setWindowOpacity(maybeTopData()->opacity/255.);        }    } else {        if (q->testAttribute(Qt::WA_SetCursor))            qt_x11_enforce_cursor(q);    }    if (extra && !extra->mask.isEmpty())        XShapeCombineRegion(X11->display, q->internalWinId(), ShapeBounding, 0, 0,                            extra->mask.handle(), ShapeSet);    if (q->hasFocus() && q->testAttribute(Qt::WA_InputMethodEnabled)) {        QInputContext *inputContext = q->inputContext();        if (inputContext)            inputContext->setFocusWidget(q);    }    if (destroyw)        qt_XDestroyWindow(q, dpy, destroyw);    // newly created windows are positioned at the window system's    // (0,0) position. If the parent uses wrect mapping to expand the    // coordinate system, we must also adjust this widget's window    // system position    if (!topLevel && !parentWidget->data->wrect.topLeft().isNull())        setWSGeometry();    else if (topLevel && (data.crect.width() == 0 || data.crect.height() == 0))        q->setAttribute(Qt::WA_OutsideWSRange, true);}/*!    Frees up window system resources. Destroys the widget window if \a    destroyWindow is true.    destroy() calls itself recursively for all the child widgets,    passing \a destroySubWindows for the \a destroyWindow parameter.    To have more control over destruction of subwidgets, destroy    subwidgets selectively first.    This function is usually called from the QWidget destructor.*/void QWidget::destroy(bool destroyWindow, bool destroySubWindows){    Q_D(QWidget);    if (!isWindow() && parentWidget())        parentWidget()->d_func()->invalidateBuffer(geometry());    d->deactivateWidgetCleanup();    if (testAttribute(Qt::WA_WState_Created)) {        setAttribute(Qt::WA_WState_Created, false);        QObjectList childList = children();        for (int i = 0; i < childList.size(); ++i) { // destroy all widget children            register QObject *obj = childList.at(i);            if (obj->isWidgetType())                static_cast<QWidget*>(obj)->destroy(destroySubWindows,                                                    destroySubWindows);        }        if (mouseGrb == this)            releaseMouse();        if (keyboardGrb == this)            releaseKeyboard();        if (isWindow())            X11->deferred_map.removeAll(this);        if (isModal()) {            // just be sure we leave modal            QApplicationPrivate::leaveModal(this);        }        else if ((windowType() == Qt::Popup))            qApp->d_func()->closePopup(this);#ifndef QT_NO_XRENDER        if (d->picture) {            if (destroyWindow)                XRenderFreePicture(X11->display, d->picture);            d->picture = 0;        }#endif // QT_NO_XRENDER        if ((windowType() == Qt::Desktop)) {            if (acceptDrops())                X11->dndEnable(this, false);        } else {            if (isWindow())                X11->dndEnable(this, false);            if (destroyWindow)                qt_XDestroyWindow(this, X11->display, data->winid);        }        d->setWinId(0);        extern void qPRCleanup(QWidget *widget); // from qapplication_x11.cpp        if (testAttribute(Qt::WA_WState_Reparented))            qPRCleanup(this);        if(d->ic) {            delete d->ic;        } else {            // release previous focus information participating with            // preedit preservation of qic            QInputContext *qic = inputContext();            if (qic)                qic->widgetDestroyed(this);        }    }}void QWidgetPrivate::setParent_sys(QWidget *parent, Qt::WindowFlags f){    Q_Q(QWidget);    QTLWExtra *topData = maybeTopData();    bool wasCreated = q->testAttribute(Qt::WA_WState_Created);    if (q->isVisible() && q->parentWidget() && parent != q->parentWidget())        q->parentWidget()->d_func()->invalidateBuffer(q->geometry());    extern void qPRCreate(const QWidget *, Window);    QCursor oldcurs;    // dnd unregister (we will register again below)    if (q->testAttribute(Qt::WA_DropSiteRegistered))        q->setAttribute(Qt::WA_DropSiteRegistered, false);    // if we are a top then remove our dnd prop for now    // it will get rest later    if (q->isWindow() && wasCreated)        X11->dndEnable(q, false);//     QWidget *oldparent = q->parentWidget();    WId old_winid = wasCreated ? data.winid : 0;    if ((q->windowType() == Qt::Desktop))        old_winid = 0;    setWinId(0);#ifndef QT_NO_XRENDER    if (picture) {        XRenderFreePicture(X11->display, picture);        picture = 0;    }#endif    // hide and reparent our own window away. Otherwise we might get    // destroyed when emitting the child remove event below. See QWorkspace.    if (wasCreated) {        XUnmapWindow(X11->display, old_winid);        XReparentWindow(X11->display, old_winid, RootWindow(X11->display, xinfo.screen()), 0, 0);    }    if (topData) {        topData->parentWinId = 0;        // zero the frame strut and mark it dirty        topData->frameStrut.setCoords(0, 0, 0, 0);        // reparenting from top-level, make sure show() works again        topData->waitingForMapNotify = 0;        topData->validWMState = 0;    }    data.fstrut_dirty = (!parent || (f & Qt::Window)); // toplevels get a dirty framestrut    QObjectPrivate::setParent_helper(parent);    bool explicitlyHidden = q->testAttribute(Qt::WA_WState_Hidden) && q->testAttribute(Qt::WA_WState_ExplicitShowHide);    data.window_flags = f;    q->setAttribute(Qt::WA_WState_Created, false);    q->setAttribute(Qt::WA_WState_Visible, false);    q->setAttribute(Qt::WA_WState_Hidden, false);    adjustFlags(data.window_flags, q);    // keep compatibility with previous versions, we need to preserve the created state    // (but we recreate the winId for the widget being reparented, again for compatibility)    if (wasCreated || (!q->isWindow() && parent->testAttribute(Qt::WA_WState_Created)))        createWinId();    if (q->isWindow() || (!parent || parent->isVisible()) || explicitlyHidden)        q->setAttribute(Qt::WA_WState_Hidden);    q->setAttribute(Qt::WA_WState_ExplicitShowHide, explicitlyHidden);    if (wasCreated) {        QObjectList chlist = q->children();        for (int i = 0; i < chlist.size(); ++i) { // reparent children            QObject *obj = chlist.at(i);            if (obj->isWidgetType()) {                QWidget *w = (QWidget *)obj;                if (!w->testAttribute(Qt::WA_WState_Created))                    continue;                if (xinfo.screen() != w->d_func()->xinfo.screen()) {                    // ### force setParent() to not shortcut out (because                    // ### we're setting the parent to the current parent)                    w->d_func()->parent = 0;                    w->setParent(q);                } else if (!w->isWindow()) {                    w->d_func()->invalidateBuffer(w->rect());                    XReparentWindow(X11->display, w->internalWinId(), q->internalWinId(),                                    w->geometry().x(), w->geometry().y());                } else if (isTransient(w)) {                    /*                      when reparenting toplevel windows with toplevel-transient children,                      we need to make sure that the window manager gets the updated                      WM_TRANSIENT_FOR information... unfortunately, some window managers                      don't handle changing WM_TRANSIENT_FOR before the toplevel window is                      visible, so we unmap and remap all toplevel-transient children *after*                      the toplevel parent has been mapped.  thankfully, this is easy in Qt :)                      note that the WM_TRANSIENT_FOR hint is actually updated in                      QWidgetPrivate::show_sys()                    */                    XUnmapWindow(X11->display, w->internalWinId());                    QApplication::postEvent(w, new QEvent(QEvent::ShowWindowRequest));                }            }        }        qPRCreate(q, old_winid);        updateSystemBackground();        if (old_winid)            qt_XDestroyWindow(q, X11->display, old_winid);    }    // check if we need to register our dropsite    if (q->testAttribute(Qt::WA_AcceptDrops)        || (!q->isWindow() && q->parentWidget() && q->parentWidget()->testAttribute(Qt::WA_DropSiteRegistered))) {        q->setAttribute(Qt::WA_DropSiteRegistered, true);    }#if !defined(QT_NO_IM)    ic = 0;#endif    invalidateBuffer(q->rect());}/*!    Translates the widget coordinate \a pos to global screen    coordinates. For example, \c{mapToGlobal(QPoint(0,0))} would give    the global coordinates of the top-left pixel of the widget.    \sa mapFromGlobal() mapTo() mapToParent()*/QPoint QWidget::mapToGlobal(const QPoint &pos) const{    Q_D(const QWidget);    if (!testAttribute(Qt::WA_WState_Created)) {        QPoint p = pos + data->crect.topLeft();        //cannot trust that !isWindow() implies parentWidget() before create        return (isWindow() || !parentWidget()) ?  p : parentWidget()->mapToGlobal(p);    }    int           x, y;    Window child;    QPoint p = d->mapToWS(pos);    XTranslateCoordinates(X11->display, internalWinId(),                          QApplication::desktop()->screen(d->xinfo.screen())->internalWinId(),                          p.x(), p.y(), &x, &y, &child);    return QPoint(x, y);}/*!    Translates the global screen coordinate \a pos to widget    coordinates.    \sa mapToGlobal() mapFrom() mapFromParent()*/QPoint QWidget::mapFromGlobal(const QPoint &pos) const{    Q_D(const QWidget);    if (!testAttribute(Qt::WA_WState_Created)) {        //cannot trust that !isWindow() implies parentWidget() before create        QPoint p = (isWindow() || !parentWidget()) ?  pos : parentWidget()->mapFromGlobal(pos);        return p - data->crect.topLeft();    }    int           x, y;    Window child;    XTranslateCoordinates(X11->display,                          QApplication::desktop()->screen(d->xinfo.screen())->internalWinId(),                          internalWinId(), pos.x(), pos.y(), &x, &y, &child);    return d->mapFromWS(QPoint(x, y));}void QWidgetPrivate::updateSystemBackground(){    Q_Q(QWidget);    if (!q->testAttribute(Qt::WA_WState_Created))        return;    QBrush brush = q->palette().brush(QPalette::Active, q->backgroundRole());    Qt::WindowType type = q->windowType();    if (brush.style() == Qt::NoBrush        || q->testAttribute(Qt::WA_NoSystemBackground)        || q->testAttribute(Qt::WA_UpdatesDisabled)        || type == Qt::Popup || type == Qt::ToolTip        )        XSetWindowBackgroundPixmap(X11->display, q->internalWinId(), XNone);    else if (brush.style() == Qt::SolidPattern && brush.isOpaque())        XSetWindowBackground(X11->display, q->internalWinId(),                             QColormap::instance(xinfo.screen()).pixel(brush.color()));    else if (isBackgroundInherited())        XSetWindowBackgroundPixmap(X11->display, q->internalWinId(), ParentRelative);    else if (brush.style() == Qt::TexturePattern)        XSetWindowBackgroundPixmap(X11->display, q->internalWinId(),                                   brush.texture().data->x11ConvertToDefaultDepth());    else        XSetWindowBackground(X11->display, q->internalWinId(),                             QColormap::instance(xinfo.screen()).pixel(brush.color()));}void QWidgetPrivate::setCursor_sys(const QCursor &){    Q_Q(QWidget);    qt_x11_enforce_cursor(q);    XFlush(X11->display);}void QWidgetPrivate::unsetCursor_sys(){    Q_Q(QWidget);    qt_x11_enforce_cursor(q);    XFlush(X11->display);}static XTextProperty*qstring_to_xtp(const QString& s){    static XTextProperty tp = { 0, 0, 0, 0 };    static bool free_prop = true; // we can't free tp.value in case it references    // the data of the static QCString below.    if (tp.value) {        if (free_prop)            XFree(tp.value);        tp.value = 0;        free_prop = true;    }

⌨️ 快捷键说明

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