本文整理汇总了C++中QRect::center方法的典型用法代码示例。如果您正苦于以下问题:C++ QRect::center方法的具体用法?C++ QRect::center怎么用?C++ QRect::center使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QRect
的用法示例。
在下文中一共展示了QRect::center方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: drawButtonLabel
/*!
\brief Draw the button label
\param painter Painter
\sa The Qt Manual on QPushButton
*/
void QwtArrowButton::drawButtonLabel(QPainter *painter)
{
const bool isVertical = d_data->arrowType == Qt::UpArrow ||
d_data->arrowType == Qt::DownArrow;
const QRect r = labelRect();
QSize boundingSize = labelRect().size();
if ( isVertical )
boundingSize.transpose();
const int w =
(boundingSize.width() - (MaxNum - 1) * Spacing) / MaxNum;
QSize arrow = arrowSize(Qt::RightArrow,
QSize(w, boundingSize.height()));
if ( isVertical )
arrow.transpose();
QRect contentsSize; // aligned rect where to paint all arrows
if ( d_data->arrowType == Qt::LeftArrow || d_data->arrowType == Qt::RightArrow ) {
contentsSize.setWidth(d_data->num * arrow.width()
+ (d_data->num - 1) * Spacing);
contentsSize.setHeight(arrow.height());
} else {
contentsSize.setWidth(arrow.width());
contentsSize.setHeight(d_data->num * arrow.height()
+ (d_data->num - 1) * Spacing);
}
QRect arrowRect(contentsSize);
arrowRect.moveCenter(r.center());
arrowRect.setSize(arrow);
painter->save();
for (int i = 0; i < d_data->num; i++) {
drawArrow(painter, arrowRect, d_data->arrowType);
int dx = 0;
int dy = 0;
if ( isVertical )
dy = arrow.height() + Spacing;
else
dx = arrow.width() + Spacing;
#if QT_VERSION >= 0x040000
arrowRect.translate(dx, dy);
#else
arrowRect.moveBy(dx, dy);
#endif
}
painter->restore();
if ( hasFocus() ) {
#if QT_VERSION >= 0x040000
QStyleOptionFocusRect option;
option.init(this);
option.backgroundColor = palette().color(QPalette::Background);
style()->drawPrimitive(QStyle::PE_FrameFocusRect,
&option, painter, this);
#else
const QRect focusRect =
style().subRect(QStyle::SR_PushButtonFocusRect, this);
style().drawPrimitive(QStyle::PE_FocusRect, painter,
focusRect, colorGroup());
#endif
}
}
示例2: mouseReleaseEvent
void DisplayWidget::mouseReleaseEvent(QMouseEvent *event)
{
QVariant v;
v.setValue(selectedTile);
switch(currentTool)
{
case t_pen:
{
model()->setData(this->indexAt(event->pos()), v);
break;
}
case t_box:
case t_hollow_box:
case t_circle:
case t_hollow_circle:
{
rubberBand->hide();
int headerHeight = this->horizontalHeader()->height();
int headerWidth = this->verticalHeader()->width();
// rubber band draws based on the displays 0,0 as origin
// indexes use inside corner of the headers as 0,0
//
// v-- this is 0,0 for rubber band
// []=================
// ||+<-- this is 0,0 for table fields
// ||
QRect selection = rubberBand->geometry().adjusted(-headerWidth, -headerHeight, -headerWidth, -headerHeight);
QModelIndex center = this->indexAt(selection.center());
QModelIndex topLeft = this->indexAt(selection.topLeft());
QModelIndex bottomRight = this->indexAt(selection.bottomRight());
// determine selections
if(currentTool == t_box)
{
for(int i = topLeft.column(); i <= bottomRight.column(); i++)
{
for(int j = topLeft.row(); j <= bottomRight.row(); j++)
{
model()->setData(model()->index(j, i), v);
}
}
}
else if(currentTool == t_hollow_box)
{
for(int i = topLeft.column(); i <= bottomRight.column(); i++)
{
model()->setData(model()->index(topLeft.row(), i), v);
model()->setData(model()->index(bottomRight.row(), i), v);
}
for(int i = topLeft.row(); i <= bottomRight.row(); i++)
{
model()->setData(model()->index(i, topLeft.column()), v);
model()->setData(model()->index(i, bottomRight.column()), v);
}
}
// currently suffer w/even diameters, index at center does not necessarily correlate to
// center of the actual circle. adjust to use diameter / 2 for calculations.
else if(currentTool == t_circle)
{
// x-radius
double a = bottomRight.column() - center.column();
// y-radius
double b = topLeft.row() - center.row();
// (x-h)^2/a^2 + (y-k)^2/b^2 <= 1
for(int i = topLeft.column(); i <= bottomRight.column(); i++)
{
for(int j = topLeft.row(); j <= bottomRight.row(); j++)
{
double topx = i - center.column();
double topy = j - center.row();
if(
(((topx * topx) / (a * a)) + ((topy * topy) / (b * b))) <= 1.0
)
{
model()->setData(model()->index(j, i), v);
}
}
}
}
else if(currentTool == t_hollow_circle)
{
// x(t) = (right - center) * cos(t) = a * cos(t)
// y(t) = (top - center) * sin(t) = b * sin(t)
int a = bottomRight.column() - center.column();
int b = topLeft.row() - center.row();
for(double d = 0.0; d <= 2 * M_PI; d+=(M_PI / 100))
{
int x = center.column() + qRound(a * cos(d));
int y = center.row() + qRound(b * sin(d));
model()->setData(model()->index(y, x), v);
}
}
break;
}
//.........这里部分代码省略.........
示例3: paint
void PlListViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
QString title = VLCModel::getMeta( index, COLUMN_TITLE );
QString duration = VLCModel::getMeta( index, COLUMN_DURATION );
if( !duration.isEmpty() ) title += QString(" [%1]").arg( duration );
QString artist = VLCModel::getMeta( index, COLUMN_ARTIST );
QString album = VLCModel::getMeta( index, COLUMN_ALBUM );
QString trackNum = VLCModel::getMeta( index, COLUMN_TRACK_NUMBER );
QString artistAlbum = artist;
if( !album.isEmpty() )
{
if( !artist.isEmpty() ) artistAlbum += ": ";
artistAlbum += album;
if( !trackNum.isEmpty() ) artistAlbum += QString( " [#%1]" ).arg( trackNum );
}
QPixmap artPix = VLCModel::getArtPixmap( index, QSize( LISTVIEW_ART_SIZE, LISTVIEW_ART_SIZE ) );
//Draw selection rectangle and current playing item indication
paintBackground( painter, option, index );
QRect artRect( artPix.rect() );
artRect.moveCenter( QPoint( artRect.center().x() + 3,
option.rect.center().y() ) );
//Draw album art
painter->drawPixmap( artRect, artPix );
//Start drawing text
painter->save();
if( option.state & QStyle::State_Selected )
painter->setPen( option.palette.color( QPalette::HighlightedText ) );
QTextOption textOpt( Qt::AlignVCenter | Qt::AlignLeft );
textOpt.setWrapMode( QTextOption::NoWrap );
QFont f( index.data( Qt::FontRole ).value<QFont>() );
//Draw title info
f.setItalic( true );
f.setPointSize( __MAX( f.pointSize() + i_zoom, 4 ) );
f.setBold( index.data( PLModel::IsCurrentRole ).toBool() );
painter->setFont( f );
QFontMetrics fm( painter->fontMetrics() );
QRect textRect = option.rect.adjusted( LISTVIEW_ART_SIZE + 10, 0, -10, 0 );
if( !artistAlbum.isEmpty() )
{
textRect.setHeight( fm.height() );
textRect.moveBottom( option.rect.center().y() - 2 );
}
//Draw children indicator
if( !index.data( PLModel::IsLeafNodeRole ).toBool() )
{
QPixmap dirPix = QPixmap( ":/type/node" );
painter->drawPixmap( QPoint( textRect.x(), textRect.center().y() - dirPix.height() / 2 ),
dirPix );
textRect.setLeft( textRect.x() + dirPix.width() + 5 );
}
painter->drawText( textRect,
fm.elidedText( title, Qt::ElideRight, textRect.width() ),
textOpt );
// Draw artist and album info
if( !artistAlbum.isEmpty() )
{
f.setItalic( false );
painter->setFont( f );
fm = painter->fontMetrics();
textRect.moveTop( textRect.bottom() + 4 );
textRect.setLeft( textRect.x() + 20 );
painter->drawText( textRect,
fm.elidedText( artistAlbum, Qt::ElideRight, textRect.width() ),
textOpt );
}
painter->restore();
}
示例4: setupShapes
//! [3]
void Window::setupShapes()
{
QPainterPath truck;
//! [3]
truck.setFillRule(Qt::WindingFill);
truck.moveTo(0.0, 87.0);
truck.lineTo(0.0, 60.0);
truck.lineTo(10.0, 60.0);
truck.lineTo(35.0, 35.0);
truck.lineTo(100.0, 35.0);
truck.lineTo(100.0, 87.0);
truck.lineTo(0.0, 87.0);
truck.moveTo(17.0, 60.0);
truck.lineTo(55.0, 60.0);
truck.lineTo(55.0, 40.0);
truck.lineTo(37.0, 40.0);
truck.lineTo(17.0, 60.0);
truck.addEllipse(17.0, 75.0, 25.0, 25.0);
truck.addEllipse(63.0, 75.0, 25.0, 25.0);
//! [4]
QPainterPath clock;
//! [4]
clock.addEllipse(-50.0, -50.0, 100.0, 100.0);
clock.addEllipse(-48.0, -48.0, 96.0, 96.0);
clock.moveTo(0.0, 0.0);
clock.lineTo(-2.0, -2.0);
clock.lineTo(0.0, -42.0);
clock.lineTo(2.0, -2.0);
clock.lineTo(0.0, 0.0);
clock.moveTo(0.0, 0.0);
clock.lineTo(2.732, -0.732);
clock.lineTo(24.495, 14.142);
clock.lineTo(0.732, 2.732);
clock.lineTo(0.0, 0.0);
//! [5]
QPainterPath house;
//! [5]
house.moveTo(-45.0, -20.0);
house.lineTo(0.0, -45.0);
house.lineTo(45.0, -20.0);
house.lineTo(45.0, 45.0);
house.lineTo(-45.0, 45.0);
house.lineTo(-45.0, -20.0);
house.addRect(15.0, 5.0, 20.0, 35.0);
house.addRect(-35.0, -15.0, 25.0, 25.0);
//! [6]
QPainterPath text;
//! [6]
QFont font;
font.setPixelSize(50);
QRect fontBoundingRect = QFontMetrics(font).boundingRect(tr("Qt"));
text.addText(-QPointF(fontBoundingRect.center()), font, tr("Qt"));
//! [7]
shapes.append(clock);
shapes.append(house);
shapes.append(text);
shapes.append(truck);
connect(shapeComboBox, SIGNAL(activated(int)),
this, SLOT(shapeSelected(int)));
}
示例5: centerOnScreen
void QQuickViewTestUtil::centerOnScreen(QQuickView *window, const QSize &size)
{
const QRect screenGeometry = window->screen()->availableGeometry();
const QPoint offset = QPoint(size.width() / 2, size.height() / 2);
window->setFramePosition(screenGeometry.center() - offset);
}
示例6: ProcessMoonPixmap
void tSunMoonDialog::ProcessMoonPixmap( QPixmap& moonPixmap )
{
if( m_MoonData.Phase < 0.99 )
{
QRect r = moonPixmap.rect();
qreal diameter = r.width() * 0.744;
QRectF rF( r.center().x() - 0.5 - diameter / 2,
r.center().y() + 1 - diameter / 2,
diameter, diameter );
QPainterPath darkMoonPath;
if( m_MoonData.Phase > 0.01 )
{
QPainterPath halfMoonPath;
halfMoonPath.moveTo( rF.left() + rF.width() / 2, rF.top() + rF.height() );
qreal sweep = 180;
if( m_MoonData.Waxing )
{
sweep *= -1;
}
halfMoonPath.arcTo( rF.left(), rF.top(), diameter, diameter, 90, sweep );
halfMoonPath.lineTo( rF.left() + rF.width() / 2, rF.top() );
QPainterPath cresentMoonPath;
cresentMoonPath.addEllipse( rF.center(), diameter * cos( m_MoonData.Phase * M_PI ) / 2, diameter / 2 );
if( m_MoonData.Phase < 0.5 )
{
darkMoonPath = halfMoonPath.united( cresentMoonPath );
}
else
{
darkMoonPath = halfMoonPath.subtracted( cresentMoonPath );
}
}
else
{
darkMoonPath.addEllipse( rF.center(), diameter / 2, diameter / 2 );
}
QPainter painter( &moonPixmap );
painter.setRenderHint( QPainter::Antialiasing );
painter.setPen( Qt::NoPen );
QColor c( 0, 0, 0, 170 );
painter.setBrush( QBrush( c ) );
painter.drawPath( darkMoonPath );
painter.end();
}
// invert the image if in northern hemisphere
if( m_Position.Y() >= 0 )
{
QPixmap tempPixmap( moonPixmap );
moonPixmap.fill( QColor( 0, 0, 0, 0 ) );
QPainter painter( &moonPixmap );
painter.rotate( 180 );
painter.drawPixmap( QPoint( -moonPixmap.width(), -moonPixmap.height() ), tempPixmap );
painter.end();
}
}
示例7: drawIconWithShadow
// Draws a cached pixmap with shadow
void StyleHelper::drawIconWithShadow(const QIcon &icon, const QRect &rect,
QPainter* p, QIcon::Mode iconMode, int radius, const QColor &color, const QPoint &offset)
{
QPixmap cache;
QString pixmapName = QString("icon %0 %1 %2").arg(icon.cacheKey()).arg(iconMode).arg(rect.height());
if (!QPixmapCache::find(pixmapName, cache)) {
QPixmap px = icon.pixmap(rect.size());
cache = QPixmap(px.size() + QSize(radius * 2, radius * 2));
cache.fill(Qt::transparent);
QPainter cachePainter(&cache);
if (iconMode == QIcon::Disabled) {
QImage im = px.toImage().convertToFormat(QImage::Format_ARGB32);
for (int y = 0; y < im.height(); ++y) {
QRgb* scanLine = (QRgb*)im.scanLine(y);
for (int x = 0; x < im.width(); ++x) {
QRgb pixel = *scanLine;
char intensity = qGray(pixel);
*scanLine = qRgba(intensity, intensity, intensity, qAlpha(pixel));
++scanLine;
}
}
px = QPixmap::fromImage(im);
}
// Draw shadow
QImage tmp(px.size() + QSize(radius * 2, radius * 2 + 1), QImage::Format_ARGB32_Premultiplied);
tmp.fill(Qt::transparent);
QPainter tmpPainter(&tmp);
tmpPainter.setCompositionMode(QPainter::CompositionMode_Source);
tmpPainter.drawPixmap(QPoint(radius, radius), px);
tmpPainter.end();
// blur the alpha channel
QImage blurred(tmp.size(), QImage::Format_ARGB32_Premultiplied);
blurred.fill(Qt::transparent);
QPainter blurPainter(&blurred);
qt_blurImage(&blurPainter, tmp, radius, false, true);
blurPainter.end();
tmp = blurred;
// blacken the image...
tmpPainter.begin(&tmp);
tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
tmpPainter.fillRect(tmp.rect(), color);
tmpPainter.end();
tmpPainter.begin(&tmp);
tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
tmpPainter.fillRect(tmp.rect(), color);
tmpPainter.end();
// draw the blurred drop shadow...
cachePainter.drawImage(QRect(0, 0, cache.rect().width(), cache.rect().height()), tmp);
// Draw the actual pixmap...
cachePainter.drawPixmap(QPoint(radius, radius) + offset, px);
QPixmapCache::insert(pixmapName, cache);
}
QRect targetRect = cache.rect();
targetRect.moveCenter(rect.center());
p->drawPixmap(targetRect.topLeft() - offset, cache);
}
示例8: QWidget
//.........这里部分代码省略.........
layout7 = new QHBoxLayout( 0, 0, 6, "layout7");
frame6 = new QFrame( this, "frame6" );
frame6->setPaletteForegroundColor( QColor( 0, 124, 206 ) );
frame6->setFrameShape( QFrame::Box );
frame6->setFrameShadow( QFrame::Plain );
frame6Layout = new QGridLayout( frame6, 1, 1, 1, 0, "frame6Layout");
lvGroups = new QListView( frame6, "lvGroups" );
lvGroups->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)7, 0, 0, lvGroups->sizePolicy().hasHeightForWidth() ) );
lvGroups->setMinimumSize( QSize( 100, 0 ) );
lvGroups->setMaximumSize( QSize( 250, 32767 ) );
lvGroups->setFrameShape( QListView::NoFrame );
lvGroups->setFrameShadow( QListView::Plain );
lvGroups->setLineWidth( 1 );
lvGroups->setHScrollBarMode( QListView::AlwaysOff );
lvGroups->setSorting( -1 ); // don't sort
frame6Layout->addWidget( lvGroups, 0, 0 );
layout7->addWidget( frame6 );
frmMain = new QFrame( this, "frmMain" );
frmMain->setPaletteForegroundColor( QColor( 0, 124, 206 ) );
frmMain->setPaletteBackgroundColor( QColor( 255, 255, 255 ) );
frmMain->setFrameShape( QFrame::Box );
frmMain->setFrameShadow( QFrame::Plain );
frmMainLayout = new QGridLayout( frmMain, 1, 1, 11, 6, "frmMainLayout");
layout6 = new QHBoxLayout( 0, 0, 6, "layout6");
tblFaceList = new QTable( frmMain, "tblFaceList" );
tblFaceList->setNumCols( tblFaceList->numCols() + 1 );
tblFaceList->horizontalHeader()->setLabel( tblFaceList->numCols() - 1, i18n("No." ) );
tblFaceList->setNumCols( tblFaceList->numCols() + 1 );
tblFaceList->horizontalHeader()->setLabel( tblFaceList->numCols() - 1, i18n("Smiley" ) );
tblFaceList->setNumCols( tblFaceList->numCols() + 1 );
tblFaceList->horizontalHeader()->setLabel( tblFaceList->numCols() - 1, i18n("Shortcut" ) );
tblFaceList->setFrameShape( QTable::GroupBoxPanel );
tblFaceList->setFrameShadow( QTable::Plain );
tblFaceList->setHScrollBarMode( QTable::AlwaysOff );
tblFaceList->setNumRows( 0 );
tblFaceList->setNumCols( 3 );
tblFaceList->setSelectionMode( QTable::MultiRow );
tblFaceList->setFocusStyle( QTable::FollowStyle );
layout6->addWidget( tblFaceList );
layout5 = new QVBoxLayout( 0, 0, 6, "layout5");
btnAdd = new QPushButton( frmMain, "btnAdd" );
layout5->addWidget( btnAdd );
btnRemove = new QPushButton( frmMain, "btnRemove" );
layout5->addWidget( btnRemove );
btnEdit = new QPushButton( frmMain, "btnEdit" );
layout5->addWidget( btnEdit );
btnUp = new QPushButton( frmMain, "btnUp" );
layout5->addWidget( btnUp );
btnDown = new QPushButton( frmMain, "btnDown" );
layout5->addWidget( btnDown );
btnMoveTo = new QPushButton( frmMain, "btnMoveTo" );
layout5->addWidget( btnMoveTo );
spacer1 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
layout5->addItem( spacer1 );
lblPreview = new QLabel( frmMain, "lblPreview" );
lblPreview->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, lblPreview->sizePolicy().hasHeightForWidth() ) );
lblPreview->setMinimumSize( QSize( 100, 85 ) );
lblPreview->setMaximumSize( QSize( 100, 85 ) );
lblPreview->setPaletteForegroundColor( QColor( 0, 124, 206 ) );
lblPreview->setFrameShape( QLabel::Box );
layout5->addWidget( lblPreview );
layout6->addLayout( layout5 );
frmMainLayout->addLayout( layout6, 0, 0 );
layout7->addWidget( frmMain );
layout9->addLayout( layout7 );
layout8 = new QHBoxLayout( 0, 0, 6, "layout8");
spacer2 = new QSpacerItem( 91, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
layout8->addItem( spacer2 );
btnOK = new QPushButton( this, "btnOK" );
layout8->addWidget( btnOK );
btnCancel = new QPushButton( this, "btnCancel" );
layout8->addWidget( btnCancel );
layout9->addLayout( layout8 );
CustomFaceManagerUILayout->addLayout( layout9, 0, 0 );
languageChange();
resize( QSize(521, 382).expandedTo(minimumSizeHint()) );
clearWState( WState_Polished );
QRect scr = KApplication::desktop()->screenGeometry();
move(scr.center()-rect().center());
}
示例9: QDialog
QtTreesearcherMainDialog::QtTreesearcherMainDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::QtTreesearcherMainDialog),
m_bd_likelihood_widget{new QtBirthDeathModelLikelihoodWidget},
m_bd_max_likelihood_widget{new QtBirthDeathModelMaxLikelihoodWidget},
m_bd_parameters_widget{new QtBirthDeathModelParametersWidget},
m_ltt_image{new QLabel},
m_phylogeny{},
m_tree_image{new QLabel}
{
ui->setupUi(this);
{
assert(!this->ui->widget_center->layout());
QHBoxLayout * const my_layout{new QHBoxLayout};
ui->widget_center->setLayout(my_layout);
my_layout->addWidget(m_ltt_image);
my_layout->addWidget(m_tree_image);
assert(this->ui->widget_center->layout());
}
{
assert(!ui->page_parameters_bd->layout());
QGridLayout * const my_layout{new QGridLayout};
ui->page_parameters_bd->setLayout(my_layout);
my_layout->addWidget(m_bd_parameters_widget);
assert(ui->page_parameters_bd->layout());
}
//BD analyse
{
assert(!ui->page_analyse_bd->layout());
QVBoxLayout * const my_layout{new QVBoxLayout};
ui->page_analyse_bd->setLayout(my_layout);
assert(ui->page_analyse_bd->layout());
my_layout->addWidget(new QLabel("Likelihood"));
my_layout->addWidget(m_bd_likelihood_widget);
my_layout->addWidget(new QLabel("Max likelihood"));
my_layout->addWidget(m_bd_max_likelihood_widget);
}
QObject::connect(m_bd_parameters_widget,SIGNAL(signal_parameters_changed()),this,SLOT(OnBirthDeathParametersChanged()));
//Parse some libraries
{
auto& r = ribi::Rinside().Get();
r.parseEvalQ("library(ape)");
r.parseEvalQ("library(geiger)");
}
//Center on screen
{
//Put the dialog in the screen center
const QRect screen = QApplication::desktop()->screenGeometry();
this->setGeometry(0,0,screen.width() * 9 / 10,screen.height() * 9 / 10);
this->move( screen.center() - this->rect().center() );
}
OnBirthDeathParametersChanged();
}
示例10: paintEvent
void RegionGrabber::paintEvent( QPaintEvent* e )
{
Q_UNUSED( e );
if ( grabbing ) // grabWindow() should just get the background
return;
QPainter painter( this );
QPalette pal(QToolTip::palette());
QFont font = QToolTip::font();
QColor handleColor = pal.color( QPalette::Active, QPalette::Highlight );
handleColor.setAlpha( 160 );
QColor overlayColor( 0, 0, 0, 160 );
QColor textColor = pal.color( QPalette::Active, QPalette::Text );
QColor textBackgroundColor = pal.color( QPalette::Active, QPalette::Base );
painter.drawPixmap(0, 0, pixmap);
painter.setFont(font);
QRect r = selection;
if ( !selection.isNull() )
{
QRegion grey( rect() );
grey = grey.subtracted( r );
painter.setClipRegion( grey );
painter.setPen( Qt::NoPen );
painter.setBrush( overlayColor );
painter.drawRect( rect() );
painter.setClipRect( rect() );
drawRect( &painter, r, handleColor );
}
if ( showHelp )
{
painter.setPen( textColor );
painter.setBrush( textBackgroundColor );
QString helpText = "Select a region using the mouse. To take the snapshot, press the Enter key or double click. Press Esc to quit.";
helpTextRect = painter.boundingRect( rect().adjusted( 2, 2, -2, -2 ), Qt::TextWordWrap, helpText );
helpTextRect.adjust( -2, -2, 4, 2 );
drawRect( &painter, helpTextRect, textColor, textBackgroundColor );
painter.drawText( helpTextRect.adjusted( 3, 3, -3, -3 ), helpText );
}
if ( selection.isNull() )
{
return;
}
// The grabbed region is everything which is covered by the drawn
// rectangles (border included). This means that there is no 0px
// selection, since a 0px wide rectangle will always be drawn as a line.
QString txt = QString( "%1x%2" ).arg( selection.width() )
.arg( selection.height() );
QRect textRect = painter.boundingRect( rect(), Qt::AlignLeft, txt );
QRect boundingRect = textRect.adjusted( -4, 0, 0, 0);
if ( textRect.width() < r.width() - 2*handleSize &&
textRect.height() < r.height() - 2*handleSize &&
( r.width() > 100 && r.height() > 100 ) ) // center, unsuitable for small selections
{
boundingRect.moveCenter( r.center() );
textRect.moveCenter( r.center() );
}
else if ( r.y() - 3 > textRect.height() &&
r.x() + textRect.width() < rect().right() ) // on top, left aligned
{
boundingRect.moveBottomLeft( QPoint( r.x(), r.y() - 3 ) );
textRect.moveBottomLeft( QPoint( r.x() + 2, r.y() - 3 ) );
}
else if ( r.x() - 3 > textRect.width() ) // left, top aligned
{
boundingRect.moveTopRight( QPoint( r.x() - 3, r.y() ) );
textRect.moveTopRight( QPoint( r.x() - 5, r.y() ) );
}
else if ( r.bottom() + 3 + textRect.height() < rect().bottom() &&
r.right() > textRect.width() ) // at bottom, right aligned
{
boundingRect.moveTopRight( QPoint( r.right(), r.bottom() + 3 ) );
textRect.moveTopRight( QPoint( r.right() - 2, r.bottom() + 3 ) );
}
else if ( r.right() + textRect.width() + 3 < rect().width() ) // right, bottom aligned
{
boundingRect.moveBottomLeft( QPoint( r.right() + 3, r.bottom() ) );
textRect.moveBottomLeft( QPoint( r.right() + 5, r.bottom() ) );
}
// if the above didn't catch it, you are running on a very tiny screen...
drawRect( &painter, boundingRect, textColor, textBackgroundColor );
painter.drawText( textRect, txt );
if ( ( r.height() > handleSize*2 && r.width() > handleSize*2 )
|| !mouseDown )
{
updateHandles();
painter.setPen( Qt::NoPen );
painter.setBrush( handleColor );
painter.setClipRegion( handleMask( StrokeMask ) );
painter.drawRect( rect() );
handleColor.setAlpha( 60 );
painter.setBrush( handleColor );
//.........这里部分代码省略.........
示例11: drawComplexControl
void CustomStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
QPainter *painter, const QWidget *widget) const
{
QColor borderColor;
QPen oldPen(2);
QPainterPath path;
int x1, x2, y1, y2;
switch (control) {
#ifndef QT_NO_COMBOBOX
case CC_ComboBox:
if (const QStyleOptionComboBox *comboBox = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
painter->save();
// backgroundColor = option->palette.color(widget->parentWidget()->backgroundRole());
bool isEnabled = (comboBox->state & State_Enabled);
bool focus = isEnabled && (comboBox->state & State_HasFocus);
oldPen = painter->pen();
painter->setPen(Qt::black);
if(!focus)
borderColor = mergedColors(QColor(0x06, 0x4C, 0xA4), QColor(0xd6, 0xd6, 0xd6));
else
borderColor = QColor(255, 255, 0);
oldPen.setColor(borderColor);
painter->setPen(oldPen);
// painter->setBrush(Qt::transparent);
painter->fillRect(option->rect, option->palette.brush(QPalette::Base));
option->rect.getCoords(&x1, &y1, &x2, &y2);
path.moveTo(x1+0, y1);
path.lineTo(x2-0, y1);
path.lineTo(x2, y1+0);
path.lineTo(x2, y2-0);
path.lineTo(x2-0, y2);
path.lineTo(x1+0, y2);
path.lineTo(x1, y2-0);
path.lineTo(x1, y1+0);
path.lineTo(x1+0, y1);
painter->drawPath(path);
QRect downArrowRect = subControlRect(CC_ComboBox, comboBox,
SC_ComboBoxArrow, widget);
if (comboBox->subControls & SC_ComboBoxArrow) {
QStyleOptionButton buttonOption;
buttonOption.QStyleOption::operator=(*comboBox);
QRect arrowRect(option->rect.right() - downArrowRect.width(),
option->rect.top(),
downArrowRect.width(),
downArrowRect.height());
buttonOption.rect = arrowRect;
if(!focus)
buttonOption.state = comboBox->state & (State_Enabled | State_MouseOver);
else
buttonOption.state = comboBox->state & (State_Enabled | State_MouseOver | State_HasFocus);
// drawControl(CE_PushButtonBevel, &buttonOption, painter, widget);
buttonOption.rect = downArrowRect;
if(!focus)
buttonOption.state = comboBox->state & (State_Enabled | State_MouseOver);
else
buttonOption.state = comboBox->state & (State_Enabled | State_MouseOver | State_HasFocus);
// drawControl(CE_PushButtonBevel, &buttonOption, painter, widget);
QImage imgLeftArrow(qt_scrollbar_button_arrow_left);
QImage imgRightArrow(qt_scrollbar_button_arrow_right);
//downArrow.setColor(1, comboBox->palette.foreground().color().rgba());
// int offset = comboBox->direction == Qt::RightToLeft ? -2 : 2;
if(!focus)
{
imgRightArrow.setColor(1,qRgb(48,255,0));
imgLeftArrow.setColor(1,qRgb(48,255,0));
}
else
{
imgRightArrow.setColor(1,qRgb(255,255,0));
imgLeftArrow.setColor(1,qRgb(255,255,0));
}
painter->drawImage(downArrowRect.center().x() - imgLeftArrow.width() / 2,// + offset,
downArrowRect.center().y() - imgLeftArrow.height() / 2 + 1, imgLeftArrow);
painter->drawImage(arrowRect.center().x() - imgRightArrow.width() / 2,// + offset,
arrowRect.center().y() - imgRightArrow.height() / 2 + 1, imgRightArrow);
}
QRect editFieldRect = subControlRect(CC_ComboBox, comboBox,
SC_ComboBoxEditField, widget);
if (comboBox->subControls & SC_ComboBoxEditField) {
// QStyleOptionButton buttonOption;
// buttonOption.rect = editFieldRect;
// if(!focus)
// buttonOption.state = comboBox->state & (State_Enabled | State_MouseOver);
// else
// buttonOption.state = comboBox->state & (State_Enabled | State_MouseOver | State_HasFocus);
// drawPrimitive(PE_FrameLineEdit, &buttonOption, painter, widget);
//.........这里部分代码省略.........
示例12: moveFocus
void QAbstractButtonPrivate::moveFocus(int key)
{
QList<QAbstractButton *> buttonList = queryButtonList();;
#ifndef QT_NO_BUTTONGROUP
bool exclusive = group ? group->d_func()->exclusive : autoExclusive;
#else
bool exclusive = autoExclusive;
#endif
QWidget *f = QApplication::focusWidget();
QAbstractButton *fb = qobject_cast<QAbstractButton *>(f);
if (!fb || !buttonList.contains(fb))
return;
QAbstractButton *candidate = 0;
int bestScore = -1;
QRect target = f->rect().translated(f->mapToGlobal(QPoint(0,0)));
QPoint goal = target.center();
uint focus_flag = qt_tab_all_widgets() ? Qt::TabFocus : Qt::StrongFocus;
for (int i = 0; i < buttonList.count(); ++i) {
QAbstractButton *button = buttonList.at(i);
if (button != f && button->window() == f->window() && button->isEnabled() && !button->isHidden() &&
(autoExclusive || (button->focusPolicy() & focus_flag) == focus_flag)) {
QRect buttonRect = button->rect().translated(button->mapToGlobal(QPoint(0,0)));
QPoint p = buttonRect.center();
//Priority to widgets that overlap on the same coordinate.
//In that case, the distance in the direction will be used as significant score,
//take also in account orthogonal distance in case two widget are in the same distance.
int score;
if ((buttonRect.x() < target.right() && target.x() < buttonRect.right())
&& (key == Qt::Key_Up || key == Qt::Key_Down)) {
//one item's is at the vertical of the other
score = (qAbs(p.y() - goal.y()) << 16) + qAbs(p.x() - goal.x());
} else if ((buttonRect.y() < target.bottom() && target.y() < buttonRect.bottom())
&& (key == Qt::Key_Left || key == Qt::Key_Right) ) {
//one item's is at the horizontal of the other
score = (qAbs(p.x() - goal.x()) << 16) + qAbs(p.y() - goal.y());
} else {
score = (1 << 30) + (p.y() - goal.y()) * (p.y() - goal.y()) + (p.x() - goal.x()) * (p.x() - goal.x());
}
if (score > bestScore && candidate)
continue;
switch(key) {
case Qt::Key_Up:
if (p.y() < goal.y()) {
candidate = button;
bestScore = score;
}
break;
case Qt::Key_Down:
if (p.y() > goal.y()) {
candidate = button;
bestScore = score;
}
break;
case Qt::Key_Left:
if (p.x() < goal.x()) {
candidate = button;
bestScore = score;
}
break;
case Qt::Key_Right:
if (p.x() > goal.x()) {
candidate = button;
bestScore = score;
}
break;
}
}
}
if (exclusive
#ifdef QT_KEYPAD_NAVIGATION
&& !QApplication::keypadNavigationEnabled()
#endif
&& candidate
&& fb->d_func()->checked
&& candidate->d_func()->checkable)
candidate->click();
if (candidate) {
if (key == Qt::Key_Up || key == Qt::Key_Left)
candidate->setFocus(Qt::BacktabFocusReason);
else
candidate->setFocus(Qt::TabFocusReason);
}
}
示例13: drawIconWithShadow
// Draws a cached pixmap with shadow
void FancyTabBar::drawIconWithShadow(const QIcon &icon, const QRect &rect, QPainter *p, QIcon::Mode iconMode, int dipRadius, const QColor &color, const QPoint &dipOffset)
{
QPixmap cache;
QString pixmapName = QString::fromLatin1("icon %0 %1 %2").arg(icon.cacheKey()).arg(iconMode).arg(rect.height());
if (!QPixmapCache::find(pixmapName, cache)) {
// High-dpi support: The in parameters (rect, radius, offset) are in
// device-independent pixels. The call to QIcon::pixmap() below might
// return a high-dpi pixmap, which will in that case have a devicePixelRatio
// different than 1. The shadow drawing caluculations are done in device
// pixels.
QPixmap px = icon.pixmap(rect.size());
//jassuncao int devicePixelRatio = qCeil(px.devicePixelRatio());
int devicePixelRatio = 1;
int radius = dipRadius * devicePixelRatio;
QPoint offset = dipOffset * devicePixelRatio;
cache = QPixmap(px.size() + QSize(radius * 2, radius * 2));
cache.fill(Qt::transparent);
QPainter cachePainter(&cache);
if (iconMode == QIcon::Disabled) {
QImage im = px.toImage().convertToFormat(QImage::Format_ARGB32);
for (int y=0; y<im.height(); ++y) {
QRgb *scanLine = (QRgb*)im.scanLine(y);
for (int x=0; x<im.width(); ++x) {
QRgb pixel = *scanLine;
char intensity = qGray(pixel);
*scanLine = qRgba(intensity, intensity, intensity, qAlpha(pixel));
++scanLine;
}
}
px = QPixmap::fromImage(im);
}
// Draw shadow
QImage tmp(px.size() + QSize(radius * 2, radius * 2 + 1), QImage::Format_ARGB32_Premultiplied);
tmp.fill(Qt::transparent);
QPainter tmpPainter(&tmp);
tmpPainter.setCompositionMode(QPainter::CompositionMode_Source);
tmpPainter.drawPixmap(QRect(radius, radius, px.width(), px.height()), px);
tmpPainter.end();
// blur the alpha channel
QImage blurred(tmp.size(), QImage::Format_ARGB32_Premultiplied);
blurred.fill(Qt::transparent);
QPainter blurPainter(&blurred);
qt_blurImage(&blurPainter, tmp, radius, false, true);
blurPainter.end();
tmp = blurred;
// blacken the image...
tmpPainter.begin(&tmp);
tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
tmpPainter.fillRect(tmp.rect(), color);
tmpPainter.end();
tmpPainter.begin(&tmp);
tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
tmpPainter.fillRect(tmp.rect(), color);
tmpPainter.end();
// draw the blurred drop shadow...
cachePainter.drawImage(QRect(0, 0, cache.rect().width(), cache.rect().height()), tmp);
// Draw the actual pixmap...
cachePainter.drawPixmap(QRect(QPoint(radius, radius) + offset, QSize(px.width(), px.height())), px);
//jassuncao: cache.setDevicePixelRatio(devicePixelRatio);
QPixmapCache::insert(pixmapName, cache);
}
QRect targetRect = cache.rect();
//jassuncao targetRect.setSize(targetRect.size() / cache.devicePixelRatio());
targetRect.moveCenter(rect.center() - dipOffset);
p->drawPixmap(targetRect, cache);
}
示例14: setMainWidget
//.........这里部分代码省略.........
}
pushButtonLast->setSizePolicy( QSizePolicy(( QSizePolicy::SizeType ) 0, ( QSizePolicy::SizeType ) 0, 0, 0,
pushButtonLast->sizePolicy().hasHeightForWidth() ) );
pushButtonLast->setMinimumSize( pbSize );
pushButtonLast->setMaximumSize( pbSize );
QPixmap rld4( QPixmap::fromMimeSource( "last.png" ) );
pushButtonLast->setIconSet( rld4 );
pushButtonLast->setAccel( QKeySequence( Qt::Key_F8 ) );
QToolTip::add( pushButtonLast, tr( "Aceptar los cambios e ir al último registro (F8)" ) );
QWhatsThis::add( pushButtonLast, tr( "Aceptar los cambios e ir al último registro (F8)" ) );
pushButtonLast->setFocusPolicy( QWidget::NoFocus );
layoutButtons->addWidget( pushButtonLast );
pushButtonLast->show();
}
if ( cursor_->modeAccess() != FLSqlCursor::BROWSE ) {
if ( showAcceptContinue_ ) {
if ( !pushButtonAcceptContinue ) {
pushButtonAcceptContinue = new QPushButton( this, "pushButtonAcceptContinue" );
connect( pushButtonAcceptContinue, SIGNAL( clicked() ), this, SLOT( acceptContinue() ) );
}
pushButtonAcceptContinue->setSizePolicy( QSizePolicy(( QSizePolicy::SizeType ) 0, ( QSizePolicy::SizeType ) 0, 0, 0,
pushButtonAcceptContinue->sizePolicy().hasHeightForWidth() ) );
pushButtonAcceptContinue->setMinimumSize( pbSize );
pushButtonAcceptContinue->setMaximumSize( pbSize );
QPixmap rld( QPixmap::fromMimeSource( "reload.png" ) );
pushButtonAcceptContinue->setIconSet( rld );
pushButtonAcceptContinue->setFocusPolicy( QWidget::NoFocus );
pushButtonAcceptContinue->setAccel( QKeySequence( Qt::Key_F9 ) );
QToolTip::add( pushButtonAcceptContinue, tr( "Aceptar los cambios y continuar con la edición de un nuevo registro (F9)" ) );
QWhatsThis::add( pushButtonAcceptContinue, tr( "Aceptar los cambios y continuar con la edición de un nuevo registro (F9)" ) );
layoutButtons->addWidget( pushButtonAcceptContinue );
pushButtonAcceptContinue->show();
}
if ( !pushButtonAccept ) {
pushButtonAccept = new QPushButton( this, "pushButtonAccept" );
connect( pushButtonAccept, SIGNAL( clicked() ), this, SLOT( accept() ) );
}
pushButtonAccept->setSizePolicy( QSizePolicy(( QSizePolicy::SizeType ) 0, ( QSizePolicy::SizeType ) 0, 0, 0,
pushButtonAccept->sizePolicy().hasHeightForWidth() ) );
pushButtonAccept->setMinimumSize( pbSize );
pushButtonAccept->setMaximumSize( pbSize );
QPixmap ok( QPixmap::fromMimeSource( "button_ok.png" ) );
pushButtonAccept->setIconSet( ok );
pushButtonAccept->setFocusPolicy( QWidget::NoFocus );
pushButtonAccept->setAccel( QKeySequence( Qt::Key_F10 ) );
QToolTip::add( pushButtonAccept, tr( "Aceptar los cambios y cerrar formulario (F10)" ) );
QWhatsThis::add( pushButtonAccept, tr( "Aceptar los cambios y cerrar formulario (F10)" ) );
layoutButtons->addWidget( pushButtonAccept );
pushButtonAccept->show();
}
if ( !pushButtonCancel ) {
pushButtonCancel = new QPushButton( this, "pushButtonCancel" );
connect( cursor_, SIGNAL( autoCommit() ), this, SLOT( disablePushButtonCancel() ) );
connect( pushButtonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
}
pushButtonCancel->setSizePolicy( QSizePolicy(( QSizePolicy::SizeType ) 0, ( QSizePolicy::SizeType ) 0, 0, 0,
pushButtonCancel->sizePolicy().hasHeightForWidth() ) );
pushButtonCancel->setMinimumSize( pbSize );
pushButtonCancel->setMaximumSize( pbSize );
QPixmap cancel( QPixmap::fromMimeSource( "button_cancel.png" ) );
pushButtonCancel->setIconSet( cancel );
if ( cursor_->modeAccess() != FLSqlCursor::BROWSE ) {
pushButtonCancel->setFocusPolicy( QWidget::NoFocus );
pushButtonCancel->setAccel( 4096 );
QToolTip::add( pushButtonCancel, tr( "Cancelar los cambios y cerrar formulario (Esc)" ) );
QWhatsThis::add( pushButtonCancel, tr( "Cancelar los cambios y cerrar formulario (Esc)" ) );
} else {
QPixmap ok( QPixmap::fromMimeSource( "button_cancel.png" ) );
pushButtonCancel->setIconSet( ok );
pushButtonCancel->setFocusPolicy( QWidget::StrongFocus );
pushButtonCancel->setFocus();
pushButtonCancel->setAccel( 4096 );
QToolTip::add( pushButtonCancel, tr( "Aceptar y cerrar formulario (Esc)" ) );
QWhatsThis::add( pushButtonCancel, tr( "Aceptar y cerrar formulario (Esc)" ) );
}
pushButtonCancel->setDefault( true );
layoutButtons->addWidget( pushButtonCancel );
pushButtonCancel->show();
mainWidget_ = w;
mainWidget_->setFocusPolicy( QWidget::NoFocus );
int mWidth = mainWidget_->width();
int mHeight = mainWidget_->height();
QWidget * actWin = qApp->activeWindow();
QRect screen = ( actWin ? actWin->geometry() : qApp->mainWidget()->geometry() );
QRect desk = QApplication::desktop()->geometry();
QPoint p = screen.center() - QPoint( mWidth / 2, mHeight / 2 );
if ( p.x() + mWidth > desk.width() )
p.setX( desk.width() - mWidth );
if ( p.y() + mHeight > desk.height() )
p.setY( desk.height() - mHeight );
if ( p.x() < 0 )
p.setX( 0 );
if ( p.y() < 0 )
p.setY( 0 );
move( p );
}
示例15: rotate
void PictureLabel::rotate(qreal angle, Qt::Axis axis)
{
if (!m_ori.isNull() && m_angle != angle)
{
//m_angle = Converter::rotation(m_angle, angle);
QTransform trans;
trans.translate(m_ori.width() / 2, m_ori.height() / 2).rotate(angle, axis);
m_ori = m_ori.transformed(trans, Qt::SmoothTransformation);
//m_ori = m_ori.transformed(QTransform().rotate(angle, axis), Qt::SmoothTransformation);
int width = m_scaled.width(), height = m_scaled.height();
// static bool rotated = false;
// if (!rotated)
// {
// rotated = true;
// QRect rect = this->geometry();
// qDebug() << __FILE__ << __LINE__ << m_scaled << rect << rect.center();
// }
if (Qt::YAxis == axis && 180 == angle && m_angle)
{
m_angle *= -1;
}
if (Qt::ZAxis == axis)
{
m_angle = angle;
m_axis = axis;
if (angle)
{
if (0 > angle)
{
angle *= -1;
}
if (90 < angle)
{
angle = 180 - angle;
}
qreal arc = angle * 3.1415926535 / 180;
int sw = qCos(arc) * width + qSin(arc) * height;
int sh = qCos(arc) * height + qSin(arc) * width;
width = sw;
height = sh;
}
else
{
width = m_default.width() + 2 * MARGIN_SPACE;
height = m_default.height() + 2 * MARGIN_SPACE;
}
}
m_bk = m_ori.scaled(width, height, Qt::KeepAspectRatio, Qt::SmoothTransformation);
m_size = m_bk.size();
QRect old = this->geometry();
//qDebug() << __FILE__ << __LINE__ << "before:" << m_size << m_angle << width << height << old.center();
setFixedSize(m_size);
QRect curr = this->geometry();
curr.moveCenter(old.center());
setGeometry(curr);
setPixmap(m_bk);
//qDebug() << __FILE__ << __LINE__ << "after:" << curr << this->geometry().center();
}
else
{
m_angle = 0;
}
}