本文整理汇总了C++中QPixmap::rect方法的典型用法代码示例。如果您正苦于以下问题:C++ QPixmap::rect方法的具体用法?C++ QPixmap::rect怎么用?C++ QPixmap::rect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPixmap
的用法示例。
在下文中一共展示了QPixmap::rect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paint
void PushButton::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
if (!styleSheet().isNull() || Theme::defaultTheme()->useNativeWidgetStyle()) {
QGraphicsProxyWidget::paint(painter, option, widget);
return;
}
QPixmap bufferPixmap;
//Normal button, pressed or not
if (isEnabled()) {
if (nativeWidget()->isDown() || nativeWidget()->isChecked()) {
d->background->setElementPrefix("pressed");
} else {
d->background->setElementPrefix("normal");
}
//flat or disabled
} else if (!isEnabled() || nativeWidget()->isFlat()) {
bufferPixmap = QPixmap(rect().size().toSize());
bufferPixmap.fill(Qt::transparent);
QPainter buffPainter(&bufferPixmap);
d->background->paintFrame(&buffPainter);
buffPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
buffPainter.fillRect(bufferPixmap.rect(), QColor(0, 0, 0, 128));
painter->drawPixmap(0, 0, bufferPixmap);
}
//if is under mouse draw the animated glow overlay
if (!nativeWidget()->isDown() && !nativeWidget()->isChecked() && isEnabled() && acceptHoverEvents() && d->background->hasElementPrefix("active")) {
if (d->hoverAnimation->state() == QAbstractAnimation::Running && !isUnderMouse() && !nativeWidget()->isDefault()) {
d->background->setElementPrefix("active");
d->background->paintFrame(painter, d->activeRect.topLeft());
} else {
painter->drawPixmap(
d->activeRect.topLeft(),
d->hoverAnimation->property("currentPixmap").value<QPixmap>());
}
} else if (isEnabled()) {
d->background->paintFrame(painter);
}
painter->setPen(Plasma::Theme::defaultTheme()->color(Theme::ButtonTextColor));
if (nativeWidget()->isDown()) {
painter->translate(QPoint(1, 1));
}
QRectF rect = contentsRect();
if (!nativeWidget()->icon().isNull()) {
const qreal iconSize = qMin(rect.width(), rect.height());
QPixmap iconPix = nativeWidget()->icon().pixmap(iconSize);
if (!isEnabled()) {
KIconEffect *effect = KIconLoader::global()->iconEffect();
iconPix = effect->apply(iconPix, KIconLoader::Toolbar, KIconLoader::DisabledState);
}
QRect pixmapRect;
if (nativeWidget()->text().isEmpty()) {
pixmapRect = nativeWidget()->style()->alignedRect(option->direction, Qt::AlignCenter, iconPix.size(), rect.toRect());
} else {
pixmapRect = nativeWidget()->style()->alignedRect(option->direction, Qt::AlignLeft|Qt::AlignVCenter, iconPix.size(), rect.toRect());
}
painter->drawPixmap(pixmapRect.topLeft(), iconPix);
if (option->direction == Qt::LeftToRight) {
rect.adjust(rect.height(), 0, 0, 0);
} else {
rect.adjust(0, 0, -rect.height(), 0);
}
}
QFontMetricsF fm(font());
// If the height is too small increase the Height of the button to shall the whole text #192988
if (rect.height() < fm.height()) {
rect.setHeight(fm.height());
rect.moveTop(boundingRect().center().y() - rect.height() / 2);
}
// If there is not enough room for the text make it to fade out
if (rect.width() < fm.width(nativeWidget()->text())) {
if (bufferPixmap.isNull()) {
bufferPixmap = QPixmap(rect.size().toSize());
}
bufferPixmap.fill(Qt::transparent);
QPainter p(&bufferPixmap);
p.setPen(painter->pen());
p.setFont(font());
// Create the alpha gradient for the fade out effect
QLinearGradient alphaGradient(0, 0, 1, 0);
alphaGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
if (option->direction == Qt::LeftToRight) {
//.........这里部分代码省略.........
示例2: paint
void PlListViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
QString title = PLModel::getMeta( index, COLUMN_TITLE );
QString duration = PLModel::getMeta( index, COLUMN_DURATION );
if( !duration.isEmpty() ) title += QString(" [%1]").arg( duration );
QString artist = PLModel::getMeta( index, COLUMN_ARTIST );
QString album = PLModel::getMeta( index, COLUMN_ALBUM );
QString trackNum = PLModel::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 = PLModel::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 );
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();
}
示例3: setPixmap
void GraphicElement::setPixmap( const QPixmap &pixmap ) {
setTransformOriginPoint( pixmap.rect().center() );
this->pixmap = pixmap;
update( boundingRect( ) );
}
示例4: drawPixmap
void QBlitterPaintEngine::drawPixmap(const QPointF &pos, const QPixmap &pm)
{
drawPixmap(QRectF(pos, pm.size()), pm, pm.rect());
}
示例5: grabBackground
//________________________________________________
void TransitionWidget::grabBackground( QPixmap& pixmap, QWidget* widget, QRect& rect ) const
{
if( !widget ) return;
QWidgetList widgets;
if( widget->autoFillBackground() )
{ widgets.append( widget ); }
QWidget *parent(0);
// get highest level parent
for( parent = widget->parentWidget(); parent; parent = parent->parentWidget() )
{
if( !( parent->isVisible() && parent->rect().isValid() ) ) continue;
// store in list
widgets.append( parent );
// stop at topLevel
if( parent->isTopLevel() || parent->autoFillBackground() ) break;
}
if( !parent ) parent = widget;
// painting
QPainter p(&pixmap);
p.setClipRect( rect );
const QBrush backgroundBrush = parent->palette().brush( parent->backgroundRole());
if( backgroundBrush.style() == Qt::TexturePattern)
{
p.drawTiledPixmap( rect, backgroundBrush.texture(), widget->mapTo( parent, rect.topLeft() ) );
} else {
p.fillRect( pixmap.rect(), backgroundBrush );
}
if( parent->isTopLevel() && parent->testAttribute(Qt::WA_StyledBackground))
{
QStyleOption option;
option.initFrom(parent);
option.rect = rect;
option.rect.translate( widget->mapTo( parent, rect.topLeft() ) );
p.translate(-option.rect.topLeft());
parent->style()->drawPrimitive ( QStyle::PE_Widget, &option, &p, parent );
p.translate(option.rect.topLeft());
}
// draw all widgets in parent list
// backward
QPaintEvent event(rect);
for( int i = widgets.size() - 1; i>=0; i-- )
{
QWidget* w = widgets.at(i);
w->render( &p, -widget->mapTo( w, rect.topLeft() ), rect, 0 );
}
// end
p.end();
}
示例6: on_actionGamma_correction_triggered
void MainWindow::on_actionGamma_correction_triggered()
{
QPixmap pixmap = pixmapItem->pixmap().copy();
QImage image = pixmap.toImage();
int width = image.width();
int height = image.height();
if (width == 0 || height == 0)
{
ui->statusBar->showMessage( tr("Error. Image bad size"), 3000 );
return;
}
DialogGammaCorrection dialog;
if (dialog.exec() == QDialog::Rejected)
return;
int maxR = -1;
int maxG = -1;
int maxB = -1;
for (int y = 0; y < height; ++y)
for (int x = 0; x < width; ++x)
{
QRgb oldColor = image.pixel(x, y);
int red = qRed(oldColor);
int green = qGreen(oldColor);
int blue = qBlue(oldColor);
if (red > maxR)
maxR = red;
if (green > maxG)
maxG = green;
if (blue > maxB)
maxB = blue;
}
double gamma = dialog.getGamma();
double cR = 255 / qPow(maxR, gamma);
double cG = 255 / qPow(maxG, gamma);
double cB = 255 / qPow(maxB, gamma);
for (int y = 0; y < height; ++y)
for (int x = 0; x < width; ++x)
{
QRgb oldColor = image.pixel(x, y);
int red = cR * qPow(qRed(oldColor), gamma);
int green = cG * qPow(qGreen(oldColor), gamma);
int blue = cB * qPow(qBlue(oldColor), gamma);
if (red < 0)
red = 0;
if (red > 255)
red = 255;
if (green < 0)
green = 0;
if (green > 255)
green = 255;
if (blue < 0)
blue = 0;
if (blue > 255)
blue = 255;
image.setPixel(x, y, qRgb(red, green, blue));
}
pixmap.convertFromImage(image);
pixmapItem_2->setPixmap(pixmap);
scene_2->setSceneRect(QRectF(pixmap.rect()));
calcHist(pixmap, hist_2, maxLevel_2);
drawHist(pixmapItem_4, hist_2, maxLevel_2);
}
示例7: main
int main(int argc, char *argv[])
{
// Инициализируем генератор псевдослучайных чисел
qsrand(QTime::currentTime().msec());
QApplication app(argc, argv);
BubbleItem::setBubblePixmap(QPixmap(":/images/bubble.png"));
// Получаем скриншот
QScreen *screen = QApplication::primaryScreen();
if (!screen)
return -1;
QPixmap screenshot = screen->grabWindow(0);
// QGraphicsScene - контейнер для создаваемых нами
// объектов класса Bubble
QGraphicsScene scene;
scene.setSceneRect( screenshot.rect() );
// Наполняем сцену непересекающимися элементами
{
const int left = scene.sceneRect().left() + BubbleItem::RADIUS;
const int top = scene.sceneRect().top() + BubbleItem::RADIUS;
const int right = scene.sceneRect().right() - BubbleItem::RADIUS;
const int bottom = scene.sceneRect().bottom() - BubbleItem::RADIUS;
for (int i = 0; i < BUBBLES_AMOUNT; ++i)
{
BubbleItem *bubble = new BubbleItem();
scene.addItem(bubble);
// Будем давать пузырю случайные координаты до тез пор
// пока он не прекратит пересекаться с другими пузырями
do
{
bubble->setPos(
left + qrand() % (right - left),
top + qrand() % (bottom - top)
);
}
while ( !scene.collidingItems(bubble).isEmpty() );
}
}
// MainWidget - главный и единственный виджет этой программы,
// он непосредственно рисует на экране элементы сцены, а также
// обрабатывает нажатие клавиш и завершает выполнение программы при
// нажатии клавиши ESC
MainWidget view(&scene);
view.setBackgroundPixmap(screenshot);
view.setRenderHint(QPainter::Antialiasing);
view.showFullScreen();
// Используем QTimer для анимации движения пузырей. Сцена будет принудительно
// обновляться EXPECTED_FPS раз в секунду
QTimer timer;
QObject::connect(&timer, SIGNAL(timeout()), &scene, SLOT(advance()));
timer.start(1000 / EXPECTED_FPS);
return app.exec();
}
示例8: drawIconWithShadow
// Draws a cached pixmap with shadow
void StyleHelper::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());
int devicePixelRatio = qCeil(pixmapDevicePixelRatio(px));
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);
#if QT_VERSION > 0x050000
cache.setDevicePixelRatio(devicePixelRatio);
#endif
QPixmapCache::insert(pixmapName, cache);
}
QRect targetRect = cache.rect();
targetRect.setSize(targetRect.size() / pixmapDevicePixelRatio(cache));
targetRect.moveCenter(rect.center() - dipOffset);
p->drawPixmap(targetRect, cache);
}
示例9: displayDetails
// --------------------------------------------------------------------------------
void QmvFormTool::displayDetails()
{
slotSetBannerText( QString("%1").arg( fh->form_desc ) );
// determine page data
// prepare the details in the list.
formDetail fd;
QRect rect;
QPixmap pm;
QPainter pt;
int x,y,w,h;
QPoint pos;
QSize size;
QColor fill;
for ( int row = 0; row < reln_fmdt->count(); row++ )
{
if (!fd.load( row, reln_fmdt) )
continue;
if ( fd.fmdt_field_type < formDetail::Label || fd.fmdt_field_type > formDetail::Special )
continue;
// the raw position from fmdt
pos = QPoint( fd.fmdt_x_coord, fd.fmdt_y_coord );
size = QSize( fd.fmdt_width, fd.fmdt_height );
fill = QColor( Qt::gray );
// special actions
switch (fd.fmdt_field_type)
{
case formDetail::Label:
break;
case formDetail::Field:
break;
case formDetail::Line:
fill = QColor( Qt::red );
size.setHeight(2);
break;
case formDetail::Calc:
break;
case formDetail::Special:
break;
default:
continue;
break;
}
// adjust for section and margins
switch (fd.fmdt_section)
{
case formDetail::ReportHeader:
case formDetail::PageHeader:
pos += QPoint( fh->form_mg_left, fh->form_mg_top );
break;
case formDetail::Detail:
pos += QPoint( fh->form_mg_left, (fh->form_mg_top + fh->form_ph_height));
break;
case formDetail::PageFooter:
case formDetail::ReportFooter:
// measure from bottom
pos += QPoint( fh->form_mg_left, (pagesize.height() - fh->form_mg_bottom - fh->form_pf_height) );
break;
}
if ( pos.x() < 0 || pos.y() < 0 || size.width() < 1 || size.height() < 1 )
continue;
// build a QRect for this detail
rect.setSize( size );
// reset origin, ready for drawing
rect.moveTopLeft( QPoint(0,0) );
// build a detail label using a pixmap
pm.resize( rect.size() );
pm.fill(getTransparentColor());
pt.begin(&pm);
// fill the background and draw the label
pt.setPen( QPen( Qt::black, 2, SolidLine ) );
pt.fillRect( rect, QBrush( fill, QBrush::SolidPattern ) );
pt.setFont( QFont( fd.fmdt_ft_family, fd.fmdt_ft_size) );
pt.drawText( rect, WordBreak|AlignCenter, fd.fmdt_text );
// draw a border around the object
pt.setBrush( Qt::NoBrush );
pt.setPen(QPen( Qt::black, 2, SolidLine ) );
pt.drawRect( rect );
pt.end();
// put the prepared pixmap on a canvas object
QmvCanvasGrid * disp_obj = new QmvCanvasGrid( getCanvas(), rect.size(), getTransparentColor() );
// use the canvas object as a key in list of displayed details
canvas_details.insert( disp_obj, new int(row) );
//.........这里部分代码省略.........
示例10: paintCells
void PixmapCachingSheetView::paintCells(QPainter& painter, const QRectF& paintRect, const QPointF& topLeft, CanvasBase* canvas, const QRect& visibleRect)
{
if (!canvas) {
SheetView::paintCells(painter, paintRect, topLeft, canvas, visibleRect);
return;
}
// paintRect: the canvas area, that should be painted; in document coordinates;
// no layout direction consideration; scrolling offset applied;
// independent from painter transformations
// topLeft: the document coordinate of the top left cell's top left corner;
// no layout direction consideration; independent from painter
// transformations
QTransform t = painter.transform();
// figure out scaling from the transformation... not really perfect, but should work as long as rotation is in 90 degree steps I think
const qreal cos_sx = t.m11();
const qreal sin_sx = t.m12();
const qreal msin_sy = t.m21();
const qreal cos_sy = t.m22();
const qreal sx = sqrt(cos_sx*cos_sx + sin_sx*sin_sx);
const qreal sy = sqrt(cos_sy*cos_sy + msin_sy*msin_sy);
//const qreal cost = (sx > 1e-10 ? cos_sx / sx : cos_sy / sy);
//const qreal ang = acos(cost);
QPointF scale = QPointF(sx, sy);
if (scale != d->lastScale) {
d->tileCache.clear();
}
d->lastScale = scale;
QRect tiles;
const QRect visibleCells = paintCellRange();
const Sheet * s = sheet();
const QPointF bottomRight(s->columnPosition(visibleCells.right() + 1), s->rowPosition(visibleCells.bottom() + 1));
tiles.setLeft(topLeft.x() * sx / TILESIZE);
tiles.setTop(topLeft.y() * sy / TILESIZE);
tiles.setRight((bottomRight.x() * sx + TILESIZE-1) / TILESIZE);
tiles.setBottom((bottomRight.y() * sy + TILESIZE-1) / TILESIZE);
bool rtl = s->layoutDirection() == Qt::RightToLeft;
if (rtl) {
for (int x = qMax(0, tiles.left()); x < tiles.right(); x++) {
for (int y = qMax(0, tiles.top()); y < tiles.bottom(); y++) {
QPixmap *p = d->getTile(s, x, y, canvas);
if (p) {
QPointF pt(paintRect.width() - (x+1) * TILESIZE / scale.x(), y * TILESIZE / scale.y());
QRectF r(pt, QSizeF(TILESIZE / sx, TILESIZE / sy));
painter.drawPixmap(r, *p, p->rect());
}
}
}
} else {
for (int x = qMax(0, tiles.left()); x < tiles.right(); x++) {
for (int y = qMax(0, tiles.top()); y < tiles.bottom(); y++) {
QPixmap *p = d->getTile(s, x, y, canvas);
if (p) {
QPointF pt(x * TILESIZE / scale.x(), y * TILESIZE / scale.y());
QRectF r(pt, QSizeF(TILESIZE / sx, TILESIZE / sy));
painter.drawPixmap(r, *p, p->rect());
}
}
}
}
}
示例11: paint_QPixmapCachedRoundedRect
void paint_QPixmapCachedRoundedRect(QPainter &p)
{
static bool first = true;
static QPixmap cacheRect;
if (first) {
const int pw = 0;
const int radius = 8;
cacheRect = QPixmap(radius*2 + 3 + pw*2, radius*2 + 3 + pw*2);
cacheRect.fill(Qt::transparent);
QPainter paint(&cacheRect);
paint.setRenderHint(QPainter::Antialiasing);
paint.setPen(Qt::black);
paint.setBrush(Qt::red);
if (pw%2)
paint.drawRoundedRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, cacheRect.width()-(pw+1), cacheRect.height()-(pw+1)), radius, radius);
else
paint.drawRoundedRect(QRectF(qreal(pw)/2, qreal(pw)/2, cacheRect.width()-pw, cacheRect.height()-pw), radius, radius);
first = false;
}
for (int i = 0; i < count; i++) {
for (int j = 0; j < lines; ++j) {
QSize size((j+1)*50, spacing-1);
p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, true);
const int pw = 0;
int xOffset = (cacheRect.width()-1)/2;
int yOffset = (cacheRect.height()-1)/2;
QMargins margins(xOffset, yOffset, xOffset, yOffset);
QTileRules rules(Qt::StretchTile, Qt::StretchTile);
//NOTE: even though our item may have qreal-based width and height, qDrawBorderPixmap only supports QRects
qDrawBorderPixmap(&p, QRect(-pw/2, j*spacing-pw/2, size.width()+pw, size.height()+pw), margins, cacheRect, cacheRect.rect(), margins, rules);
}
}
}
示例12: pix
const QPixmap& PointImp::getLegendPixmap(bool bSelected) const
{
static QPixmap pix(25, 15);
static QPixmap selectedPix(25, 15);
static QColor pixColor;
static Point::PointSymbolType pixSymbol;
static int pixWidth;
static int pixHeight;
static QColor selectedPixColor;
static Point::PointSymbolType selectedPixSymbol;
static int selectedPixWidth;
static int selectedPixHeight;
int iSymbolWidth = mSymbolSize;
int iSymbolHeight = mSymbolSize;
if (bSelected == true)
{
iSymbolWidth = mSymbolSize * 2;
iSymbolHeight = mSymbolSize * 2;
}
int iWidth = iSymbolWidth;
int iHeight = iSymbolHeight;
if (iWidth < 25)
{
iWidth = 25;
}
if (iHeight < 15)
{
iHeight = 15;
}
if ((bSelected == true) && (selectedPix.isNull() == false))
{
if ((selectedPixColor != mColor) || (selectedPixSymbol != mSymbol) ||
(selectedPixWidth != iWidth) || (selectedPixHeight != iHeight))
{
selectedPixColor = mColor;
selectedPixSymbol = mSymbol;
selectedPixWidth = iWidth;
selectedPixHeight = iHeight;
selectedPix.fill(Qt::transparent);
QRect rcPix = selectedPix.rect();
int iSymbolMinX = rcPix.center().x() - iSymbolWidth / 2.0;
int iSymbolMinY = rcPix.center().y() - iSymbolHeight / 2.0;
QRect rcSymbol(iSymbolMinX, iSymbolMinY, iSymbolWidth, iSymbolHeight);
QPainter p(&selectedPix);
p.setPen(QPen(mColor, 1));
// Used with drawPolygon
QPointF points[8];
switch (mSymbol)
{
case Point::SOLID: default:
p.fillRect(rcSymbol, mColor);
break;
case Point::X:
p.drawLine(rcSymbol.topLeft(), rcSymbol.bottomRight());
p.drawLine(rcSymbol.topRight(), rcSymbol.bottomLeft());
break;
case Point::CROSS_HAIR:
p.drawLine(rcSymbol.left(), rcSymbol.center().y(), rcSymbol.right(),
rcSymbol.center().y());
p.drawLine(rcSymbol.center().x(), rcSymbol.top(), rcSymbol.center().x(),
rcSymbol.bottom());
break;
case Point::ASTERISK:
p.drawLine(rcSymbol.center().x(), rcSymbol.top(), rcSymbol.center().x(),
rcSymbol.bottom());
p.drawLine(rcSymbol.left(), rcSymbol.top() + (rcSymbol.height() / 4), rcSymbol.right(),
rcSymbol.top() + ((rcSymbol.height() / 4) * 3));
p.drawLine(rcSymbol.left(), rcSymbol.top() + ((rcSymbol.height() / 4) * 3),
rcSymbol.right(), rcSymbol.top() + (rcSymbol.height() / 4));
break;
case Point::VERTICAL_LINE:
p.drawLine(rcSymbol.center().x(), rcSymbol.top(), rcSymbol.center().x(),
rcSymbol.bottom());
break;
case Point::HORIZONTAL_LINE:
p.drawLine(rcSymbol.left(), rcSymbol.center().y(), rcSymbol.right(),
rcSymbol.center().y());
break;
case Point::FORWARD_SLASH:
p.drawLine(rcSymbol.topRight(), rcSymbol.bottomLeft());
break;
case Point::BACK_SLASH:
p.drawLine(rcSymbol.topLeft(), rcSymbol.bottomRight());
//.........这里部分代码省略.........
示例13: drawControl
void WindowsModernStyle::drawControl( ControlElement element, const QStyleOption* option,
QPainter* painter, const QWidget* widget ) const
{
switch ( element ) {
case CE_MenuBarEmptyArea:
return;
case CE_MenuBarItem:
if ( option->state & QStyle::State_Sunken && option->state & QStyle::State_Enabled ) {
painter->setPen( m_colorMenuBorder );
QLinearGradient gradient( option->rect.topLeft(), option->rect.bottomLeft() );
gradient.setColorAt( 0.0, m_colorMenuTitleBegin );
gradient.setColorAt( 1.0, m_colorMenuTitleEnd );
painter->setBrush( gradient );
painter->drawRect( option->rect.adjusted( 0, 0, -1, 0 ) );
} else if ( option->state & QStyle::State_Selected && option->state & QStyle::State_Enabled ) {
painter->setPen( m_colorItemBorder );
QLinearGradient gradient( option->rect.topLeft(), option->rect.bottomLeft() );
gradient.setColorAt( 0.0, m_colorItemBackgroundBegin );
gradient.setColorAt( 1.0, m_colorItemBackgroundEnd );
painter->setBrush( gradient );
painter->drawRect( option->rect.adjusted( 0, 0, -1, -1 ) );
}
if ( const QStyleOptionMenuItem* optionItem = qstyleoption_cast<const QStyleOptionMenuItem*>( option ) ) {
int flags = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
if ( !styleHint( SH_UnderlineShortcut, option, widget ) )
flags |= Qt::TextHideMnemonic;
if ( !optionItem->icon.isNull() ) {
QPixmap pixmap = optionItem->icon.pixmap( pixelMetric( PM_SmallIconSize, option, widget ), QIcon::Normal );
drawItemPixmap( painter, option->rect, flags, pixmap );
} else {
drawItemText( painter, option->rect, flags, option->palette, true, optionItem->text, QPalette::Text );
}
}
return;
case CE_MenuEmptyArea:
painter->fillRect( option->rect, m_colorMenuBackground );
return;
case CE_MenuItem: {
if ( option->state & QStyle::State_Selected && option->state & QStyle::State_Enabled ) {
painter->setPen( m_colorItemBorder );
painter->setBrush( m_colorItemBackgroundBegin );
painter->drawRect( option->rect.adjusted( 1, 0, -3, -1 ) );
} else {
QLinearGradient gradient( QPoint( 0, 0 ), QPoint( 25, 0 ) );
gradient.setColorAt( 0.0, m_colorBarBegin );
gradient.setColorAt( 1.0, m_colorBarEnd );
QRect margin = option->rect;
margin.setWidth( 25 );
painter->fillRect( margin, gradient );
QRect background = option->rect;
background.setLeft( margin.right() + 1 );
painter->fillRect( background, m_colorMenuBackground );
}
if ( const QStyleOptionMenuItem* optionItem = qstyleoption_cast<const QStyleOptionMenuItem*>( option ) ) {
if ( optionItem->menuItemType == QStyleOptionMenuItem::Separator ) {
painter->setPen( m_colorSeparator );
painter->drawLine( option->rect.left() + 32, ( option->rect.top() + option->rect.bottom() ) / 2,
option->rect.right(), ( option->rect.top() + option->rect.bottom() ) / 2 );
return;
}
QRect checkRect = option->rect.adjusted( 2, 1, -2, -2 );
checkRect.setWidth( 20 );
if ( optionItem->checked && option->state & QStyle::State_Enabled ) {
painter->setPen( m_colorItemBorder );
if ( option->state & QStyle::State_Selected && option->state & QStyle::State_Enabled )
painter->setBrush( m_colorItemSunkenBegin );
else
painter->setBrush( m_colorItemCheckedBegin );
painter->drawRect( checkRect );
}
if ( !optionItem->icon.isNull() ) {
QIcon::Mode mode;
if ( optionItem->state & State_Enabled )
mode = ( optionItem->state & State_Selected ) ? QIcon::Active : QIcon::Normal;
else
mode = QIcon::Disabled;
QIcon::State state = optionItem->checked ? QIcon::On : QIcon::Off;
QPixmap pixmap = optionItem->icon.pixmap( pixelMetric( PM_SmallIconSize, option, widget ), mode, state );
QRect rect = pixmap.rect();
rect.moveCenter( checkRect.center() );
painter->drawPixmap( rect.topLeft(), pixmap );
} else if ( optionItem->checked ) {
QStyleOption optionCheckMark;
optionCheckMark.initFrom( widget );
optionCheckMark.rect = checkRect;
if ( !( option->state & State_Enabled ) )
optionCheckMark.palette.setBrush( QPalette::Text, optionCheckMark.palette.brush( QPalette::Disabled, QPalette::Text ) );
drawPrimitive( PE_IndicatorMenuCheckMark, &optionCheckMark, painter, widget );
}
QRect textRect = option->rect.adjusted( 32, 1, -16, -1 );
int flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
if ( !styleHint( SH_UnderlineShortcut, option, widget ) )
flags |= Qt::TextHideMnemonic;
QString text = optionItem->text;
int pos = text.indexOf( '\t' );
if ( pos >= 0 ) {
drawItemText( painter, textRect, flags | Qt::AlignRight, option->palette, option->state & State_Enabled,
//.........这里部分代码省略.........
示例14: pixmap
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
** $QT_END_LICENSE$
**
****************************************************************************/
//! [0]
static const char * const start_xpm[]={
"16 15 8 1",
"a c #cec6bd",
....
//! [0]
//! [1]
QPixmap myPixmap;
myPixmap->setMask(myPixmap->createHeuristicMask());
//! [1]
//! [2]
QPixmap pixmap("background.png");
QRegion exposed;
pixmap.scroll(10, 10, pixmap.rect(), &exposed);
//! [2]
示例15: on_actionGray_world_triggered
void MainWindow::on_actionGray_world_triggered()
{
QPixmap pixmap = pixmapItem->pixmap().copy();
QImage image = pixmap.toImage();
int width = image.width();
int height = image.height();
if (width == 0 || height == 0)
{
ui->statusBar->showMessage( tr("Error. Image bad size"), 3000 );
return;
}
double avgRed = 0.0;
double avgGreen = 0.0;
double avgBlue = 0.0;
for (int y = 0; y < height; ++y)
for (int x = 0; x < width; ++x)
{
QRgb oldColor = image.pixel(x, y);
avgRed += qRed(oldColor);
avgGreen += qGreen(oldColor);
avgBlue += qBlue(oldColor);
}
int length = width * height;
avgRed /= length;
avgGreen /= length;
avgBlue /= length;
double avg = (avgRed + avgGreen + avgBlue) / 3;
for (int y = 0; y < height; ++y)
for (int x = 0; x < width; ++x)
{
QRgb oldColor = image.pixel(x, y);
double red = qRed(oldColor) * avg / avgRed;
double green = qGreen(oldColor) * avg / avgGreen;
double blue = qBlue(oldColor) * avg / avgBlue;
if (red < 0)
red = 0;
if (red > 255)
red = 255;
if (green < 0)
green = 0;
if (green > 255)
green = 255;
if (blue < 0)
blue = 0;
if (blue > 255)
blue = 255;
image.setPixel(x, y, qRgb(red, green, blue));
}
pixmap.convertFromImage(image);
pixmapItem_2->setPixmap(pixmap);
scene_2->setSceneRect(QRectF(pixmap.rect()));
calcHist(pixmap, hist_2, maxLevel_2);
drawHist(pixmapItem_4, hist_2, maxLevel_2);
}