Esempio n. 1
0
void LocationCompleter::showPopup()
{
    Q_ASSERT(m_locationBar);

    if (s_model->rowCount() == 0) {
        s_view->close();
        return;
    }

    if (s_view->isVisible()) {
        adjustPopupSize();
        return;
    }

    QRect popupRect(m_locationBar->mapToGlobal(m_locationBar->pos()), m_locationBar->size());
    popupRect.setY(popupRect.bottom());

    s_view->setGeometry(popupRect);
    s_view->setFocusProxy(m_locationBar);
    s_view->setCurrentIndex(QModelIndex());

    connect(s_view, SIGNAL(closed()), this, SLOT(slotPopupClosed()));
    connect(s_view, SIGNAL(indexActivated(QModelIndex)), this, SLOT(indexActivated(QModelIndex)));
    connect(s_view, SIGNAL(indexCtrlActivated(QModelIndex)), this, SLOT(indexCtrlActivated(QModelIndex)));
    connect(s_view, SIGNAL(indexShiftActivated(QModelIndex)), this, SLOT(indexShiftActivated(QModelIndex)));
    connect(s_view, SIGNAL(indexDeleteRequested(QModelIndex)), this, SLOT(indexDeleteRequested(QModelIndex)));
    connect(s_view->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(currentChanged(QModelIndex)));

    adjustPopupSize();
}
Esempio n. 2
0
void SpecialButton::showPopup()
{
    if (!m_stylesWidget) {
        return;
    }

    QRect popupRect(mapToGlobal(QPoint(0, height())), m_stylesWidget->sizeHint());
    // Make sure the popup is not drawn outside the screen area
    QRect screenRect = QApplication::desktop()->availableGeometry(this);
    if (popupRect.right() > screenRect.right())
        popupRect.translate(screenRect.right() - popupRect.right(), 0);
    if (popupRect.left() < screenRect.left())
        popupRect.translate(screenRect.left() - popupRect.left(), 0);
    if (popupRect.bottom() > screenRect.bottom())
        popupRect.translate(0, -(height() + m_stylesWidget->height()));

    m_stylesWidget->setGeometry(popupRect);
    m_stylesWidget->raise();
    m_stylesWidget->show();
    isPopupVisible = true;
}
Esempio n. 3
0
void LocationCompleter::showPopup()
{
    Q_ASSERT(m_window);
    Q_ASSERT(m_locationBar);

    if (!m_locationBar->hasFocus() || s_model->rowCount() == 0) {
        s_view->close();
        return;
    }

    if (s_view->isVisible()) {
        adjustPopupSize();
        return;
    }

    QRect popupRect(m_locationBar->mapToGlobal(m_locationBar->pos()), m_locationBar->size());
    popupRect.setY(popupRect.bottom());

    s_view->setGeometry(popupRect);
    s_view->setFocusProxy(m_locationBar);
    s_view->setCurrentIndex(QModelIndex());

    connect(s_view, SIGNAL(closed()), this, SLOT(slotPopupClosed()));
    connect(s_view, SIGNAL(indexActivated(QModelIndex)), this, SLOT(indexActivated(QModelIndex)));
    connect(s_view, SIGNAL(indexCtrlActivated(QModelIndex)), this, SLOT(indexCtrlActivated(QModelIndex)));
    connect(s_view, SIGNAL(indexShiftActivated(QModelIndex)), this, SLOT(indexShiftActivated(QModelIndex)));
    connect(s_view, SIGNAL(indexDeleteRequested(QModelIndex)), this, SLOT(indexDeleteRequested(QModelIndex)));
    connect(s_view, &LocationCompleterView::loadRequested, this, &LocationCompleter::loadRequested);
    connect(s_view, &LocationCompleterView::searchEnginesDialogRequested, this, &LocationCompleter::openSearchEnginesDialog);
    connect(s_view->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(currentChanged(QModelIndex)));

    s_view->createWinId();
    s_view->windowHandle()->setTransientParent(m_window->windowHandle());

    adjustPopupSize();
}
Esempio n. 4
0
void KoSliderCombo::KoSliderComboPrivate::showPopup()
{
    if(firstShowOfSlider) {
        container->show(); //show container a bit early so the slider can be layout'ed
        firstShowOfSlider = false;
    }

    QStyleOptionSlider opt;
    opt.init(slider);
    opt.maximum=256;
    opt.sliderPosition = opt.sliderValue = slider->value();
    int hdlPos = thePublic->style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle).center().x();

    QStyleOptionComboBox optThis;
    optThis.init(thePublic);
    optThis.subControls = QStyle::SC_All;
    optThis.editable = true;
    int arrowPos = thePublic->style()->subControlRect(QStyle::CC_ComboBox, &optThis, QStyle::SC_ComboBoxArrow).center().x();

    QSize popSize = container->size();
    QRect popupRect(thePublic->mapToGlobal(QPoint(arrowPos - hdlPos - slider->x(), thePublic->size().height())), popSize);

    // Make sure the popup is not drawn outside the screen area
    QRect screenRect = QApplication::desktop()->availableGeometry(thePublic);
    if (popupRect.right() > screenRect.right())
        popupRect.translate(screenRect.right() - popupRect.right(), 0);
    if (popupRect.left() < screenRect.left())
        popupRect.translate(screenRect.left() - popupRect.left(), 0);
    if (popupRect.bottom() > screenRect.bottom())
        popupRect.translate(0, -(thePublic->height() + container->height()));

    container->setGeometry(popupRect);
    container->raise();
    container->show();
    slider->setFocus();
}
void WebPopupMenuProxyWin::calculatePositionAndSize(const IntRect& rect)
{
    // Convert the rect (which is in view cooridates) into screen coordinates.
    IntRect rectInScreenCoords = rect;
    POINT location(rectInScreenCoords .location());
    if (!::ClientToScreen(m_webView->window(), &location))
        return;
    rectInScreenCoords.setLocation(location);

    int itemCount = m_items.size();
    m_itemHeight = m_data.m_itemHeight;

    int naturalHeight = m_itemHeight * itemCount;
    int popupHeight = min(maxPopupHeight, naturalHeight);

    // The popup should show an integral number of items (i.e. no partial items should be visible)
    popupHeight -= popupHeight % m_itemHeight;

    // Next determine its width
    int popupWidth = m_data.m_popupWidth;

    if (naturalHeight > maxPopupHeight) {
        // We need room for a scrollbar
        popupWidth += ScrollbarTheme::nativeTheme()->scrollbarThickness(SmallScrollbar);
    }

    popupHeight += 2 * popupWindowBorderWidth;

    // The popup should be at least as wide as the control on the page
    popupWidth = max(rectInScreenCoords.width() - m_data.m_clientInsetLeft - m_data.m_clientInsetRight, popupWidth);

    // Always left-align items in the popup.  This matches popup menus on the mac.
    int popupX = rectInScreenCoords.x() + m_data.m_clientInsetLeft;

    IntRect popupRect(popupX, rectInScreenCoords.maxY(), popupWidth, popupHeight);

    // The popup needs to stay within the bounds of the screen and not overlap any toolbars
    HMONITOR monitor = ::MonitorFromWindow(m_webView->window(), MONITOR_DEFAULTTOPRIMARY);
    MONITORINFOEX monitorInfo;
    monitorInfo.cbSize = sizeof(MONITORINFOEX);
    ::GetMonitorInfo(monitor, &monitorInfo);
    FloatRect screen = monitorInfo.rcWork;

    // Check that we don't go off the screen vertically
    if (popupRect.maxY() > screen.height()) {
        // The popup will go off the screen, so try placing it above the client
        if (rectInScreenCoords.y() - popupRect.height() < 0) {
            // The popup won't fit above, either, so place it whereever's bigger and resize it to fit
            if ((rectInScreenCoords.y() + rectInScreenCoords.height() / 2) < (screen.height() / 2)) {
                // Below is bigger
                popupRect.setHeight(screen.height() - popupRect.y());
            } else {
                // Above is bigger
                popupRect.setY(0);
                popupRect.setHeight(rectInScreenCoords.y());
            }
        } else {
            // The popup fits above, so reposition it
            popupRect.setY(rectInScreenCoords.y() - popupRect.height());
        }
    }

    // Check that we don't go off the screen horizontally
    if (popupRect.x() < screen.x()) {
        popupRect.setWidth(popupRect.width() - (screen.x() - popupRect.x()));
        popupRect.setX(screen.x());
    }

    m_windowRect = popupRect;
}
Esempio n. 6
0
/**
* Places the dialog items according to the current visible window position.
* When hiding items, uses SetExtent() instead of just SetPosition() in order to call
* SizeChanged() of the moved item. For example, this is needed for the editor to
* change its cursor accordingly.
*
* @param aRect Rectangle of the form window
* @param aTop Number of items above the window
* @param aMiddle Number of items inside the window
* @param aBottom Number of items below the window
*
* Parameter value equal to -1 means that the parameter is not defined and will be
* calculated automatically. Normally, either the top number or the bottom one
* is only defined. If @a aTop is defined, the items will be placed from top downwards, leaving
* @a aTop items above the window. If @a aBottom is defined, the items will be placed from bottom
* upwards, leaving @a aBottom items below the window.
*
* This function panics, if neither @a aTop nor @a aBottom are defined.
*
* The function first checks if the provided @a aTop and @a aBottom are consistent with
* the item sizes and the given window rectangle. If they are not, they will be
* corrected. Usually, @a aTop and @a aBottom come out of sync with the item sizes
* after the dynamic layout change.
*/
void CEikCapCArray::SetRect(const TRect& aRect, TInt aTop, TInt /*aMiddle*/, TInt aBottom)
{
    TAknLayoutRect formtLayoutRect;
    formtLayoutRect.LayoutRect(aRect, AknLayoutScalable_Avkon::listscroll_form_pane().LayoutLine());
    formtLayoutRect.LayoutRect(formtLayoutRect.Rect(), AknLayoutScalable_Avkon::list_form_gen_pane().LayoutLine());
    TRect formRect = formtLayoutRect.Rect();

    CEikCapCArrayExtension *extension_or_null = ExtensionOrNull();
    if (extension_or_null)
    {
        extension_or_null->iRect = formRect;
    }

    // controls need to be placed in real locations if physics is enabled
    if ( Count() > 0 )
    {
        CEikCaptionedControl* control = (*this)[0];

        if ( control->DialogPage()->IsForm() )
        {
            SetRealRect( aRect, aTop, aBottom );
            return;
        }
    }

    TBool topDefined = EFalse;   // top or bottom number defined?
    if( aTop > -1 )
    {
        topDefined = ETrue;
    }
    else if( aBottom > -1 )
    {
        topDefined = EFalse;
    }
    else    // aBottom == aTop == -1
    {
        User::Panic( _L("CEikCapCArray::SetRect(): Neither top nor bottom items number defined"), EAknPanicInvalidValue );
    }
    const TInt count = Count();
    const TInt rectHeight = aRect.Height();
    /**
    * Special invisible points are used for placing the items that are
    * outside the window. CCoeControl's invisible flag cannot be used,
    * as it is controlled by third-party applications.
    */
    const TPoint topInvisPoint( -10000, -10000 );
    const TPoint bottomInvisPoint( 10000, 10000 );

    CEikCaptionedControl *firstCapCC = count > 0 ? (*this)[0] : NULL;
    if( firstCapCC && firstCapCC->iIsFormControl )  // Forms
    {
        CEikCaptionedControl *selectedLine( NULL );
        if( firstCapCC->DialogPage())
            selectedLine = firstCapCC->DialogPage()->CurrentLine();

        // Check height of items and the input parameters aTop and aBottom.
        TInt rest = 0;  // number of the rest items without aTop or aBottom
        TInt index = 0;
        if( topDefined )
        {
            rest = count - aTop;
            index = aTop;
        }
        else
        {
            rest = count - aBottom;
            index = rest - 1;
        }
        TInt height = 0;
        for( TInt ii = 0; ii < rest; ii++ )
        {
            CEikCaptionedControl* line = (*this)[index];
            height += line->MinimumSize().iHeight;  // Use MinimumSize() here as a protection from dynamic layout change
            if( height >= rectHeight )
                break;  // Input params are OK
            topDefined? index++ : index--;
        }
        /**
        * If the window contains too few items inside and there are still items outside,
        * correct the input parameters @a aTop and @a aBottom to fill up the window.
        */
        if( height < rectHeight )
        {
            if( topDefined && aTop > 0 )    // For top-down placement and there are items above the window
            {
                // Calculate height of controls above the window also
                for( TInt ii = 0; ii < aTop; ii++ )
                {
                    CEikCaptionedControl* line = (*this)[ii];
                    height += line->MinimumSize().iHeight;
                    if( height >= rectHeight )  // All items don't fit to the window anyway
                    {
                        topDefined = EFalse;   // Reverse direction to bottom-up
                        aBottom = 0;
                        break;
                    }
                }
                if( height < rectHeight )  // All items fit to the window
                {
                    aTop = 0; // Just place them from the first item
                }
            }
            else if( !topDefined )  // For bottom-up placement
            {
                topDefined = ETrue;   // Reverse direction to top-down
                aTop = 0;
            }
        }

        // Hiding items that are explicitly defined to be outside the window
        TInt start;
        TInt end;
        TPoint invisPoint;    // current invisible point, depends on placement direction
        if( topDefined )
        {
            start = 0;
            end = aTop;
            invisPoint = topInvisPoint;
        }
        else
        {
            start = count - aBottom;
            end = count;
            invisPoint = bottomInvisPoint;
        }
        for( TInt ii = start; ii < end; ii++ )
        {
            CEikCaptionedControl* line = (*this)[ii];
            line->SetPosition( invisPoint );
        }

        // Setting rects for the rest of the items
        if( topDefined )
        {
            rest = count - aTop;
            invisPoint = bottomInvisPoint;
            index = aTop;
        }
        else
        {
            rest = count - aBottom;
            invisPoint = topInvisPoint;
            index = rest - 1;
        }
        TInt reservedHeight = 0; // in pixels
        TBool insideWindow = ETrue; // The current item is still inside the window
        TInt topY = 0;


        for( TInt ii = 0; ii < rest; ii++ )
        {
            CEikCaptionedControl* line = (*this)[index];
            TSize lineSize( line->Size() );
            if( insideWindow )
            {
                ResetHides( line );
                if( topDefined )
                {   // Top-down placement
                    topY = aRect.iTl.iY + reservedHeight;
                }
                else
                {   // Bottom-up placement
                    topY = aRect.iBr.iY - reservedHeight - lineSize.iHeight;
                }
                line->SetExtent( TPoint( formRect.iTl.iX, topY ), lineSize );
                AknsUtils::RegisterControlPosition( line );
                AknsUtils::RegisterControlPosition( line->iCaption );
                AknsUtils::RegisterControlPosition( line->iControl );
                AknsUtils::RegisterControlPosition( line->iTrailer );
                AknsUtils::RegisterControlPosition( line->iBitmap );
                reservedHeight += lineSize.iHeight;
                /**
                * The control at a window edge is considered as partially-visible.
                * Its subcontrols must be checked for visibility individually.
                */
                if( reservedHeight > rectHeight )
                {
                    TInt visibleSubctrls = HideLines( line, aRect );    // Check how many subcontrols stayed visible
                    insideWindow = EFalse;
                    /**
                    * For the bottom-up placement:
                    * if the window contains only an empty "partially-visible" control and a
                    * a selected popup field, make the popup to hang at the top alone.
                    */
                    if( !topDefined && index < count - 1 ) // bottom-up and not last
                    {
                        CEikCaptionedControl* lineBelow = (*this)[index+1];
                        if( visibleSubctrls == 0 && ii == 1 &&
                                IsPopupField( lineBelow ) && lineBelow == selectedLine )
                        {
                            TRect popupRect( lineBelow->Rect() );
                            TInt diff = aRect.iTl.iY - popupRect.iTl.iY; // negative
                            popupRect.Move( 0, diff );
                            lineBelow->SetRect( popupRect );
                        }
                    }
                }
            }
            else
            {
                line->SetPosition( invisPoint );
            }
            topDefined? index++ : index--;
        }
    }
    else    // Dialogs other than forms:
    {
        TRect rect=aRect;
        const TInt fullWidth=rect.iBr.iX-rect.iTl.iX;
        const TInt count=Count();
        const TInt topMargin=iDensePacking ? KAknNoTopMargin : KAknTopMargin;
        const TInt verticalSpacing=iDensePacking ? KVerticalSpacingSquash : KVerticalSpacing;
        rect.iTl.iY+=topMargin;
        TInt deltaHeight=0;
        for (TInt ii=0; ii<count; ++ii)
        {
            CEikCaptionedControl* line=(*this)[ii];
            TSize thisSize=line->MinimumSize();
            TInt thisDeltaHeight=thisSize.iHeight+verticalSpacing;
            if (deltaHeight<thisDeltaHeight)
                deltaHeight=thisDeltaHeight;
            if (!(line->iCaptionWidth))
                thisSize.iWidth=fullWidth;
            else
            {
                CEikCapCArrayExtension *ext = ExtensionOrNull();
                TInt deltaWidth = 0;
                if (ext)
                    deltaWidth = ext->iCaptionWidth-line->iCaptionWidth;
                thisSize.iWidth+=deltaWidth;
                if (ext)
                    line->iCaptionWidth=ext->iCaptionWidth;
                else
                    line->iCaptionWidth = 0;
                line->iMinSize.iWidth+=deltaWidth;
            }
            line->iFullWidth=fullWidth;
            line->SetExtent(rect.iTl,thisSize);
            if (!(line->LatentGroupLineFollows()))
            {
                rect.iTl.iY+=deltaHeight;
                deltaHeight=0;
            }
        }
    }
}