Exemple #1
0
void SpinBox::focusOutEvent(QFocusEvent *event)
{
    QGraphicsWidget *widget = parentWidget();
    Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);

    while (!applet && widget) {
        widget = widget->parentWidget();
        applet = qobject_cast<Plasma::Applet *>(widget);
    }

    if (applet) {
        applet->setStatus(Plasma::UnknownStatus);
    }

    QEvent closeEvent(QEvent::CloseSoftwareInputPanel);
    if (qApp) {
        if (QGraphicsView *view = qobject_cast<QGraphicsView*>(qApp->focusWidget())) {
            if (view->scene() && view->scene() == scene()) {
                QApplication::sendEvent(view, &closeEvent);
            }
        }
    }

    QGraphicsProxyWidget::focusOutEvent(event);
}
/*!
    \internal

    \a mw is the new parent. all items in the layout will be a child of \a mw.
 */
void QGraphicsLayoutPrivate::reparentChildWidgets(QGraphicsWidget *mw)
{
    Q_Q(QGraphicsLayout);
    int n =  q->count();
    //bool mwVisible = mw && mw->isVisible();
    for (int i = 0; i < n; ++i) {
        QGraphicsLayoutItem *item = q->itemAt(i);
        if (item->isLayout()) {
            QGraphicsLayout *l = static_cast<QGraphicsLayout*>(item);
            l->d_func()->reparentChildWidgets(mw);
        } else {
            QGraphicsWidget *w = static_cast<QGraphicsWidget*>(item);
            QGraphicsWidget *pw = w->parentWidget();
#ifdef QT_DEBUG
            if (pw && pw != mw && qt_graphicsLayoutDebug()) {
                qWarning("QGraphicsLayout::addChildLayout: widget %s \"%s\" in wrong parent; moved to correct parent",
                         w->metaObject()->className(), w->objectName().toLocal8Bit().constData());
            }
#endif
            //bool needShow = mwVisible && !(w->isHidden() && w->testAttribute(Qt::WA_WState_ExplicitShowHide));
            if (pw != mw)
                w->setParentItem(mw);
            //if (needShow)
            //    QMetaObject::invokeMethod(w, "_q_showIfNotHidden", Qt::QueuedConnection); //show later
        }
    }
}
Exemple #3
0
/*!
    \internal
*/
void QGraphicsWidgetPrivate::clearFocusWidget()
{
    // Reset focus child chain.
    QGraphicsWidget *parent = static_cast<QGraphicsWidget *>(q_ptr);
    do {
        if (parent->d_func()->focusChild != q_ptr)
            break;
        parent->d_func()->focusChild = 0;
    } while (!parent->isWindow() && (parent = parent->parentWidget()));
}
Exemple #4
0
/*!
    \internal
*/
void QGraphicsWidgetPrivate::setFocusWidget()
{
    // Update focus child chain.
    QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(q_ptr);
    QGraphicsWidget *parent = widget;
    bool hidden = !visible;
    do {
        parent->d_func()->focusChild = widget;
    } while (!parent->isWindow() && (parent = parent->parentWidget()) && (!hidden || !parent->d_func()->visible));
}
Exemple #5
0
void SpinBox::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
    QGraphicsWidget *widget = parentWidget();
    Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);

    while (!applet && widget) {
        widget = widget->parentWidget();
        applet = qobject_cast<Plasma::Applet *>(widget);
    }

    if (applet) {
        applet->setStatus(Plasma::AcceptingInputStatus);
    }
    QGraphicsProxyWidget::mousePressEvent(event);
}
void QGraphicsWidgetPrivate::setLayoutDirection_helper(Qt::LayoutDirection direction)
{
    Q_Q(QGraphicsWidget);
    if ((direction == Qt::RightToLeft) == (testAttribute(Qt::WA_RightToLeft)))
        return;
    q->setAttribute(Qt::WA_RightToLeft, (direction == Qt::RightToLeft));

    // Propagate this change to all children.
    for (int i = 0; i < children.size(); ++i) {
        QGraphicsItem *item = children.at(i);
        if (item->isWidget()) {
            QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(item);
            if (widget->parentWidget() && !widget->testAttribute(Qt::WA_SetLayoutDirection))
                widget->d_func()->setLayoutDirection_helper(direction);
        }
    }

    // Send the notification event to this widget item.
    QEvent e(QEvent::LayoutDirectionChange);
    QApplication::sendEvent(q, &e);
}
void HbComboBoxPrivate::positionDropDown( )
{
    Q_Q( HbComboBox );
    QRectF popupRect;
    QRectF sceneRect( QPointF( ), HbDeviceProfile::profile( q ).logicalSize( ) );
    QPointF widgetPos = q->scenePos( );
    QAbstractItemModel *model = mDropDown->mList->model( );
    calculateListItemHeight( );
    qreal totalHeightRequd = model->rowCount( ) * mListItemHeight;
    qreal maxPopupHeight = 0.0;

    //read the maximum rows in drop down for different orientation from css
    if( q->mainWindow( )->orientation( ) == Qt::Horizontal ) {
        if( mDropDownRowsInLandscape == -1 ) {
            HbStyleParameters params;
            q->style( )->parameters( params );
            params.addParameter( "max-rows-in-dropdown" );
            q->polish( params );
            mDropDownRowsInLandscape = params.value( "max-rows-in-dropdown" ).toInt( );
        }
        maxPopupHeight = mDropDownRowsInLandscape * mListItemHeight;
    } else if( q->mainWindow( )->orientation( ) == Qt::Vertical ) {
        if( mDropDownRowsInPortrait == -1 ) {
            HbStyleParameters params;
            q->style( )->parameters( params );
            params.addParameter( "max-rows-in-dropdown" );
            q->polish( params );
            mDropDownRowsInPortrait = params.value( "max-rows-in-dropdown" ).toInt( );
        }
        maxPopupHeight = mDropDownRowsInPortrait * mListItemHeight;
    }

    if ( totalHeightRequd < maxPopupHeight ) {
        maxPopupHeight = totalHeightRequd;
    }
    QSizeF popupSize = QSizeF( q->rect( ).width( ), maxPopupHeight );
    QPointF popupPos;
    if( !mDropDown->vkbOpened ) {
        //position of drop down in both editable and non-editable combobox depends upon
        //the available space above and below combobox
        if( ( widgetPos.y( ) + q->rect( ).height( ) + maxPopupHeight) < sceneRect.height( ) ) {
            popupPos = QPointF( widgetPos.x( ), widgetPos.y( ) + q->rect( ).height( ) );
            #ifdef HB_EFFECTS
            if ( !mHasDownEffect ) {
                 mHasDownEffect = true;
                 mHasUpEffect = false;
                 // this is temporary until proper effect theming comes.
                 //this Effect will be shown when there is space in the view bottom.
                 HbEffectInternal::add( mDropDown, "combo_appear_down", "appear" );
                 HbEffectInternal::add( mDropDown, "combo_disappear_downl", "disappear" );
            }
            #endif
        } else if( widgetPos.y( ) - maxPopupHeight  > 0.0 ) {
            popupPos = QPointF( widgetPos.x( ), widgetPos.y( ) - maxPopupHeight );
            #ifdef HB_EFFECTS
            if ( !mHasUpEffect ) {
                 // this is temporary until proper effect theming comes.
                 //this Effect will be shown when there is no space in the view bottom
                 mHasUpEffect = true;
                 mHasDownEffect = false;
                 HbEffectInternal::add( mDropDown, "combo_appear_up", "appear" );
                 HbEffectInternal::add( mDropDown, "combo_disappear_up", "disappear" );
            }
            #endif
        } else {
            qreal topScreenHeight = sceneRect.height( ) - maxPopupHeight;
            if( topScreenHeight > sceneRect.height( ) - topScreenHeight ) {
                popupPos = QPointF( widgetPos.x( ), 0.0 );
                #ifdef HB_EFFECTS
                if ( !mHasDownEffect ) {
                    mHasDownEffect = true;
                    mHasUpEffect = false;
                    // this is temporary until proper effect theming comes.
                    //this Effect will be shown when there is more space in the view bottom.
                    HbEffectInternal::add( mDropDown, "combo_appear_down", "appear" );
                    HbEffectInternal::add( mDropDown, "combo_disappear_down", "disappear" );
                }
                #endif
            } else {
                popupPos = QPointF( widgetPos.x( ), sceneRect.height( ) - maxPopupHeight );
                #ifdef HB_EFFECTS
                if ( !mHasUpEffect ) {
                     mHasUpEffect = true;
                     mHasDownEffect = false;
                     // this is temporary until proper effect theming comes.
                     //this Effect will be shown when there is more space in the view bottom.
                     HbEffectInternal::add( mDropDown, "combo_appear_up", "appear" );
                     HbEffectInternal::add( mDropDown, "combo_disappear_up", "disappear" );
                }
                #endif
            }
        }
    } else {
        // positioning drop down when vkb is positioned
        // drop down will come on top/below of combo based upon which side has more space
        // available 
        HbEditorInterface editorInterface( q );
        HbVkbHost *host = editorInterface.vkbHost( );
        if ( host ) {
            QSizeF keyBoardArea = host->keyboardArea( );
            QSize screenSize = HbDeviceProfile::profile( q ).logicalSize( );

            qreal heightDifference = screenSize.height( ) - keyBoardArea.height( );
            qreal topSpace = widgetPos.y( );
            qreal bottomSpace = heightDifference - topSpace - q->boundingRect( ).height( );

            if( topSpace > bottomSpace ) {
                //display drop down at top
                if( widgetPos.y( ) - maxPopupHeight  > 0.0 ) {
                    popupPos = QPointF( widgetPos.x( ), widgetPos.y( ) - maxPopupHeight );
                } else {
                    popupPos = QPointF( widgetPos.x( ), 0.0 );
                    popupSize.setHeight( topSpace );
                }
                #ifdef HB_EFFECTS
                if ( !mHasUpEffect ) {
                     mHasUpEffect = true;
                     mHasDownEffect = false;
                     // this is temporary until proper effect theming comes.
                     //this Effect will be shown when there is more space in the view bottom.
                     HbEffectInternal::add( mDropDown, "combo_appear_up", "appear" );
                     HbEffectInternal::add( mDropDown, "combo_disappear_up", "disappear" );
                }
                #endif
            } else {
                //display drop down at bottom
                popupPos = QPointF( widgetPos.x( ), widgetPos.y( ) + q->rect( ).height( ) );
                if( bottomSpace < maxPopupHeight ) {
                    popupSize.setHeight( bottomSpace );
                }
                #ifdef HB_EFFECTS
                if ( !mHasDownEffect ) {
                    mHasDownEffect = true;
                    mHasUpEffect = false;
                    // this is temporary until proper effect theming comes.
                    //this Effect will be shown when there is more space in the view bottom.
                    HbEffectInternal::add( mDropDown, "combo_appear_down", "appear" );
                    HbEffectInternal::add( mDropDown, "combo_disappear_down", "disappear" );
                }
                #endif
            }
        }
    }
    mDropDown->setPreferredSize( popupSize );
    mDropDown->setMinimumSize( popupSize );
    mDropDown->setMaximumSize( popupSize );
    mDropDown->setPos( popupPos );
    QGraphicsWidget *p = q;
    while ( p->parentWidget( ) ) {
        p = p->parentWidget( );
    }
    mDropDown->setZValue( p->zValue( ) + 1 );
}