void bringToFront() { #if defined(Q_WS_X11) { qDebug() << Q_FUNC_INFO; QWidget* widget = tomahawkWindow(); if ( !widget ) return; widget->show(); widget->activateWindow(); widget->raise(); WId wid = widget->winId(); NETWM::init(); XEvent e; e.xclient.type = ClientMessage; e.xclient.message_type = NETWM::NET_ACTIVE_WINDOW; e.xclient.display = QX11Info::display(); e.xclient.window = wid; e.xclient.format = 32; e.xclient.data.l[0] = 2; e.xclient.data.l[1] = QX11Info::appTime(); e.xclient.data.l[2] = 0; e.xclient.data.l[3] = 0l; e.xclient.data.l[4] = 0l; XSendEvent( QX11Info::display(), RootWindow( QX11Info::display(), DefaultScreen( QX11Info::display() ) ), False, SubstructureRedirectMask | SubstructureNotifyMask, &e ); } #elif defined(Q_WS_WIN) { qDebug() << Q_FUNC_INFO; QWidget* widget = tomahawkWindow(); if ( !widget ) return; widget->show(); widget->activateWindow(); widget->raise(); WId wid = widget->winId(); HWND hwndActiveWin = GetForegroundWindow(); int idActive = GetWindowThreadProcessId(hwndActiveWin, NULL); if ( AttachThreadInput(GetCurrentThreadId(), idActive, TRUE) ) { SetForegroundWindow( wid ); SetFocus( wid ); AttachThreadInput(GetCurrentThreadId(), idActive, FALSE); } } #endif }
void tst_QRadioButton::task190739_focus() { QWidget widget; QPushButton button1(&widget); button1.setText("button1"); QLineEdit edit(&widget); edit.setFocus(); QRadioButton radio1(&widget); radio1.setText("radio1"); radio1.setFocusPolicy(Qt::TabFocus); radio1.setShortcut(QKeySequence("Ctrl+O")); QVBoxLayout layout(&widget); layout.addWidget(&button1); layout.addWidget(&edit); layout.addWidget(&radio1); widget.show(); widget.activateWindow(); QApplication::setActiveWindow(&widget); QTest::qWait(100); QVERIFY(edit.hasFocus()); QVERIFY(!radio1.isChecked()); QTest::keyClick(&edit, Qt::Key_O, Qt::ControlModifier, 20); QTest::qWait(200); QVERIFY(radio1.isChecked()); QVERIFY(edit.hasFocus()); QVERIFY(!radio1.hasFocus()); }
void tst_QMenu::tearOff() { QWidget widget; QMenu *menu = new QMenu(&widget); QVERIFY(!menu->isTearOffEnabled()); //default value menu->setTearOffEnabled(true); menu->addAction("aaa"); menu->addAction("bbb"); QVERIFY(menu->isTearOffEnabled()); widget.show(); widget.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&widget)); menu->popup(QPoint(0,0)); QVERIFY(QTest::qWaitForWindowActive(menu)); QVERIFY(!menu->isTearOffMenuVisible()); QTest::mouseClick(menu, Qt::LeftButton, 0, QPoint(3, 3), 10); QTRY_VERIFY(menu->isTearOffMenuVisible()); QPointer<QMenu> torn = 0; foreach (QWidget *w, QApplication::allWidgets()) { if (w->inherits("QTornOffMenu")) { torn = static_cast<QMenu *>(w); break; } } QVERIFY(torn); QVERIFY(torn->isVisible()); menu->hideTearOffMenu(); QVERIFY(!menu->isTearOffMenuVisible()); QVERIFY(!torn->isVisible()); }
void bringToFront(QWidget *widget, bool) { Q_ASSERT(widget); QWidget* w = widget->window(); #ifdef Q_WS_X11 // If we're not on the current desktop, do the hide/show trick long dsk, curr_dsk; Window win = w->winId(); if(desktopOfWindow(&win, &dsk) && currentDesktop(&curr_dsk)) { if((dsk != curr_dsk) && (dsk != -1)) { // second condition for sticky windows w->hide(); } } // FIXME: multi-desktop hacks for Win and Mac required #endif if(w->isMaximized()) w->showMaximized(); else w->showNormal(); //if(grabFocus) // w->setActiveWindow(); w->raise(); w->activateWindow(); #ifdef Q_WS_WIN // TODO: unify with AdvancedWidget::bringToFront() ForceForegroundWindow(w->winId()); #endif }
void MainWindow::configureFilter() { QWidget *widget = filter.settings(); if(widget) { widget->show(); widget->activateWindow(); widget->raise(); } }
void ConnectionPageWindowObject::showAndActivate() { QWidget *widget = dynamic_cast<QWidget*>(this); Q_ASSERT(widget); widget->show(); widget->activateWindow(); widget->raise(); }
//----------------------------------------------------------------------------- void MemPanel::editData(int n) { if(tab->rowCount()<1) return; if(n<0) n = tab->currentRow(); if(n<0) n = 0; mglDataA *v = parser.FindVar(tab->item(n,0)->text().toStdString().c_str()); if(!v) return; QWidget *t; if(v->o) t = (QWidget *)v->o; else t = newDataWnd(infoDlg,wnd,v); t->showMaximized(); t->activateWindow(); }
void WindowMenu::showWindow() { QAction* pAction = qobject_cast<QAction*>(sender()); if (!pAction) return; QWidget* pWidget = pAction->data().value<QWidget*>(); if (!pWidget) return; if (pWidget->isMinimized()) pWidget->setWindowState(pWidget->windowState() & ~Qt::WindowMinimized); pWidget->activateWindow(); }
void ICore::raiseWindow(QWidget *widget) { if (!widget) return; QWidget *window = widget->window(); if (window == m_mainwindow) { m_mainwindow->raiseWindow(); } else { window->raise(); window->activateWindow(); } }
//----------------------------------------------------------------------------- void MemPanel::newTable() { bool ok; QString name = QInputDialog::getText(this, tr("UDAV - New variable"), tr("Enter name for new variable"), QLineEdit::Normal, "", &ok); if(!ok || name.isEmpty()) return; mglData *v = parser.AddVar(name.toStdString().c_str()); QWidget *t; if(v->o) t = (QWidget *)v->o; else t = newDataWnd(infoDlg,wnd,v); t->showMaximized(); t->activateWindow(); refresh(); }
/*! \reimp */ bool QAccessibleApplication::doAction(int action, int child, const QVariantList ¶m) { if (action == 0 || action == 1) { QWidget *w = 0; w = QApplication::activeWindow(); if (!w) w = topLevelWidgets().at(0); if (!w) return false; w->activateWindow(); return true; } return QAccessibleObject::doAction(action, child, param); }
void Dialog::showView() { prepareView(); QWidget * w = asQWidget(); if (w->isVisible()) { w->raise(); w->activateWindow(); } else w->show(); if (wantInitialFocus()) w->setFocus(); else { lyxview_->raise(); lyxview_->activateWindow(); lyxview_->setFocus(); } }
void Application::parseArgs( const QStringList &args ) { QStringList params = args; params.removeAll("-capi"); params.removeAll("-cng"); params.removeAll("-pkcs11"); params.removeAll("-noNativeFileDialog"); QWidget *w = new MainWindow(); #ifdef Q_OS_MAC w->installEventFilter( d->bar ); #endif w->addAction( d->closeAction ); w->activateWindow(); w->show(); w->raise(); if( !params.isEmpty() ) QMetaObject::invokeMethod( w, "open", Q_ARG(QStringList,params) ); }
bool SessionsManager::hasUrl(const QUrl &url, bool activate) { for (int i = 0; i < m_managers.count(); ++i) { if (m_managers.at(i)->hasUrl(url, activate)) { QWidget *window = qobject_cast<QWidget*>(m_managers.at(i)->parent()); if (window) { window->raise(); window->activateWindow(); } return true; } } return false; }
/* void TabDropDock::mousePressEvent(QMouseEvent *e) { if (e->button() == Qt::LeftButton) m_startDragPos = e->pos(); } void TabDropDock::mouseMoveEvent(QMouseEvent *e) { if (e->buttons() & Qt::LeftButton) { int distance = (e->pos() - m_startDragPos).manhattanLength(); if (distance >= QApplication::startDragDistance()) performDrag(); } } */ void TabDropDock::slotPerformDrag() { // emit(signalFloatOrDockMe(this)); QDrag *drag = new QDrag(this); QWidget *widget = currentWidget(); if (widget) { WidgetMimeData *mimeData = new WidgetMimeData(widget); drag->setMimeData(mimeData); if (drag->exec(Qt::MoveAction) != Qt::MoveAction) { if (widget->parent() != 0) { widget->setParent(0); widget->setGeometry(QCursor::pos().x(),QCursor::pos().y(),width(),height()); widget->show(); widget->raise(); widget->activateWindow(); // removeTab(currentIndex()); } } } // this->repaint(); }
void tst_QWindowContainer::testActivation() { QWidget root; QWindow *window = new QWindow(); QWidget *container = QWidget::createWindowContainer(window, &root); container->setGeometry(100, 100, 200, 100); root.setGeometry(100, 100, 400, 300); root.show(); root.activateWindow(); QVERIFY(QTest::qWaitForWindowExposed(&root)); QVERIFY(QTest::qWaitForWindowActive(root.windowHandle())); QVERIFY(QGuiApplication::focusWindow() == root.windowHandle()); // Verify that all states in the root widget indicate it is active QVERIFY(root.windowHandle()->isActive()); QVERIFY(root.isActiveWindow()); QCOMPARE(root.palette().currentColorGroup(), QPalette::Active); // Under KDE (ubuntu 12.10), we experience that doing two activateWindow in a row // does not work. The second gets ignored by the window manager, even though the // timestamp in the xcb connection is unique for both. if (QGuiApplication::platformName() == "xcb") QTest::qWait(100); window->requestActivate(); QTRY_VERIFY(QGuiApplication::focusWindow() == window); // Verify that all states in the root widget still indicate it is active QVERIFY(root.windowHandle()->isActive()); QVERIFY(root.isActiveWindow()); QCOMPARE(root.palette().currentColorGroup(), QPalette::Active); }
QString qt_mac_get_save_file_name(const QFileDialogArgs &args, QString *pwd, QString *selectedFilter) { QWidget *parent = args.parent; OSErr err; QString retstr; NavDialogCreationOptions options; NavGetDefaultDialogCreationOptions(&options); static const int w = 450, h = 350; if (args.options & QFileDialog::DontConfirmOverwrite) options.optionFlags |= kNavDontConfirmReplacement; options.modality = kWindowModalityAppModal; options.location.h = options.location.v = -1; if (!args.directory.isEmpty()) options.saveFileName = QCFString::toCFStringRef(args.selection); if (!args.caption.isEmpty()) options.windowTitle = QCFString::toCFStringRef(args.caption); if (parent && parent->isVisible()) { WindowClass wclass; GetWindowClass(qt_mac_window_for(parent), &wclass); if (!(args.options & QFileDialog::DontUseSheet) && (wclass == kDocumentWindowClass || wclass == kFloatingWindowClass || wclass == kMovableModalWindowClass)) { options.modality = kWindowModalityWindowModal; options.parentWindow = qt_mac_window_for(parent); // The parent needs to be active for the sheet to get keyboard focus. if (!parent->isActiveWindow()) parent->activateWindow(); } else { parent = parent->window(); QString s = parent->windowTitle(); options.clientName = CFStringCreateWithCharacters(0, (UniChar *)s.unicode(), s.length()); options.location.h = (parent->x() + (parent->width() / 2)) - (w / 2); options.location.v = (parent->y() + (parent->height() / 2)) - (h / 2); QRect r = QApplication::desktop()->screenGeometry( QApplication::desktop()->screenNumber(parent)); if (options.location.h + w > r.right()) options.location.h -= (options.location.h + w) - r.right() + 10; if (options.location.v + h > r.bottom()) options.location.v -= (options.location.v + h) - r.bottom() + 10; } #if 0 } else if (QWidget *p = qApp->mainWidget()) { static int last_screen = -1; int scr = QApplication::desktop()->screenNumber(p); if (last_screen != scr) { QRect r = QApplication::desktop()->screenGeometry(scr); options.location.h = (r.x() + (r.width() / 2)) - (w / 2); options.location.v = (r.y() + (r.height() / 2)) - (h / 2); } #endif } QList<qt_mac_filter_name*> filts = qt_mac_make_filters_list(args.filter); qt_mac_nav_filter_type t; t.saveDialog = true; t.index = 0; t.filts = &filts; if (filts.count() > 1) { int i = 0; CFStringRef *arr = static_cast<CFStringRef *>(malloc(sizeof(CFStringRef) * filts.count())); for (QList<qt_mac_filter_name*>::const_iterator it = filts.constBegin(); it != filts.constEnd(); ++it) arr[i++] = QCFString::toCFStringRef((*it)->description); options.popupExtension = CFArrayCreate(0, reinterpret_cast<const void **>(arr), filts.count(), 0); } NavDialogRef dlg; if (NavCreatePutFileDialog(&options, 'cute', kNavGenericSignature, make_navProcUPP(), static_cast<void *>(filts.isEmpty() ? 0 : &t), &dlg)) { qDebug("Shouldn't happen %s:%d", __FILE__, __LINE__); return retstr; } if (pwd && !pwd->isEmpty()) { FSRef fsref; if (qt_mac_create_fsref(*pwd, &fsref) == noErr) { AEDesc desc; if (AECreateDesc(typeFSRef, &fsref, sizeof(FSRef), &desc) == noErr) NavCustomControl(dlg, kNavCtlSetLocation, (void*)&desc); } } NavDialogRun(dlg); if (selectedFilter) { NavMenuItemSpec navSpec; bzero(&navSpec, sizeof(NavMenuItemSpec)); qt_mac_filter_name *sel_filt_name = qt_mac_make_filters_list(*selectedFilter).at(0); for (int i = 0; i < filts.count(); ++i) { const qt_mac_filter_name *filter = filts.at(i); if (sel_filt_name->description == filter->description && sel_filt_name->regxp == filter->regxp && sel_filt_name->filter == filter->filter) { navSpec.menuType = i; break; } } NavCustomControl(dlg, kNavCtlSelectCustomType, &navSpec); } if (options.modality == kWindowModalityWindowModal) { //simulate modality QWidget modal_widg(parent, Qt::Sheet); modal_widg.createWinId(); QApplicationPrivate::enterModal(&modal_widg); while (g_nav_blocking) qApp->processEvents(QEventLoop::WaitForMoreEvents); QApplicationPrivate::leaveModal(&modal_widg); } if (NavDialogGetUserAction(dlg) != kNavUserActionSaveAs) { NavDialogDispose(dlg); return retstr; } NavReplyRecord ret; NavDialogGetReply(dlg, &ret); NavDialogDispose(dlg); long count; err = AECountItems(&(ret.selection), &count); if (!ret.validRecord || err != noErr || !count) { NavDisposeReply(&ret); return retstr; } AEKeyword keyword; DescType type; Size size; FSRef ref; err = AEGetNthPtr(&(ret.selection), 1, typeFSRef, &keyword, &type, &ref, sizeof(ref), &size); if (err == noErr) { if (!str_buffer) { qAddPostRoutine(cleanup_str_buffer); str_buffer = (UInt8 *)malloc(1024); } FSRefMakePath(&ref, str_buffer, 1024); retstr = QString::fromUtf8((const char *)str_buffer); //now filename CFStringGetCString(ret.saveFileName, (char *)str_buffer, 1024, kCFStringEncodingUTF8); retstr += QLatin1String("/") + QString::fromUtf8((const char *)str_buffer); } NavDisposeReply(&ret); if (selectedFilter) *selectedFilter = filts.at(t.index)->filter; while (!filts.isEmpty()) delete filts.takeFirst(); return retstr; }
void QWidgetProto::activateWindow() { QWidget *item = qscriptvalue_cast<QWidget*>(thisObject()); if (item) item->activateWindow(); }
void QWidgetWindow::handleMouseEvent(QMouseEvent *event) { static const QEvent::Type contextMenuTrigger = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::ContextMenuOnMouseRelease).toBool() ? QEvent::MouseButtonRelease : QEvent::MouseButtonPress; if (qApp->d_func()->inPopupMode()) { QWidget *activePopupWidget = qApp->activePopupWidget(); QWidget *popup = activePopupWidget; QPoint mapped = event->pos(); if (popup != m_widget) mapped = popup->mapFromGlobal(event->globalPos()); bool releaseAfter = false; QWidget *popupChild = popup->childAt(mapped); if (popup != qt_popup_down) { qt_button_down = 0; qt_popup_down = 0; } switch (event->type()) { case QEvent::MouseButtonPress: case QEvent::MouseButtonDblClick: qt_button_down = popupChild; qt_popup_down = popup; break; case QEvent::MouseButtonRelease: releaseAfter = true; break; default: break; // nothing for mouse move } int oldOpenPopupCount = openPopupCount; if (popup->isEnabled()) { // deliver event qt_replay_popup_mouse_event = false; QWidget *receiver = popup; QPoint widgetPos = mapped; if (qt_button_down) receiver = qt_button_down; else if (popupChild) receiver = popupChild; if (receiver != popup) widgetPos = receiver->mapFromGlobal(event->globalPos()); QWidget *alien = m_widget->childAt(m_widget->mapFromGlobal(event->globalPos())); QMouseEvent e(event->type(), widgetPos, event->windowPos(), event->screenPos(), event->button(), event->buttons(), event->modifiers()); QGuiApplicationPrivate::setMouseEventSource(&e, QGuiApplicationPrivate::mouseEventSource(event)); e.setTimestamp(event->timestamp()); QApplicationPrivate::sendMouseEvent(receiver, &e, alien, m_widget, &qt_button_down, qt_last_mouse_receiver); } else { // close disabled popups when a mouse button is pressed or released switch (event->type()) { case QEvent::MouseButtonPress: case QEvent::MouseButtonDblClick: case QEvent::MouseButtonRelease: popup->close(); break; default: break; } } if (qApp->activePopupWidget() != activePopupWidget && qt_replay_popup_mouse_event) { if (m_widget->windowType() != Qt::Popup) qt_button_down = 0; if (event->type() == QEvent::MouseButtonPress) { // the popup disappeared, replay the mouse press event QWidget *w = QApplication::widgetAt(event->globalPos()); if (w && !QApplicationPrivate::isBlockedByModal(w)) { // activate window of the widget under mouse pointer if (!w->isActiveWindow()) { w->activateWindow(); w->raise(); } QWindow *win = w->windowHandle(); if (!win) win = w->nativeParentWidget()->windowHandle(); if (win && win->geometry().contains(event->globalPos())) { const QPoint localPos = win->mapFromGlobal(event->globalPos()); QMouseEvent e(QEvent::MouseButtonPress, localPos, localPos, event->globalPos(), event->button(), event->buttons(), event->modifiers()); QGuiApplicationPrivate::setMouseEventSource(&e, QGuiApplicationPrivate::mouseEventSource(event)); e.setTimestamp(event->timestamp()); QApplication::sendSpontaneousEvent(win, &e); } } } qt_replay_popup_mouse_event = false; #ifndef QT_NO_CONTEXTMENU } else if (event->type() == contextMenuTrigger && event->button() == Qt::RightButton && (openPopupCount == oldOpenPopupCount)) { QWidget *popupEvent = popup; if (qt_button_down) popupEvent = qt_button_down; else if(popupChild) popupEvent = popupChild; QContextMenuEvent e(QContextMenuEvent::Mouse, mapped, event->globalPos(), event->modifiers()); QApplication::sendSpontaneousEvent(popupEvent, &e); #endif } if (releaseAfter) { qt_button_down = 0; qt_popup_down = 0; } return; } // modal event handling if (QApplicationPrivate::instance()->modalState() && !qt_try_modal(m_widget, event->type())) return; // which child should have it? QWidget *widget = m_widget->childAt(event->pos()); QPoint mapped = event->pos(); if (!widget) widget = m_widget; if (event->type() == QEvent::MouseButtonPress) qt_button_down = widget; QWidget *receiver = QApplicationPrivate::pickMouseReceiver(m_widget, event->windowPos().toPoint(), &mapped, event->type(), event->buttons(), qt_button_down, widget); if (!receiver) { if (event->type() == QEvent::MouseButtonRelease) QApplicationPrivate::mouse_buttons &= ~event->button(); return; } if ((event->type() != QEvent::MouseButtonPress) || !(event->flags().testFlag(Qt::MouseEventCreatedDoubleClick))) { // The preceding statement excludes MouseButtonPress events which caused // creation of a MouseButtonDblClick event. QTBUG-25831 QMouseEvent translated(event->type(), mapped, event->windowPos(), event->screenPos(), event->button(), event->buttons(), event->modifiers()); QGuiApplicationPrivate::setMouseEventSource(&translated, QGuiApplicationPrivate::mouseEventSource(event)); translated.setTimestamp(event->timestamp()); QApplicationPrivate::sendMouseEvent(receiver, &translated, widget, m_widget, &qt_button_down, qt_last_mouse_receiver); } #ifndef QT_NO_CONTEXTMENU if (event->type() == contextMenuTrigger && event->button() == Qt::RightButton) { QContextMenuEvent e(QContextMenuEvent::Mouse, mapped, event->globalPos(), event->modifiers()); QGuiApplication::sendSpontaneousEvent(receiver, &e); } #endif }
void Adaptor::RaiseWindow() { QWidget * pp = qobject_cast<QWidget*>(parent()); pp->activateWindow(); pp->raise(); }
void QApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent *e) { if (!e->widget) return; // qDebug() << "handleMouseEvent" << tlw << ev.pos() << ev.globalPos() << hex << ev.buttons(); static QWeakPointer<QWidget> implicit_mouse_grabber; QEvent::Type type; // move first Qt::MouseButtons stateChange = e->buttons ^ buttons; if (e->globalPos != QPoint(qt_last_x, qt_last_y) && (stateChange != Qt::NoButton)) { QWindowSystemInterfacePrivate::MouseEvent * newMouseEvent = new QWindowSystemInterfacePrivate::MouseEvent(e->widget.data(), e->timestamp, e->localPos, e->globalPos, e->buttons); QWindowSystemInterfacePrivate::windowSystemEventQueue.prepend(newMouseEvent); // just in case the move triggers a new event loop stateChange = Qt::NoButton; } QWidget * tlw = e->widget.data(); QPoint localPoint = e->localPos; QPoint globalPoint = e->globalPos; QWidget *mouseWindow = tlw; Qt::MouseButton button = Qt::NoButton; if (qt_last_x != globalPoint.x() || qt_last_y != globalPoint.y()) { type = QEvent::MouseMove; qt_last_x = globalPoint.x(); qt_last_y = globalPoint.y(); if (qAbs(globalPoint.x() - mousePressX) > mouse_double_click_distance|| qAbs(globalPoint.y() - mousePressY) > mouse_double_click_distance) mousePressButton = Qt::NoButton; } else { // check to see if a new button has been pressed/released for (int check = Qt::LeftButton; check <= Qt::XButton2; check = check << 1) { if (check & stateChange) { button = Qt::MouseButton(check); break; } } if (button == Qt::NoButton) { // Ignore mouse events that don't change the current state return; } buttons = e->buttons; if (button & e->buttons) { if ((e->timestamp - mousePressTime) < static_cast<ulong>(QApplication::doubleClickInterval()) && button == mousePressButton) { type = QEvent::MouseButtonDblClick; mousePressButton = Qt::NoButton; } else { type = QEvent::MouseButtonPress; mousePressTime = e->timestamp; mousePressButton = button; mousePressX = qt_last_x; mousePressY = qt_last_y; } } else type = QEvent::MouseButtonRelease; } if (self->inPopupMode()) { //popup mouse handling is magical... mouseWindow = qApp->activePopupWidget(); implicit_mouse_grabber.clear(); //### how should popup mode and implicit mouse grab interact? } else if (tlw && app_do_modal && !qt_try_modal(tlw, QEvent::MouseButtonRelease) ) { //even if we're blocked by modality, we should deliver the mouse release event.. //### this code is not completely correct: multiple buttons can be pressed simultaneously if (!(implicit_mouse_grabber && buttons == Qt::NoButton)) { //qDebug() << "modal blocked mouse event to" << tlw; return; } } // find the tlw if we didn't get it from the plugin if (!mouseWindow) { mouseWindow = QApplication::topLevelAt(globalPoint); } if (!mouseWindow && !implicit_mouse_grabber) mouseWindow = QApplication::desktop(); if (mouseWindow && mouseWindow != tlw) { //we did not get a sensible localPoint from the window system, so let's calculate it localPoint = mouseWindow->mapFromGlobal(globalPoint); } // which child should have it? QWidget *mouseWidget = mouseWindow; if (mouseWindow) { QWidget *w = mouseWindow->childAt(localPoint); if (w) { mouseWidget = w; } } //handle implicit mouse grab if (type == QEvent::MouseButtonPress && !implicit_mouse_grabber) { implicit_mouse_grabber = mouseWidget; Q_ASSERT(mouseWindow); mouseWindow->activateWindow(); //focus } else if (implicit_mouse_grabber) { mouseWidget = implicit_mouse_grabber.data(); mouseWindow = mouseWidget->window(); if (mouseWindow != tlw) localPoint = mouseWindow->mapFromGlobal(globalPoint); } Q_ASSERT(mouseWidget); //localPoint is local to mouseWindow, but it needs to be local to mouseWidget localPoint = mouseWidget->mapFrom(mouseWindow, localPoint); if (buttons == Qt::NoButton) { //qDebug() << "resetting mouse grabber"; implicit_mouse_grabber.clear(); } if (mouseWidget != qt_last_mouse_receiver) { dispatchEnterLeave(mouseWidget, qt_last_mouse_receiver); qt_last_mouse_receiver = mouseWidget; } // Remember, we might enter a modal event loop when sending the event, // so think carefully before adding code below this point. // qDebug() << "sending mouse ev." << ev.type() << localPoint << globalPoint << ev.button() << ev.buttons() << mouseWidget << "mouse grabber" << implicit_mouse_grabber; QMouseEvent ev(type, localPoint, globalPoint, button, buttons, QApplication::keyboardModifiers()); QList<QWeakPointer<QPlatformCursor> > cursors = QPlatformCursorPrivate::getInstances(); foreach (QWeakPointer<QPlatformCursor> cursor, cursors) { if (cursor) cursor.data()->pointerEvent(ev); } int oldOpenPopupCount = openPopupCount; QApplication::sendSpontaneousEvent(mouseWidget, &ev); #ifndef QT_NO_CONTEXTMENU if (type == QEvent::MouseButtonPress && button == Qt::RightButton && (openPopupCount == oldOpenPopupCount)) { QContextMenuEvent e(QContextMenuEvent::Mouse, localPoint, globalPoint, QApplication::keyboardModifiers()); QApplication::sendSpontaneousEvent(mouseWidget, &e); } #endif // QT_NO_CONTEXTMENU }
/** \return **/ void BfCompany::cargaConf() { BL_FUNC_DEBUG QFile file ( g_confpr->value( CONF_DIR_USER ) + "bulmafact_" + dbName() + ".cfn" ); QDomDocument doc ( "mydocument" ); if ( !file.open ( QIODevice::ReadOnly ) ) return; if ( !doc.setContent ( &file ) ) { file.close(); return; } file.close(); // print out the element names of all elements that are direct children // of the outermost element. QDomElement docElem = doc.documentElement(); QDomElement principal = docElem.firstChildElement ( "PRINCIPAL" ); /// Cogemos la coordenada X QString nx = principal.firstChildElement ( "X" ).toElement().text(); /// Cogemos la coordenada Y QString ny = principal.firstChildElement ( "Y" ).toElement().text(); /// Cogemos el ancho QString nwidth = principal.firstChildElement ( "WIDTH" ).toElement().text(); /// Cogemos el alto QString nheight = principal.firstChildElement ( "HEIGHT" ).toElement().text(); /// Si está maximizada, ignoramos las otras dimensiones if (principal.firstChildElement ( "MAXIMIZED" ).toElement().text() == "true") m_bulmafact->setWindowState(Qt::WindowMaximized); else /// Establecemos la geometria de la ventana principal. m_bulmafact->setGeometry ( nx.toInt(), ny.toInt(), nwidth.toInt(), nheight.toInt() ); /// Cogemos el indexador QString indexador = principal.firstChildElement ( "INDEXADOR" ).toElement().text(); if ( indexador == "true" ) { s_indexadorCambiaEstado ( true ); m_bulmafact->actionIndexador->setChecked ( true ); } else { s_indexadorCambiaEstado ( false ); m_bulmafact->actionIndexador->setChecked ( false ); } // end if /// Cogemos el ancho del indexador m_bulmafact->restoreState ( QByteArray::fromBase64 ( QByteArray ( principal.firstChildElement ( "TOOLBARSDOCKWIDGETS" ).toElement().text().toLatin1() ) ) ); /// Tratamos cada ventana QWidget *activewindow = NULL; QDomNodeList nodos = docElem.elementsByTagName ( "VENTANA" ); for ( int i = 0; i < nodos.count(); i++ ) { QDomNode ventana = nodos.item ( i ); QDomElement e1 = ventana.toElement(); /// try to convert the node to an element. if ( !e1.isNull() ) { /// the node was really an element. QString vname = e1.firstChildElement ( "VNAME" ).toElement().text(); for ( int j = 0; j < m_windowListDock->numVentanas(); j++ ) { QObject *obj = m_windowListDock->ventana ( j ); QWidget *wid = ( QWidget * ) obj; if ( obj->objectName() == vname ) { QString vx = e1.firstChildElement ( "VX" ).toElement().text(); QString vy = e1.firstChildElement ( "VY" ).toElement().text(); QString vwidth = e1.firstChildElement ( "VWIDTH" ).toElement().text(); QString vheight = e1.firstChildElement ( "VHEIGHT" ).toElement().text(); QString vvisible = e1.firstChildElement ( "VVISIBLE" ).toElement().text(); QString vmaximized = e1.firstChildElement ( "VMAXIMIZED" ).toElement().text(); QString vactivewindow = e1.firstChildElement ( "VACTIVEWINDOW" ).toElement().text(); /// Establecemos la geometria de la ventana principal. wid->resize ( vwidth.toInt(), vheight.toInt() ); wid->parentWidget() ->move ( vx.toInt(), vy.toInt() ); if ( vvisible == "true" ) { wid->showNormal(); } // end if if ( vmaximized == "true" ) { wid->showMaximized(); } if ( vactivewindow == "true" ) { activewindow = wid; } } // end if } // end for } // end if } // end for /// Si hay una ventana activa se pone como activa. if ( activewindow ) activewindow->activateWindow(); }
void QWidgetWindow::handleMouseEvent(QMouseEvent *event) { static const QEvent::Type contextMenuTrigger = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::ContextMenuOnMouseRelease).toBool() ? QEvent::MouseButtonRelease : QEvent::MouseButtonPress; if (qApp->d_func()->inPopupMode()) { QWidget *activePopupWidget = qApp->activePopupWidget(); QPoint mapped = event->pos(); if (activePopupWidget != m_widget) mapped = activePopupWidget->mapFromGlobal(event->globalPos()); bool releaseAfter = false; QWidget *popupChild = activePopupWidget->childAt(mapped); if (activePopupWidget != qt_popup_down) { qt_button_down = 0; qt_popup_down = 0; } switch (event->type()) { case QEvent::MouseButtonPress: case QEvent::MouseButtonDblClick: qt_button_down = popupChild; qt_popup_down = activePopupWidget; break; case QEvent::MouseButtonRelease: releaseAfter = true; break; default: break; // nothing for mouse move } int oldOpenPopupCount = openPopupCount; if (activePopupWidget->isEnabled()) { // deliver event qt_replay_popup_mouse_event = false; QWidget *receiver = activePopupWidget; QPoint widgetPos = mapped; if (qt_button_down) receiver = qt_button_down; else if (popupChild) receiver = popupChild; if (receiver != activePopupWidget) widgetPos = receiver->mapFromGlobal(event->globalPos()); QWidget *alien = receiver; #if !defined(Q_OS_OSX) && !defined(Q_OS_IOS) // Cocoa tracks popups const bool reallyUnderMouse = activePopupWidget->rect().contains(mapped); const bool underMouse = activePopupWidget->underMouse(); if (activePopupWidget != m_widget || (!underMouse && qt_button_down)) { // If active popup menu is not the first-level popup menu then we must emulate enter/leave events, // because first-level popup menu grabs the mouse and enter/leave events are delivered only to it // by QPA. Make an exception for first-level popup menu when the mouse button is pressed on widget. if (underMouse != reallyUnderMouse) { if (reallyUnderMouse) { QApplicationPrivate::dispatchEnterLeave(receiver, Q_NULLPTR, event->screenPos()); qt_last_mouse_receiver = receiver; } else { QApplicationPrivate::dispatchEnterLeave(Q_NULLPTR, qt_last_mouse_receiver, event->screenPos()); qt_last_mouse_receiver = receiver; receiver = activePopupWidget; } } } else if (!reallyUnderMouse) { alien = Q_NULLPTR; } #endif QMouseEvent e(event->type(), widgetPos, event->windowPos(), event->screenPos(), event->button(), event->buttons(), event->modifiers(), event->source()); e.setTimestamp(event->timestamp()); QApplicationPrivate::sendMouseEvent(receiver, &e, alien, receiver->window(), &qt_button_down, qt_last_mouse_receiver); qt_last_mouse_receiver = receiver; } else { // close disabled popups when a mouse button is pressed or released switch (event->type()) { case QEvent::MouseButtonPress: case QEvent::MouseButtonDblClick: case QEvent::MouseButtonRelease: activePopupWidget->close(); break; default: break; } } if (qApp->activePopupWidget() != activePopupWidget && qt_replay_popup_mouse_event && QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::ReplayMousePressOutsidePopup).toBool()) { if (m_widget->windowType() != Qt::Popup) qt_button_down = 0; if (event->type() == QEvent::MouseButtonPress) { // the popup disappeared, replay the mouse press event QWidget *w = QApplication::widgetAt(event->globalPos()); if (w && !QApplicationPrivate::isBlockedByModal(w)) { // activate window of the widget under mouse pointer if (!w->isActiveWindow()) { w->activateWindow(); w->raise(); } QWindow *win = w->windowHandle(); if (!win) win = w->nativeParentWidget()->windowHandle(); if (win) { const QRect globalGeometry = win->isTopLevel() ? win->geometry() : QRect(win->mapToGlobal(QPoint(0, 0)), win->size()); if (globalGeometry.contains(event->globalPos())) { // Use postEvent() to ensure the local QEventLoop terminates when called from QMenu::exec() const QPoint localPos = win->mapFromGlobal(event->globalPos()); QMouseEvent *e = new QMouseEvent(QEvent::MouseButtonPress, localPos, localPos, event->globalPos(), event->button(), event->buttons(), event->modifiers(), event->source()); QCoreApplicationPrivate::setEventSpontaneous(e, true); e->setTimestamp(event->timestamp()); QCoreApplication::postEvent(win, e); } } } } qt_replay_popup_mouse_event = false; #ifndef QT_NO_CONTEXTMENU } else if (event->type() == contextMenuTrigger && event->button() == Qt::RightButton && (openPopupCount == oldOpenPopupCount)) { QWidget *popupEvent = activePopupWidget; if (qt_button_down) popupEvent = qt_button_down; else if(popupChild) popupEvent = popupChild; QContextMenuEvent e(QContextMenuEvent::Mouse, mapped, event->globalPos(), event->modifiers()); QApplication::sendSpontaneousEvent(popupEvent, &e); #endif } if (releaseAfter) { qt_button_down = 0; qt_popup_down = 0; } return; } // modal event handling if (QApplicationPrivate::instance()->modalState() && !qt_try_modal(m_widget, event->type())) return; // which child should have it? QWidget *widget = m_widget->childAt(event->pos()); QPoint mapped = event->pos(); if (!widget) widget = m_widget; if (event->type() == QEvent::MouseButtonPress) qt_button_down = widget; QWidget *receiver = QApplicationPrivate::pickMouseReceiver(m_widget, event->windowPos().toPoint(), &mapped, event->type(), event->buttons(), qt_button_down, widget); if (!receiver) { if (event->type() == QEvent::MouseButtonRelease) QApplicationPrivate::mouse_buttons &= ~event->button(); return; } if ((event->type() != QEvent::MouseButtonPress) || !(event->flags().testFlag(Qt::MouseEventCreatedDoubleClick))) { // The preceding statement excludes MouseButtonPress events which caused // creation of a MouseButtonDblClick event. QTBUG-25831 QMouseEvent translated(event->type(), mapped, event->windowPos(), event->screenPos(), event->button(), event->buttons(), event->modifiers(), event->source()); translated.setTimestamp(event->timestamp()); QApplicationPrivate::sendMouseEvent(receiver, &translated, widget, m_widget, &qt_button_down, qt_last_mouse_receiver); event->setAccepted(translated.isAccepted()); } #ifndef QT_NO_CONTEXTMENU if (event->type() == contextMenuTrigger && event->button() == Qt::RightButton && m_widget->rect().contains(event->pos())) { QContextMenuEvent e(QContextMenuEvent::Mouse, mapped, event->globalPos(), event->modifiers()); QGuiApplication::sendSpontaneousEvent(receiver, &e); } #endif }