void CSizeGrip::updateMacSizer(bool hide) const { if (QApplication::closingDown() || !parent) return; QWidget *topLevelWindow = qt_sizegrip_topLevelWidget(const_cast<CSizeGrip *>(this)); if(topLevelWindow && topLevelWindow->isWindow()) QWidget::qt_mac_update_sizer(topLevelWindow, hide ? -1 : 1); }
bool VPropertyFormWidget::eventFilter(QObject *object, QEvent *event) { if (!d_ptr->UpdateEditors) { return false; } QWidget* editor = qobject_cast<QWidget*>(object); if (!editor) { return false; } if (event->type() == QEvent::KeyPress) { switch (static_cast<QKeyEvent *>(event)->key()) { case Qt::Key_Tab: case Qt::Key_Backtab: case Qt::Key_Enter: case Qt::Key_Return: case Qt::Key_Escape: commitData(editor); event->accept(); return true; default: return false; } } else if (event->type() == QEvent::FocusOut || (event->type() == QEvent::Hide && editor->isWindow())) { commitData(editor); return false; } else if (event->type() == QEvent::ShortcutOverride) { if (static_cast<QKeyEvent*>(event)->key() == Qt::Key_Escape) { commitData(editor); event->accept(); return true; } } else if (event->type() == MyCustomEventType) { commitData(editor); event->accept(); return true; } else { return QGroupBox::eventFilter(object, event); } // Default: return false; }
/*! \internal Wraps the Motif dialog by setting the X window for the QtMotifDialog to the X window id of the dialog shell. */ void QtMotifDialog::realize( Widget w ) { // use the winid of the dialog shell, reparent any children we have if ( XtWindow( w ) != winId() ) { XSync(QtMotif::display(), FALSE); XtSetMappedWhenManaged( d->shell, False ); // save the window title QString wtitle = windowTitle(); if (wtitle.isEmpty()) { char *t = 0; XtVaGetValues(w, XtNtitle, &t, NULL); wtitle = QString::fromLocal8Bit(t); } setWindowTitle(QString()); // make sure setWindowTitle() works below QString icontext = windowIconText(); if (icontext.isEmpty()) { char *iconName = 0; XtVaGetValues(w, XtNiconName, &iconName, NULL); icontext = QString::fromLocal8Bit(iconName); } setWindowIconText(QString()); // make sure setWindowTitle() works below Window newid = XtWindow(w); QObjectList list = children(); for (int i = 0; i < list.size(); ++i) { QWidget *widget = qobject_cast<QWidget*>(list.at(i)); if (!widget || widget->isWindow()) continue; XReparentWindow(widget->x11Info().display(), widget->winId(), newid, widget->x(), widget->y()); } QApplication::syncX(); create( newid, true, true ); // restore the window title and icon text if (!wtitle.isEmpty()) setWindowTitle(wtitle); if (!icontext.isEmpty()) setWindowIconText(icontext); // if this dialog was created without a QWidget parent, then the transient // for will be set to the root window, which is not acceptable. // instead, set it to the window id of the shell's parent if ( ! parent() && XtParent( d->shell ) ) XSetTransientForHint(x11Info().display(), newid, XtWindow(XtParent(d->shell))); } QtMotif::registerWidget( this ); }
void AccessManager::setCookieJarWindowId(WId id) { QWidget* window = QWidget::find(id); if (!window) { return; } KIO::Integration::CookieJar *jar = qobject_cast<KIO::Integration::CookieJar *> (cookieJar()); if (jar) { jar->setWindowId(id); } d->window = window->isWindow() ? window : window->window(); }
void QWidgetWindow::handleDragEnterMoveEvent(QDragMoveEvent *event) { Q_ASSERT(event->type() ==QEvent::DragMove || !m_dragTarget); // Find a target widget under mouse that accepts drops (QTBUG-22987). QWidget *widget = m_widget->childAt(event->pos()); if (!widget) widget = m_widget; for ( ; widget && !widget->isWindow() && !widget->acceptDrops(); widget = widget->parentWidget()) ; if (widget && !widget->acceptDrops()) widget = 0; // Target widget unchanged: DragMove if (widget && widget == m_dragTarget.data()) { Q_ASSERT(event->type() == QEvent::DragMove); const QPoint mapped = widget->mapFromGlobal(m_widget->mapToGlobal(event->pos())); QDragMoveEvent translated(mapped, event->possibleActions(), event->mimeData(), event->mouseButtons(), event->keyboardModifiers()); translated.setDropAction(event->dropAction()); if (event->isAccepted()) { // Handling 'DragEnter' should suffice for the application. translated.accept(); translated.setDropAction(event->dropAction()); } QGuiApplication::sendSpontaneousEvent(widget, &translated); if (translated.isAccepted()) { event->accept(); } else { event->ignore(); } event->setDropAction(translated.dropAction()); return; } // Target widget changed: Send DragLeave to previous, DragEnter to new if there is any if (m_dragTarget.data()) { QDragLeaveEvent le; QGuiApplication::sendSpontaneousEvent(m_dragTarget.data(), &le); m_dragTarget = 0; } if (!widget) { event->ignore(); return; } m_dragTarget = widget; const QPoint mapped = widget->mapFromGlobal(m_widget->mapToGlobal(event->pos())); QDragEnterEvent translated(mapped, event->possibleActions(), event->mimeData(), event->mouseButtons(), event->keyboardModifiers()); QGuiApplication::sendSpontaneousEvent(widget, &translated); if (translated.isAccepted()) { event->accept(); } else { event->ignore(); } event->setDropAction(translated.dropAction()); }
void QToolBarAreaLayout::saveState(QDataStream &stream) const { // save toolbar state stream << (uchar) ToolBarStateMarkerEx; int lineCount = 0; for (int i = 0; i < QInternal::DockCount; ++i) lineCount += docks[i].lines.count(); stream << lineCount; for (int i = 0; i < QInternal::DockCount; ++i) { const QToolBarAreaLayoutInfo &dock = docks[i]; for (int j = 0; j < dock.lines.count(); ++j) { const QToolBarAreaLayoutLine &line = dock.lines.at(j); stream << i << line.toolBarItems.count(); for (int k = 0; k < line.toolBarItems.count(); ++k) { const QToolBarAreaLayoutItem &item = line.toolBarItems.at(k); QWidget *widget = const_cast<QLayoutItem*>(item.widgetItem)->widget(); QString objectName = widget->objectName(); if (objectName.isEmpty()) { qWarning("QMainWindow::saveState(): 'objectName' not set for QToolBar %p '%s'", widget, widget->windowTitle().toLocal8Bit().constData()); } stream << objectName; // we store information as: // 1st bit: 1 if shown // 2nd bit: 1 if orientation is vertical (default is horizontal) uchar shownOrientation = (uchar)!widget->isHidden(); if (QToolBar * tb= qobject_cast<QToolBar*>(widget)) { if (tb->orientation() == Qt::Vertical) shownOrientation |= 2; } stream << shownOrientation; stream << item.pos; //we store the preferred size. If the use rdidn't resize the toolbars it will be -1 stream << item.preferredSize; uint geom0, geom1; packRect(&geom0, &geom1, widget->geometry(), widget->isWindow()); stream << geom0 << geom1; } } } }
static bool isChildOf(QWidget* child, QWidget *parent) { if (!child) return false; QObjectList list = parent->children(); for (int i = 0; i < list.size(); ++i) { QObject *obj = list.at(i); if (!obj->isWidgetType()) continue; QWidget *widget = static_cast<QWidget *>(obj); if (!widget->isWindow()) continue; if (widget == child || isChildOf(child, widget)) return true; } return false; }
void PropertyEditor::setupPaletteProperty(QtVariantProperty *property) { QPalette value = qvariant_cast<QPalette>(property->value()); QPalette superPalette = QPalette(); QWidget *currentWidget = qobject_cast<QWidget *>(m_object); if (currentWidget) { if (currentWidget->isWindow()) superPalette = QApplication::palette(currentWidget); else { if (currentWidget->parentWidget()) superPalette = currentWidget->parentWidget()->palette(); } } m_updatingBrowser = true; property->setAttribute(m_strings.m_superPaletteAttribute, superPalette); m_updatingBrowser = false; }
QT_BEGIN_NAMESPACE static QList<QWidget*> childWidgets(const QWidget *widget) { QList<QObject*> list = widget->children(); QList<QWidget*> widgets; for (int i = 0; i < list.size(); ++i) { QWidget *w = qobject_cast<QWidget *>(list.at(i)); if (w && !w->isWindow() && !qobject_cast<QFocusFrame*>(w) #if !defined(QT_NO_MENU) && !qobject_cast<QMenu*>(w) #endif && w->objectName() != QLatin1String("qt_rubberband")) widgets.append(w); } return widgets; }
GetPluginDialog::GetPluginDialog(QWidget *parent) : QDialog(parent), ui(new Ui::GetPluginDialog()){ ui->setupUi(this); selected = false; //nothing selected by default //Now center the window on the parent if(parent!=0){ QWidget *top = parent; while(!top->isWindow()){ top = top->parentWidget(); } QPoint center = top->geometry().center(); this->move(center.x()-(this->width()/2), center.y()-(this->height()/2) ); } //Load the icons ui->push_cancel->setIcon( LXDG::findIcon("dialog-cancel","") ); ui->push_accept->setIcon( LXDG::findIcon("dialog-ok","") ); this->setWindowIcon( LXDG::findIcon("preferences-plugin") ); //Connect the signals/slots connect(ui->combo_list, SIGNAL(currentIndexChanged(int)), this, SLOT(pluginchanged()) ); connect(ui->push_cancel, SIGNAL(clicked()), this, SLOT(close()) ); connect(ui->push_accept, SIGNAL(clicked()), this, SLOT(accept()) ); }
QDesignerFormWindowInterface *QDesignerFormWindowInterface::findFormWindow(QObject *object) { while (object != 0) { if (QDesignerFormWindowInterface *fw = qobject_cast<QDesignerFormWindowInterface*>(object)) { return fw; } else { QWidget *w = qobject_cast<QWidget *>(object); // QDesignerMenu is a window, so stopFindAtTopLevel(w) returns 0. // However, we want to find the form window for QActions of a menu. // If this check is inside stopFindAtTopLevel(w), it will break designer // menu editing (e.g. when clicking on items inside an opened menu) if (w && w->isWindow() && stopFindAtTopLevel(w, false)) break; } object = object->parent(); } return 0; }
QList<QWidget*> childWidgets(const QWidget *widget) { if (widget == 0) return QList<QWidget*>(); QList<QObject*> list = widget->children(); QList<QWidget*> widgets; for (int i = 0; i < list.size(); ++i) { QWidget *w = qobject_cast<QWidget *>(list.at(i)); if (!w) continue; QString objectName = w->objectName(); if (!w->isWindow() && !qobject_cast<QFocusFrame*>(w) && !qobject_cast<QMenu*>(w) && objectName != QLatin1String("qt_rubberband") && objectName != QLatin1String("qt_qmainwindow_extended_splitter")) { widgets.append(w); } } return widgets; }
/*! Sets the region currently visible on the screen to be the given \a clip region. \sa clipRegion() */ void QWSWindowSurface::setClipRegion(const QRegion &clip) { if (clip == d_ptr->clip) return; QRegion expose = (clip - d_ptr->clip); d_ptr->clip = clip; if (expose.isEmpty() || clip.isEmpty()) return; // No repaint or flush required. QWidget *win = window(); if (!win) return; if (isBuffered()) { // No repaint required. Flush exposed area via the backing store. win->d_func()->syncBackingStore(expose); return; } #ifndef QT_NO_QWS_MANAGER // Invalidate exposed decoration area. if (win && win->isWindow()) { QTLWExtra *topextra = win->d_func()->extra->topextra; if (QWSManager *manager = topextra->qwsManager) { QRegion decorationExpose(manager->region()); decorationExpose.translate(-win->geometry().topLeft()); decorationExpose &= expose; if (!decorationExpose.isEmpty()) { expose -= decorationExpose; manager->d_func()->dirtyRegion(QDecoration::All, QDecoration::Normal, decorationExpose); } } } #endif // Invalidate exposed widget area. win->d_func()->invalidateBuffer(expose); }
void customerInformation(QWidget* parent, int pCustid) { ParameterList params; params.append("cust_id", pCustid); QWidget * w = parent; while(w && !w->isWindow()) w = w->parentWidget(); if(w && w->isModal()) { params.append("modal"); dspCustomerInformation * newdlg = new dspCustomerInformation(w, Qt::Window); newdlg->set(params); omfgThis->handleNewWindow(newdlg); } else { dspCustomerInformation * newdlg = new dspCustomerInformation(); newdlg->set(params); omfgThis->handleNewWindow(newdlg); } }
void QToolBarAreaLayout::saveState(QDataStream &stream) const { // save toolbar state stream << (uchar) ToolBarStateMarkerEx; int lineCount = 0; for (int i = 0; i < QInternal::DockCount; ++i) lineCount += docks[i].lines.count(); stream << lineCount; for (int i = 0; i < QInternal::DockCount; ++i) { const QToolBarAreaLayoutInfo &dock = docks[i]; for (int j = 0; j < dock.lines.count(); ++j) { const QToolBarAreaLayoutLine &line = dock.lines.at(j); stream << i << line.toolBarItems.count(); for (int k = 0; k < line.toolBarItems.count(); ++k) { const QToolBarAreaLayoutItem &item = line.toolBarItems.at(k); QWidget *widget = const_cast<QLayoutItem*>(item.widgetItem)->widget(); QString objectName = widget->objectName(); if (objectName.isEmpty()) { qWarning("QMainWindow::saveState(): 'objectName' not set for QToolBar %p '%s'", widget, widget->windowTitle().toLocal8Bit().constData()); } stream << objectName; stream << (uchar) !widget->isHidden(); stream << item.pos; stream << item.size; uint geom0, geom1; packRect(&geom0, &geom1, widget->geometry(), widget->isWindow()); stream << geom0 << geom1; } } } }
void TaskView::updateWatcher(void) { // In case a child of the TaskView has the focus and get hidden we have // to make sure that set the focus on a widget that won't be hidden or // deleted because otherwise Qt may forward the focus via focusNextPrevChild() // to the mdi area which may switch to another mdi view which is not an // acceptable behaviour. QWidget *fw = QApplication::focusWidget(); if (!fw) this->setFocus(); QPointer<QWidget> fwp = fw; while (fw && !fw->isWindow()) { if (fw == this) { this->setFocus(); break; } fw = fw->parentWidget(); } // add all widgets for all watcher to the task view for (std::vector<TaskWatcher*>::iterator it=ActiveWatcher.begin();it!=ActiveWatcher.end();++it) { bool match = (*it)->shouldShow(); std::vector<QWidget*> &cont = (*it)->getWatcherContent(); for (std::vector<QWidget*>::iterator it2=cont.begin();it2!=cont.end();++it2) { if (match) (*it2)->show(); else (*it2)->hide(); } } // In case the previous widget that had the focus is still visible // give it the focus back. if (fwp && fwp->isVisible()) fwp->setFocus(); }
bool BlurHelper::eventFilter (QObject* object, QEvent* event) { switch (event->type()) { case QEvent::Show: case QEvent::Hide: case QEvent::Resize: /* the theme may changed from Kvantum and to it again */ case QEvent::StyleChange: { QWidget* widget (qobject_cast<QWidget*>(object)); /* take precautions */ if (!widget || !widget->isWindow()) break; pendingWidgets_.insert (widget, widget); delayedUpdate(); break; } default: break; } // never eat events return false; }
/*! \reimp */ QAccessible::State QAccessibleWidget::state() const { QAccessible::State state; QWidget *w = widget(); if (w->testAttribute(Qt::WA_WState_Visible) == false) state.invisible = true; if (w->focusPolicy() != Qt::NoFocus) state.focusable = true; if (w->hasFocus()) state.focused = true; if (!w->isEnabled()) state.disabled = true; if (w->isWindow()) { if (w->windowFlags() & Qt::WindowSystemMenuHint) state.movable = true; if (w->minimumSize() != w->maximumSize()) state.sizeable = true; if (w->isActiveWindow()) state.active = true; } return state; }
void QSplitter::childEvent(QChildEvent *c) { Q_D(QSplitter); if (!c->child()->isWidgetType()) return; QWidget *w = static_cast<QWidget*>(c->child()); if (c->added() && !d->blockChildAdd && !w->isWindow() && !d->findWidget(w)) { d->insertWidget_helper(d->list.count(), w, false); } else if (c->polished() && !d->blockChildAdd) { if (isVisible() && !(w->isHidden() && w->testAttribute(Qt::WA_WState_ExplicitShowHide))) w->show(); } else if (c->type() == QEvent::ChildRemoved) { for (int i = 0; i < d->list.size(); ++i) { QSplitterLayoutStruct *s = d->list.at(i); if (s->widget == w) { d->list.removeAt(i); delete s; d->recalc(isVisible()); return; } } } }
bool WindowSticker::eventFilter(QObject *AWatched, QEvent *AEvent) { if (AEvent->type() == QEvent::NonClientAreaMouseButtonPress) { QWidget *window = qobject_cast<QWidget *>(AWatched); if (window && window->isWindow()) { FCurWindow = window; } } else if (AEvent->type() == QEvent::NonClientAreaMouseButtonRelease) { FCurWindow = NULL; } else if (AEvent->type() == QEvent::NonClientAreaMouseMove) { FCurWindow = NULL; } else if (AEvent->type() == QEvent::WindowStateChange) { FCurWindow = NULL; } else if (AWatched==FCurWindow && AEvent->type()==QEvent::Move) { const int delta = 15; QPoint cursorPos = QCursor::pos(); QRect windowRect = FCurWindow->frameGeometry(); QRect desckRect = QApplication::desktop()->availableGeometry(FCurWindow); int borderTop = cursorPos.y() - windowRect.y(); int borderLeft = cursorPos.x() - windowRect.x(); int borderRight = cursorPos.x() + desckRect.right() - windowRect.right(); int borderBottom = cursorPos.y() + desckRect.bottom() - windowRect.bottom(); FStickPos = windowRect.topLeft(); if (qAbs(borderTop - cursorPos.y()) < delta) { FStickPos.setY(0); } else if (qAbs(borderBottom - cursorPos.y()) < delta) { FStickPos.setY(desckRect.bottom() - windowRect.height()); } if (qAbs(borderLeft - cursorPos.x()) < delta) { FStickPos.setX(0); } else if(qAbs(borderRight - cursorPos.x()) < delta) { FStickPos.setX(desckRect.right() - windowRect.width()); } if (FStickPos != windowRect.topLeft()) { QEvent *stickEvent = new QEvent((QEvent::Type)FStickEvent); QApplication::postEvent(AWatched,stickEvent,Qt::HighEventPriority); } } else if (FCurWindow==AWatched && AEvent->type()==FStickEvent) { FCurWindow->move(FStickPos); return true; } return QObject::eventFilter(AWatched,AEvent); }
/*! \fn void CSizeGrip::mouseMoveEvent(QMouseEvent * event) Resizes the top-level widget containing this widget. The mouse move event is passed in the \a event parameter. */ void CSizeGrip::mouseMoveEvent(QMouseEvent * e) { if (e->buttons() != Qt::LeftButton) { QWidget::mouseMoveEvent(e); return; } QWidget* tlw = qt_sizegrip_topLevelWidget(); if (!gotMousePress || tlw->testAttribute(Qt::WA_WState_ConfigPending)) return; #ifdef Q_WS_X11 #if QT_VERSION >= 0x050000 if (tlw->isWindow() && X11->isSupportedByWM(ATOM(_NET_WM_MOVERESIZE)) && tlw->isTopLevel() && !(tlw->windowFlags() & Qt::X11BypassWindowManagerHint) && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !qt_widget_private(tlw)->hasHeightForWidth()) return; #endif #endif #ifdef Q_WS_WIN #if QT_VERSION >= 0x050000 if (tlw->isWindow() && GetSystemMenu(tlw->winId(), FALSE) != 0 && internalWinId() && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !qt_widget_private(tlw)->hasHeightForWidth()) { MSG msg; while(PeekMessage(&msg, winId(), WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE)); return; } #endif #endif QPoint np(e->globalPos()); // Don't extend beyond the available geometry; bound to dyMax and dxMax. QSize ns; if (atBottom()) ns.rheight() = r.height() + qMin(np.y() - p.y(), dyMax); else ns.rheight() = r.height() - qMax(np.y() - p.y(), dyMax); if (atLeft()) ns.rwidth() = r.width() - qMax(np.x() - p.x(), dxMax); else ns.rwidth() = r.width() + qMin(np.x() - p.x(), dxMax); ns = QLayout::closestAcceptableSize(tlw, ns); QPoint p; QRect nr(p, ns); if (atBottom()) { if (atLeft()) nr.moveTopRight(r.topRight()); else nr.moveTopLeft(r.topLeft()); } else { if (atLeft()) nr.moveBottomRight(r.bottomRight()); else nr.moveBottomLeft(r.bottomLeft()); } ((CPObject*)tlw)->changeGeometrySize(nr.x(),nr.y(),nr.width(),nr.height()); }
void QGLContext::updatePaintDevice() { Q_D(QGLContext); d->update = false; #if 0 //(MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) { if(d->paintDevice->devType() == QInternal::Widget) { QWidget *w = (QWidget *)d->paintDevice; aglSetHIViewRef((AGLContext)d->cx, (HIViewRef)w->winId()); } else if(d->paintDevice->devType() == QInternal::Pixmap) { QPixmap *pm = (QPixmap *)d->paintDevice; aglSetOffScreen((AGLContext)d->cx, pm->width(), pm->height(), qt_mac_pixmap_get_bytes_per_line(pm), qt_mac_pixmap_get_base(pm)); } else { qWarning("QGLContext::updatePaintDevice(): Not sure how to render OpenGL on this device!"); } } else #endif { #ifndef Q_OS_MAC64 if(d->paintDevice->devType() == QInternal::Widget) { //get control information QWidget *w = (QWidget *)d->paintDevice; HIViewRef hiview = (HIViewRef)w->winId(); WindowPtr window = qt_mac_window_for(hiview); #ifdef DEBUG_OPENGL_REGION_UPDATE static int serial_no_gl = 0; qDebug("[%d] %p setting on %s::%s %p/%p [%s]", ++serial_no_gl, w, w->metaObject()->className(), w->objectName().toLatin1().constData(), hiview, window, w->handle() ? "Inside" : "Outside"); #endif //update drawable if(0 && w->isWindow() && w->isFullScreen()) { aglSetDrawable((AGLContext)d->cx, 0); aglSetFullScreen((AGLContext)d->cx, w->width(), w->height(), 0, QApplication::desktop()->screenNumber(w)); w->hide(); } else { AGLDrawable old_draw = aglGetDrawable((AGLContext)d->cx), new_draw = GetWindowPort(window); if(old_draw != new_draw) aglSetDrawable((AGLContext)d->cx, new_draw); } if(!w->isWindow()) { QRegion clp = qt_mac_get_widget_rgn(w); //get drawable area #ifdef DEBUG_OPENGL_REGION_UPDATE if(clp.isEmpty()) { qDebug(" Empty area!"); } else { QVector<QRect> rs = clp.rects(); for(int i = 0; i < rs.count(); i++) qDebug(" %d %d %d %d", rs[i].x(), rs[i].y(), rs[i].width(), rs[i].height()); } #endif //update the clip if(!aglIsEnabled((AGLContext)d->cx, AGL_BUFFER_RECT)) aglEnable((AGLContext)d->cx, AGL_BUFFER_RECT); if(clp.isEmpty()) { GLint offs[4] = { 0, 0, 0, 0 }; aglSetInteger((AGLContext)d->cx, AGL_BUFFER_RECT, offs); if(aglIsEnabled((AGLContext)d->cx, AGL_CLIP_REGION)) aglDisable((AGLContext)d->cx, AGL_CLIP_REGION); } else { HIPoint origin = { 0., 0. }; HIViewConvertPoint(&origin, HIViewRef(w->winId()), 0); const GLint offs[4] = { qRound(origin.x), w->window()->frameGeometry().height() - (qRound(origin.y) + w->height()), w->width(), w->height() }; aglSetInteger((AGLContext)d->cx, AGL_BUFFER_RECT, offs); aglSetInteger((AGLContext)d->cx, AGL_CLIP_REGION, (const GLint *)clp.handle(true)); if(!aglIsEnabled((AGLContext)d->cx, AGL_CLIP_REGION)) aglEnable((AGLContext)d->cx, AGL_CLIP_REGION); } } } else if(d->paintDevice->devType() == QInternal::Pixmap) { QPixmap *pm = (QPixmap *)d->paintDevice; PixMapHandle mac_pm = GetGWorldPixMap((GWorldPtr)pm->macQDHandle()); aglSetOffScreen((AGLContext)d->cx, pm->width(), pm->height(), GetPixRowBytes(mac_pm), GetPixBaseAddr(mac_pm)); } else { qWarning("QGLContext::updatePaintDevice(): Not sure how to render OpenGL on this device!"); } #endif // Q_OS_MAC64 } aglUpdateContext((AGLContext)d->cx); }
bool CFileListItemDelegate::eventFilter(QObject * object, QEvent * event) { QWidget *editor = qobject_cast<QWidget*>(object); if (!editor) return false; if (event->type() == QEvent::KeyPress) { switch (static_cast<QKeyEvent *>(event)->key()) { case Qt::Key_Tab: emit closeEditor(editor, EditNextItem); return true; case Qt::Key_Backtab: emit closeEditor(editor, EditPreviousItem); return true; case Qt::Key_Enter: // Numpad Enter case Qt::Key_Return: // don't filter enter key events for QTextEdit if (!qobject_cast<QTextEdit *>(editor) && !qobject_cast<QPlainTextEdit*>(editor)) { // commit data emit commitData(editor); emit closeEditor(editor); return true; } return QStyledItemDelegate::eventFilter(object, event); case Qt::Key_Escape: // don't commit data emit closeEditor(editor, QAbstractItemDelegate::RevertModelCache); return true; case Qt::Key_Up: case Qt::Key_Down: // don't commit data emit closeEditor(editor, QAbstractItemDelegate::RevertModelCache); // Don't consume the event so that the TreeView will handle this event and highlight the next item properly return QStyledItemDelegate::eventFilter(object, event); default: return QStyledItemDelegate::eventFilter(object, event); } } else if (event->type() == QEvent::FocusOut || (event->type() == QEvent::Hide && editor->isWindow())) { //the Hide event will take care of he editors that are in fact complete dialogs if (!editor->isActiveWindow() || (QApplication::focusWidget() != editor)) { QWidget *w = QApplication::focusWidget(); while (w) { // don't worry about focus changes internally in the editor if (w == editor) return QStyledItemDelegate::eventFilter(object, event); w = w->parentWidget(); } emit closeEditor(editor, NoHint); } } else if (event->type() == QEvent::ShortcutOverride) { if (static_cast<QKeyEvent*>(event)->key() == Qt::Key_Escape) { event->accept(); return true; } } return QStyledItemDelegate::eventFilter(object, event); }
void ScreenshotService::getScreenshot(TasCommandModel& model, TasResponse& response) { QListIterator<TasTarget*> i(model.targetList()); QString errorMsg = PARSE_ERROR; QImage screenshot; QString pictureFormat = "PNG"; while (i.hasNext()) { TasTarget* commandTarget = i.next(); QString targetId = commandTarget->id(); QString targetType = commandTarget->type(); TasCommand* command = commandTarget->findCommand("Screenshot"); // are required for command completion if (targetId.isEmpty() || targetType.isEmpty() || !command) { continue; } if (!command->parameter("format").isEmpty()) { pictureFormat = command->parameter("format"); } if (!isFormatSupported(pictureFormat)) { errorMsg = "Given format " + pictureFormat + "is not supported. Supported formats are: PNG, JPEG and BMP."; break; } bool draw = (command->parameter("draw") == "true"); QWidget* widget = 0; QQuickWindow* qtQuickWindow = 0; WId winId = 0; QRect rect(0,0,-1,-1); errorMsg = "Taking screenshot failed!"; if (targetType == TYPE_GRAPHICS_VIEW) { //TasLogger::logger()->debug("TYPE_GRAPHICS_VIEW Target id:" + targetId); QGraphicsItem* item = findGraphicsItem(targetId); if (item) { QGraphicsView* view = getViewForItem(item); if(view) { ItemLocationDetails locationDetails = TestabilityUtils::getItemLocationDetails(item); rect = QRect(locationDetails.windowPoint.x(), locationDetails.windowPoint.y(), locationDetails.width, locationDetails.height); if (draw) { widget = view->window(); } else { winId = view->window()->winId(); } } else { errorMsg = "Could not find a GraphicsView for the GraphicsItem!"; } } else { errorMsg = "Could not find the GraphicsItem!"; } } else if (targetType == TYPE_STANDARD_VIEW) { //TasLogger::logger()->debug("TYPE_STANDARD_VIEW about to find widget Target id:" + targetId); widget = findWidget(targetId); if (widget) { if ((widget->isWindow() && !draw) || widget->inherits("QDesktopWidget")) { winId = widget->winId(); widget = 0; } else if (!draw) { QPoint point = widget->mapToGlobal(QPoint(0,0)); QPoint windowPoint = widget->window()->mapFromGlobal(point); rect = QRect(windowPoint.x(), windowPoint.y(), widget->rect().width(), widget->rect().width()); winId = widget->window()->winId(); widget = 0; } } else { TasLogger::logger()->debug("ScreenshotService::executeService application has no visible ui!"); errorMsg = "Application has no visible ui!"; } } else if (targetType == TYPE_QSCENEGRAPH) { QQuickItem* item = TestabilityUtils::findQuickItem(targetId); if (item) { QPointF offset = item->mapToScene(QPointF(0,0)); rect = QRect(-offset.x(), -offset.y(), item->width(), item->height()); qtQuickWindow = item->window(); } } else { //TasLogger::logger()->debug("TYPE_APPLICATION_VIEW about to find application window Target id:" + targetId); widget = getApplicationWidget(); if (!widget) { QWindow *window = getApplicationWindow(); //in case no window false, return the desktop qtQuickWindow = qobject_cast<QQuickWindow *>(window); if (!window) { widget = qApp->desktop(); } } } if (widget) { screenshot = widget->grab(rect).toImage(); if (!screenshot.isNull()) { screenshot.setText("tas_id", objectId(widget)); } } else if (qtQuickWindow) { screenshot = qtQuickWindow->grabWindow(); if (!screenshot.isNull()) { screenshot.setText("tas_id", objectId(qtQuickWindow)); } } else if (winId) { screenshot = QPixmap::grabWindow(winId, rect.x(), rect.y(), rect.width(), rect.height()).toImage(); if (!screenshot.isNull()) { screenshot.setText("tas_id", QString::number(winId)); } } break; } if (!screenshot.isNull()) { QByteArray bytes; QBuffer buffer(&bytes); buffer.open(QIODevice::WriteOnly); screenshot.save(&buffer, pictureFormat.toLatin1()); response.setData(bytes); buffer.close(); } else { response.setErrorMessage(errorMsg); } }
void QWidgetPrivate::setWSGeometry(bool dontShow, const QRect &) { // Note: based on x11 implementation static const int XCOORD_MAX = 16383; static const int WRECT_MAX = 16383; Q_Q(QWidget); Q_ASSERT(q->testAttribute(Qt::WA_WState_Created)); /* There are up to four different coordinate systems here: Qt coordinate system for this widget. Symbian coordinate system for this widget (relative to wrect). Qt coordinate system for parent Symbian coordinate system for parent (relative to parent's wrect). */ QRect validRange(-XCOORD_MAX,-XCOORD_MAX, 2*XCOORD_MAX, 2*XCOORD_MAX); QRect wrectRange(-WRECT_MAX,-WRECT_MAX, 2*WRECT_MAX, 2*WRECT_MAX); QRect wrect; //xrect is the Symbian geometry of my widget. (starts out in parent's Qt coord sys, and ends up in parent's Symbian coord sys) QRect xrect = data.crect; const QWidget *const parent = q->parentWidget(); QRect parentWRect = parent->data->wrect; if (parentWRect.isValid()) { // parent is clipped, and we have to clip to the same limit as parent if (!parentWRect.contains(xrect)) { xrect &= parentWRect; wrect = xrect; //translate from parent's to my Qt coord sys wrect.translate(-data.crect.topLeft()); } //translate from parent's Qt coords to parent's X coords xrect.translate(-parentWRect.topLeft()); } else { // parent is not clipped, we may or may not have to clip if (data.wrect.isValid() && QRect(QPoint(),data.crect.size()).contains(data.wrect)) { // This is where the main optimization is: we are already // clipped, and if our clip is still valid, we can just // move our window, and do not need to move or clip // children QRect vrect = xrect & parent->rect(); vrect.translate(-data.crect.topLeft()); //the part of me that's visible through parent, in my Qt coords if (data.wrect.contains(vrect)) { xrect = data.wrect; xrect.translate(data.crect.topLeft()); if (data.winid) data.winid->SetExtent(TPoint(xrect.x(), xrect.y()), TSize(xrect.width(), xrect.height())); return; } } if (!validRange.contains(xrect)) { // we are too big, and must clip xrect &=wrectRange; wrect = xrect; wrect.translate(-data.crect.topLeft()); //parent's X coord system is equal to parent's Qt coord //sys, so we don't need to map xrect. } } // unmap if we are outside the valid window system coord system bool outsideRange = !xrect.isValid(); bool mapWindow = false; if (q->testAttribute(Qt::WA_OutsideWSRange) != outsideRange) { q->setAttribute(Qt::WA_OutsideWSRange, outsideRange); if (outsideRange) { if (data.winid) data.winid->DrawableWindow()->SetVisible(EFalse); q->setAttribute(Qt::WA_Mapped, false); } else if (!q->isHidden()) { mapWindow = true; } } if (outsideRange) return; bool jump = (data.wrect != wrect); data.wrect = wrect; // and now recursively for all children... for (int i = 0; i < children.size(); ++i) { QObject *object = children.at(i); if (object->isWidgetType()) { QWidget *w = static_cast<QWidget *>(object); if (!w->isWindow() && w->testAttribute(Qt::WA_WState_Created)) w->d_func()->setWSGeometry(jump); } } if (data.winid) { // move ourselves to the new position and map (if necessary) after // the movement. Rationale: moving unmapped windows is much faster // than moving mapped windows if (!parent->internalWinId()) xrect.translate(parent->mapTo(q->nativeParentWidget(), QPoint(0, 0))); data.winid->SetExtent(TPoint(xrect.x(), xrect.y()), TSize(xrect.width(), xrect.height())); } if (mapWindow and !dontShow) { q->setAttribute(Qt::WA_Mapped); if (q->internalWinId()) q->internalWinId()->DrawableWindow()->SetVisible(ETrue); } if (jump && data.winid) { RWindow *const window = static_cast<RWindow *>(data.winid->DrawableWindow()); window->Invalidate(TRect(0, 0, wrect.width(), wrect.height())); } }
bool QDragManager::eventFilter(QObject *o, QEvent *e) { if (beingCancelled) { return false; } if (!o->isWidgetType()) return false; switch(e->type()) { case QEvent::MouseButtonPress: { } case QEvent::MouseMove: { if (!object) { //#### this should not happen qWarning("QDragManager::eventFilter: No object"); return true; } QDragManager *manager = QDragManager::self(); QMimeData *dropData = manager->object ? manager->dragPrivate()->data : manager->dropData; if (manager->object) possible_actions = manager->dragPrivate()->possible_actions; else possible_actions = Qt::IgnoreAction; QMouseEvent *me = (QMouseEvent *)e; if (me->buttons()) { Qt::DropAction prevAction = global_accepted_action; QWidget *cw = QApplication::widgetAt(me->globalPos()); // map the Coords relative to the window. if (!cw) return true; while (cw && !cw->acceptDrops() && !cw->isWindow()) cw = cw->parentWidget(); bool oldWillDrop = willDrop; if (object->target() != cw) { if (object->target()) { QDragLeaveEvent dle; QApplication::sendEvent(object->target(), &dle); willDrop = false; global_accepted_action = Qt::IgnoreAction; if (oldWillDrop != willDrop) updateCursor(); object->d_func()->target = 0; } if (cw && cw->acceptDrops()) { object->d_func()->target = cw; QDragEnterEvent dee(cw->mapFromGlobal(me->globalPos()), possible_actions, dropData, me->buttons(), me->modifiers()); QApplication::sendEvent(object->target(), &dee); willDrop = dee.isAccepted() && dee.dropAction() != Qt::IgnoreAction; global_accepted_action = willDrop ? dee.dropAction() : Qt::IgnoreAction; if (oldWillDrop != willDrop) updateCursor(); } } else if (cw) { QDragMoveEvent dme(cw->mapFromGlobal(me->globalPos()), possible_actions, dropData, me->buttons(), me->modifiers()); if (global_accepted_action != Qt::IgnoreAction) { dme.setDropAction(global_accepted_action); dme.accept(); } QApplication::sendEvent(cw, &dme); willDrop = dme.isAccepted(); global_accepted_action = willDrop ? dme.dropAction() : Qt::IgnoreAction; if (oldWillDrop != willDrop) { updatePixmap(); updateCursor(); } } if (global_accepted_action != prevAction) emitActionChanged(global_accepted_action); } return true; // Eat all mouse events } case QEvent::MouseButtonRelease: { qApp->removeEventFilter(this); #ifndef QT_NO_CURSOR if (restoreCursor) { QApplication::restoreOverrideCursor(); willDrop = false; restoreCursor = false; } #endif if (object && object->target()) { QMouseEvent *me = (QMouseEvent *)e; QDragManager *manager = QDragManager::self(); QMimeData *dropData = manager->object ? manager->dragPrivate()->data : manager->dropData; QDropEvent de(object->target()->mapFromGlobal(me->globalPos()), possible_actions, dropData, me->buttons(), me->modifiers()); QApplication::sendEvent(object->target(), &de); if (de.isAccepted()) global_accepted_action = de.dropAction(); else global_accepted_action = Qt::IgnoreAction; if (object) object->deleteLater(); drag_object = object = 0; } eventLoop->exit(); return true; // Eat all mouse events } default: break; } return false; }
bool QDragManager::eventFilter(QObject *o, QEvent *e) { if (beingCancelled) { if (e->type() == QEvent::KeyRelease && static_cast<QKeyEvent*>(e)->key() == Qt::Key_Escape) { qApp->removeEventFilter(this); Q_ASSERT(object == 0); beingCancelled = false; #ifndef QT_NO_LOCALEVENTLOOP eventLoop->exit(); #else asyncDragFinished(); #endif return true; // block the key release } return false; } if (!o->isWidgetType()) return false; switch(e->type()) { case QEvent::ShortcutOverride: // prevent accelerators from firing while dragging e->accept(); return true; case QEvent::KeyPress: case QEvent::KeyRelease: { QKeyEvent *ke = ((QKeyEvent*)e); if (ke->key() == Qt::Key_Escape && e->type() == QEvent::KeyPress) { cancel(); qApp->removeEventFilter(this); beingCancelled = false; #ifndef QT_NO_LOCALEVENTLOOP eventLoop->exit(); #else asyncDragFinished(); #endif } else { updateCursor(); } return true; // Eat all key events } case QEvent::MouseButtonPress: case QEvent::MouseMove: { if (!object) { //#### this should not happen qWarning("QDragManager::eventFilter: No object"); return true; } QDragManager *manager = QDragManager::self(); QMimeData *dropData = manager->object ? manager->dragPrivate()->data : manager->dropData; if (manager->object) possible_actions = manager->dragPrivate()->possible_actions; else possible_actions = Qt::IgnoreAction; QMouseEvent *me = (QMouseEvent *)e; if (me->buttons()) { Qt::DropAction prevAction = global_accepted_action; QWidget *cw = QApplication::widgetAt(me->globalPos()); // Fix for when we move mouse on to the deco widget if (qt_qws_dnd_deco && cw == qt_qws_dnd_deco) cw = object->target(); while (cw && !cw->acceptDrops() && !cw->isWindow()) cw = cw->parentWidget(); if (object->target() != cw) { if (object->target()) { QDragLeaveEvent dle; QApplication::sendEvent(object->target(), &dle); willDrop = false; global_accepted_action = Qt::IgnoreAction; updateCursor(); restoreCursor = true; object->d_func()->target = 0; } if (cw && cw->acceptDrops()) { object->d_func()->target = cw; QDragEnterEvent dee(cw->mapFromGlobal(me->globalPos()), possible_actions, dropData, me->buttons(), me->modifiers()); QApplication::sendEvent(object->target(), &dee); willDrop = dee.isAccepted() && dee.dropAction() != Qt::IgnoreAction; global_accepted_action = willDrop ? dee.dropAction() : Qt::IgnoreAction; updateCursor(); restoreCursor = true; } } else if (cw) { QDragMoveEvent dme(cw->mapFromGlobal(me->globalPos()), possible_actions, dropData, me->buttons(), me->modifiers()); if (global_accepted_action != Qt::IgnoreAction) { dme.setDropAction(global_accepted_action); dme.accept(); } QApplication::sendEvent(cw, &dme); willDrop = dme.isAccepted(); global_accepted_action = willDrop ? dme.dropAction() : Qt::IgnoreAction; updatePixmap(); updateCursor(); } if (global_accepted_action != prevAction) emitActionChanged(global_accepted_action); } return true; // Eat all mouse events } case QEvent::MouseButtonRelease: { qApp->removeEventFilter(this); if (restoreCursor) { willDrop = false; #ifndef QT_NO_CURSOR QApplication::restoreOverrideCursor(); #endif restoreCursor = false; } if (object && object->target()) { QMouseEvent *me = (QMouseEvent *)e; QDragManager *manager = QDragManager::self(); QMimeData *dropData = manager->object ? manager->dragPrivate()->data : manager->dropData; QDropEvent de(object->target()->mapFromGlobal(me->globalPos()), possible_actions, dropData, me->buttons(), me->modifiers()); QApplication::sendEvent(object->target(), &de); if (de.isAccepted()) global_accepted_action = de.dropAction(); else global_accepted_action = Qt::IgnoreAction; if (object) object->deleteLater(); drag_object = object = 0; } #ifndef QT_NO_LOCALEVENTLOOP eventLoop->exit(); #else asyncDragFinished(); #endif return true; // Eat all mouse events } default: break; } return false; }
QT_BEGIN_NAMESPACE QPixmap QPixmap::grabWindow(WId window, int x, int y, int w, int h) { QWidget *widget = QWidget::find(window); if (!widget) return QPixmap(); QRect grabRect = widget->frameGeometry(); if (!widget->isWindow()) grabRect.translate(widget->parentWidget()->mapToGlobal(QPoint())); if (w < 0) w = widget->width() - x; if (h < 0) h = widget->height() - y; grabRect &= QRect(x, y, w, h).translated(widget->mapToGlobal(QPoint())); QScreen *screen = qt_screen; QDesktopWidget *desktop = QApplication::desktop(); if (!desktop) return QPixmap(); if (desktop->numScreens() > 1) { const int screenNo = desktop->screenNumber(widget); if (screenNo != -1) screen = qt_screen->subScreens().at(screenNo); grabRect = grabRect.translated(-screen->region().boundingRect().topLeft()); } if (screen->pixelFormat() == QImage::Format_Invalid) { qWarning("QPixmap::grabWindow(): Unable to copy pixels from framebuffer"); return QPixmap(); } if (screen->isTransformed()) { const QSize screenSize(screen->width(), screen->height()); grabRect = screen->mapToDevice(grabRect, screenSize); } QWSDisplay::grab(false); QPixmap pixmap; QImage img(screen->base(), screen->deviceWidth(), screen->deviceHeight(), screen->linestep(), screen->pixelFormat()); img = img.copy(grabRect); QWSDisplay::ungrab(); if (screen->isTransformed()) { QMatrix matrix; switch (screen->transformOrientation()) { case 1: matrix.rotate(90); break; case 2: matrix.rotate(180); break; case 3: matrix.rotate(270); break; default: break; } img = img.transformed(matrix); } if (screen->pixelType() == QScreen::BGRPixel) img = img.rgbSwapped(); return QPixmap::fromImage(img); }
/*! \fn void CSizeGrip::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 CSizeGrip::mousePressEvent(QMouseEvent * e) { ungrabGesture(Qt::TapAndHoldGesture); if (e->button() != Qt::LeftButton) { QWidget::mousePressEvent(e); return; } QWidget *tlw = qt_sizegrip_topLevelWidget(); p = e->globalPos(); gotMousePress = true; r = tlw->geometry(); #ifdef Q_WS_X11 #if QT_VERSION >= 0x050000 // Use a native X11 sizegrip for "real" top-level windows if supported. if (tlw->isWindow() && X11->isSupportedByWM(ATOM(_NET_WM_MOVERESIZE)) && !(tlw->windowFlags() & Qt::X11BypassWindowManagerHint) && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !qt_widget_private(tlw)->hasHeightForWidth()) { XEvent xev; xev.xclient.type = ClientMessage; xev.xclient.message_type = ATOM(_NET_WM_MOVERESIZE); xev.xclient.display = X11->display; xev.xclient.window = tlw->winId(); xev.xclient.format = 32; xev.xclient.data.l[0] = e->globalPos().x(); xev.xclient.data.l[1] = e->globalPos().y(); if (atBottom()) xev.xclient.data.l[2] = atLeft() ? 6 : 4; // bottomleft/bottomright else xev.xclient.data.l[2] = atLeft() ? 0 : 2; // topleft/topright xev.xclient.data.l[3] = Button1; xev.xclient.data.l[4] = 0; XUngrabPointer(X11->display, X11->time); XSendEvent(X11->display, QX11Info::appRootWindow(x11Info().screen()), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); return; } #endif #endif // Q_WS_X11 #ifdef Q_WS_WIN #if QT_VERSION >= 0x050000 if (tlw->isWindow() && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !qt_widget_private(tlw)->hasHeightForWidth()) { uint orientation = 0; if (atBottom()) orientation = atLeft() ? SZ_SIZEBOTTOMLEFT : SZ_SIZEBOTTOMRIGHT; else orientation = atLeft() ? SZ_SIZETOPLEFT : SZ_SIZETOPRIGHT; ReleaseCapture(); PostMessage(tlw->winId(), WM_SYSCOMMAND, orientation, 0); return; } #endif #endif // Q_WS_WIN // Find available desktop/workspace geometry. QRect availableGeometry; bool hasVerticalSizeConstraint = true; bool hasHorizontalSizeConstraint = true; if (tlw->isWindow()) availableGeometry = QApplication::desktop()->availableGeometry(tlw); else { const QWidget *tlwParent = tlw->parentWidget(); // Check if tlw is inside QAbstractScrollArea/QScrollArea. // If that's the case tlw->parentWidget() will return the viewport // and tlw->parentWidget()->parentWidget() will return the scroll area. #ifndef QT_NO_SCROLLAREA QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea *>(tlwParent->parentWidget()); if (scrollArea) { hasHorizontalSizeConstraint = scrollArea->horizontalScrollBarPolicy() == Qt::ScrollBarAlwaysOff; hasVerticalSizeConstraint = scrollArea->verticalScrollBarPolicy() == Qt::ScrollBarAlwaysOff; } #endif // QT_NO_SCROLLAREA availableGeometry = tlwParent->contentsRect(); } // Find frame geometries, title bar height, and decoration sizes. const QRect frameGeometry = tlw->frameGeometry(); const int titleBarHeight = qMax(tlw->geometry().y() - frameGeometry.y(), 0); const int bottomDecoration = qMax(frameGeometry.height() - tlw->height() - titleBarHeight, 0); const int leftRightDecoration = qMax((frameGeometry.width() - tlw->width()) / 2, 0); // Determine dyMax depending on whether the sizegrip is at the bottom // of the widget or not. if (atBottom()) { if (hasVerticalSizeConstraint) dyMax = availableGeometry.bottom() - r.bottom() - bottomDecoration; else dyMax = INT_MAX; } else { if (hasVerticalSizeConstraint) dyMax = availableGeometry.y() - r.y() + titleBarHeight; else dyMax = -INT_MAX; } // In RTL mode, the size grip is to the left; find dxMax from the desktop/workspace // geometry, the size grip geometry and the width of the decoration. if (atLeft()) { if (hasHorizontalSizeConstraint) dxMax = availableGeometry.x() - r.x() + leftRightDecoration; else dxMax = -INT_MAX; } else { if (hasHorizontalSizeConstraint) dxMax = availableGeometry.right() - r.right() - leftRightDecoration; else dxMax = INT_MAX; } }
bool ShortcutHandler::eventFilter(QObject *o, QEvent *e) { if (!o->isWidgetType()) return QObject::eventFilter(o, e); QWidget *widget = static_cast<QWidget*>(o); switch(e->type()) { case QEvent::KeyPress: if (Qt::Key_Alt==static_cast<QKeyEvent *>(e)->key()) { m_altDown = true; if(qobject_cast<QMenu *>(widget)) { m_seenAlt.insert(widget); updateWidget(widget); if(widget->parentWidget() && widget->parentWidget()->window()) m_seenAlt.insert(widget->parentWidget()->window()); } else { widget = widget->window(); m_seenAlt.insert(widget); QList<QWidget*> l = widget->findChildren<QWidget*>(); for (int pos = 0;pos < l.size();++pos) { QWidget *w = l.at(pos); if (!(w->isWindow() || !w->isVisible())) // || w->style()->styleHint(QStyle::SH_UnderlineShortcut, 0, w))) updateWidget(w); } QList<QMenuBar*> m = widget->findChildren<QMenuBar*>(); for (int i = 0;i < m.size();++i) { updateWidget(m.at(i)); } } } break; case QEvent::WindowDeactivate: case QEvent::KeyRelease: if (QEvent::WindowDeactivate == e->type() || static_cast<QKeyEvent*>(e)->key() == Qt::Key_Alt) { m_altDown = false; for (QWidget *widget: const_(m_updated)) { widget->update(); } if (!m_updated.contains(widget)) widget->update(); m_seenAlt.clear(); m_updated.clear(); } break; case QEvent::Show: if(qobject_cast<QMenu *>(widget)) { QWidget *prev=m_openMenus.count() ? m_openMenus.last() : 0L; m_openMenus.append(widget); if(m_altDown && prev) prev->update(); connect(widget, &QWidget::destroyed, this, &ShortcutHandler::widgetDestroyed); } break; case QEvent::Hide: if(qobject_cast<QMenu *>(widget)) { m_seenAlt.remove(widget); m_updated.remove(widget); m_openMenus.removeAll(widget); if(m_altDown) { if(m_openMenus.count()) m_openMenus.last()->update(); else if(widget->parentWidget() && widget->parentWidget()->window()) widget->parentWidget()->window()->update(); } } break; case QEvent::Close: // Reset widget when closing m_seenAlt.remove(widget); m_updated.remove(widget); m_seenAlt.remove(widget->window()); m_openMenus.removeAll(widget); if(m_altDown) { if(m_openMenus.count()) m_openMenus.last()->update(); else if(widget->parentWidget() && widget->parentWidget()->window()) widget->parentWidget()->window()->update(); } break; default: break; } return QObject::eventFilter(o, e); }