本文整理汇总了C++中QRect::coords方法的典型用法代码示例。如果您正苦于以下问题:C++ QRect::coords方法的具体用法?C++ QRect::coords怎么用?C++ QRect::coords使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QRect
的用法示例。
在下文中一共展示了QRect::coords方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: neededRect
// static
QRect kpTool::neededRect (const QRect &rect, int lineWidth)
{
int x1, y1, x2, y2;
rect.coords (&x1, &y1, &x2, &y2);
if (lineWidth < 1)
lineWidth = 1;
return QRect (QPoint (x1 - lineWidth + 1, y1 - lineWidth + 1),
QPoint (x2 + lineWidth - 1, y2 + lineWidth - 1));
}
示例2: kDrawRoundButton
KDEFX_EXPORT void kDrawRoundButton(QPainter *p, const QRect &r, const QColorGroup &g,
bool sunken)
{
int x, y, x2, y2;
r.coords(&x, &y, &x2, &y2);
if(r.width() > 16 && r.height() > 16){
QPen oldPen = p->pen();
QPointArray hPntArray, lPntArray;
hPntArray.putPoints(0, 12, x+4,y+1, x+5,y+1, // top left
x+3,y+2, x+2,y+3, x+1,y+4, x+1,y+5,
x+1,y2-5, x+1,y2-4, x+2,y2-3, // half corners
x2-5,y+1, x2-4,y+1, x2-3,y+2);
lPntArray.putPoints(0, 17, x2-5,y2-1, x2-4,y2-1, // btm right
x2-3,y2-2, x2-2,y2-3, x2-1,y2-5, x2-1,y2-4,
x+3,y2-2, x+4,y2-1, x+5,y2-1, //half corners
x2-2,y+3, x2-1,y+4, x2-1,y+5,
x2-5,y2-2, x2-4,y2-2, // testing
x2-3,y2-3,
x2-2,y2-5, x2-2,y2-4);
p->setPen(sunken ? g.dark() : g.light());
p->drawLine(x+6, y, x2-6, y);
p->drawLine(0, y+6, 0, y2-6);
p->drawPoints(hPntArray);
p->setPen(sunken ? g.light() : g.dark());
p->drawLine(x+6, y2, x2-6, y2);
p->drawLine(x+6, y2-1, x2-6, y2-1);
p->drawLine(x2, y+6, x2, y2-6);
p->drawLine(x2-1, y+6, x2-1, y2-6);
p->drawPoints(lPntArray);
p->setPen(oldPen);
}
else
qDrawWinPanel(p, x, y, r.width(), r.height(), g, sunken);
}
示例3: paintEvent
void PlastikClient::paintEvent(QPaintEvent *e)
{
QRegion region = e->region();
PlastikHandler *handler = Handler();
if(oldCaption != caption())
clearCaptionPixmaps();
bool active = isActive();
bool toolWindow = isToolWindow();
QPainter painter(widget());
// often needed coordinates
QRect r = widget()->rect();
int r_w = r.width();
// int r_h = r.height();
int r_x, r_y, r_x2, r_y2;
r.coords(&r_x, &r_y, &r_x2, &r_y2);
const int borderLeft = layoutMetric(LM_BorderLeft);
const int borderRight = layoutMetric(LM_BorderRight);
const int borderBottom = layoutMetric(LM_BorderBottom);
const int titleHeight = layoutMetric(LM_TitleHeight);
const int titleEdgeTop = layoutMetric(LM_TitleEdgeTop);
const int titleEdgeBottom = layoutMetric(LM_TitleEdgeBottom);
const int titleEdgeLeft = layoutMetric(LM_TitleEdgeLeft);
const int titleEdgeRight = layoutMetric(LM_TitleEdgeRight);
const int borderBottomTop = r_y2 - borderBottom + 1;
const int borderLeftRight = r_x + borderLeft - 1;
const int borderRightLeft = r_x2 - borderRight + 1;
const int titleEdgeBottomBottom = r_y + titleEdgeTop + titleHeight + titleEdgeBottom - 1;
const int sideHeight = borderBottomTop - titleEdgeBottomBottom - 1;
QRect Rtitle =
QRect(r_x + titleEdgeLeft + buttonsLeftWidth(), r_y + titleEdgeTop,
r_x2 - titleEdgeRight - buttonsRightWidth() - (r_x + titleEdgeLeft + buttonsLeftWidth()), titleEdgeBottomBottom - (r_y + titleEdgeTop));
QRect tempRect;
// topSpacer
if(titleEdgeTop > 0)
{
tempRect.setRect(r_x + 2, r_y, r_w - 2 * 2, titleEdgeTop);
if(tempRect.isValid() && region.contains(tempRect))
{
painter.drawTiledPixmap(tempRect, handler->pixmap(TitleBarTileTop, active, toolWindow));
}
}
// leftTitleSpacer
int titleMarginLeft = 0;
int titleMarginRight = 0;
if(titleEdgeLeft > 0)
{
tempRect.setRect(r_x, r_y, borderLeft, titleEdgeTop + titleHeight + titleEdgeBottom);
if(tempRect.isValid() && region.contains(tempRect))
{
painter.drawTiledPixmap(tempRect, handler->pixmap(TitleBarLeft, active, toolWindow));
titleMarginLeft = borderLeft;
}
}
// rightTitleSpacer
if(titleEdgeRight > 0)
{
tempRect.setRect(borderRightLeft, r_y, borderRight, titleEdgeTop + titleHeight + titleEdgeBottom);
if(tempRect.isValid() && region.contains(tempRect))
{
painter.drawTiledPixmap(tempRect, handler->pixmap(TitleBarRight, active, toolWindow));
titleMarginRight = borderRight;
}
}
// titleSpacer
const QPixmap &caption = captionPixmap();
if(Rtitle.width() > 0)
{
m_captionRect = captionRect(); // also update m_captionRect!
if(m_captionRect.isValid() && region.contains(m_captionRect))
{
painter.drawTiledPixmap(m_captionRect, caption);
}
// left to the title
tempRect.setRect(r_x + titleMarginLeft, m_captionRect.top(), m_captionRect.left() - (r_x + titleMarginLeft), m_captionRect.height());
if(tempRect.isValid() && region.contains(tempRect))
{
painter.drawTiledPixmap(tempRect, handler->pixmap(TitleBarTile, active, toolWindow));
}
// right to the title
tempRect.setRect(m_captionRect.right() + 1, m_captionRect.top(), (r_x2 - titleMarginRight) - m_captionRect.right(), m_captionRect.height());
if(tempRect.isValid() && region.contains(tempRect))
{
painter.drawTiledPixmap(tempRect, handler->pixmap(TitleBarTile, active, toolWindow));
}
//.........这里部分代码省略.........
示例4: drawControl
void MetalStyle::drawControl( ControlElement element,
QPainter *p,
const QWidget *widget,
const QRect &r,
const QColorGroup &cg,
SFlags how,
const QStyleOption& opt ) const
{
switch( element ) {
case CE_PushButton:
{
const QPushButton *btn;
btn = (const QPushButton*)widget;
int x1, y1, x2, y2;
r.coords( &x1, &y1, &x2, &y2 );
p->setPen( cg.foreground() );
p->setBrush( QBrush(cg.button(), NoBrush) );
QBrush fill;
if ( btn->isDown() )
fill = cg.brush( QColorGroup::Mid );
else if ( btn->isOn() )
fill = QBrush( cg.mid(), Dense4Pattern );
else
fill = cg.brush( QColorGroup::Button );
if ( btn->isDefault() ) {
QPointArray a;
a.setPoints( 9,
x1, y1, x2, y1, x2, y2, x1, y2, x1, y1+1,
x2-1, y1+1, x2-1, y2-1, x1+1, y2-1, x1+1, y1+1 );
p->setPen( Qt::black );
p->drawPolyline( a );
x1 += 2;
y1 += 2;
x2 -= 2;
y2 -= 2;
}
SFlags flags = Style_Default;
if ( btn->isOn() )
flags |= Style_On;
if ( btn->isDown() )
flags |= Style_Down;
if ( !btn->isFlat() && !btn->isDown() )
flags |= Style_Raised;
drawPrimitive( PE_ButtonCommand, p,
QRect( x1, y1, x2 - x1 + 1, y2 - y1 + 1),
cg, flags, opt );
if ( btn->isMenuButton() ) {
flags = Style_Default;
if ( btn->isEnabled() )
flags |= Style_Enabled;
int dx = ( y1 - y2 - 4 ) / 3;
drawPrimitive( PE_ArrowDown, p,
QRect(x2 - dx, dx, y1, y2 - y1),
cg, flags, opt );
}
if ( p->brush().style() != NoBrush )
p->setBrush( NoBrush );
break;
}
case CE_PushButtonLabel:
{
const QPushButton *btn;
btn = (const QPushButton*)widget;
int x, y, w, h;
r.rect( &x, &y, &w, &h );
int x1, y1, x2, y2;
r.coords( &x1, &y1, &x2, &y2 );
int dx = 0;
int dy = 0;
if ( btn->isMenuButton() )
dx = ( y2 - y1 ) / 3;
if ( btn->isOn() || btn->isDown() ) {
dx--;
dy--;
}
if ( dx || dy )
p->translate( dx, dy );
x += 2;
y += 2;
w -= 4;
h -= 4;
drawItem( p, QRect( x, y, w, h ),
AlignCenter|ShowPrefix,
cg, btn->isEnabled(),
btn->pixmap(), btn->text(), -1,
(btn->isDown() || btn->isOn())? &cg.brightText() : &cg.buttonText() );
if ( dx || dy )
p->translate( -dx, -dy );
break;
}
default:
QWindowsStyle::drawControl( element, p, widget, r, cg, how, opt );
//.........这里部分代码省略.........
示例5: mousePosition
KCommonDecoration::Position KCommonDecoration::mousePosition(const QPoint &point) const
{
const int corner = 18+3*layoutMetric(LM_BorderBottom, false)/2;
Position pos = PositionCenter;
QRect r = widget()->rect();
int r_x, r_y, r_x2, r_y2;
r.coords(&r_x, &r_y, &r_x2, &r_y2);
int p_x = point.x();
int p_y = point.y();
const int borderLeft = layoutMetric(LM_BorderLeft);
// const int borderRight = layoutMetric(LM_BorderRight);
const int borderBottom = layoutMetric(LM_BorderBottom);
const int titleHeight = layoutMetric(LM_TitleHeight);
const int titleEdgeTop = layoutMetric(LM_TitleEdgeTop);
const int titleEdgeBottom = layoutMetric(LM_TitleEdgeBottom);
const int titleEdgeLeft = layoutMetric(LM_TitleEdgeLeft);
const int titleEdgeRight = layoutMetric(LM_TitleEdgeRight);
const int borderBottomTop = r_y2-borderBottom+1;
const int borderLeftRight = r_x+borderLeft-1;
// const int borderRightLeft = r_x2-borderRight+1;
const int titleEdgeLeftRight = r_x+titleEdgeLeft-1;
const int titleEdgeRightLeft = r_x2-titleEdgeRight+1;
const int titleEdgeBottomBottom = r_y+titleEdgeTop+titleHeight+titleEdgeBottom-1;
const int titleEdgeTopBottom = r_y+titleEdgeTop-1;
if (p_y <= titleEdgeTopBottom) {
if (p_x <= r_x+corner)
pos = PositionTopLeft;
else if (p_x >= r_x2-corner)
pos = PositionTopRight;
else
pos = PositionTop;
} else if (p_y <= titleEdgeBottomBottom) {
if (p_x <= titleEdgeLeftRight)
pos = PositionTopLeft;
else if (p_x >= titleEdgeRightLeft)
pos = PositionTopRight;
else
pos = PositionCenter; // title bar
} else if (p_y < borderBottomTop) {
if (p_y < r_y2-corner) {
if (p_x <= borderLeftRight)
pos = PositionLeft;
else
pos = PositionRight;
} else {
if (p_x <= borderLeftRight)
pos = PositionBottomLeft;
else
pos = PositionBottomRight;
}
} else if(p_y >= borderBottomTop) {
if (p_x <= r_x+corner)
pos = PositionBottomLeft;
else if (p_x >= r_x2-corner)
pos = PositionBottomRight;
else
pos = PositionBottom;
}
return pos;
}
示例6: updateLayout
void KCommonDecoration::updateLayout() const
{
QRect r = widget()->rect();
int r_x, r_y, r_x2, r_y2;
r.coords(&r_x, &r_y, &r_x2, &r_y2);
// layout preview widget
if (m_previewWidget) {
const int borderLeft = layoutMetric(LM_BorderLeft);
const int borderRight = layoutMetric(LM_BorderRight);
const int borderBottom = layoutMetric(LM_BorderBottom);
const int titleHeight = layoutMetric(LM_TitleHeight);
const int titleEdgeTop = layoutMetric(LM_TitleEdgeTop);
const int titleEdgeBottom = layoutMetric(LM_TitleEdgeBottom);
int left = r_x+borderLeft;
int top = r_y+titleEdgeTop+titleHeight+titleEdgeBottom;
int width = r_x2-borderRight-left+1;
int height = r_y2-borderBottom-top+1;
m_previewWidget->setGeometry(left, top, width, height);
moveWidget(left,top, m_previewWidget);
resizeWidget(width, height, m_previewWidget);
}
// resize buttons...
for (int n=0; n<NumButtons; n++) {
if (m_button[n]) {
QSize newSize = QSize(layoutMetric(LM_ButtonWidth, true, m_button[n]),
layoutMetric(LM_ButtonHeight, true, m_button[n]) );
if (newSize != m_button[n]->size() )
m_button[n]->setSize(newSize);
}
}
// layout buttons
int y = r_y + layoutMetric(LM_TitleEdgeTop) + layoutMetric(LM_ButtonMarginTop);
if (m_buttonsLeft.count() > 0) {
const int buttonSpacing = layoutMetric(LM_ButtonSpacing);
int x = r_x + layoutMetric(LM_TitleEdgeLeft);
for (ButtonContainer::const_iterator it = m_buttonsLeft.begin(); it != m_buttonsLeft.end(); ++it) {
bool elementLayouted = false;
if (*it) {
if (!(*it)->isHidden() ) {
moveWidget(x,y, *it);
x += layoutMetric(LM_ButtonWidth, true, ::qt_cast<KCommonDecorationButton*>(*it) );
elementLayouted = true;
}
} else {
x+= layoutMetric(LM_ExplicitButtonSpacer);
elementLayouted = true;
}
if (elementLayouted && it != m_buttonsLeft.end() )
x += buttonSpacing;
}
}
if (m_buttonsRight.count() > 0) {
const int titleEdgeRightLeft = r_x2-layoutMetric(LM_TitleEdgeRight)+1;
const int buttonSpacing = layoutMetric(LM_ButtonSpacing);
int x = titleEdgeRightLeft - buttonContainerWidth(m_buttonsRight);
for (ButtonContainer::const_iterator it = m_buttonsRight.begin(); it != m_buttonsRight.end(); ++it) {
bool elementLayouted = false;
if (*it) {
if (!(*it)->isHidden() ) {
moveWidget(x,y, *it);
x += layoutMetric(LM_ButtonWidth, true, ::qt_cast<KCommonDecorationButton*>(*it) );;
elementLayouted = true;
}
} else {
x += layoutMetric(LM_ExplicitButtonSpacer);
elementLayouted = true;
}
if (elementLayouted && it != m_buttonsRight.end() )
x += buttonSpacing;
}
}
}
示例7: drawControl
/*!\reimp
*/
void QPlatinumStyle::drawControl( ControlElement element,
QPainter *p,
const QWidget *widget,
const QRect &r,
const QColorGroup &cg,
SFlags how,
const QStyleOption& opt ) const
{
switch( element ) {
case CE_PushButton:
{
#ifndef QT_NO_PUSHBUTTON
QColorGroup myCg( cg );
const QPushButton *btn;
int x1, y1, x2, y2;
bool useBevelButton;
SFlags flags;
flags = Style_Default;
btn = (const QPushButton*)widget;
p->setBrushOrigin( -widget->backgroundOffset().x(),
-widget->backgroundOffset().y() );
// take care of the flags based on what we know...
if ( btn->isDown() )
flags |= Style_Down;
if ( btn->isOn() )
flags |= Style_On;
if ( btn->isEnabled() )
flags |= Style_Enabled;
if ( btn->isDefault() )
flags |= Style_Default;
if (! btn->isFlat() && !(flags & Style_Down))
flags |= Style_Raised;
r.coords( &x1, &y1, &x2, &y2 );
p->setPen( cg.foreground() );
p->setBrush( QBrush(cg.button(), NoBrush) );
QBrush fill;
if ( btn->isDown() ) {
fill = cg.brush( QColorGroup::Dark );
// this could be done differently, but this
// makes a down Bezel drawn correctly...
myCg.setBrush( QColorGroup::Mid, fill );
} else if ( btn->isOn() ) {
fill = QBrush( cg.mid(), Dense4Pattern );
myCg.setBrush( QColorGroup::Mid, fill );
}
// to quote the old QPlatinumStlye drawPushButton...
// small or square image buttons as well as toggle buttons are
// bevel buttons (what a heuristic....)
if ( btn->isToggleButton()
|| ( btn->pixmap() &&
(btn->width() * btn->height() < 1600 ||
QABS( btn->width() - btn->height()) < 10 )) )
useBevelButton = TRUE;
else
useBevelButton = FALSE;
int diw = pixelMetric( PM_ButtonDefaultIndicator, widget );
if ( btn->isDefault() ) {
x1 += 1;
y1 += 1;
x2 -= 1;
y2 -= 1;
QColorGroup cg2( myCg );
SFlags myFlags = flags;
// don't draw the default button sunken, unless it's necessary.
if ( myFlags & Style_Down )
myFlags ^= Style_Down;
if ( myFlags & Style_Sunken )
myFlags ^= Style_Sunken;
cg2.setColor( QColorGroup::Button, cg.mid() );
if ( useBevelButton ) {
drawPrimitive( PE_ButtonBevel, p, QRect( x1, y1,
x2 - x1 + 1,
y2 - y1 + 1 ),
myCg, myFlags, opt );
} else {
drawPrimitive( PE_ButtonCommand, p, QRect( x1, y1,
x2 - x1 + 1,
y2 - y1 + 1 ),
cg2, myFlags, opt );
}
}
if ( btn->isDefault() || btn->autoDefault() ) {
x1 += diw;
y1 += diw;
x2 -= diw;
y2 -= diw;
}
if ( !btn->isFlat() || btn->isOn() || btn->isDown() ) {
if ( useBevelButton ) {
// fix for toggle buttons...
//.........这里部分代码省略.........