bool operator()(unsigned int a, unsigned int b) { QDesktopWidget qdw; QRect rectA = qdw.screenGeometry(a); QRect rectB = qdw.screenGeometry(b); int x, y, width, height; rectA.getRect(&x, &y, &width, &height); rectB.getRect(&x, &y, &width, &height); if (_isQTIndexDisorder) // means return !(rectB.x() > rectA.x()); else return (rectB.x() > rectA.x()); }
QPixmap FX::applyAlpha(const QPixmap &toThisPix, const QPixmap &fromThisPix, const QRect &rect, const QRect &alphaRect) { QPixmap pix; int sx,sy,ax,ay,w,h; if (rect.isNull()) { sx = sy = 0; w = toThisPix.width(); h = toThisPix.height(); } else rect.getRect(&sx,&sy,&w,&h); if (alphaRect.isNull()) { ax = ay = 0; } else { ax = alphaRect.x(); ay = alphaRect.y(); w = qMin(alphaRect.width(),w); h = qMin(alphaRect.height(),h); } if (w > fromThisPix.width() || h > fromThisPix.height()) pix = QPixmap(w, h); else pix = fromThisPix.copy(0,0,w,h); // cause slow depth conversion... pix.fill(Qt::transparent); QPainter p(&pix); p.drawPixmap(0, 0, toThisPix, sx, sy, w, h); p.setCompositionMode(QPainter::CompositionMode_DestinationIn); p.drawPixmap(0, 0, fromThisPix, ax, ay, w, h); p.end(); return pix; }
void QDirectFbBlitter::drawDebugRect(const QRect &rect, const QColor &color) { int x, y, w, h; DFBResult result; // check parameters rect.getRect(&x, &y ,&w, &h); if ((w <= 0) || (h <= 0)) return; m_surface->SetDrawingFlags(m_surface.data(), DFBSurfaceDrawingFlags(m_premult ? (DSDRAW_BLEND | DSDRAW_SRC_PREMULTIPLY) : DSDRAW_BLEND)); m_surface->SetPorterDuff(m_surface.data(), DSPD_SRC_OVER); // set color m_surface->SetColor(m_surface.data(), color.red(), color.green(), color.blue(), 120); result = m_surface->DrawLine(m_surface.data(), x, y, x + w-1, y); if (result != DFB_OK) DirectFBError("QDirectFBBlitter::drawDebugRect()", result); result = m_surface->DrawLine(m_surface.data(), x + w-1, y, x + w-1, y + h-1); if (result != DFB_OK) DirectFBError("QDirectFBBlitter::drawDebugRect()", result); result = m_surface->DrawLine(m_surface.data(), x + w-1, y + h-1, x, y + h-1); if (result != DFB_OK) DirectFBError("QDirectFBBlitter::drawDebugRect()", result); result = m_surface->DrawLine(m_surface.data(), x, y + h-1, x, y); if (result != DFB_OK) DirectFBError("QDirectFBBlitter::drawDebugRect()", result); m_surface->SetColor(m_surface.data(), color.red(), color.green(), color.blue(), 10); result = m_surface->FillRectangle(m_surface.data(), x, y, w, h); if (result != DFB_OK) DirectFBError("QDirectFBBlitter::drawDebugRect()", result); }
void QColorButton::paintEvent (QPaintEvent *p) { QPushButton::paintEvent (p); QStyleOptionButton option; option.initFrom (this); int x, y, w, h; QRect r = style()->subElementRect (QStyle::SE_PushButtonContents, &option, this); r.getRect (&x, &y, &w, &h); int margin = style()->pixelMetric (QStyle::PM_ButtonMargin, &option, this); x += margin; y += margin; w -= 2*margin; h -= 2*margin; if (isChecked() || isDown()) { x += style()->pixelMetric (QStyle::PM_ButtonShiftHorizontal, &option, this ); y += style()->pixelMetric (QStyle::PM_ButtonShiftVertical, &option, this ); } QPainter painter (this); QColor fillCol = isEnabled() ? col : palette().brush(QPalette::Window).color(); qDrawShadePanel (&painter, x, y, w, h, palette(), true, 1, NULL); if (fillCol.isValid()) painter.fillRect (x+1, y+1, w-2, h-2, fillCol); if (hasFocus()) { style()->subElementRect (QStyle::SE_PushButtonFocusRect, &option, this); style()->drawPrimitive (QStyle::PE_FrameFocusRect, &option, &painter, this); } }
void QColorButton::paintEvent( QPaintEvent * event ) { QPainter painter( this ); int x, y, w, h; QStyleOptionButton opt; opt.rect = event->rect(); style()->drawControl(QStyle::CE_PushButtonBevel, &opt, &painter, this); QRect r = style()->subElementRect( QStyle::SE_PushButtonContents, &opt, this ); r.getRect(&x, &y, &w, &h); //int margin = style()->pixelMetric( QStyle::PM_ButtonMargin, &opt, this ); //x += margin; //y += margin; //w -= 2*margin; //h -= 2*margin; //if (isOn() || isDown()) { // x += style()->pixelMetric( QStyle::PM_ButtonShiftHorizontal, &opt, this ); // y += style()->pixelMetric( QStyle::PM_ButtonShiftVertical, &opt, this ); //} const QColor fillCol = isEnabled() ? col : palette().background().color(); qDrawShadePanel( &painter, x, y, w, h, palette(), true, 1, NULL); if ( fillCol.isValid() ) painter.fillRect( x+1, y+1, w-2, h-2, fillCol ); //if ( hasFocus() ) { // QRect focusRect = style()->subElementRect( QStyle::SE_PushButtonFocusRect, &opt, this ); // style()->drawPrimitive( QStyle::PE_FrameFocusRect, &opt, &painter, this ); //} }
void QSFMLCanvas::setGeometry(QRect rect) { int x, y, width, height; rect.getRect(&x, &y, &width, &height); move(QPoint(x,y)); resize(QSize(width, height)); }
QImage KisImagePyramid::convertToQImageFast(KisPaintDeviceSP paintDevice, const QRect& unscaledRect) { qint32 x, y, w, h; unscaledRect.getRect(&x, &y, &w, &h); QImage image = QImage(w, h, QImage::Format_ARGB32); paintDevice->dataManager()->readBytes(image.bits(), x, y, w, h); return image; }
//_______________________________________________________________________ QRegion DecoHelper::decoRoundedMask( const QRect& r, int left, int right, int top, int bottom ) const { // get rect geometry int x, y, w, h; r.getRect(&x, &y, &w, &h); QRegion mask(x + 3*left, y + 0*top, w-3*(left+right), h-0*(top+bottom)); mask += QRegion(x + 0*left, y + 3*top, w-0*(left+right), h-3*(top+bottom)); mask += QRegion(x + 1*left, y + 1*top, w-1*(left+right), h-1*(top+bottom)); return mask; }
void QArvCamera::setROI(QRect roi) { int x, y, width, height; roi.getRect(&x, &y, &width, &height); auto hmin = getROIHeightBounds(); auto wmin = getROIWidthBounds(); arv_device_set_integer_feature_value(device, "Width", wmin.first); arv_device_set_integer_feature_value(device, "Height", hmin.first); arv_device_set_integer_feature_value(device, "OffsetX", x); arv_device_set_integer_feature_value(device, "OffsetY", y); arv_device_set_integer_feature_value(device, "Width", width); arv_device_set_integer_feature_value(device, "Height", height); emit dataChanged(QModelIndex(), QModelIndex()); }
QRect KisImagePyramid::downsampleByFactor2(const QRect& srcRect, KisPaintDevice* src, KisPaintDevice* dst) { qint32 srcX, srcY, srcWidth, srcHeight; srcRect.getRect(&srcX, &srcY, &srcWidth, &srcHeight); alignRectBy2(srcX, srcY, srcWidth, srcHeight); // Nothing to do if (srcWidth < 1) return QRect(); if (srcHeight < 1) return QRect(); qint32 dstX = srcX / 2; qint32 dstY = srcY / 2; qint32 dstWidth = srcWidth / 2; qint32 dstHeight = srcHeight / 2; KisHLineConstIteratorSP srcIt0 = src->createHLineConstIteratorNG(srcX, srcY, srcWidth); KisHLineConstIteratorSP srcIt1 = src->createHLineConstIteratorNG(srcX, srcY + 1, srcWidth); KisHLineIteratorSP dstIt = dst->createHLineIteratorNG(dstX, dstY, dstWidth); int conseqPixels = 0; for (int row = 0; row < dstHeight; ++row) { do { int srcItConseq = srcIt0->nConseqPixels(); int dstItConseq = dstIt->nConseqPixels(); conseqPixels = qMin(srcItConseq, dstItConseq * 2); Q_ASSERT(!isOdd(conseqPixels)); downsamplePixels(srcIt0->oldRawData(), srcIt1->oldRawData(), dstIt->rawData(), conseqPixels); srcIt1->nextPixels(conseqPixels); dstIt->nextPixels(conseqPixels / 2); } while (srcIt0->nextPixels(conseqPixels)); srcIt0->nextRow(); srcIt0->nextRow(); srcIt1->nextRow(); srcIt1->nextRow(); dstIt->nextRow(); } return QRect(dstX, dstY, dstWidth, dstHeight); }
QRect KisImagePyramid::downsampleByFactor2(const QRect& srcRect, KisPaintDevice* src, KisPaintDevice* dst) { qint32 srcX, srcY, srcWidth, srcHeight; srcRect.getRect(&srcX, &srcY, &srcWidth, &srcHeight); alignRectBy2(srcX, srcY, srcWidth, srcHeight); qint32 dstX = srcX / 2; qint32 dstY = srcY / 2; qint32 dstWidth = srcWidth / 2; qint32 dstHeight = srcHeight / 2; KisHLineConstIteratorPixel srcIt0 = src->createHLineConstIterator(srcX, srcY, srcWidth); KisHLineConstIteratorPixel srcIt1 = src->createHLineConstIterator(srcX, srcY + 1, srcWidth); KisHLineIteratorPixel dstIt = dst->createHLineIterator(dstX, dstY, dstWidth); for (int row = 0; row < dstHeight; ++row) { while (!dstIt.isDone()) { int srcItConseq = srcIt0.nConseqHPixels(); int dstItConseq = dstIt.nConseqHPixels(); int conseqPixels = qMin(srcItConseq, dstItConseq * 2); Q_ASSERT(!isOdd(conseqPixels)); downsamplePixels(srcIt0.rawData(), srcIt1.rawData(), dstIt.rawData(), conseqPixels); srcIt0 += conseqPixels; srcIt1 += conseqPixels; dstIt += conseqPixels / 2; } srcIt0.nextRow(); srcIt0.nextRow(); srcIt1.nextRow(); srcIt1.nextRow(); dstIt.nextRow(); } return QRect(dstX, dstY, dstWidth, dstHeight); }
void ColorButton::paintEvent( QPaintEvent * ) { QPainter painter(this); //First, we need to draw the bevel. QStyleOptionButton butOpt; initStyleOption(&butOpt); style()->drawControl( QStyle::CE_PushButtonBevel, &butOpt, &painter, this ); //OK, now we can muck around with drawing out pretty little color box //First, sort out where it goes QRect labelRect = style()->subElementRect( QStyle::SE_PushButtonContents, &butOpt, this ); int shift = style()->pixelMetric( QStyle::PM_ButtonMargin ); labelRect.adjust(shift, shift, -shift, -shift); int x, y, w, h; labelRect.getRect(&x, &y, &w, &h); if (isChecked() || isDown()) { x += style()->pixelMetric( QStyle::PM_ButtonShiftHorizontal ); y += style()->pixelMetric( QStyle::PM_ButtonShiftVertical ); } QColor fillCol = isEnabled() ? btnColor : palette().color(backgroundRole()); qDrawShadePanel( &painter, x, y, w, h, palette(), true, 1, NULL); if ( fillCol.isValid() ) painter.fillRect( x+1, y+1, w-2, h-2, fillCol ); if ( hasFocus() ) { QRect focusRect = style()->subElementRect( QStyle::SE_PushButtonFocusRect, &butOpt, this ); QStyleOptionFocusRect focusOpt; focusOpt.init(this); focusOpt.rect = focusRect; focusOpt.backgroundColor = palette().background().color(); style()->drawPrimitive( QStyle::PE_FrameFocusRect, &focusOpt, &painter, this ); } }
robotViz::robotViz(QWidget *parent) : QWidget(parent), ui(new Ui::robotViz) { ui->setupUi(this); // ui->customPlot=new Qui->customPlot; QRect rec = QApplication::desktop()->screenGeometry(); int x[1],y[1],w[1],h[1]; rec.getRect(x,y,w,h); setGeometry(x[0]+150,y[0]+25,640,480); // give the axes some labels: ui->customPlot->xAxis->setLabel("x"); ui->customPlot->yAxis->setLabel("y"); // set axes ranges, so we see all data: ui->customPlot->xAxis->setRange(-MAX_AREA/2, MAX_AREA); ui->customPlot->yAxis->setRange(-MAX_AREA/2, MAX_AREA); ui->customPlot->setBackground(Qt::transparent); ui->customPlot->setAttribute(Qt::WA_OpaquePaintEvent, false); ui->customPlot->addGraph(); // red line for traj ui->customPlot->graph(0)->setPen(QPen(Qt::red,2)); ui->customPlot->addGraph(); // blue dot robot position ui->customPlot->graph(1)->setPen(QPen(Qt::blue,2)); ui->customPlot->graph(1)->setLineStyle(QCPGraph::lsNone); ui->customPlot->graph(1)->setScatterStyle(QCPScatterStyle::ssDisc); ui->customPlot->addGraph(); // blue dot robot position ui->customPlot->graph(2)->setPen(QPen(QColor(255, 100, 0),2)); ui->customPlot->graph(2)->setLineStyle(QCPGraph::lsNone); ui->customPlot->graph(2)->setScatterStyle(QCPScatterStyle::ssDisc); }
void ScrollZoomWidget::paintEvent(QPaintEvent * /*paintEvent*/, QPainter & painter) { //draw scroll bar UpdateScrollBarPosition(); //draw slider UpdateSliderPosition(); painter.setPen(Qt::black); //draw increase box { painter.setPen(Qt::black); QRect increaseRect = GetIncreaseRect(); painter.drawRect(increaseRect); int increaseRectX1; int increaseRectY1; int increaseRectX2; int increaseRectY2; increaseRect.getRect(&increaseRectX1, &increaseRectY1, &increaseRectX2, &increaseRectY2); int vertLineX1 = increaseRectX1 + increaseRect.width()/2; int vertLineY1 = increaseRectY1; int vertLineX2 = vertLineX1; int vertLineY2 = increaseRectY1+ increaseRectY2; painter.drawLine(vertLineX1, vertLineY1, vertLineX2, vertLineY2); int horLineX1 = increaseRectX1 ; int horLineY1 = increaseRectY1 + increaseRect.height()/2; int horLineX2 = increaseRectX1 + increaseRectX2; int horLineY2 = horLineY1; painter.drawLine(horLineX1, horLineY1, horLineX2, horLineY2); } //draw scale value { char scaleChar[10]; sprintf(scaleChar, "%.0f", scale * 100); QString scale(scaleChar); painter.setPen(Qt::black); QRect scaleRect(GetScaleRect()); scaleRect.setWidth(SCALE_WIDTH); painter.drawText(scaleRect.bottomLeft(), scale); } //draw decrease box { painter.setPen(Qt::black); QRect decreaseRect = GetDecreaseRect(); painter.drawRect(decreaseRect); int decreaseRectX1; int decreaseRectY1; int decreaseRectX2; int decreaseRectY2; decreaseRect.getRect(&decreaseRectX1, &decreaseRectY1, &decreaseRectX2, &decreaseRectY2); int horLineX1 = decreaseRectX1 ; int horLineY1 = decreaseRectY1 + decreaseRect.height()/2; int horLineX2 = decreaseRectX1 + decreaseRectX2; int horLineY2 = horLineY1; painter.drawLine(horLineX1, horLineY1, horLineX2, horLineY2); } }
KESM_NAMESPACE_START bool Cropper::crop(QString imageName, QRect &rect, QString croppedImageName, bool overWrite) { if(QFile::exists(croppedImageName) && !overWrite) { return false; } ////////////// // reader ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName( imageName.toStdString() ); try { reader->Update(); } catch( itk::ExceptionObject & err ) { std::cerr << "ExceptionObject caught !" << std::endl; std::cerr << err << std::endl; return false; // EXIT_FAILURE; } //////////////////////////////////////////// // !!! LowerBoundar is the top left. // !!! UpperBoundary is the right bottom. // This is very confusing. This may be a bug. ////////////////// // get crop size ImageType::SizeType cropSizeUpper, cropSizeLower; int x, y, width, height; rect.getRect(&x, &y, &width, &height); cropSizeLower[0] = x, cropSizeLower[1] = y; // get input image size ImageType::SizeType imageSize = reader->GetOutput()->GetLargestPossibleRegion().GetSize(); cropSizeUpper[0] = imageSize[0]-(width+x); if(height == -1) // use the image height cropSizeUpper[1] = 0; else cropSizeUpper[1] = imageSize[1]-(height+y); ////////////// // filter FilterType::Pointer filter = FilterType::New(); filter->SetInput(reader->GetOutput()); filter->SetUpperBoundaryCropSize(cropSizeUpper); filter->SetLowerBoundaryCropSize(cropSizeLower); try { filter->Update(); } catch( itk::ExceptionObject & err ) { std::cerr << "ExceptionObject caught !" << std::endl; std::cerr << err << std::endl; return false; // EXIT_FAILURE; } WriterType::Pointer writer = WriterType::New(); writer->SetFileName(croppedImageName.toStdString()); writer->SetInput( filter->GetOutput() ); try { writer->Update(); } catch ( itk::ExceptionObject &err) { std::cerr << "ExceptionObject caught !" << std::endl; std::cerr << err << std::endl; return false; } return true; }
//___________________________________________________________ void TileSet::render(const QRect &r, QPainter *p, Tiles t) const { const bool oldHint( p->testRenderHint( QPainter::SmoothPixmapTransform ) ); if( _stretch ) p->setRenderHint( QPainter::SmoothPixmapTransform, true ); // check initialization if( _pixmaps.size() < 9 ) return; int x0, y0, w, h; r.getRect(&x0, &y0, &w, &h); // calculate pixmaps widths int wLeft(0); int wRight(0); if( _w1+_w3 > 0 ) { qreal wRatio( qreal( _w1 )/qreal( _w1 + _w3 ) ); wLeft = (t&Right) ? qMin( _w1, int(w*wRatio) ):_w1; wRight = (t&Left) ? qMin( _w3, int(w*(1.0-wRatio)) ):_w3; } // calculate pixmap heights int hTop(0); int hBottom(0); if( _h1+_h3 > 0 ) { qreal hRatio( qreal( _h1 )/qreal( _h1 + _h3 ) ); hTop = (t&Bottom) ? qMin( _h1, int(h*hRatio) ):_h1; hBottom = (t&Top) ? qMin( _h3, int(h*(1.0-hRatio)) ):_h3; } // calculate corner locations w -= wLeft + wRight; h -= hTop + hBottom; const int x1 = x0 + wLeft; const int x2 = x1 + w; const int y1 = y0 + hTop; const int y2 = y1 + h; const int w2 = _pixmaps.at(7).width(); const int h2 = _pixmaps.at(5).height(); // corner if( bits(t, Top|Left) ) p->drawPixmap(x0, y0, _pixmaps.at(0), 0, 0, wLeft, hTop); if( bits(t, Top|Right) ) p->drawPixmap(x2, y0, _pixmaps.at(2), _w3-wRight, 0, wRight, hTop); if( bits(t, Bottom|Left) ) p->drawPixmap(x0, y2, _pixmaps.at(6), 0, _h3-hBottom, wLeft, hBottom); if( bits(t, Bottom|Right) ) p->drawPixmap(x2, y2, _pixmaps.at(8), _w3-wRight, _h3-hBottom, wRight, hBottom ); // top and bottom if( w > 0 ) { if (t & Top ) { if( _stretch ) p->drawPixmap(x1, y0, w, hTop, _pixmaps.at(1)); else p->drawTiledPixmap(x1, y0, w, hTop, _pixmaps.at(1)); } if (t & Bottom ) { if( _stretch ) p->drawPixmap(x1, y2, w, hBottom, _pixmaps.at(7), 0, _h3-hBottom, w2, hBottom ); else p->drawTiledPixmap(x1, y2, w, hBottom, _pixmaps.at(7), 0, _h3-hBottom ); } } // left and right if( h > 0 ) { if (t & Left ) { if( _stretch ) p->drawPixmap(x0, y1, wLeft, h, _pixmaps.at(3)); else p->drawTiledPixmap(x0, y1, wLeft, h, _pixmaps.at(3)); } if (t & Right ) { if( _stretch ) p->drawPixmap(x2, y1, wRight, h, _pixmaps.at(5), _w3-wRight, 0, wRight, h2 ); else p->drawTiledPixmap(x2, y1, wRight, h, _pixmaps.at(5), _w3-wRight, 0 ); } } // center if ( (t & Center) && h > 0 && w > 0 ) { if( _stretch ) p->drawPixmap(x1, y1, w, h, _pixmaps.at(4)); else p->drawTiledPixmap(x1, y1, w, h, _pixmaps.at(4)); } if( _stretch ) p->setRenderHint( QPainter::SmoothPixmapTransform, oldHint ); }