Esempio n. 1
0
/*!
    \property QStackedLayout::currentIndex
    \brief the index position of the widget that is visible

    The current index is -1 if there is no current widget.

    \sa currentWidget(), indexOf()
*/
void QStackedLayout::setCurrentIndex(int index)
{
    Q_D(QStackedLayout);
    QWidget *prev = currentWidget();
    QWidget *next = widget(index);
    if (!next || next == prev)
        return;

    bool reenableUpdates = false;
    QWidget *parent = parentWidget();

    if (parent && parent->updatesEnabled()) {
        reenableUpdates = true;
        parent->setUpdatesEnabled(false);
    }

    QPointer<QWidget> fw = parent ? parent->window()->focusWidget() : 0;
    const bool focusWasOnOldPage = fw && (prev && prev->isAncestorOf(fw));

    if (prev) {
        prev->clearFocus();
        if (d->stackingMode == StackOne)
            prev->hide();
    }

    d->index = index;
    next->raise();
    next->show();

    // try to move focus onto the incoming widget if focus
    // was somewhere on the outgoing widget.

    if (parent) {
        if (focusWasOnOldPage) {
            // look for the best focus widget we can find
            if (QWidget *nfw = next->focusWidget())
                nfw->setFocus();
            else {
                // second best: first child widget in the focus chain
                if (QWidget *i = fw) {
                    while ((i = i->nextInFocusChain()) != fw) {
                        if (((i->focusPolicy() & Qt::TabFocus) == Qt::TabFocus)
                            && !i->focusProxy() && i->isVisibleTo(next) && i->isEnabled()
                            && next->isAncestorOf(i)) {
                            i->setFocus();
                            break;
                        }
                    }
                    // third best: incoming widget
                    if (i == fw )
                        next->setFocus();
                }
            }
        }
    }
    if (reenableUpdates)
        parent->setUpdatesEnabled(true);
    emit currentChanged(index);
}
Esempio n. 2
0
bool QWidgetProto::isAncestorOf(const QWidget *child) const
{
  QWidget *item = qscriptvalue_cast<QWidget*>(thisObject());
  if (item)
    return item->isAncestorOf(child);
  return false;
}
Esempio n. 3
0
// ---------------------------------------------------------------------
string Form::getfocus()
{
  QWidget *w=app->focusWidget();
  if (!w || !this->children.size()) return "";
  for (int i=this->children.size()-1; 0<=i; i--) {
    QWidget *c;
    if ((c=this->children.at(i)->widget) && (w==c || c->isAncestorOf(w)))
      return this->children.at(i)->id;
  }
  return "";
}
Esempio n. 4
0
IDirectFBSurface *QDirectFBWindowSurface::surfaceForWidget(const QWidget *widget, QRect *rect) const
{
    Q_ASSERT(widget);
    if (!dfbSurface)
        return 0;
    QWidget *win = window();
    Q_ASSERT(win);
    if (rect) {
        if (win == widget) {
            *rect = widget->rect();
        } else {
            *rect = QRect(widget->mapTo(win, QPoint(0, 0)), widget->size());
        }
    }

    Q_ASSERT(win == widget || win->isAncestorOf(widget));
    return dfbSurface;
}
Esempio n. 5
0
void StackLayout::setCurrentIndex(int index)
{
    QWidget *prev = currentWidget();
    QWidget *next = widget(index);
    if (!next || next == prev)
        return;

    _index = index;

    if(!parent()) return;

    bool reenableUpdates = false;
    QWidget *parent = parentWidget();

    if (parent && parent->updatesEnabled()) {
        reenableUpdates = true;
        parent->setUpdatesEnabled(false);
    }

    QWidget *fw = parent ? parent->window()->focusWidget() : 0;
    if (prev) {
        prev->clearFocus();
        if (_mode == StackOne)
            prev->hide();
    }

    next->raise();
    next->show();

    // try to move focus onto the incoming widget if focus
    // was somewhere on the outgoing widget.

    if (parent) {
        if (fw && (prev && prev->isAncestorOf(fw))) { // focus was on old page
            // look for the best focus widget we can find
            if (QWidget *nfw = next->focusWidget())
                nfw->setFocus();
            else {
                // second best: first child widget in the focus chain
                QWidget *i = fw;
                while ((i = i->nextInFocusChain()) != fw) {
                    if (((i->focusPolicy() & Qt::TabFocus) == Qt::TabFocus)
                        && !i->focusProxy() && i->isVisibleTo(next) && i->isEnabled()
                        && next->isAncestorOf(i)) {
                        i->setFocus();
                        break;
                    }
                }
                // third best: incoming widget
                if (i == fw )
                    next->setFocus();
            }
        }
    }
    if (reenableUpdates)
        parent->setUpdatesEnabled(true);

    if (_mode == StackOne)
      // expandingDirections() might have changed, so invalidate():
      invalidate();
}
Esempio n. 6
0
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 );
}