示例#1
0
static void onKey(
    HWND hwnd, UINT vk, BOOL fDown, int cRepeat, UINT flags )
{
    long start = getStart( hwnd );
    long end   = getEnd( hwnd );

    const BOOL controlKey = GetAsyncKeyState( VK_CONTROL ) < 0;

    if ( VK_ESCAPE == vk ) {
        if ( htNone != getHTCode( hwnd ) ) {
            setHTCode( hwnd, htNone );
            const LONG oldStart = getSaveStart( hwnd );
            const LONG oldEnd   = getSaveEnd  ( hwnd );
            setStart( hwnd, oldStart );
            setEnd  ( hwnd, oldEnd   );
            invalidateRect( hwnd );
            //onLButtonUp( hwnd, 0, 0, 0 ); // TODO retain capture anyway?
            // TODO notify parent
            return; //** FUNCTION EXIT POINT
        }
    }

    const UINT left_key  = isVertical( hwnd ) ? VK_UP   : VK_LEFT ;
    const UINT right_key = isVertical( hwnd ) ? VK_DOWN : VK_RIGHT;

    long granularity = getGranularity( hwnd );
    if ( granularity <= 0 ) {
        granularity = 1;
    }

    if ( left_key == vk ) {
        if ( controlKey ) {
            if ( getMinRange( hwnd ) < end - start ) {
                end -= granularity;
            }
        } else if ( getLower( hwnd ) < start ) {
            start -= granularity;
            end   -= granularity;
        }
    } else if ( right_key == vk ) {
        if ( end < getUpper( hwnd ) ) {
            end += granularity;
            if ( !controlKey ) {
                start += granularity;
            }
        }
    } else if ( VK_PRIOR == vk ) {
        scroll( hwnd, -1, 0 );
        return; //*** FUNCTION EXIT POINT
    } else if ( VK_NEXT == vk ) {
        scroll( hwnd, 1, 0 );
        return; //*** FUNCTION EXIT POINT
    } else if ( VK_HOME == vk ) {
        const long range = abs( getLower( hwnd ) - start );
        start -= range;
        end   -= range;
    } else if ( VK_END == vk ) {
        const long range = abs( getUpper( hwnd ) - end );
        start += range;
        end   += range;
    }

    start = adjust( hwnd, start );
    end   = adjust( hwnd, end   );
    if ( start != getStart( hwnd ) || end != getEnd( hwnd ) ) {
        setStart( hwnd, start );
        setEnd  ( hwnd, end );
        invalidateRect( hwnd );
        invalidateCursor();
        notifyParent( hwnd );
    }
}
示例#2
0
inline LONG getWidth( HWND hwnd ) {

    const RECT rc = getClientRect( hwnd );
    const int width = isVertical( hwnd ) ? rc.bottom - rc.top : rc.right - rc.left;
    return width - 2 * getHandle( hwnd );
}
示例#3
0
inline int hitTest( HWND hwnd ) {

    const POINT pt = getCursorPos( hwnd );
    return hitTest( hwnd, isVertical( hwnd ) ? pt.y : pt.x );
}
示例#4
0
//------------------------------------------------------------------------------
// serialize() -- print functions
//------------------------------------------------------------------------------
std::ostream& Field::serialize(std::ostream& sout, const int i, const bool slotsOnly) const
{
    int j = 0;
    if ( !slotsOnly ) {
        sout << "( " << getFormName() << std::endl;
        j = 4;
    }

    BaseClass::serialize(sout,i+j,true);

    if (line() > 0 && column() > 0) {
        indent(sout,i+j);
        sout << "position: [ " << line() << " " << column() << " ]" << std::endl;
    }

    if ( width() > 0) {
        indent(sout,i+j);
        sout << "width: "	<< (unsigned int)width()	<< std::endl;
    }

    if ( isHighLighted() ) {
        indent(sout,i+j);
        sout << "highLight: " << isHighLighted() << std::endl;
    }

    if ( isUnderlined() ) {
        indent(sout,i+j);
        sout << "underline: " << isUnderlined() << std::endl;
    }

    if ( isReversed() ) {
        indent(sout,i+j);
        sout << "reversed: " << isReversed() << std::endl;
    }

    if ( isVertical() ) {
        indent(sout,i+j);
        sout << "vertical: " << isVertical() << std::endl;
    }

    if ( areBracketsOn() ) {
        indent(sout,i+j);
        sout << "brackets: " << areBracketsOn() << std::endl;
    }

    indent(sout,i+j);
    sout << "justification: ";
    switch (jmode) {
        case Basic::String::NONE   : sout << "\"none\"";    break;
        case Basic::String::LEFT   : sout << "\"left\"";    break;
        case Basic::String::CENTER : sout << "\"center\"";  break;
        case Basic::String::RIGHT  : sout << "\"right\"";   break;
    }
    sout << std::endl;

    if ( !slotsOnly ) {
        indent(sout,i);
        sout << ")" << std::endl;
    }
    return sout;
}
void ResizableEdgeComponent::paint (Graphics& g)
{
    getLookAndFeel().drawStretchableLayoutResizerBar (g, getWidth(), getHeight(), isVertical(),
                                                      isMouseOver(), isMouseButtonDown());
}
示例#6
0
void Splitter::drawSplitter()
{
	PAINTSTRUCT ps;
	RECT rc, rcToDraw1, rcToDraw2, TLrc, BRrc;

	HDC hdc = ::BeginPaint(_hSelf, &ps);
	getClientRect(rc);

	if ((_spiltterSize >= 4) && (_dwFlags & SV_RESIZEWTHPERCNT))
	{
		adjustZoneToDraw(TLrc, ZONE_TYPE::topLeft);
		adjustZoneToDraw(BRrc, ZONE_TYPE::bottomRight);
		paintArrow(hdc, TLrc, isVertical() ? Arrow::left : Arrow::up);
	}

	if (isVertical())
	{
		rcToDraw2.top    = (_dwFlags & SV_RESIZEWTHPERCNT) ? _clickZone2TL.bottom : 0;
		rcToDraw2.bottom = rcToDraw2.top + 2;

		rcToDraw1.top    = rcToDraw2.top + 1;
		rcToDraw1.bottom = rcToDraw1.top + 2;
	}
	else
	{
		rcToDraw2.top    = 1;
		rcToDraw2.bottom = 3;

		rcToDraw1.top    = 2;
		rcToDraw1.bottom = 4;
	}

	int bottom = 0;
	if (_dwFlags & SV_RESIZEWTHPERCNT)
		bottom = (isVertical() ? rc.bottom - _clickZone2BR.bottom : rc.bottom);
	else
		bottom = rc.bottom;

	while (rcToDraw1.bottom <= bottom)
	{
		if (isVertical())
		{
			rcToDraw2.left  = 1;
			rcToDraw2.right = 3;

			rcToDraw1.left  = 2;
			rcToDraw1.right = 4;
		}
		else
		{
			rcToDraw2.left = _clickZone2TL.right;
			rcToDraw2.right = rcToDraw2.left + 2;

			rcToDraw1.left = rcToDraw2.left;
			rcToDraw1.right = rcToDraw1.left + 2;
		}

		while (rcToDraw1.right <= (isVertical() ? rc.right : rc.right - _clickZone2BR.right))
		{
			::FillRect(hdc, &rcToDraw1, (HBRUSH)(RGB(0xFF, 0xFF, 0xFF)));
			::FillRect(hdc, &rcToDraw2, (HBRUSH)(COLOR_3DSHADOW+1));

			rcToDraw2.left += 4;
			rcToDraw2.right += 4;
			rcToDraw1.left += 4;
			rcToDraw1.right += 4;
		}

		rcToDraw2.top += 4;
		rcToDraw2.bottom += 4;
		rcToDraw1.top += 4;
		rcToDraw1.bottom += 4;
	}

	if ((_spiltterSize >= 4) && (_dwFlags & SV_RESIZEWTHPERCNT))
		paintArrow(hdc, BRrc, isVertical() ? Arrow::right : Arrow::down);

	::EndPaint(_hSelf, &ps);
}
示例#7
0
//------------------------------------------------------------------------------
// drawFunc -- draw this text field
//------------------------------------------------------------------------------
void Field::drawFunc()
{
    // Get a pointer to the current display
    BasicGL::Display* dsp = getDisplay();
    if (dsp == 0) return;

    // ---
    // When our container is also a Field, get a pointer to it.
    // ---
    BasicGL::Field* parent = 0;
    if (container() != 0) {
        BasicGL::Field* fp = dynamic_cast<BasicGL::Field*>(container());
        if (fp != 0) parent = fp;
    }

    // ---
    // If we don't have a position, try to get one from our container
    // ---
    int ll = line();
    int cc = column();
    if (ll == 0 && parent != 0) {
        ll = parent->line();
        cc = parent->column();
    }

    // ---
    // Select the correct font based on font name if there is one, and if not, then do it normally
    // ---
    if (fontName != 0) dsp->selectFont(isReversed(), isUnderlined(), dsp->getFont(fontName->getString()));    
    else dsp->selectFont(isReversed(), isUnderlined());
    
    
    // ---
    // Set the color
    // ---
    bool restoreColor = false;
    osg::Vec4 ocolor = dsp->getCurrentColor();
    // only use default colors if we aren't inheriting our container's colors

    if (!isInheritColor()) {
        if (getColorName() == 0 && getColor() == 0) {
            const Basic::Color* cc = 0;
            if (isHighLighted()) cc = dsp->getHighlightColor();
            else cc = dsp->getNormColor();
            if (cc != 0) {
                const osg::Vec4* p = cc->getRGBA();
                dsp->setColor(*p);
                restoreColor = true;
            }
        }
    }

    // ---
    // draw the string
    // ---
    
    if (str.len() > 0) {
        // Draw the text string
        const char* sp = str;
        if (ll > 0 && cc > 0)
            dsp->outputTextLC(ll, cc, sp, int(width()), isVertical());
        else
            dsp->outputText(sp, int(width()), isVertical());
    }

    // ---
    // draw the brackets
    // ---
    if (areBracketsOn() && ll > 0 && cc > 0) {
        if (isVertical()) {
            // Position for vertical text
            dsp->drawLeftBracket(ll-1, cc);
            dsp->drawRightBracket(ll+int(width()), cc);
        }
        else {
            // Position for normal text
            dsp->drawLeftBracket(ll, cc-1);
            dsp->drawRightBracket(ll, cc+int(width()));
        }
    }

    // ---
    // If we used default colors, restore the old value
    // ---
    if (restoreColor) dsp->setColor(ocolor);

}
示例#8
0
void KURLBar::setOrientation(Qt::Orientation orient)
{
    m_listBox->setOrientation(orient);
    setSizePolicy(
        QSizePolicy(isVertical() ? QSizePolicy::Maximum : QSizePolicy::Preferred, isVertical() ? QSizePolicy::Preferred : QSizePolicy::Maximum));
}
示例#9
0
void Splitter::init( HINSTANCE hInst, HWND hPere, int splitterSize, double iSplitRatio, DWORD dwFlags)
{
	if (hPere == NULL)
		throw std::runtime_error("Splitter::init : Parameter hPere is null");

	if (iSplitRatio < 0)
		throw std::runtime_error("Splitter::init : Parameter iSplitRatio shoulds be 0 < ratio < 100");

	Window::init(hInst, hPere);
	_spiltterSize = splitterSize;

	WNDCLASSEX wcex;
	DWORD dwExStyle = 0L;
	DWORD dwStyle   = WS_CHILD | WS_VISIBLE;


	_hParent = hPere;
	_dwFlags = dwFlags;

	if (_dwFlags & SV_FIXED)
	{
		//Fixed spliter
		_isFixed = true;
	}
	else
	{
		if (iSplitRatio >= 100)
		{
			//cant be 100 % or more
			throw std::runtime_error("Splitter::init : Parameter iSplitRatio shoulds be 0 < ratio < 100");
		}
	}

	_splitPercent = iSplitRatio;

	wcex.cbSize			= sizeof(WNDCLASSEX);
	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= (WNDPROC)staticWndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= _hInst;
	wcex.hIcon			= NULL;

	::GetClientRect(_hParent, &_rect);

	if (_dwFlags & SV_HORIZONTAL) //Horizontal spliter
	{
		_rect.top  = (LONG)((_rect.bottom * _splitPercent)/100);
		// y axis determined by the split% of the parent windows height

		_rect.left = 0;
		// x axis is always 0

		_rect.bottom = _spiltterSize;
		// the height of the spliter

		// the width of the splitter remains the same as the width of the parent window.
	}
	else //Vertical spliter
	{
		// y axis is 0 always

		_rect.left = (LONG)((_rect.right * _splitPercent)/100);
		// x axis determined by split% of the parent windows width.

		_rect.right = _spiltterSize;
		// width of the spliter.

		//height of the spliter remains the same as the height of the parent window
	}

	if (!_isFixed)
	{
		if ((_dwFlags & SV_ENABLERDBLCLK) || (_dwFlags & SV_ENABLELDBLCLK))
		{
			wcex.style = wcex.style | CS_DBLCLKS;
			// enable mouse double click messages.
		}
	}

	if (_isFixed)
	{
		wcex.hCursor		= ::LoadCursor(NULL, IDC_ARROW);
		// if fixed spliter then choose default cursor type.
        if (_dwFlags & SV_HORIZONTAL)
		    wcex.lpszClassName	= TEXT("fxdnsspliter");
        else
            wcex.lpszClassName	= TEXT("fxdwespliter");
	}
	else
	{
		if (_dwFlags & SV_HORIZONTAL)
		{
			//double sided arrow pointing north-south as cursor
			wcex.hCursor		= ::LoadCursor(NULL,IDC_SIZENS);
			wcex.lpszClassName	= TEXT("nsspliter");
		}
		else
		{
			// double sided arrow pointing east-west as cursor
			wcex.hCursor		= ::LoadCursor(NULL,IDC_SIZEWE);
			wcex.lpszClassName	= TEXT("wespliter");
		}
	}

	wcex.hbrBackground	= (HBRUSH)(COLOR_3DFACE+1);
	wcex.lpszMenuName	= NULL;
	wcex.hIconSm		= NULL;

	if ((_dwFlags & SV_HORIZONTAL)&&(!_isHorizontalRegistered))
	{
		RegisterClassEx(&wcex);
		_isHorizontalRegistered = true;
	}
	else if (isVertical()&&(!_isVerticalRegistered))
	{
		RegisterClassEx(&wcex);
		_isVerticalRegistered = true;
	}
    else if ((_dwFlags & SV_HORIZONTAL)&&(!_isHorizontalFixedRegistered))
    {
        RegisterClassEx(&wcex);
        _isHorizontalFixedRegistered = true;
    }
    else if (isVertical()&&(!_isVerticalFixedRegistered))
    {
        RegisterClassEx(&wcex);
        _isVerticalFixedRegistered = true;
    }

	_hSelf = CreateWindowEx(dwExStyle, wcex.lpszClassName,
		TEXT(""),
		dwStyle,
		_rect.left, _rect.top, _rect.right, _rect.bottom,
		_hParent, NULL, _hInst, this);

	if (!_hSelf)
		throw std::runtime_error("Splitter::init : CreateWindowEx() function return null");

	RECT rc;
	getClientRect(rc);
	//::GetClientRect(_hParent,&rc);

	_clickZone2TL.left   = rc.left;
	_clickZone2TL.top    = rc.top;

	int clickZoneWidth   = getClickZone(WH::width);
	int clickZoneHeight  = getClickZone(WH::height);
	_clickZone2TL.right  = clickZoneWidth;
	_clickZone2TL.bottom = clickZoneHeight;

	_clickZone2BR.left   = rc.right - clickZoneWidth;
	_clickZone2BR.top    = rc.bottom - clickZoneHeight;
	_clickZone2BR.right  = clickZoneWidth;
	_clickZone2BR.bottom = clickZoneHeight;

	display();
	::SendMessage(_hParent, WM_RESIZE_CONTAINER, _rect.left, _rect.top);
}
void TabbedButtonBar::resized()
{
    LookAndFeel& lf = getLookAndFeel();

    int depth = getWidth();
    int length = getHeight();

    if (! isVertical())
        std::swap (depth, length);

    const int overlap = lf.getTabButtonOverlap (depth) + lf.getTabButtonSpaceAroundImage() * 2;

    int totalLength = jmax (0, overlap);
    int numVisibleButtons = tabs.size();

    for (int i = 0; i < tabs.size(); ++i)
    {
        TabBarButton* const tb = tabs.getUnchecked(i)->button;

        totalLength += tb->getBestTabLength (depth) - overlap;
        tb->overlapPixels = jmax (0, overlap / 2);
    }

    double scale = 1.0;

    if (totalLength > length)
        scale = jmax (minimumScale, length / (double) totalLength);

    const bool isTooBig = (int) (totalLength * scale) > length;
    int tabsButtonPos = 0;

    if (isTooBig)
    {
        if (extraTabsButton == nullptr)
        {
            addAndMakeVisible (extraTabsButton = lf.createTabBarExtrasButton());
            extraTabsButton->addListener (behindFrontTab);
            extraTabsButton->setAlwaysOnTop (true);
            extraTabsButton->setTriggeredOnMouseDown (true);
        }

        const int buttonSize = jmin (proportionOfWidth (0.7f), proportionOfHeight (0.7f));
        extraTabsButton->setSize (buttonSize, buttonSize);

        if (isVertical())
        {
            tabsButtonPos = getHeight() - buttonSize / 2 - 1;
            extraTabsButton->setCentrePosition (getWidth() / 2, tabsButtonPos);
        }
        else
        {
            tabsButtonPos = getWidth() - buttonSize / 2 - 1;
            extraTabsButton->setCentrePosition (tabsButtonPos, getHeight() / 2);
        }

        totalLength = 0;

        for (int i = 0; i < tabs.size(); ++i)
        {
            TabBarButton* const tb = tabs.getUnchecked(i)->button;
            const int newLength = totalLength + tb->getBestTabLength (depth);

            if (i > 0 && newLength * minimumScale > tabsButtonPos)
            {
                totalLength += overlap;
                break;
            }

            numVisibleButtons = i + 1;
            totalLength = newLength - overlap;
        }

        scale = jmax (minimumScale, tabsButtonPos / (double) totalLength);
    }
    else
    {
        extraTabsButton = nullptr;
    }

    int pos = 0;

    TabBarButton* frontTab = nullptr;

    for (int i = 0; i < tabs.size(); ++i)
    {
        if (TabBarButton* const tb = getTabButton (i))
        {
            const int bestLength = roundToInt (scale * tb->getBestTabLength (depth));

            if (i < numVisibleButtons)
            {
                if (isVertical())
                    tb->setBounds (0, pos, getWidth(), bestLength);
                else
                    tb->setBounds (pos, 0, bestLength, getHeight());

                tb->toBack();

                if (i == currentTabIndex)
                    frontTab = tb;

                tb->setVisible (true);
            }
            else
            {
                tb->setVisible (false);
            }

            pos += bestLength - overlap;
        }
    }

    behindFrontTab->setBounds (getLocalBounds());

    if (frontTab != nullptr)
    {
        frontTab->toFront (false);
        behindFrontTab->toBehind (frontTab);
    }
}
示例#11
0
void Toolbar::updateAllItemPositions (const bool animate)
{
    if (getWidth() > 0 && getHeight() > 0)
    {
        StretchableObjectResizer resizer;

        int i;
        for (i = 0; i < items.size(); ++i)
        {
            ToolbarItemComponent* const tc = items.getUnchecked(i);

            tc->setEditingMode (isEditingActive ? ToolbarItemComponent::editableOnToolbar
                                                : ToolbarItemComponent::normalMode);

            tc->setStyle (toolbarStyle);

            ToolbarSpacerComp* const spacer = dynamic_cast <ToolbarSpacerComp*> (tc);

            int preferredSize = 1, minSize = 1, maxSize = 1;

            if (tc->getToolbarItemSizes (getThickness(), isVertical(),
                                         preferredSize, minSize, maxSize))
            {
                tc->isActive = true;
                resizer.addItem (preferredSize, minSize, maxSize,
                                 spacer != nullptr ? spacer->getResizeOrder() : 2);
            }
            else
            {
                tc->isActive = false;
                tc->setVisible (false);
            }
        }

        resizer.resizeToFit (getLength());

        int totalLength = 0;

        for (i = 0; i < resizer.getNumItems(); ++i)
            totalLength += (int) resizer.getItemSize (i);

        const bool itemsOffTheEnd = totalLength > getLength();

        const int extrasButtonSize = getThickness() / 2;
        missingItemsButton->setSize (extrasButtonSize, extrasButtonSize);
        missingItemsButton->setVisible (itemsOffTheEnd);
        missingItemsButton->setEnabled (! isEditingActive);

        if (vertical)
            missingItemsButton->setCentrePosition (getWidth() / 2,
                                                   getHeight() - 4 - extrasButtonSize / 2);
        else
            missingItemsButton->setCentrePosition (getWidth() - 4 - extrasButtonSize / 2,
                                                   getHeight() / 2);

        const int maxLength = itemsOffTheEnd ? (vertical ? missingItemsButton->getY()
                                                         : missingItemsButton->getX()) - 4
                                             : getLength();

        int pos = 0, activeIndex = 0;
        for (i = 0; i < items.size(); ++i)
        {
            ToolbarItemComponent* const tc = items.getUnchecked(i);

            if (tc->isActive)
            {
                const int size = (int) resizer.getItemSize (activeIndex++);

                Rectangle<int> newBounds;
                if (vertical)
                    newBounds.setBounds (0, pos, getWidth(), size);
                else
                    newBounds.setBounds (pos, 0, size, getHeight());

                if (animate)
                {
                    Desktop::getInstance().getAnimator().animateComponent (tc, newBounds, 1.0f, 200, false, 3.0, 0.0);
                }
                else
                {
                    Desktop::getInstance().getAnimator().cancelAnimation (tc, false);
                    tc->setBounds (newBounds);
                }

                pos += size;
                tc->setVisible (pos <= maxLength
                                 && ((! tc->isBeingDragged)
                                      || tc->getEditingMode() == ToolbarItemComponent::editableOnPalette));
            }
        }
    }
}
示例#12
0
void gSlider::checkInverted()
{
	gtk_range_set_inverted(GTK_RANGE(widget), !isVertical() && gDesktop::rightToLeft());
}
示例#13
0
void KMultiTabBarTab::paintEvent(QPaintEvent*) {
	QPainter painter(this);

	QStyleOptionToolButton opt;
	initStyleOption(&opt);

	// Paint bevel..
	if (underMouse() || isChecked()) {
		opt.text.clear();
		opt.icon = QIcon();
		style()->drawComplexControl(QStyle::CC_ToolButton, &opt, &painter, this);
	}

	int hMargin, vMargin;
	computeMargins(&hMargin, &vMargin);

	// We first figure out how much room we have for the text, based on
	// icon size and margin, try to fit in by eliding, and perhaps
	// give up on drawing the text entirely if we're too short on room
	QPixmap icon = iconPixmap();
	int textRoom = 0;
	int iconRoom = 0;

	QString t;
	if (shouldDrawText()) {
		if (isVertical()) {
			iconRoom = icon.height() + 2*vMargin;
			textRoom = height() - iconRoom - vMargin;
		} else {
			iconRoom = icon.width() + 2*hMargin;
			textRoom = width() - iconRoom - hMargin;
		}

		t = painter.fontMetrics().elidedText(text(), Qt::ElideRight, textRoom);

		// See whether anything is left. Qt will return either
		// ... or the ellipsis unicode character, 0x2026
		if (t == QLatin1String("...") || t == QChar(0x2026))
			t.clear();
	}

	// Label time.... Simple case: no text, so just plop down the icon right in the center
	// We only do this when the button never draws the text, to avoid jumps in icon position
	// when resizing
 	if (!shouldDrawText()) {
 		style()->drawItemPixmap(&painter, rect(), Qt::AlignCenter | Qt::AlignVCenter, icon);
 		return;
 	}

	// Now where the icon/text goes depends on text direction and tab position
	QRect iconArea;
	QRect labelArea;

	bool bottomIcon = false;
	bool rtl = layoutDirection() == Qt::RightToLeft;
	if (isVertical()) {
		if (m_position == KMultiTabBar::Left && !rtl)
			bottomIcon = true;
		if (m_position == KMultiTabBar::Right && rtl)
			bottomIcon = true;
	}
	//alignFlags = Qt::AlignLeading | Qt::AlignVCenter;

	if (isVertical()) {
		if (bottomIcon) {
			labelArea = QRect(0, vMargin, width(), textRoom);
			iconArea  = QRect(0, vMargin + textRoom, width(), iconRoom);
		} else {
			labelArea = QRect(0, iconRoom, width(), textRoom);
			iconArea  = QRect(0, 0, width(), iconRoom);
		}
	} else {
		// Pretty simple --- depends only on RTL/LTR
		if (rtl) {
			labelArea = QRect(hMargin, 0, textRoom, height());
			iconArea  = QRect(hMargin + textRoom, 0, iconRoom, height());
		} else {
			labelArea = QRect(iconRoom, 0, textRoom, height());
			iconArea  = QRect(0, 0, iconRoom, height());
		}
	}

	style()->drawItemPixmap(&painter, iconArea, Qt::AlignCenter | Qt::AlignVCenter, icon);

	if (t.isEmpty())
		return;

	QRect labelPaintArea = labelArea;

	if (isVertical()) {
		// If we're vertical, we paint to a simple 0,0 origin rect,
		// and get the transformations to get us in the right place
		labelPaintArea = QRect(0, 0, labelArea.height(), labelArea.width());

		QTransform tr;

		if (bottomIcon) {
			tr.translate(labelArea.x(), labelPaintArea.width() + labelArea.y());
			tr.rotate(-90);
		} else {
			tr.translate(labelPaintArea.height() + labelArea.x(), labelArea.y());
			tr.rotate(90);
		}
		painter.setTransform(tr);
	}

	style()->drawItemText(&painter, labelPaintArea, Qt::AlignLeading | Qt::AlignVCenter,
	                      palette(), true, t, QPalette::ButtonText);
}
示例#14
0
文件: Line.hpp 项目: psyllo/misc
 bool sameAngle(Line* line2) {
   return(isVertical() && line2->isVertical() || isHorizontal() && line2->isHorizontal());
 }
示例#15
0
void ScrollView::updateIndicatorPosition() {
	if (!_indicatorVisible) {
		return;
	}

	float scrollWidth = _contentSize.width;
	float scrollHeight = _contentSize.height;

	float scrollLength = getScrollLength();
	if (isnan(scrollLength)) {
		_indicator->setVisible(false);
	} else {
		_indicator->setVisible(_indicatorVisible);
	}

	auto paddingLocal = _paddingGlobal;
	if (_indicatorIgnorePadding) {
		if (isVertical()) {
			paddingLocal.top = 0;
			paddingLocal.bottom = 0;
		} else {
			paddingLocal.left = 0;
			paddingLocal.right = 0;
		}
	}

	if (scrollLength > _scrollSize) {
		if (isVertical()) {
			float h = (scrollHeight - 4 - paddingLocal.top - paddingLocal.bottom) * scrollHeight / scrollLength;
			if (h < 20) {
				h = 20;
			}
			float r = scrollHeight - h - 4 - paddingLocal.top - paddingLocal.bottom;
			float value = (_scrollPosition - getScrollMinPosition()) / (getScrollMaxPosition() - getScrollMinPosition());

			_indicator->setContentSize(Size(3, h));
			_indicator->setPosition(Vec2(scrollWidth - 2, paddingLocal.bottom + 2 + r * (1.0f - value)));
			_indicator->setAnchorPoint(Vec2(1, 0));
		} else {
			float h = (scrollWidth - 4 - paddingLocal.left - paddingLocal.right) * scrollWidth / scrollLength;
			if (h < 20) {
				h = 20;
			}
			float r = scrollWidth - h - 4 - paddingLocal.left - paddingLocal.right;
			float value = (_scrollPosition - getScrollMinPosition()) / (getScrollMaxPosition() - getScrollMinPosition());

			_indicator->setContentSize(Size(h, 3));
			_indicator->setPosition(Vec2(paddingLocal.left + 2 + r * (value), 2));
			_indicator->setAnchorPoint(Vec2(0, 0));
		}
		if (_indicator->getOpacity() != 255) {
			cocos2d::Action *a = _indicator->getActionByTag(19);
			if (!a) {
				a = cocos2d::FadeTo::create(progress(0.1f, 0.0f, _indicator->getOpacity() / 255.0f), 255);
				a->setTag(19);
				_indicator->runAction(a);
			}
		}

		_indicator->stopActionByTag(18);
		auto fade = cocos2d::Sequence::create(cocos2d::DelayTime::create(2.0f), cocos2d::FadeOut::create(0.25f), nullptr);
		fade->setTag(18);
		_indicator->runAction(fade);
	} else {
		_indicator->setVisible(false);
	}
}
示例#16
0
    float scoreForWidget(GuiWidget const &widget, ui::Direction dir) const
    {
        if (!widget.canBeFocused() || &widget == thisPublic)
        {
            return -1;
        }

        Rectanglef const viewRect  = self().root().viewRule().rect();
        Rectanglef const selfRect  = self().hitRule().rect();
        Rectanglef const otherRect = widget.hitRule().rect();
        Vector2f const otherMiddle =
                (dir == ui::Up?   otherRect.midBottom() :
                 dir == ui::Down? otherRect.midTop()    :
                 dir == ui::Left? otherRect.midRight()  :
                                  otherRect.midLeft()  );
                //otherRect.middle();

        if (!viewRect.contains(otherMiddle))
        {
            return -1;
        }

        bool const axisOverlap =
                (isHorizontal(dir) && !selfRect.vertical()  .intersection(otherRect.vertical())  .isEmpty()) ||
                (isVertical(dir)   && !selfRect.horizontal().intersection(otherRect.horizontal()).isEmpty());

        // Check for contacting edges.
        float edgeDistance = 0; // valid only if axisOverlap
        if (axisOverlap)
        {
            switch (dir)
            {
            case ui::Left:
                edgeDistance = selfRect.left() - otherRect.right();
                break;

            case ui::Up:
                edgeDistance = selfRect.top() - otherRect.bottom();
                break;

            case ui::Right:
                edgeDistance = otherRect.left() - selfRect.right();
                break;

            default:
                edgeDistance = otherRect.top() - selfRect.bottom();
                break;
            }
            // Very close edges are considered contacting.
            if (edgeDistance >= 0 && edgeDistance < toDevicePixels(5))
            {
                return edgeDistance;
            }
        }

        Vector2f const middle    = (dir == ui::Up?   selfRect.midTop()    :
                                    dir == ui::Down? selfRect.midBottom() :
                                    dir == ui::Left? selfRect.midLeft()   :
                                                     selfRect.midRight() );
        Vector2f const delta     = otherMiddle - middle;
        Vector2f const dirVector = directionVector(dir);
        auto dotProd = delta.normalize().dot(dirVector);
        if (dotProd <= 0)
        {
            // On the wrong side.
            return -1;
        }
        float distance = delta.length();
        if (axisOverlap)
        {
            dotProd = 1.0;
            if (edgeDistance > 0)
            {
                distance = de::min(distance, edgeDistance);
            }
        }

        float favorability = 1;
        if (widget.parentWidget() == self().parentWidget())
        {
            favorability = .1f; // Siblings are much preferred.
        }
        else if (self().hasAncestor(widget) || widget.hasAncestor(self()))
        {
            favorability = .2f; // Ancestry is also good.
        }

        // Prefer widgets that are nearby, particularly in the specified direction.
        return distance * (.5f + acos(dotProd)) * favorability;
    }