Example #1
0
void
Hover::timerEvent(QTimerEvent * event)
{
    if (event->timerId() != timer.timerId() || noAnimations())
        return;

    Items::iterator it = items.begin();
    int *step = 0;
    QWidget *widget = 0;
    while (it != items.end())
    {
        widget = it.key();
        if (!widget)
        {
            it = items.erase(it);
            continue;
        }
        step = &it.value()._step;
        if (it.value().backwards)
        {   // fade OUT
            --(*step);
            widget->update();
            if (*step < 1)
            {
#if WOBBLE_HOVER
                if (widget->testAttribute(Qt::WA_UnderMouse))
                    it.value().backwards = false;
                else
#endif
                    it = items.erase(it);
            }
            else
                ++it;
        }
        else
        {   // fade IN
            *step += HOVER_IN_STEP;
            widget->update();
            if ((uint)(*step) > maxSteps-2)
            {
#if WOBBLE_HOVER
                if (widget->testAttribute(Qt::WA_UnderMouse))
                    it.value().backwards = true;
                else
#endif
                    it = items.erase(it);
            }
            else
                ++it;
        }
    }
    if (noAnimations())
        timer.stop();
}
Example #2
0
QAccessible::State QAccessibleMenuItem::state() const
{
    QAccessible::State s;
    QWidget *own = owner();

    if (own && (own->testAttribute(Qt::WA_WState_Visible) == false || m_action->isVisible() == false)) {
        s.invisible = true;
    }

    if (QMenu *menu = qobject_cast<QMenu*>(own)) {
        if (menu->activeAction() == m_action)
            s.focused = true;
#ifndef QT_NO_MENUBAR
    } else if (QMenuBar *menuBar = qobject_cast<QMenuBar*>(own)) {
        if (menuBar->activeAction() == m_action)
            s.focused = true;
#endif
    }
    if (own && own->style()->styleHint(QStyle::SH_Menu_MouseTracking))
        s.hotTracked = true;
    if (m_action->isSeparator() || !m_action->isEnabled())
        s.disabled = true;
    if (m_action->isChecked())
        s.checked = true;

    return s;
}
Example #3
0
void QSplitter::childEvent(QChildEvent *c)
{
    Q_D(QSplitter);
    if (!c->child()->isWidgetType()) {
        if (c->type() == QEvent::ChildAdded && qobject_cast<QLayout *>(c->child()))
            qWarning("Adding a QLayout to a QSplitter is not supported.");
        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;
            }
        }
    }
}
Example #4
0
bool QGLContext::chooseContext(const QGLContext* shareContext)
{
    Q_D(QGLContext);
    if(!d->paintDevice || d->paintDevice->devType() != QInternal::Widget) {
        d->valid = false;
    }else {
        QWidget *widget = static_cast<QWidget *>(d->paintDevice);
        if (!widget->platformWindow()){
            QGLFormat glformat = format();
            QPlatformWindowFormat winFormat = QGLFormat::toPlatformWindowFormat(glformat);
            if (shareContext) {
                winFormat.setSharedContext(shareContext->d_func()->platformContext);
            }
            if (widget->testAttribute(Qt::WA_TranslucentBackground))
                winFormat.setAlpha(true);
            winFormat.setWindowApi(QPlatformWindowFormat::OpenGL);
            winFormat.setWindowSurface(false);
            widget->setPlatformWindowFormat(winFormat);
            widget->winId();//make window
        }
        d->platformContext = widget->platformWindow()->glContext();
        Q_ASSERT(d->platformContext);
        d->glFormat = QGLFormat::fromPlatformWindowFormat(d->platformContext->platformWindowFormat());
        d->valid =(bool) d->platformContext;
        if (d->valid) {
            d->platformContext->setQGLContextHandle(this,qDeleteQGLContext);
        }
        d->setupSharing();
    }


    return d->valid;
}
Example #5
0
void QtFallbackWebPopupCombo::hidePopup()
{
#ifndef QT_NO_IM
    QWidget* activeFocus = QApplication::focusWidget();
    if (activeFocus && activeFocus == QComboBox::view()
        && activeFocus->testAttribute(Qt::WA_InputMethodEnabled)) {
        QInputContext* qic = activeFocus->inputContext();
        if (qic) {
            qic->reset();
            qic->setFocusWidget(0);
        }
    }
#endif // QT_NO_IM

    QComboBox::hidePopup();

    if (QGraphicsProxyWidget* proxy = graphicsProxyWidget())
        proxy->setVisible(false);

    if (!m_ownerPopup.m_popupVisible)
        return;

    m_ownerPopup.m_popupVisible = false;
    m_ownerPopup.popupDidHide();
}
static void qWinProcessConfigRequests()                // perform requests in queue
{
    if (!configRequests)
        return;
    QWinConfigRequest *r;
    for (;;) {
        if (configRequests->isEmpty())
            break;
        r = configRequests->takeLast();
        QWidget *w = QWidget::find(r->id);
        QRect rect(r->x, r->y, r->w, r->h);
        int req = r->req;
        delete r;

        if ( w ) {                              // widget exists
            if (w->testAttribute(Qt::WA_WState_ConfigPending))
                return;                         // biting our tail
            if (req == 0)
                w->move(rect.topLeft());
            else if (req == 1)
                w->resize(rect.size());
            else
                w->setGeometry(rect);
        }
    }
    delete configRequests;
    configRequests = 0;
}
Example #7
0
//! Update the cached information about the current style sheet
void QwtPlotAbstractCanvas::updateStyleSheetInfo()
{
    QWidget *w = canvasWidget();

    if ( !w->testAttribute( Qt::WA_StyledBackground ) )
        return;

    QwtStyleSheetRecorder recorder( w->size() );

    QPainter painter( &recorder );

    QStyleOption opt;
    opt.initFrom(w);
    w->style()->drawPrimitive( QStyle::PE_Widget, &opt, &painter, w);

    painter.end();

    d_data->styleSheet.hasBorder = !recorder.border.rectList.isEmpty();
    d_data->styleSheet.cornerRects = recorder.clipRects;

    if ( recorder.background.path.isEmpty() )
    {
        if ( !recorder.border.rectList.isEmpty() )
        {
            d_data->styleSheet.borderPath =
                qwtCombinePathList( w->rect(), recorder.border.pathList );
        }
    }
    else
    {
        d_data->styleSheet.borderPath = recorder.background.path;
        d_data->styleSheet.background.brush = recorder.background.brush;
        d_data->styleSheet.background.origin = recorder.background.origin;
    }
}
Example #8
0
void Widget::invalidateRect(const IntRect& r)
{
    if (data->m_widget) //plugins
        return data->m_widget->update(r);

    IntRect windowRect = convertToContainingWindow(r);

    // Get our clip rect and intersect with it to ensure we don't invalidate too much.
    IntRect clipRect = windowClipRect();
    windowRect.intersect(clipRect);

    QWidget *canvas = qwidget(); //regular frameview
    if (!canvas && parent())
        canvas = parent()->qwidget(); //scrollbars

    if (!canvas)  // not visible anymore
        return;

    bool painting = canvas->testAttribute(Qt::WA_WState_InPaintEvent);
    if (painting) {
        QWebPage *page = qobject_cast<QWebPage*>(canvas);
        QPainter p(page);
        page->mainFrame()->render(&p, windowRect);
    } else {
        canvas->update(windowRect);
    }
}
Example #9
0
bool QWidgetProto::testAttribute(int attribute) const
{
  QWidget *item = qscriptvalue_cast<QWidget*>(thisObject());
  if (item)
    return item->testAttribute((Qt::WidgetAttribute)attribute);
  return false;
}
Example #10
0
void QwtPanner::showCursor(bool on)
{
    QWidget *w = parentWidget();
    if ( w == NULL || d_data->cursor == NULL )
        return;

    if ( on )
    {
#if QT_VERSION < 0x040000
        if ( w->testWState(WState_OwnCursor) )
#else
        if ( w->testAttribute(Qt::WA_SetCursor) )
#endif
        {
            delete d_data->restoreCursor;
            d_data->restoreCursor = new QCursor(w->cursor());
        }
        w->setCursor(*d_data->cursor);
    }
    else
    {
        if ( d_data->restoreCursor )
        {
            w->setCursor(*d_data->restoreCursor);
            delete d_data->restoreCursor;
            d_data->restoreCursor = NULL;
        }
        else
            w->unsetCursor();
    }
}
/*! \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;
}
Example #12
0
void QwtPanner::showCursor( bool on )
{
    if ( on == d_data->hasCursor )
        return;

    QWidget *w = parentWidget();
    if ( w == NULL || d_data->cursor == NULL )
        return;

    d_data->hasCursor = on;

    if ( on )
    {
        if ( w->testAttribute( Qt::WA_SetCursor ) )
        {
            delete d_data->restoreCursor;
            d_data->restoreCursor = new QCursor( w->cursor() );
        }
        w->setCursor( *d_data->cursor );
    }
    else
    {
        if ( d_data->restoreCursor )
        {
            w->setCursor( *d_data->restoreCursor );
            delete d_data->restoreCursor;
            d_data->restoreCursor = NULL;
        }
        else
            w->unsetCursor();
    }
}
Example #13
0
void QWSWindowSurface::setGeometry(const QRect &rect, const QRegion &mask)
{
    if (rect == geometry()) // XXX: && mask == prevMask
        return;

    const bool isResize = rect.size() != geometry().size();
    const bool needsRepaint = isResize || !isBuffered();

    QWindowSurface::setGeometry(rect);

    const QRegion region = mask & rect;
    QWidget *win = window();
    // Only request regions for widgets visible on the screen.
    // (Added the !win check for compatibility reasons, because
    // there was no "if (win)" check before).
    const bool requestQWSRegion = !win || !win->testAttribute(Qt::WA_DontShowOnScreen);
    if (requestQWSRegion)
        QWidget::qwsDisplay()->requestRegion(winId(), key(), permanentState(), region);

    if (needsRepaint)
        invalidateBuffer();

    if (!requestQWSRegion) {
        // We didn't request a region, hence we won't get a QWSRegionEvent::Allocation
        // event back from the server so we set the clip directly. We have to
        // do this after the invalidateBuffer() call above, as it might trigger a
        // backing store sync, resulting in too many update requests.
        setClipRegion(region);
    }
}
/*!
  Draw the background of the canvas
  \param painter Painter
*/ 
void QwtPlotGLCanvas::drawBackground( QPainter *painter )
{
    painter->save();

    QWidget *w = qwtBGWidget( this );

    const QPoint off = mapTo( w, QPoint() );
    painter->translate( -off );

    const QRect fillRect = rect().translated( off );

    if ( w->testAttribute( Qt::WA_StyledBackground ) )
    {
        painter->setClipRect( fillRect );

        QStyleOption opt;
        opt.initFrom( w );
        w->style()->drawPrimitive( QStyle::PE_Widget, &opt, painter, w);
    }
    else 
    {
        painter->fillRect( fillRect,
            w->palette().brush( w->backgroundRole() ) );
    }

    painter->restore();
}
Example #15
0
void QWidget::activateWindow()
{
    QWidget *tlw = window();
    if (tlw->isVisible()) {
        Q_ASSERT(tlw->testAttribute(Qt::WA_WState_Created));
        qwsDisplay()->requestFocus(tlw->internalWinId(), true);
    }
}
Example #16
0
/**
  Determines if the program is still running - YES! Nowadays that's not so
  easy to tell: If the MainWindow is still open - we're fine, don't check any
  further. If not, check if there are visible top level widgets left.
  */
bool running() {
    if (window->isVisible()) {
        return true;
    }

    QWidgetList list = QApplication::topLevelWidgets();
    for (int i = 0; i < list.size(); ++i) {
        QWidget *w = list.at(i);
        if ((w->isVisible() &&
             !w->testAttribute(Qt::WA_DontShowOnScreen))
             && !w->parentWidget() &&
             w->testAttribute(Qt::WA_QuitOnClose)) {
                   return true;
        }
    }
    return false;
}
bool pTabbedWorkspace::eventFilter( QObject* o, QEvent* e )
{
	// get event type
	QEvent::Type t = e->type();
	
	// get document
	QWidget* td = qobject_cast<QWidget*>( o );
	
	// child modified state
	if ( t == QEvent::ModifiedChange )
		mTabBar->setTabText( indexOf( td ), td->windowTitle().append( td->isWindowModified() ? QString( "*" ) : QString::null ) );

	// if mode is toplevel and event is activate, activate correct window if needed
	else if ( mTabMode == tmTopLevel && t == QEvent::WindowActivate )
	{
		if ( td && td != currentDocument() )
			setCurrentDocument( td );
	}

	// remove document from workspace
	else if ( t == QEvent::Close && td )
	{
		// get closeevent
		QCloseEvent* ce = static_cast<QCloseEvent*>( e );
		
		// emit that document will be close, giving event so user can cancel it
		emit aboutToCloseTab( indexOf( td ), ce );
		emit aboutToCloseDocument( td, ce );
		
		// close document if accepted
		if ( !ce->isAccepted() && td->property( "ForceClose" ).toBool() && !td->testAttribute( Qt::WA_DeleteOnClose ) )
			td->deleteLater();
		else if ( ce->isAccepted() && !td->testAttribute( Qt::WA_DeleteOnClose ) )
			removeDocument( td );
		else
			return true;
	}

	// return default event filter
	return QWidget::eventFilter( o, e );
}
Example #18
0
void MyScrollArea::setWidget(QWidget *w)
{
    widget = w;
    widget->setParent(viewport());
    if (!widget->testAttribute(Qt::WA_Resized))
        widget->resize(widget->sizeHint());

    verticalScrollBar()->setValue(0);
    verticalScrollBar()->setValue(0);

    updateArea();
}
/*!
    \internal
*/
void QGraphicsProxyWidgetPrivate::updateProxyInputMethodAcceptanceFromWidget()
{
    Q_Q(QGraphicsProxyWidget);
    if (!widget)
        return;

    QWidget *focusWidget = widget->focusWidget();
    if (!focusWidget)
        focusWidget = widget;
    q->setFlag(QGraphicsItem::ItemAcceptsInputMethod,
               focusWidget->testAttribute(Qt::WA_InputMethodEnabled));
}
static QWidget *qwtBGWidget( QWidget *widget )
{
    QWidget *w = widget;

    for ( ; w->parentWidget() != NULL; w = w->parentWidget() )
    {
        if ( w->autoFillBackground() || 
            w->testAttribute( Qt::WA_StyledBackground ) )
        {
            return w;
        }
    }

    return w;
}
Example #21
0
bool hasAlphaChannel(const QWidget *widget)
{
#ifdef QTC_ENABLE_X11
    QWidget *window;
    if (!(widget && (window = widget->window())))
        return false;
    if (WId wid = qtcGetQWidgetWid(window)) {
        return qtcX11HasAlpha(wid);
    }
    return window->testAttribute(Qt::WA_TranslucentBackground);
#else
    Q_UNUSED(widget);
    return compositingActive();
#endif
}
Example #22
0
bool 
QLuaApplication::notify(QObject *receiver, QEvent *event)
{
  // capture window polish events
  if (event->type() == QEvent::Show)
    if (receiver->isWidgetType())
      {
        QWidget *w = static_cast<QWidget*>(receiver);
        if (w->windowType() == Qt::Window)
#if QT_VERSION >= 0x040400 
          if (!w->testAttribute(Qt::WA_DontShowOnScreen))
#endif
            emit windowShown(w);
      }
  return QApplication::notify(receiver, event);
}
Example #23
0
void KoCursorPrivateAutoHideEventFilter::hideCursor()
{
    m_autoHideTimer.stop();

    if ( m_isCursorHidden )
        return;

    m_isCursorHidden = true;

    QWidget* w = mouseWidget();

    m_isOwnCursor = w->testAttribute(Qt::WA_SetCursor);
    if ( m_isOwnCursor )
        m_oldCursor = w->cursor();

    w->setCursor( QCursor( Qt::BlankCursor ) );
}
Example #24
0
/*!\reimp */
void QGroupBox::childEvent(QChildEvent *c)
{
    Q_D(QGroupBox);
    if (c->type() != QEvent::ChildAdded || !c->child()->isWidgetType())
        return;
    QWidget *w = (QWidget*)c->child();
    if (d->checkable) {
        if (d->checked) {
            if (!w->testAttribute(Qt::WA_ForceDisabled))
                w->setEnabled(true);
        } else {
            if (w->isEnabled()) {
                w->setEnabled(false);
                w->setAttribute(Qt::WA_ForceDisabled, false);
            }
        }
    }
}
Example #25
0
void QWidget::destroy(bool destroyWindow, bool destroySubWindows)
{
    Q_D(QWidget);

    d->aboutToDestroy();
    if (!isWindow() && parentWidget())
        parentWidget()->d_func()->invalidateBuffer(d->effectiveRectFor(geometry()));
    d->deactivateWidgetCleanup();

    if ((windowType() == Qt::Popup) && qApp)
        qApp->d_func()->closePopup(this);

    if (this == QApplicationPrivate::active_window)
        QApplication::setActiveWindow(0);
    if (QWidget::mouseGrabber() == this)
        releaseMouse();
    if (QWidget::keyboardGrabber() == this)
        releaseKeyboard();

    setAttribute(Qt::WA_WState_Created, false);

    if (windowType() != Qt::Desktop) {
        if (destroySubWindows) {
            QObjectList childList(children());
            for (int i = 0; i < childList.size(); i++) {
                QWidget *widget = qobject_cast<QWidget *>(childList.at(i));
                if (widget && widget->testAttribute(Qt::WA_NativeWindow)) {
                    if (widget->windowHandle()) {
                        widget->destroy();
                    }
                }
            }
        }
        if (destroyWindow) {
            d->deleteTLSysExtra();
        } else {
            if (parentWidget() && parentWidget()->testAttribute(Qt::WA_WState_Created)) {
                d->hide_sys();
            }
        }

        d->setWinId(0);
    }
}
Example #26
0
void QWebPopup::hidePopup()
{
    QWidget* activeFocus = QApplication::focusWidget();
    if (activeFocus && activeFocus == view()
        && activeFocus->testAttribute(Qt::WA_InputMethodEnabled)) {
        QInputContext* qic = activeFocus->inputContext();
        if (qic) {
            qic->reset();
            qic->setFocusWidget(0);
        }
    }

    QComboBox::hidePopup();
    if (!m_popupVisible)
        return;

    m_popupVisible = false;
    m_client->popupDidHide();
}
Example #27
0
/*
  sets all children of the group box except the qt_groupbox_checkbox
  to either disabled/enabled
*/
void QGroupBoxPrivate::_q_setChildrenEnabled(bool b)
{
    Q_Q(QGroupBox);
    QObjectList childList = q->children();
    for (int i = 0; i < childList.size(); ++i) {
        QObject *o = childList.at(i);
        if (o->isWidgetType()) {
            QWidget *w = static_cast<QWidget *>(o);
            if (b) {
                if (!w->testAttribute(Qt::WA_ForceDisabled))
                    w->setEnabled(true);
            } else {
                if (w->isEnabled()) {
                    w->setEnabled(false);
                    w->setAttribute(Qt::WA_ForceDisabled, false);
                }
            }
        }
    }
}
Example #28
0
QS60WindowSurface::~QS60WindowSurface()
{
#if defined(QT_GRAPHICSSYSTEM_RUNTIME) && defined(Q_SYMBIAN_SUPPORTS_SURFACES)
    if(QApplicationPrivate::runtime_graphics_system) {
        QRuntimeGraphicsSystem *runtimeGraphicsSystem =
                static_cast<QRuntimeGraphicsSystem*>(QApplicationPrivate::graphics_system);
        if(runtimeGraphicsSystem->graphicsSystemName() == QLatin1String("openvg")) {

            // Graphics system has been switched from raster to openvg.
            // Issue empty redraw to clear the UI surface

            QWidget *w = window();
            if (w->testAttribute(Qt::WA_WState_Created)) {
                RWindow *const window = static_cast<RWindow *>(w->winId()->DrawableWindow());
                window->BeginRedraw();
                window->EndRedraw();
            }
        }
    }
#endif

    delete d_ptr;
}
Example #29
0
bool QGLContext::chooseContext(const QGLContext* shareContext)
{
    Q_D(QGLContext);
    if(!d->paintDevice || d->paintDevice->devType() != QInternal::Widget) {
        d->valid = false;
    }else {
        QWidget *widget = static_cast<QWidget *>(d->paintDevice);
        QGLFormat glformat = format();
        QSurfaceFormat winFormat = QGLFormat::toSurfaceFormat(glformat);
        if (widget->testAttribute(Qt::WA_TranslucentBackground))
            winFormat.setAlphaBufferSize(qMax(winFormat.alphaBufferSize(), 8));

        if (!widget->windowHandle()->handle()) {
            widget->windowHandle()->setSurfaceType(QWindow::OpenGLSurface);
            widget->windowHandle()->setFormat(winFormat);
            widget->winId();//make window
        }

        if (d->ownContext)
            delete d->guiGlContext;
        d->ownContext = true;
        QOpenGLContext *shareGlContext = shareContext ? shareContext->d_func()->guiGlContext : 0;
        d->guiGlContext = new QOpenGLContext;
        d->guiGlContext->setFormat(winFormat);
        d->guiGlContext->setShareContext(shareGlContext);
        d->valid = d->guiGlContext->create();

        if (d->valid)
            d->guiGlContext->setQGLContextHandle(this,qDeleteQGLContext);

        d->glFormat = QGLFormat::fromSurfaceFormat(d->guiGlContext->format());
        d->setupSharing();
    }


    return d->valid;
}
/*! \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;
}