void MainWindowPlugin::onOptionsChanged(const OptionsNode &ANode) { QWidget * widget = FMainWindowBorder ? (QWidget*)FMainWindowBorder : (QWidget*)FMainWindow; if (ANode.path() == OPV_MAINWINDOW_STAYONTOP) { bool show = widget->isVisible(); if (ANode.value().toBool()) widget->setWindowFlags(widget->windowFlags() | Qt::WindowStaysOnTopHint); else widget->setWindowFlags(widget->windowFlags() & ~Qt::WindowStaysOnTopHint); if (show) showMainWindow(); } #ifdef Q_OS_WIN else if (ANode.path() == OPV_MAINWINDOW_MINIMIZETOTRAY_W7) { if (QSysInfo::windowsVersion() == QSysInfo::WV_WINDOWS7) { bool minimize = ANode.value().toBool(); FMainWindowBorder->setMinimizeOnClose(!minimize); FMainWindowBorder->setShowInTaskBar(!minimize); if (minimize) disconnect(FMainWindowBorder ? (QObject*)FMainWindowBorder : (QObject*)FMainWindow, SIGNAL(closed()), this, SLOT(onMainWindowClosed())); else connect(FMainWindowBorder ? (QObject*)FMainWindowBorder : (QObject*)FMainWindow, SIGNAL(closed()), SLOT(onMainWindowClosed())); } else FMainWindowBorder->setShowInTaskBar(false); } #endif }
void SAChasyAppSettingsDialog::apply() { mSettingsForm->applySettings(); bool pravSutKur, dStrelka, ignoreDST, simpleView, showDate; int updateInterval, side; QColor backgroundColor; QColor shadowColor = mShadowColorButton->color(); mSettingsForm->getSettings(pravSutKur, dStrelka, ignoreDST, simpleView, showDate, updateInterval, backgroundColor, side); QSettings s; s.beginGroup("/SAKalendar/SAChasyApp"); s.setValue("PravSutKrug", pravSutKur); s.setValue("ShowDoly", dStrelka); s.setValue("IgnoreDST", ignoreDST); s.setValue("SimpleView", simpleView); s.setValue("ShowDate", showDate); s.setValue("UpdateInterval", updateInterval); s.setValue("BackgroundColor", backgroundColor); s.setValue("SideSize", side); s.setValue("StayOnTop", mWindowStaysOnTopCheckBox->isChecked()); s.setValue("ShadowColor", shadowColor); s.endGroup(); QWidget *parentW = parentWidget(); parentW->resize(side, side); parentW->setWindowFlags(mWindowStaysOnTopCheckBox->isChecked() ? parentW->windowFlags() | Qt::WindowStaysOnTopHint : parentW->windowFlags() ^ Qt::WindowStaysOnTopHint); parentW->show(); mDropShadowEffect->setColor(shadowColor); }
void MainWindowPlugin::onOptionsChanged(const OptionsNode &ANode) { if (ANode.path() == OPV_MAINWINDOW_STAYONTOP) { #ifdef Q_WS_MAC setWindowOntop(FMainWindow, ANode.value().toBool()); #else QWidget *widget = mainWindowTopWidget(); bool show = widget->isVisible(); if (ANode.value().toBool()) widget->setWindowFlags(widget->windowFlags() | Qt::WindowStaysOnTopHint); else widget->setWindowFlags(widget->windowFlags() & ~Qt::WindowStaysOnTopHint); if (show) showMainWindow(); #endif } else if (ANode.path() == OPV_MAINWINDOW_MINIMIZETOTRAY_W7) { if (isMinimizeToTray()) { Options::node(OPV_MAINWINDOW_MINIMIZENOTIFY_SHOWCOUNT).setValue(MINIMIZENOTIFY_MAX_SHOWCOUNT+1); } if (FMainWindowBorder) { FMainWindowBorder->setMinimizeOnClose(!isMinimizeToTray()); } if (!isMinimizeToTray() && !mainWindowTopWidget()->isVisible()) { hideMainWindow(); } } }
bool QSoftKeyManagerPrivateS60::skipCbaUpdate() { // Lets not update softkeys if // 1. We don't have application panes, i.e. cba // 2. Our CBA is not active, i.e. S60 native dialog or menu with custom CBA is shown // 2.1. Except if thre is no current CBA at all and WindowSoftkeysRespondHint is set // Note: Cannot use IsDisplayingMenuOrDialog since CBA update can be triggered before // menu/dialog CBA is actually displayed i.e. it is being costructed. CEikButtonGroupContainer *appUiCba = S60->buttonGroupContainer(); if (!appUiCba) return true; // CEikButtonGroupContainer::Current returns 0 if CBA is not visible at all CEikButtonGroupContainer *currentCba = CEikButtonGroupContainer::Current(); // Check if softkey need to be update even they are not visible bool cbaRespondsWhenInvisible = false; QWidget *window = QApplication::activeWindow(); if (window && (window->windowFlags() & Qt::WindowSoftkeysRespondHint)) cbaRespondsWhenInvisible = true; if (QApplication::testAttribute(Qt::AA_S60DontConstructApplicationPanes) || (appUiCba != currentCba && !cbaRespondsWhenInvisible)) { return true; } return false; }
bool KApplication::notify(QObject *receiver, QEvent *event) { QEvent::Type t = event->type(); if( t == QEvent::Show && receiver->isWidgetType()) { QWidget* w = static_cast< QWidget* >( receiver ); #if defined Q_WS_X11 if( w->isTopLevel() && !startupId().isEmpty()) // TODO better done using window group leader? KStartupInfo::setWindowStartupId( w->winId(), startupId()); #endif if( w->isTopLevel() && !( w->windowFlags() & Qt::X11BypassWindowManagerHint ) && w->windowType() != Qt::Popup && !event->spontaneous()) { if( d->app_started_timer == NULL ) { d->app_started_timer = new QTimer( this ); connect( d->app_started_timer, SIGNAL(timeout()), SLOT(_k_checkAppStartedSlot())); } if( !d->app_started_timer->isActive()) { d->app_started_timer->setSingleShot( true ); d->app_started_timer->start( 0 ); } } } return QApplication::notify(receiver, event); }
/*! \reimp */ QAccessible::State QAccessibleWidget::state(int child) const { if (child) return Normal; QAccessible::State state = Normal; QWidget *w = widget(); if (w->testAttribute(Qt::WA_WState_Visible) == false) state |= Invisible; if (w->focusPolicy() != Qt::NoFocus) state |= Focusable; if (w->hasFocus()) state |= Focused; if (!w->isEnabled()) state |= Unavailable; if (w->isWindow()) { if (w->windowFlags() & Qt::WindowSystemMenuHint) state |= Movable; if (w->minimumSize() != w->maximumSize()) state |= Sizeable; } return state; }
extern "C" void qtns_shutdown() { if (clients.count() > 0) { QMap<QtNPInstance *, QX11EmbedWidget *>::iterator it = clients.begin(); while (it != clients.end()) { delete it.value(); ++it; } clients.clear(); } if (!ownsqapp) return; // check if qApp still runs widgets (in other DLLs) QWidgetList widgets = qApp->allWidgets(); int count = widgets.count(); for (int w = 0; w < widgets.count(); ++w) { // ignore all Qt generated widgets QWidget *widget = widgets.at(w); if (widget->windowFlags() & Qt::Desktop) count--; } if (count) // qApp still used return; delete qApp; ownsqapp = false; }
int NWidgetPrototype::windowFlags() { QWidget *widget = qscriptvalue_cast<QWidget *>(thisObject()); if (widget) return (int)widget->windowFlags(); else return 0; }
/* Should we require that q is a toplevel window ??? Used by QWSManager */ void QWidgetPrivate::blitToScreen(const QRegion &globalrgn) { Q_Q(QWidget); QWidget *win = q->window(); QBrush bgBrush = win->palette().brush(win->backgroundRole()); bool opaque = bgBrush.style() == Qt::NoBrush || bgBrush.isOpaque(); QWidget::qwsDisplay()->repaintRegion(win->data->winid, win->windowFlags(), opaque, globalrgn); }
bool QWidgetProxy::alwaysOnTop() { QWidget *w = widget(); if(!w) return false; Qt::WindowFlags flags = w->windowFlags(); if( flags & Qt::Window && flags & Qt::WindowStaysOnTopHint ) return true; else return false; }
void pFileDialog::setDialog( pFileDialog* dlg, const QString& caption, const QString& dir, const QString& filter, bool enabledTextCodec, bool enabledOpenReadOnly, const QString& selectedFilter, QFileDialog::FileMode mode, QFileDialog::Options options ) { #if defined( Q_OS_MAC ) && QT_VERSION < 0x040500 if ( !options.testFlag( QFileDialog::DontUseSheet ) ) { // that's impossible to have a sheet in a sheet QWidget* parent = dlg->parentWidget(); if ( parent && !parent->windowFlags().testFlag( Qt::Sheet ) ) { dlg->setWindowFlags( dlg->windowFlags() | Qt::Sheet ); } } #endif // dialog settings dlg->setWindowTitle( caption ); dlg->setFileMode( mode ); dlg->setDirectory( dir.isEmpty() ? QDir::currentPath() : dir ); dlg->setTextCodecEnabled( enabledTextCodec ); dlg->setOpenReadOnlyEnabled( enabledOpenReadOnly ); dlg->setOptions( options ); switch ( mode ) { case QFileDialog::Directory: case QFileDialog::DirectoryOnly: case QFileDialog::ExistingFile: case QFileDialog::ExistingFiles: dlg->setAcceptMode( AcceptOpen ); break; case QFileDialog::AnyFile: dlg->setAcceptMode( AcceptSave ); break; } // set filters if needed if ( !filter.isEmpty() ) { dlg->setNameFilter( filter ); } // select file if needed ) if ( !dir.isEmpty() ) { dlg->selectFile( dir ); } // select correct filter if needed if ( !selectedFilter.isEmpty() ) { dlg->selectNameFilter( selectedFilter ); } }
virtual QObjectProxy *newInstance( PyrObject *po, QList<QVariant> & arguments ){ if( arguments.count() < 5 ) return 0; bool scroll = arguments[4].value<bool>(); QWidget *window; QWidget *canvas; if( scroll ) { QcScrollArea *scroll = new QcScrollArea(); window = scroll; canvas = scroll->widget(); } else { window = canvas = new QcCustomPainted(); } QString name = arguments[0].toString(); window->setWindowTitle( name ); QRect geom = arguments[1].value<QRect>(); bool resizable = arguments[2].value<bool>(); if( resizable ) { window->setGeometry( geom ); } else { window->move( geom.topLeft() ); window->setFixedSize( geom.size() ); } bool border = arguments[3].value<bool>(); if( !border ) window->setWindowFlags( window->windowFlags() | Qt::FramelessWindowHint ); QShortcut *closeShortcut = new QShortcut( QKeySequence( Qt::CTRL | Qt::Key_W ), window ); QObject::connect( closeShortcut, SIGNAL(activated()), window, SLOT(close()) ); QWidgetProxy *proxy = new QWidgetProxy( window, po ); QObject::connect( canvas, SIGNAL(painting(QPainter*)), proxy, SLOT(customPaint(QPainter*)) ); return proxy; }
quint32 AmbienteIntegration::parentWindowId(QWidget *widget) const { QWidget *parent = NULL; QWidget *test = widget; while (test) { Qt::WindowFlags type = test->windowFlags() & Qt::WindowType_Mask; if (type == Qt::Window) { parent = test; break; } else test = test->parentWidget(); } return m_ids.value(parent); }
void Utils::setCenter(QWidget *widget) { QRect rect = widget->geometry(); QWidget *parent = widget->parentWidget(); if (!parent){ rect.moveCenter(QApplication::desktop()->screenGeometry(widget).center()); } else{ if (widget->isWindow()){ QPoint center = parent->geometry().center(); if ((parent->windowFlags()&Qt::CustomizeWindowHint)){ center.ry() += widget->style()->pixelMetric(QStyle::PM_TitleBarHeight) / 2; } rect.moveCenter(center); } else{ rect.moveCenter(parent->rect().center()); } } widget->setGeometry(rect); }
/*! \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; }
bool VideoOutputEventFilter::eventFilter(QObject *watched, QEvent *event) { // a widget shown means it's available and not deleted if (event->type() == QEvent::Show || event->type() == QEvent::ShowToParent) { mRendererIsQObj = !!mpRenderer->widget(); return false; } if (!mRendererIsQObj) return false; /* * deleted renderer (after destroyed()) can not access it's member, so we must mark it as invalid. * hide event is sent when close. what about QEvent::Close? */ if (event->type() == QEvent::Close || event->type() == QEvent::Hide) { mRendererIsQObj = false; return true; } if (!mpRenderer) return false; if (!mpRenderer->isDefaultEventFilterEnabled()) return false; if (watched != mpRenderer->widget() /* && watched != mpRenderer->graphicsWidget()*/ //no showFullScreen() etc. ) return false; switch (event->type()) { case QEvent::KeyPress: { QKeyEvent *key_event = static_cast<QKeyEvent*>(event); int key = key_event->key(); //Qt::KeyboardModifiers modifiers = key_event->modifiers(); switch (key) { case Qt::Key_F: switchFullScreen(); break; case Qt::Key_I: mpRenderer->setQuality(VideoRenderer::Quality(((int)mpRenderer->quality()+1)%3)); break; case Qt::Key_T: { QWidget *w = mpRenderer->widget()->window(); Qt::WindowFlags wf = w->windowFlags(); if (wf & Qt::WindowStaysOnTopHint) { qDebug("Window not stays on top"); w->setWindowFlags(wf & ~Qt::WindowStaysOnTopHint); } else { qDebug("Window stays on top"); w->setWindowFlags(wf | Qt::WindowStaysOnTopHint); } //call setParent() when changing the flags, causing the widget to be hidden w->show(); } break; } } break; case QEvent::MouseButtonDblClick: switchFullScreen(); break; case QEvent::MouseButtonPress: { QMouseEvent *me = static_cast<QMouseEvent*>(event); Qt::MouseButton mbt = me->button(); if (mbt == Qt::LeftButton) { gMousePos = me->globalPos(); iMousePos = me->pos(); } } break; case QEvent::MouseButtonRelease: { QMouseEvent *me = static_cast<QMouseEvent*>(event); Qt::MouseButton mbt = me->button(); if (mbt != Qt::LeftButton) return false; iMousePos = QPoint(); gMousePos = QPoint(); } break; case QEvent::MouseMove: { if (iMousePos.isNull() || gMousePos.isNull()) return false; QMouseEvent *me = static_cast<QMouseEvent*>(event); QWidget *window = mpRenderer->widget()->window(); int x = window->pos().x(); int y = window->pos().y(); int dx = me->globalPos().x() - gMousePos.x(); int dy = me->globalPos().y() - gMousePos.y(); gMousePos = me->globalPos(); window->move(x + dx, y + dy); } break; default: break; } return false; }
/*! \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; } }
void QWidgetPrivate::show_sys() { Q_Q(QWidget); q->setAttribute(Qt::WA_Mapped); if (q->testAttribute(Qt::WA_DontShowOnScreen)) { invalidateBuffer(q->rect()); return; } if (q->isWindow()) { if (!q->testAttribute(Qt::WA_ShowWithoutActivating) && q->windowType() != Qt::Popup && q->windowType() != Qt::Tool && q->windowType() != Qt::ToolTip) { QWidget::qwsDisplay()->requestFocus(data.winid,true); } if (QWindowSurface *surface = q->windowSurface()) { const QRect frameRect = q->frameGeometry(); if (surface->geometry() != frameRect) surface->setGeometry(frameRect); } QRegion r = localRequestedRegion(); #ifndef QT_NO_QWS_MANAGER if (extra && extra->topextra && extra->topextra->qwsManager) { r.translate(data.crect.topLeft()); r += extra->topextra->qwsManager->region(); r.translate(-data.crect.topLeft()); } #endif data.fstrut_dirty = true; invalidateBuffer(r); bool staysontop = (q->windowFlags() & Qt::WindowStaysOnTopHint) || q->windowType() == Qt::Popup; if (!staysontop && q->parentWidget()) { // if our parent stays on top, so must we QWidget *ptl = q->parentWidget()->window(); if (ptl && (ptl->windowFlags() & Qt::WindowStaysOnTopHint)) staysontop = true; } QWSChangeAltitudeCommand::Altitude altitude; altitude = staysontop ? QWSChangeAltitudeCommand::StaysOnTop : QWSChangeAltitudeCommand::Raise; QWidget::qwsDisplay()->setAltitude(data.winid, altitude, true); if (!q->objectName().isEmpty()) { QWidget::qwsDisplay()->setWindowCaption(q, q->windowTitle()); } } #ifdef Q_BACKINGSTORE_SUBSURFACES else if ( extra && extra->topextra && extra->topextra->windowSurface) { QWSWindowSurface *surface; surface = static_cast<QWSWindowSurface*>(q->windowSurface()); const QPoint p = q->mapToGlobal(QPoint()); surface->setGeometry(QRect(p, q->size())); } #endif if (!q->window()->data->in_show) { invalidateBuffer(q->rect()); } }
/*! \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()); }
bool EventFilter::eventFilter(QObject *watched, QEvent *event) { //qDebug("EventFilter::eventFilter to %p", watched); Q_UNUSED(watched); /*if (watched == reinterpret_cast<QObject*>(player->renderer)) { qDebug("Event target is renderer: %s", watched->objectName().toAscii().constData()); }*/ //TODO: if not send to QWidget based class, return false; instanceOf()? QEvent::Type type = event->type(); switch (type) { case QEvent::MouseButtonPress: qDebug("EventFilter: Mouse press"); static_cast<QMouseEvent*>(event)->button(); //TODO: wheel to control volume etc. return false; break; case QEvent::KeyPress: { //qDebug("Event target = %p %p", watched, player->renderer); //avoid receive an event multiple times int key = static_cast<QKeyEvent*>(event)->key(); switch (key) { case Qt::Key_C: //capture player->captureVideo(); break; case Qt::Key_N: //check playing? player->playNextFrame(); break; case Qt::Key_P: player->play(); break; case Qt::Key_S: player->stop(); //check playing? break; case Qt::Key_Space: //check playing? qDebug("isPaused = %d", player->isPaused()); player->pause(!player->isPaused()); break; case Qt::Key_F: { //TODO: move to gui QWidget *w = qApp->activeWindow(); if (!w) return false; if (w->isFullScreen()) w->showNormal(); else w->showFullScreen(); } break; case Qt::Key_Up: if (player->audio) { qreal v = player->audio->volume(); if (v > 0.5) v += 0.1; else if (v > 0.1) v += 0.05; else v += 0.025; player->audio->setVolume(v); qDebug("vol = %.3f", player->audio->volume()); } break; case Qt::Key_Down: if (player->audio) { qreal v = player->audio->volume(); if (v > 0.5) v -= 0.1; else if (v > 0.1) v -= 0.05; else v -= 0.025; player->audio->setVolume(v); qDebug("vol = %.3f", player->audio->volume()); } break; case Qt::Key_O: { //TODO: emit a signal so we can use custome dialogs QString file = QFileDialog::getOpenFileName(0, tr("Open a video")); if (!file.isEmpty()) player->play(file); } break; case Qt::Key_Left: qDebug("<-"); player->seekBackward(); break; case Qt::Key_Right: qDebug("->"); player->seekForward(); break; case Qt::Key_M: if (player->audio) { player->audio->setMute(!player->audio->isMute()); } break; case Qt::Key_T: { QWidget *w = qApp->activeWindow(); if (!w) return false; Qt::WindowFlags wf = w->windowFlags(); if (wf & Qt::WindowStaysOnTopHint) { qDebug("Window not stays on top"); w->setWindowFlags(wf & ~Qt::WindowStaysOnTopHint); } else { qDebug("Window stays on top"); w->setWindowFlags(wf | Qt::WindowStaysOnTopHint); } //call setParent() when changing the flags, causing the widget to be hidden w->show(); } break; default: return false; } break; } default: return false; } return true; //false: for text input }
bool KCompletionBox::eventFilter( QObject *o, QEvent *e ) { int type = e->type(); QWidget *wid = qobject_cast<QWidget*>(o); if (o == this) { return false; } if (wid && wid == d->m_parent && (type == QEvent::Move || type == QEvent::Resize)) { hide(); return false; } if (wid && (wid->windowFlags() & Qt::Window) && type == QEvent::Move && wid == d->m_parent->window()) { hide(); return false; } if (type == QEvent::MouseButtonPress && (wid && !isAncestorOf(wid))) { if (!d->emitSelected && currentItem() && !qobject_cast<QScrollBar*>(o)) { Q_ASSERT(currentItem()); emit currentTextChanged(currentItem()->text() ); } hide(); e->accept(); return true; } if (wid && wid->isAncestorOf(d->m_parent) && isVisible()) { if ( type == QEvent::KeyPress ) { QKeyEvent *ev = static_cast<QKeyEvent *>( e ); switch ( ev->key() ) { case Qt::Key_Backtab: if ( d->tabHandling && (ev->modifiers() == Qt::NoButton || (ev->modifiers() & Qt::ShiftModifier)) ) { up(); ev->accept(); return true; } break; case Qt::Key_Tab: if ( d->tabHandling && (ev->modifiers() == Qt::NoButton) ) { down(); // #65877: Key_Tab should complete using the first // (or selected) item, and then offer completions again if (count() == 1) { KLineEdit* parent = qobject_cast<KLineEdit*>(d->m_parent); if (parent) { parent->doCompletion(currentItem()->text()); } else { hide(); } } ev->accept(); return true; } break; case Qt::Key_Down: down(); ev->accept(); return true; case Qt::Key_Up: // If there is no selected item and we've popped up above // our parent, select the first item when they press up. if ( !selectedItems().isEmpty() || mapToGlobal( QPoint( 0, 0 ) ).y() > d->m_parent->mapToGlobal( QPoint( 0, 0 ) ).y() ) up(); else down(); ev->accept(); return true; case Qt::Key_PageUp: pageUp(); ev->accept(); return true; case Qt::Key_PageDown: pageDown(); ev->accept(); return true; case Qt::Key_Escape: canceled(); ev->accept(); return true; case Qt::Key_Enter: case Qt::Key_Return: if ( ev->modifiers() & Qt::ShiftModifier ) { hide(); ev->accept(); // Consume the Enter event return true; } break; case Qt::Key_End: if ( ev->modifiers() & Qt::ControlModifier ) { end(); ev->accept(); return true; } break; case Qt::Key_Home: if ( ev->modifiers() & Qt::ControlModifier ) { home(); ev->accept(); return true; } default: break; } } else if ( type == QEvent::ShortcutOverride ) { // Override any accelerators that match // the key sequences we use here... QKeyEvent *ev = static_cast<QKeyEvent *>( e ); switch ( ev->key() ) { case Qt::Key_Down: case Qt::Key_Up: case Qt::Key_PageUp: case Qt::Key_PageDown: case Qt::Key_Escape: case Qt::Key_Enter: case Qt::Key_Return: ev->accept(); return true; break; case Qt::Key_Tab: case Qt::Key_Backtab: if ( ev->modifiers() == Qt::NoButton || (ev->modifiers() & Qt::ShiftModifier)) { ev->accept(); return true; } break; case Qt::Key_Home: case Qt::Key_End: if ( ev->modifiers() & Qt::ControlModifier ) { ev->accept(); return true; } break; default: break; } } else if ( type == QEvent::FocusOut ) { QFocusEvent* event = static_cast<QFocusEvent*>( e ); if (event->reason() != Qt::PopupFocusReason #ifdef Q_WS_WIN && (event->reason() != Qt::ActiveWindowFocusReason || QApplication::activeWindow() != this) #endif ) hide(); } } return KListWidget::eventFilter( o, e ); }
int Dialog::showDialog(const QString& view, QObject* viewModel, int type) { QDialog* dialog = NULL; QMainWindow* mainWindow = NULL; QWidget* windowWidget = NULL; QWidget* layoutWidget = NULL; switch (type) { case Dialog::MainWindow: mainWindow = new QMainWindow(); windowWidget = mainWindow; layoutWidget = new QWidget(windowWidget); mainWindow->setCentralWidget(layoutWidget); break; case Dialog::ModalDialog: dialog = new QDialog(QApplication::activeWindow()); windowWidget = dialog; layoutWidget = dialog; break; default: dialog = new QDialog(); windowWidget = dialog; layoutWidget = dialog; break; } QGridLayout* layout = new QGridLayout(layoutWidget); // Create view QDeclarativeView* v = new QDeclarativeView(layoutWidget); if (viewModel) { int count = viewModel->metaObject()->propertyCount(); for (int i = 0; i < count; ++i) { QMetaProperty p = viewModel->metaObject()->property(i); if (p.isReadable() && p.typeName() == QString("QDeclarativeImageProvider*")) { QString name = p.name(); QDeclarativeImageProvider* value = p.read(viewModel).value<QDeclarativeImageProvider*>(); v->engine()->addImageProvider(name.toLatin1(), new ProxyImageProvider(value)); } } v->rootContext()->setContextProperty("dataContext", viewModel); } QString path; foreach (path, importPaths) v->engine()->addImportPath(path); foreach (path, pluginPaths) v->engine()->addPluginPath(path); v->setSource(QUrl(view)); v->setResizeMode(QDeclarativeView::SizeRootObjectToView); // Initialize dialog QGraphicsObject* root = v->rootObject(); QVariant property = root->property("dialogTitle"); if (property.isValid()) windowWidget->setWindowTitle(property.toString()); property = root->property("dialogMinWidth"); if (property.isValid()) layoutWidget->setMinimumWidth(property.toInt()); property = root->property("dialogMinHeight"); if (property.isValid()) layoutWidget->setMinimumHeight(property.toInt()); property = root->property("dialogMaxWidth"); if (property.isValid()) layoutWidget->setMaximumWidth(property.toInt()); property = root->property("dialogMaxHeight"); if (property.isValid()) layoutWidget->setMaximumHeight(property.toInt()); property = root->property("dialogResizable"); if (property.isValid() && !property.toBool()) layout->setSizeConstraint(QLayout::SetFixedSize); Qt::WindowStates states = windowWidget->windowState(); Qt::WindowFlags flags = windowWidget->windowFlags(); property = root->property("dialogMinimizeButton"); if (property.isValid()) flags = property.toBool() ? flags | Qt::WindowMinimizeButtonHint : flags & ~Qt::WindowMinimizeButtonHint; property = root->property("dialogMaximizeButton"); if (property.isValid()) flags = property.toBool() ? flags | Qt::WindowMaximizeButtonHint : flags & ~Qt::WindowMaximizeButtonHint; property = root->property("dialogCloseButton"); if (property.isValid()) flags = property.toBool() ? flags | Qt::WindowCloseButtonHint : flags & ~Qt::WindowCloseButtonHint; property = root->property("dialogFullScreen"); if (property.isValid()) states = property.toBool() ? states | Qt::WindowFullScreen : states & ~Qt::WindowFullScreen; flags = flags & ~Qt::WindowContextHelpButtonHint; windowWidget->setWindowFlags(flags); windowWidget->setWindowState(states); property = root->property("dialogToolBar"); if (type == Dialog::MainWindow && property.isValid() && property.typeName() == QString("QDeclarativeListProperty<QDeclarativeItem>")) { QToolBar* toolbar = new QToolBar(mainWindow); toolbar->setMovable(false); toolbar->setFloatable(false); toolbar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); toolbar->setAllowedAreas(Qt::TopToolBarArea); QDeclarativeListProperty<QDeclarativeItem> btnList = property.value< QDeclarativeListProperty<QDeclarativeItem> >(); int btnCount = btnList.count(&btnList); for (int i = 0; i < btnCount; ++i) { QDeclarativeItem* item = btnList.at(&btnList, i); if (!item->property("text").isValid()) continue; QString itemText = item->property("text").toString(); QString itemTooltip = item->property("tooltip").isValid() ? item->property("tooltip").toString() : ""; QString itemIconSource = item->property("iconSource").isValid() ? item->property("iconSource").toString() : ""; int itemIconSize = item->property("iconSize").isValid() ? item->property("iconSize").toInt() : -1; if (itemText == "|") { toolbar->addSeparator(); } else if (itemText == "-") { QWidget* spacer = new QWidget(); spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); toolbar->addWidget(spacer); } else { QAction* action = new QAction(mainWindow); action->setText(itemText); action->setToolTip(itemTooltip); action->setIcon(QIcon(itemIconSource)); QObject::connect(action, SIGNAL(triggered()), item, SLOT(trigger())); if (item->property("enabled").isValid()) new PropertyBinding(action, "enabled", item, "enabled", PropertyBinding::OneWay, NULL, this); if (item->property("visible").isValid()) new PropertyBinding(action, "visible", item, "visible", PropertyBinding::OneWay, NULL, this); toolbar->addAction(action); } if (itemIconSize != -1) toolbar->setIconSize(QSize(itemIconSize, itemIconSize)); } mainWindow->setUnifiedTitleAndToolBarOnMac(true); mainWindow->addToolBar(toolbar); } property = root->property("dialogMenu"); if (type == Dialog::MainWindow && property.isValid() && property.typeName() == QString("QDeclarativeListProperty<QDeclarativeItem>")) { QDeclarativeListProperty<QDeclarativeItem> list = property.value< QDeclarativeListProperty<QDeclarativeItem> >(); int count = list.count(&list); for (int i = 0; i < count; ++i) { QDeclarativeItem* item = list.at(&list, i); if (!item->property("text").isValid()) continue; QString itemText = item->property("text").toString(); QMenu * menuItem = mainWindow->menuBar()->addMenu(itemText); if (!item->property("submenu").isValid() || item->property("submenu").typeName() != QString("QDeclarativeListProperty<QDeclarativeItem>")) continue; QDeclarativeListProperty<QDeclarativeItem> innerList = item->property("submenu").value< QDeclarativeListProperty<QDeclarativeItem> >(); int innerCount = innerList.count(&innerList); for (int j = 0; j < innerCount; ++j) { QDeclarativeItem* innerItem = innerList.at(&innerList, j); if (!innerItem->property("text").isValid()) continue; QString innerItemText = innerItem->property("text").toString(); QString innerItemShortcut = innerItem->property("shortcut").isValid() ? innerItem->property("shortcut").toString() : ""; QString innerItemIconSource = innerItem->property("iconSource").isValid() ? innerItem->property("iconSource").toString() : ""; if (innerItemText == "-") { menuItem->addSeparator(); } else { QAction * action = menuItem->addAction(QIcon(innerItemIconSource), innerItemText); action->setShortcut(QKeySequence(innerItemShortcut)); QObject::connect(action, SIGNAL(triggered()), innerItem, SLOT(trigger())); if (innerItem->property("enabled").isValid()) new PropertyBinding(action, "enabled", innerItem, "enabled", PropertyBinding::OneWay, NULL, this); if (innerItem->property("visible").isValid()) new PropertyBinding(action, "visible", innerItem, "visible", PropertyBinding::OneWay, NULL, this); } } } } new DialogCallbacks(windowWidget, v, root); // Initialize layout layout->setMargin(0); layout->addWidget(v, 0, 0); // Execute switch (type) { case Dialog::ModalDialog: dialog->exec(); break; case Dialog::MainWindow: { if (mainWindowGeometry.isEmpty()) { mainWindow->adjustSize(); mainWindow->move(QApplication::desktop()->screen()->rect().center() - mainWindow->rect().center()); } else mainWindow->restoreGeometry(mainWindowGeometry); } default: windowWidget->setAttribute(Qt::WA_DeleteOnClose); windowWidget->show(); break; } int result = 0; property = root->property("dialogResult"); if (property.isValid()) result = property.toInt(); if (type == Dialog::ModalDialog) delete dialog; return result; }
bool EventFilter::eventFilter(QObject *watched, QEvent *event) { Q_UNUSED(watched); AVPlayer *player = static_cast<AVPlayer*>(parent()); if (!player || !player->renderer() || !player->renderer()->widget()) return false; if (qobject_cast<QWidget*>(watched) != player->renderer()->widget()) { return false; } #ifndef QT_NO_DYNAMIC_CAST //dynamic_cast is defined as a macro to force a compile error if (player->renderer() != dynamic_cast<VideoRenderer*>(watched)) { // return false; } #endif QEvent::Type type = event->type(); switch (type) { case QEvent::KeyPress: { QKeyEvent *key_event = static_cast<QKeyEvent*>(event); int key = key_event->key(); Qt::KeyboardModifiers modifiers = key_event->modifiers(); switch (key) { case Qt::Key_C: //capture player->captureVideo(); break; case Qt::Key_N: //check playing? player->playNextFrame(); break; case Qt::Key_P: player->play(); break; case Qt::Key_Q: case Qt::Key_Escape: qApp->quit(); break; case Qt::Key_S: player->stop(); //check playing? break; case Qt::Key_Space: //check playing? qDebug("isPaused = %d", player->isPaused()); player->pause(!player->isPaused()); break; case Qt::Key_F: { //TODO: move to gui QWidget *w = qApp->activeWindow(); if (!w) return false; if (w->isFullScreen()) w->showNormal(); else w->showFullScreen(); } break; case Qt::Key_Up: { AudioOutput *ao = player->audio(); if (modifiers == Qt::ControlModifier) { qreal s = player->speed(); if (s < 1.4) s += 0.02; else s += 0.05; if (qAbs<qreal>(s-1.0) <= 0.01) s = 1.0; player->setSpeed(s); return true; } if (ao && ao->isAvailable()) { qreal v = player->audio()->volume(); if (v > 0.5) v += 0.1; else if (v > 0.1) v += 0.05; else v += 0.025; player->audio()->setVolume(v); qDebug("vol = %.3f", player->audio()->volume()); } } break; case Qt::Key_Down: { AudioOutput *ao = player->audio(); if (modifiers == Qt::ControlModifier) { qreal s = player->speed(); if (s < 1.4) s -= 0.02; else s -= 0.05; if (qAbs<qreal>(s-1.0) <= 0.01) s = 1.0; s = qMax<qreal>(s, 0.0); player->setSpeed(s); return true; } if (ao && ao->isAvailable()) { qreal v = player->audio()->volume(); if (v > 0.5) v -= 0.1; else if (v > 0.1) v -= 0.05; else v -= 0.025; player->audio()->setVolume(v); qDebug("vol = %.3f", player->audio()->volume()); } } break; case Qt::Key_O: { if (modifiers == Qt::ControlModifier) { //TODO: emit a signal so we can use custome dialogs? openLocalFile(); } else/* if (m == Qt::NoModifier) */{ emit showNextOSD(); } } break; case Qt::Key_Left: qDebug("<-"); player->seekBackward(); break; case Qt::Key_Right: qDebug("->"); player->seekForward(); break; case Qt::Key_M: if (player->audio()) { player->audio()->setMute(!player->audio()->isMute()); } break; case Qt::Key_R: { VideoRenderer* renderer = player->renderer(); VideoRenderer::OutAspectRatioMode r = renderer->outAspectRatioMode(); renderer->setOutAspectRatioMode(VideoRenderer::OutAspectRatioMode(((int)r+1)%2)); } break; case Qt::Key_T: { QWidget *w = qApp->activeWindow(); if (!w) return false; Qt::WindowFlags wf = w->windowFlags(); if (wf & Qt::WindowStaysOnTopHint) { qDebug("Window not stays on top"); w->setWindowFlags(wf & ~Qt::WindowStaysOnTopHint); } else { qDebug("Window stays on top"); w->setWindowFlags(wf | Qt::WindowStaysOnTopHint); } //call setParent() when changing the flags, causing the widget to be hidden w->show(); } break; case Qt::Key_F1: help(); break; default: return false; } break; } case QEvent::DragEnter: case QEvent::DragMove: { QDropEvent *e = static_cast<QDropEvent*>(event); e->acceptProposedAction(); } break; case QEvent::Drop: { QDropEvent *e = static_cast<QDropEvent*>(event); QString path = e->mimeData()->urls().first().toLocalFile(); player->stop(); player->load(path); player->play(); e->acceptProposedAction(); } break; case QEvent::GraphicsSceneContextMenu: { QGraphicsSceneContextMenuEvent *e = static_cast<QGraphicsSceneContextMenuEvent*>(event); showMenu(e->screenPos()); } break; case QEvent::ContextMenu: { QContextMenuEvent *e = static_cast<QContextMenuEvent*>(event); showMenu(e->globalPos()); } break; default: return false; } return true; //false: for text input }
// taken from qt/x11 (doing this sucks sucks sucks sucks sucks) void reparent_good(QWidget *that, Qt::WindowFlags f, bool showIt) { extern void qPRCreate( const QWidget *, Window ); extern void qt_XDestroyWindow( const QWidget *destroyer, Display *display, Window window ); extern bool qt_dnd_enable( QWidget* w, bool on ); QWidget *parent = 0; Display *dpy = that->x11Display(); QCursor oldcurs; bool setcurs = that->windowState(Qt::WState_OwnCursor); if ( setcurs ) { oldcurs = that->cursor(); that->unsetCursor(); } // dnd unregister (we will register again below) bool accept_drops = that->acceptDrops(); that->setAcceptDrops( false ); // clear mouse tracking, re-enabled below bool mouse_tracking = that->hasMouseTracking(); that->clearWState(Qt::WState_MouseTracking); QWidget* oldtlw = that->window(); QWidget *oldparent = that->parentWidget(); WId old_winid = that->winid; if ( that->windowFlags(Qt::WType_Desktop) ) old_winid = 0; that->setWinId( 0 ); // hide and reparent our own window away. Otherwise we might get // destroyed when emitting the child remove event below. See QWorkspace. XUnmapWindow( that->x11Display(), old_winid ); XReparentWindow( that->x11Display(), old_winid, RootWindow( that->x11Display(), that->x11Screen() ), 0, 0 ); if ( that->isTopLevel() ) { // input contexts are associated with toplevel widgets, so we need // destroy the context here. if we are reparenting back to toplevel, // then we will have another context created, otherwise we will // use our new toplevel's context that->destroyInputContext(); } if ( that->isTopLevel() || !parent ) // we are toplevel, or reparenting to toplevel that->topData()->parentWinId = 0; if ( parent != that->parentObj ) { if ( that->parentObj ) // remove from parent that->parentObj->removeChild( that ); if ( parent ) // insert into new parent parent->insertChild( that ); } bool enable = that->isEnabled(); // remember status Qt::FocusPolicy fp = that->focusPolicy(); QSize s = that->size(); QPixmap *bgp = (QPixmap *)that->backgroundPixmap(); QColor bgc = that->bg_col; // save colors QString capt= that->caption(); that->widget_flags = f; that->clearWState( Qt::WState_Created | Qt::WState_Visible | Qt::WState_ForceHide ); that->create(); if ( that->isTopLevel() || (!parent || parent->isVisible() ) ) that->setWState( Qt::WState_ForceHide ); // new widgets do not show up in already visible parents const QObjectList *chlist = that->children(); if ( chlist ) { // reparent children QObjectListIt it( *chlist ); QObject *obj; while ( (obj=it.current()) ) { if ( obj->isWidgetType() ) { QWidget *w = (QWidget *)obj; if ( !w->isTopLevel() ) { XReparentWindow( that->x11Display(), w->winId(), that->winId(), w->geometry().x(), w->geometry().y() ); } else if ( w->isPopup() || w->windowFlags(Qt::WStyle_DialogBorder) || w->windowFlags(Qt::WType_Dialog) || w->windowFlags(Qt::WStyle_Tool) ) { XSetTransientForHint( that->x11Display(), w->winId(), that->winId() ); } } ++it; } } qPRCreate( that, old_winid ); if ( bgp ) XSetWindowBackgroundPixmap( dpy, that->winid, bgp->handle() ); else XSetWindowBackground( dpy, that->winid, bgc.pixel(that->x11Screen()) ); // all this just to do a stupid resize instead of setGeometry //setGeometry( p.x(), p.y(), s.width(), s.height() ); that->resize(s.width(), s.height()); that->setEnabled( enable ); that->setFocusPolicy( fp ); if ( !capt.isNull() ) { that->extra->topextra->caption = QString::null; that->setWindowTitle( capt ); } if ( showIt ) that->show(); if ( old_winid ) qt_XDestroyWindow( that, dpy, old_winid ); if ( setcurs ) that->setCursor(oldcurs); that->reparentFocusWidgets( oldtlw ); // re-register dnd if (oldparent) oldparent->checkChildrenDnd(); if ( accept_drops ) that->setAcceptDrops( true ); else { that->checkChildrenDnd(); that->topData()->dnd = 0; qt_dnd_enable(that, (that->extra && that->extra->children_use_dnd)); } // re-enable mouse tracking if (mouse_tracking) that->setMouseTracking(mouse_tracking); }