/** * 功能 * 当前单元格子元素布局 */ void WinDigitalDelegate::doLayout(const QStyleOptionViewItem & option, QRectF &valRect, QRectF &unitRect, QRectF &tagRect, QRectF &alarmRect, qreal &alarmSpan) const { /***********测量值***********/ valRect = option.rect; valRect.setHeight(valRect.height()/3); valRect.moveTop(valRect.bottom()); valRect.setRight(valRect.right() - valRect.width()/18- 3); /************标记**********/ tagRect = valRect; tagRect.moveBottom(tagRect.top()); tagRect.setTop(tagRect.top() + option.rect.height()/10); /************单位***********/ unitRect = valRect; unitRect.moveTop(unitRect.bottom()); unitRect.setRight(unitRect.right() - 15); /*************报警标记**********/ alarmRect = unitRect; alarmRect.setHeight(alarmRect.height()/3); alarmRect.moveTop(alarmRect.bottom()); alarmRect.setLeft(alarmRect.center().x() - 4*alarmRect.height()); alarmRect.setWidth(alarmRect.height()); alarmSpan = alarmRect.width() * 2; }
// The draw function for unspecified is so easy, just calculate the clone marker without a singleShape() drawing function QPainterPath SimpleChemEPN::clone_marker() const { QPainterPath p_front, p_back, p_clone; // this glyph has to be cirular: qreal draw_width = width(); if ( height() < width()) draw_width = height(); QRectF cloneRect = QRectF( -draw_width/2, -draw_width/2, draw_width, draw_width*0.7 ); if (this->multimer == true) { QPainterPath p_front2, p_back2; p_clone.setFillRule(Qt::WindingFill); p_front.addEllipse( -draw_width/2, -draw_width/2, draw_width-GLYPH_PADDING, draw_width-GLYPH_PADDING ); p_back.addRect(cloneRect); p_clone.addPath(p_front.subtracted(p_back)); cloneRect.moveTop( -draw_width/2+GLYPH_PADDING ); p_front2.addEllipse( -draw_width/2+GLYPH_PADDING, -draw_width/2+GLYPH_PADDING, draw_width-GLYPH_PADDING, draw_width-GLYPH_PADDING ); p_back2.addRect(cloneRect); p_clone.addPath(p_front2.subtracted(p_back2)); } else { p_front.addEllipse( -draw_width/2, -draw_width/2, draw_width, draw_width ); p_back.addRect(cloneRect); p_clone = p_front.subtracted(p_back); } return p_clone; }
// slot void PrintWidget::printAreaMoved() { QRectF area = map_printer->getPrintArea(); area.moveLeft(left_edit->value()); area.moveTop(-top_edit->value()); // Flip sign! map_printer->setPrintArea(area); }
QPainterPath ComplexEPN::clone_marker() const { QPainterPath p_clone, p_front, p_back; int indent = 10; // indent on the width/height for the cut-off corners QRectF cloneRect = QRectF( -width()/2, -height()/2, width(), height()*0.7 ); if (this->multimer == true) { p_front = ComplexEPN::frontMultimerShape( width(), height(), indent ); p_back.addRect(cloneRect); p_clone = p_front.subtracted(p_back); QPainterPath p_front2, p_back2; p_front2 = ComplexEPN::backMultimerShape( width(), height(), indent ); cloneRect.moveTop( -height()/2+GLYPH_PADDING ); p_back2.addRect(cloneRect); p_clone.setFillRule(Qt::WindingFill); p_clone.addPath(p_front2.subtracted(p_back2)); } else { p_front = ComplexEPN::singleShape( width(), height(), indent ); p_back.addRect(cloneRect); p_clone = p_front.subtracted(p_back); } return p_clone; }
void EditorView::mouseMoveEvent(QMouseEvent *event) { if (mWheelPressed) { if (mMouseOldPosition != QPointF()) { QRectF rect = sceneRect(); qreal dx = (event->posF().x() - mMouseOldPosition.x()); qreal dy = (event->posF().y() - mMouseOldPosition.y()); rect.moveLeft(rect.left() - dx); rect.moveTop(rect.top() - dy); setSceneRect(rect); } mMouseOldPosition = event->posF(); } QGraphicsView::mouseMoveEvent(event); if (event->buttons() & Qt::RightButton) { setDragMode(NoDrag); } else { if (event->buttons() & Qt::LeftButton ) { UML::EdgeElement *newEdgeEl = dynamic_cast<UML::EdgeElement *>(itemAt(event->pos())); if (newEdgeEl == NULL) { setDragMode(RubberBandDrag); } else { if (newEdgeEl->isBreakPointPressed()) { newEdgeEl->breakPointUnpressed(); setDragMode(NoDrag); } } } } if (mScene->getNeedDrawGrid()) mScene->invalidate(); }
void EditorView::mouseMoveEvent(QMouseEvent *event) { if (mWheelPressed) { if (mMouseOldPosition != QPointF()) { QRectF rect = sceneRect(); qreal dx = (event->localPos().x() - mMouseOldPosition.x()); qreal dy = (event->localPos().y() - mMouseOldPosition.y()); rect.moveLeft(rect.left() - dx); rect.moveTop(rect.top() - dy); setSceneRect(rect); translate(dx, dy); } mMouseOldPosition = event->localPos(); } QGraphicsView::mouseMoveEvent(event); if (event->buttons() & Qt::RightButton) { setDragMode(NoDrag); } else { if ((event->buttons() & Qt::LeftButton) && (event->modifiers() & Qt::ControlModifier)) { setDragMode(RubberBandDrag); mScene->itemSelectUpdate(); /*} else if ((event->buttons() & Qt::LeftButton) && (event->modifiers() & Qt::ShiftModifier)) { setDragMode(ScrollHandDrag); // (see #615) mScene->itemSelectUpdate();*/ } else if (event->buttons() & Qt::LeftButton ) { EdgeElement *newEdgeEl = dynamic_cast<EdgeElement *>(itemAt(event->pos())); if (newEdgeEl && newEdgeEl->isBreakPointPressed()) { newEdgeEl->breakPointUnpressed(); setDragMode(NoDrag); } } } if (mScene->getNeedDrawGrid()) mScene->invalidate(); }
void NodeInspector::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option); Q_UNUSED(widget); const auto r = boundingRect().adjusted(border, border, -border, -border); if (glow) { painter->setBrush(Qt::NoBrush); painter->setPen(QPen(QColor(255, 255, 255, Colors::base02.red()), 20)); painter->drawRoundedRect(r, 8, 8); } painter->setBrush(Colors::base01); painter->setPen(Qt::NoPen); painter->drawRoundedRect(r, 8, 8); painter->setBrush(Colors::base03); QRectF br = title_row->boundingRect(); br.setWidth(r.width()); br.setHeight(br.height() + 2); painter->drawRoundedRect(br, 8, 8); br.setHeight(br.height()/2); br.moveTop(br.height()); painter->drawRect(br); painter->setBrush(Qt::NoBrush); if (isSelected()) painter->setPen(QPen(Colors::base05, 2)); else painter->setPen(QPen(Colors::base03, 2)); painter->drawRoundedRect(r, 8, 8); }
QVariant PixmapItem::itemChange(GraphicsItemChange change, const QVariant &value) { if (change == ItemPositionChange) { // value is the new position. QPointF newPos = value.toPointF(); QRectF rect = parentItem()->boundingRect(); rect.moveLeft(boundingRect().width()*3/4*-1); rect.setWidth(rect.width() + boundingRect().width()*2/4 ); rect.moveTop(boundingRect().height()*3/4*-1); rect.setHeight(rect.height() + boundingRect().height()*2/4 ); CardItem *card = qgraphicsitem_cast<CardItem *>(parentItem()); if (!rect.contains(newPos)) { // Keep the item inside the scene rect. int newX = (int)qMin(rect.right(), qMax(newPos.x(), rect.left())); int newY = (int)qMin(rect.bottom(), qMax(newPos.y(), rect.top())); if(card->isAlign()) { int gridSize = card->getGridSize(); newX = (newX/(10*gridSize))*(10*gridSize); newY = (newY/(10*gridSize))*(10*gridSize); } newPos.setX(newX); newPos.setY(newY); return newPos; } else { int newX = newPos.x(); int newY = newPos.y(); if(card->isAlign()) { int gridSize = card->getGridSize(); newX = newPos.x()/(10*gridSize); newX = newX * (10*gridSize); newY = newPos.y()/(10*gridSize); newY = newY*(10*gridSize); } newPos.setX(newX); newPos.setY(newY); return newPos; } } return QGraphicsItem::itemChange(change, value); }
void TextDocumentAdapter::PaintPage (QPainter *painter, int page) { const auto& size = Doc_->pageSize (); QRectF rect (QPointF (0, 0), size); rect.moveTop (rect.height () * page); Doc_->drawContents (painter, rect); }
void ShapeSideBar::onYChanged(int y) { if (d->rectLayer) { QRectF rect = d->rectLayer->rect(); rect.moveTop(y); layerScene()->setLayerProperty(d->rectLayer, rect, RoleRect, tr("Change Rectangle y")); } }
void relayoutExtender() { if (!m_extenders.contains(q->scene()) || !m_extenders[q->scene()] || q != m_extenders[q->scene()]->parentItem()) return; QRectF geometry = QRectF(QPointF(0, 0), q->size()); // extender()->borders = Plasma::FrameSvg::AllBorders; borders = Plasma::FrameSvg::AllBorders; switch (extenderPosition) { case TopExtender: geometry.setHeight(EXTENDER_SIZE); geometry.moveTop(- EXTENDER_SIZE); // borders &= ~ Plasma::FrameSvg::TopBorder; // extender()->borders &= ~ Plasma::FrameSvg::BottomBorder; break; case BottomExtender: geometry.moveTop(geometry.bottom()); geometry.setHeight(EXTENDER_SIZE); // borders &= ~ Plasma::FrameSvg::BottomBorder; // extender()->borders &= ~ Plasma::FrameSvg::TopBorder; break; case LeftExtender: geometry.setWidth(EXTENDER_SIZE); geometry.moveLeft(- EXTENDER_SIZE); // borders &= ~ Plasma::FrameSvg::LeftBorder; // extender()->borders &= ~ Plasma::FrameSvg::RightBorder; break; case RightExtender: geometry.moveLeft(geometry.right()); geometry.setWidth(EXTENDER_SIZE); // borders &= ~ Plasma::FrameSvg::RightBorder; // extender()->borders &= ~ Plasma::FrameSvg::LeftBorder; break; case NoExtender: break; } extender()->setGeometry(geometry); extender()->setPreferredSize(geometry.size()); // qreal left, top, right, bottom; // q->getContentsMargins(&left, &top, &right, &bottom); }
// QtPluginIconPalletTool Interface void dmz::QtPluginIconPalletTool::_add_type (const ObjectType &Type) { const String IconResource = config_to_string ( get_plugin_name () + ".resource", Type.get_config()); const String IconName = _rc.find_file (IconResource); if (IconName) { const String Name = Type.get_name (); if (Name) { QImage back ( (int)_iconExtent, (int)_iconExtent, QImage::Format_ARGB32_Premultiplied); QPainter painter (&back); painter.setCompositionMode (QPainter::CompositionMode_Source); painter.fillRect (back.rect (), Qt::transparent); painter.setCompositionMode (QPainter::CompositionMode_SourceOver); QSvgRenderer qsr (QString (IconName.get_buffer ())); QRectF size = qsr.viewBoxF (); qreal width = size.width (); qreal height = size.height (); qreal scale = (width > height) ? width : height; if (scale <= 0.0f) { scale = 1.0f; } scale = _iconExtent / scale; width *= scale; height *= scale; size.setWidth (width); size.setHeight (height); if (height < _iconExtent) { size.moveTop ((_iconExtent - height) * 0.5f); } if (width < _iconExtent) { size.moveLeft ((_iconExtent - width) * 0.5f); } qsr.render (&painter, size); painter.end (); QIcon icon; icon.addPixmap (QPixmap::fromImage (back)); QStandardItem *item = new QStandardItem (icon, Name.get_buffer ()); item->setEditable (false); _model.appendRow (item); } } else if (IconResource) { _log.error << "Unable to find icon resource: " << IconResource << " for object type: " << Type.get_name () << endl; } RuntimeIterator it; ObjectType next; while (Type.get_next_child (it, next)) { _add_type (next); } }
void GraphNode::setCenter(const QPointF& pt) { cx = pt.x(); cy = pt.y(); QRectF newRect = rect(); newRect.moveLeft(cx - r); newRect.moveTop(cy - r); setRect(newRect); }
foreach(QReportWidgetBase *widget, _selectedWidgets) { QRectF widgetRect = _widgetRects[widget]; QSizeF sizeby( rc.width() / selectionRect.width(), rc.height() / selectionRect.height()); widgetRect.moveTop(widgetRect.top() - selectionRect.top()); widgetRect.moveLeft(widgetRect.left() - selectionRect.left()); widgetRect.setTop(widgetRect.top() *sizeby.height()); widgetRect.setBottom(widgetRect.bottom() *sizeby.height()); widgetRect.setLeft(widgetRect.left() *sizeby.width()); widgetRect.setRight(widgetRect.right() *sizeby.width()); widgetRect.moveTop(widgetRect.top() + rc.top()); widgetRect.moveLeft(widgetRect.left() + rc.left()); widgetRect.moveTopLeft(widget->parentItem()->mapFromScene(widgetRect.topLeft())); widget->setPos(widgetRect.topLeft()); widget->setSize(widgetRect.width(), widgetRect.height()); }
QList<QRectF> Mode4::locate() { QList<QRectF> results; if (rect.height() > 360){ return results; } QSize size = ARender::instance()->getActualSize(); QRectF init = rect; init.moveCenter(QPointF(size.width() / 2.0, 0)); init.moveBottom(size.height()*(Config::getValue("/Danmaku/Protect", false) ? 0.85 : 1)); int stp = Config::getValue("/Danmaku/Grating", 10); for (int height = init.top(); height >= 0; height -= stp){ init.moveTop(height); results.append(init); } return results; }
QList<QRectF> Mode6::locate() { QList<QRectF> results; if (rect.height() > 360){ return results; } QSize size = ARender::instance()->getActualSize(); QRectF init = rect; init.moveRight(0); int end = size.height()*(Config::getValue("/Danmaku/Protect", false) ? 0.85 : 1) - rect.height(); int stp = Config::getValue("/Danmaku/Grating", 10); for (int height = 0; height <= end; height += stp){ init.moveTop(height); results.append(init); } return results; }
void QGraphicsVolumeView::moveToVolume(int i) { if (i >= _volumeDisplays.size()) { return; } QGraphicsPixmapItem* firstItem = _volumeDisplays[i].GetSliceData<QGraphicsPixmapItem>(0); if (firstItem == NULL) { return; } QRect contentsRect = viewport()->contentsRect(); QPolygonF visibleScene = mapToScene(contentsRect); QRectF visibleRect = visibleScene.boundingRect(); QPointF firstPosition = firstItem->pos(); visibleRect.moveTop(firstPosition.y()); this->ensureVisible(visibleRect, 0, 0); // QPoint displacement = mapFromScene(0, firstPosition.y() - visibleRect.top()); // this->scroll(0, displacement.y()); }
QRectF PrintJob::preparePage(int pageNumber) { int sheetPageNumber = pageNumber; Sheet* sheet = d->getSheetPageNumber(&sheetPageNumber); if (!sheet) return QRectF(); // Move the painter offset according to the page layout. const double scale = POINT_TO_INCH(printer().resolution()); const KoPageLayout pageLayout = sheet->printSettings()->pageLayout(); painter().translate(pageLayout.left * scale, pageLayout.top * scale); // Apply the print zoom factor, const double zoom = d->printManager(sheet)->zoom(); painter().scale(zoom, zoom); // Prepare the page for shape printing. const QRect cellRange = d->printManager(sheet)->cellRange(sheetPageNumber); QRectF pageRect = sheet->cellCoordinatesToDocument(cellRange); painter().translate(-pageRect.left() * scale, -pageRect.top() * scale); // Center the table on the page. if (sheet->printSettings()->centerHorizontally()) { const double printWidth = sheet->printSettings()->printWidth(); // FIXME respect repeated columns const double offset = 0.5 * (printWidth / zoom - pageRect.width()); painter().translate(offset * scale, 0.0); pageRect.moveLeft(offset); // scale will be applied below } if (sheet->printSettings()->centerVertically()) { const double printHeight = sheet->printSettings()->printHeight(); // FIXME respect repeated rows const double offset = 0.5 * (printHeight / zoom - pageRect.height()); painter().translate(0.0, offset * scale); pageRect.moveTop(offset); // scale will be applied below } return QRectF(pageRect.left() * scale, pageRect.top() * scale, pageRect.width() * scale, pageRect.height() * scale); }
QImage DocumentAdapter::RenderPage (int page, double xScale, double yScale) { const auto& size = Doc_->pageSize (); auto imgSize = size.toSize (); imgSize.rwidth () *= xScale; imgSize.rheight () *= yScale; QImage image (imgSize, QImage::Format_ARGB32); image.fill (Qt::white); QRectF rect (QPointF (0, 0), size); rect.moveTop (rect.height () * page); QPainter painter; painter.begin (&image); painter.scale (xScale, yScale); painter.translate (0, rect.height () * (-page)); Doc_->drawContents (&painter, rect); painter.end (); return image; }
void paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*) { FullScreenTheme::RenderInfo info = FullScreenTheme::renderInfo(FullScreenTheme::CountDownWidget); painter->setRenderHint(QPainter::Antialiasing); const int circle = 5760; const int start = circle / 4; // Start at 12h, not 3h const int end = int(circle * mValue); painter->setBrush(info.bgBrush); painter->setPen(info.borderPen); QRectF square = boundingRect().adjusted(.5, .5, -.5, -.5); qreal width = square.width(); qreal height = square.height(); if (width < height) { square.setHeight(width); square.moveTop((height - width) / 2); } else { square.setWidth(height); square.moveLeft((width - height) / 2); } painter->drawPie(square, start, end); }
void QWaterfallWidget::__drawWaterfall(QPainter &painter) { float widthF = (float)rect().width() / m_columns; float heightF = (float)rect().height() / m_rows; float posX = 0.0, posY = 0.0; QRectF rectF = QRectF(0.0, 0.0, widthF, heightF); painter.setPen(Qt::NoPen); int temp; for(int i = 0; i < m_rows; i++) { rectF.moveTop(posY); posX = 0.0; for(int j = 0; j < m_columns; j++) { rectF.moveLeft(posX); temp = m_data[i][j]*1023; temp = (temp > 1023) ? 1023 : temp; temp = (temp < 0) ? 0 : temp; painter.setBrush(v_lookupTable[temp]); painter.drawRect(rectF); posX += widthF; } posY += heightF; } }
QRectF QgsComposerItem::evalItemRect( const QRectF &newRect, const bool resizeOnly, const QgsExpressionContext *context ) { QRectF result = newRect; //TODO QGIS 3.0 //maintain pre 2.12 API. remove when API break allowed QgsExpressionContext scopedContext = createExpressionContext(); const QgsExpressionContext *evalContext = context ? context : &scopedContext; //data defined position or size set? if so, update rect with data defined values bool ok = false; double ddWidth = mDataDefinedProperties.valueAsDouble( QgsComposerObject::ItemWidth, *evalContext, 0, &ok ); //evaulate width and height first, since they may affect position if non-top-left reference point set if ( ok ) { result.setWidth( ddWidth ); } double ddHeight = mDataDefinedProperties.valueAsDouble( QgsComposerObject::ItemHeight, *evalContext, 0, &ok ); if ( ok ) { result.setHeight( ddHeight ); } double x = result.left(); //initially adjust for position mode to get x coordinate if ( !resizeOnly ) { //adjust x-coordinate if placement is not done to a left point if ( mLastUsedPositionMode == UpperMiddle || mLastUsedPositionMode == Middle || mLastUsedPositionMode == LowerMiddle ) { x += newRect.width() / 2.0; } else if ( mLastUsedPositionMode == UpperRight || mLastUsedPositionMode == MiddleRight || mLastUsedPositionMode == LowerRight ) { x += newRect.width(); } } else { if ( mLastUsedPositionMode == UpperMiddle || mLastUsedPositionMode == Middle || mLastUsedPositionMode == LowerMiddle ) { x += rect().width() / 2.0; } else if ( mLastUsedPositionMode == UpperRight || mLastUsedPositionMode == MiddleRight || mLastUsedPositionMode == LowerRight ) { x += rect().width(); } } double ddPosX = mDataDefinedProperties.valueAsDouble( QgsComposerObject::PositionX, *evalContext, 0.0, &ok ); if ( ok ) { x = ddPosX; } double y = result.top(); //initially adjust for position mode to get y coordinate if ( !resizeOnly ) { //adjust y-coordinate if placement is not done to an upper point if ( mLastUsedPositionMode == MiddleLeft || mLastUsedPositionMode == Middle || mLastUsedPositionMode == MiddleRight ) { y += newRect.height() / 2.0; } else if ( mLastUsedPositionMode == LowerLeft || mLastUsedPositionMode == LowerMiddle || mLastUsedPositionMode == LowerRight ) { y += newRect.height(); } } else { if ( mLastUsedPositionMode == MiddleLeft || mLastUsedPositionMode == Middle || mLastUsedPositionMode == MiddleRight ) { y += rect().height() / 2.0; } else if ( mLastUsedPositionMode == LowerLeft || mLastUsedPositionMode == LowerMiddle || mLastUsedPositionMode == LowerRight ) { y += rect().height(); } } double ddPosY = mDataDefinedProperties.valueAsDouble( QgsComposerObject::PositionY, *evalContext, 0, &ok ); if ( ok ) { y = ddPosY; } //adjust x-coordinate if placement is not done to a left point if ( mLastUsedPositionMode == UpperMiddle || mLastUsedPositionMode == Middle || mLastUsedPositionMode == LowerMiddle ) { x -= result.width() / 2.0; } else if ( mLastUsedPositionMode == UpperRight || mLastUsedPositionMode == MiddleRight || mLastUsedPositionMode == LowerRight ) { x -= result.width(); } //adjust y-coordinate if placement is not done to an upper point if ( mLastUsedPositionMode == MiddleLeft || mLastUsedPositionMode == Middle || mLastUsedPositionMode == MiddleRight ) { y -= result.height() / 2.0; } else if ( mLastUsedPositionMode == LowerLeft || mLastUsedPositionMode == LowerMiddle || mLastUsedPositionMode == LowerRight ) { y -= result.height(); } result.moveLeft( x ); result.moveTop( y ); return result; }
void SingleCellViewGraphPanelPlotWidget::drawCoordinates(QPainter *pPainter, const QPointF &pCoordinates, const QColor &pBackgroundColor, const QColor &pForegroundColor, const Location &pLocation, const bool &pCanMoveLocation) { // Retrieve the size of coordinates as they will appear on the screen, // which means using the same font as the one used for the axes pPainter->setFont(axisFont(QwtPlot::xBottom)); QString coords = QString("(%1, %2)").arg(QString::number(pCoordinates.x()), QString::number(pCoordinates.y())); QRect desktopGeometry = qApp->desktop()->availableGeometry(); QRectF coordsRect = pPainter->boundingRect(QRectF(0.0, 0.0, desktopGeometry.width(), desktopGeometry.height()), coords); // Determine where the coordinates and its background should be drawn QPoint coordinates = QPoint(canvasMap(QwtPlot::xBottom).transform(pCoordinates.x()), canvasMap(QwtPlot::yLeft).transform(pCoordinates.y())); switch (pLocation) { case TopLeft: coordsRect.moveTo(coordinates.x()-coordsRect.right()-1, coordinates.y()-coordsRect.bottom()-1); break; case TopRight: coordsRect.moveTo(coordinates.x()+2, coordinates.y()-coordsRect.bottom()-1); break; case BottomLeft: coordsRect.moveTo(coordinates.x()-coordsRect.right()-1, coordinates.y()+2); break; case BottomRight: coordsRect.moveTo(coordinates.x()+2, coordinates.y()+2); break; } if (pCanMoveLocation) { if (coordsRect.top() < 0) coordsRect.moveTop(coordinates.y()+2); if (coordsRect.left() < 0) coordsRect.moveLeft(coordinates.x()+2); if (coordsRect.bottom() > plotLayout()->canvasRect().height()) coordsRect.moveTop(coordinates.y()-coordsRect.height()-1); if (coordsRect.right() > plotLayout()->canvasRect().width()) coordsRect.moveLeft(coordinates.x()-coordsRect.width()-1); } // Draw a filled rectangle to act as the background of the coordinates // we are to show pPainter->fillRect(coordsRect, pBackgroundColor); // Draw the text for the coordinates, using a white pen QPen pen = pPainter->pen(); pen.setColor(pForegroundColor); pPainter->setPen(pen); pPainter->drawText(coordsRect, coords); }
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) { alphaGradient.setColorAt(0, QColor(0, 0, 0, 255)); alphaGradient.setColorAt(1, QColor(0, 0, 0, 0)); p.drawText(bufferPixmap.rect(), Qt::AlignLeft|Qt::AlignVCenter|Qt::TextShowMnemonic, nativeWidget()->text()); } else { alphaGradient.setColorAt(0, QColor(0, 0, 0, 0)); alphaGradient.setColorAt(1, QColor(0, 0, 0, 255)); p.drawText(bufferPixmap.rect(), Qt::AlignRight|Qt::AlignVCenter|Qt::TextShowMnemonic, nativeWidget()->text()); } p.setCompositionMode(QPainter::CompositionMode_DestinationIn); p.fillRect(bufferPixmap.rect(), alphaGradient); painter->drawPixmap(rect.topLeft(), bufferPixmap); } else { painter->setFont(font()); painter->drawText(rect, Qt::AlignCenter|Qt::TextShowMnemonic, nativeWidget()->text()); } }
void PanelAppletOverlay::mouseMoveEvent(QMouseEvent *event) { if (!m_layout || !m_applet) { //kDebug() << "no layout"; return; } const int margin = 9; if (m_applet->inherits("PanelSpacer")) { if (m_applet->formFactor() == Plasma::Horizontal) { if (event->pos().x() < margin || event->pos().x() > m_applet->size().width() - margin) { setCursor(Qt::SizeHorCursor); } else { setCursor(Qt::ArrowCursor); } } else if (m_applet->formFactor() == Plasma::Vertical) { if (event->pos().y() < margin || event->pos().y() > m_applet->size().height() - margin) { setCursor(Qt::SizeVerCursor); } else { setCursor(Qt::ArrowCursor); } } } if (!m_clickDrag && !(event->buttons() & Qt::LeftButton)) { //kDebug() << "no left button and we aren't click dragging"; return; } Plasma::FormFactor f = m_applet->formFactor(); if (!m_applet->inherits("PanelSpacer") && (((f != Plasma::Horizontal && f != Plasma::Vertical) && rect().intersects(m_applet->rect().toRect())) || ((f == Plasma::Horizontal || f == Plasma::Vertical) && !rect().contains(event->globalPos()))) ) { Plasma::View *view = Plasma::View::topLevelViewAt(event->globalPos()); //kDebug() << "checking view" << view << m_applet->view(); if (!view) { view = dynamic_cast<Plasma::View*>(parent()); } if (!view) { return; } if (view != m_applet->view() && (event->buttons() & Qt::LeftButton)) { Plasma::Containment *c = view->containment(); if (!c) { return; } syncOrientation(); syncGeometry(); if (m_spacer) { if (m_layout) { m_layout->removeItem(m_spacer); } m_spacer->deleteLater(); m_spacer = 0; } QPointF pos = c->view()->mapFromGlobal(event->globalPos()); QRectF g = m_applet->geometry(); pos += QPoint(m_offset, m_offset); g.moveTo(pos); m_applet->setGeometry(g); m_layout = 0; c->addApplet(m_applet, pos, true); m_applet->flushPendingConstraintsEvents(); m_applet->setPos(pos); releaseMouse(); emit moved(this); return; } } else if (m_applet->inherits("PanelSpacer") && m_dragAction != Move) { if (m_applet->formFactor() == Plasma::Horizontal) { if (m_dragAction == LeftResize) { int fixedWidth = m_applet->size().width()+(m_lastGlobalPos.x() - event->globalPos().x()); m_applet->setPos(m_applet->pos().x()-(fixedWidth-m_applet->size().width()), m_applet->pos().y()); m_applet->setMinimumWidth(fixedWidth); m_applet->setMaximumWidth(fixedWidth); } else if (m_dragAction == RightResize) { int fixedWidth = m_applet->size().width()-(m_lastGlobalPos.x() - event->globalPos().x()); m_applet->setMinimumWidth(fixedWidth); m_applet->setMaximumWidth(fixedWidth); } } else if (m_applet->formFactor() == Plasma::Vertical) { if (m_dragAction == LeftResize) { int fixedHeight = m_applet->size().height()+(m_lastGlobalPos.y() - event->globalPos().y()); m_applet->setPos(m_applet->pos().x(), m_applet->pos().y()-(fixedHeight-m_applet->size().height())); m_applet->setMinimumHeight(fixedHeight); m_applet->setMaximumHeight(fixedHeight); } else if (m_dragAction == RightResize) { int fixedHeight = m_applet->size().height()-(m_lastGlobalPos.y() - event->globalPos().y()); m_applet->setMinimumHeight(fixedHeight); m_applet->setMaximumHeight(fixedHeight); } } m_lastGlobalPos = event->globalPos(); return; } if (!m_spacer) { m_spacer = new AppletMoveSpacer(m_applet); m_spacer->setMinimumSize(m_applet->geometry().size()); m_spacer->setMaximumSize(m_applet->geometry().size()); if (m_layout) { m_layout->removeItem(m_applet); m_layout->insertItem(m_index, m_spacer); } } QPoint p = mapToParent(event->pos()); QRectF g = m_applet->geometry(); //kDebug() << p << g << "<-- movin'?"; if (m_orientation == Qt::Horizontal) { g.moveLeft(p.x() + m_offset); } else { g.moveTop(p.y() + m_offset); } m_applet->setGeometry(g); //FIXME: assumption on how panel containment works, presence of a non applet spacer in last position (if they were swapped would be impossible to save and restore) if ((m_index > 0 && m_layout->itemAt(m_index - 1)) || m_index == 0) { const bool prevIsApplet = dynamic_cast<Plasma::Applet*>(m_layout->itemAt(m_index - 1)) != 0; const bool nextIsApplet = dynamic_cast<Plasma::Applet*>(m_layout->itemAt(m_index + 1)) != 0; QPointF mousePos = event->pos() + g.topLeft(); // swap items if we pass completely over the next/previous item or cross // more than halfway across it, whichever comes first if (m_orientation == Qt::Horizontal) { //kDebug() << prevIsApplet << m_prevGeom << g << nextIsApplet << m_nextGeom; if (QApplication::layoutDirection() == Qt::RightToLeft) { if (prevIsApplet && m_prevGeom.isValid() && mousePos.x() >= m_prevGeom.right()) { swapWithPrevious(); } else if (nextIsApplet && m_nextGeom.isValid() && mousePos.x() <= m_nextGeom.left()) { swapWithNext(); } } else if (prevIsApplet && m_prevGeom.isValid() && mousePos.x() <= m_prevGeom.left()) { swapWithPrevious(); } else if (nextIsApplet && m_nextGeom.isValid() && mousePos.x() >= m_nextGeom.right()) { swapWithNext(); } } else if (prevIsApplet && m_prevGeom.isValid() && mousePos.y() <= m_prevGeom.top()) { swapWithPrevious(); } else if (nextIsApplet && m_nextGeom.isValid() && mousePos.y() >= m_nextGeom.bottom()) { swapWithNext(); } } m_lastGlobalPos = event->globalPos(); //kDebug() << "================================="; }
void PrintWidget::centerOnMap(QRectF& area) const { QRectF map_extent = map->calculateExtent(false, show_templates_check->isChecked(), main_view); area.moveLeft(map_extent.center().x() - 0.5f * area.width()); area.moveTop(map_extent.center().y() - 0.5f * area.height()); }
void QcMultiSlider::paintEvent( QPaintEvent *e ) { using namespace QtCollider::Style; using QtCollider::Style::Ellipse; using QtCollider::Style::RoundRect; Q_UNUSED(e); QPainter p(this); p.setRenderHint( QPainter::Antialiasing, true ); RoundRect frame(rect(), 2); drawSunken( &p, palette(), frame, background(), hasFocus() ? focusColor() : QColor() ); if( !_values.count() ) return; p.setRenderHint( QPainter::Antialiasing, false ); bool horiz = ort == Qt::Horizontal; QRect bounds( contentsRect() ); p.setClipRect( bounds ); if( horiz ) { p.translate( bounds.topLeft() ); p.rotate(90); p.scale(1.0, -1.0); bounds.setSize( QSize( bounds.height(), bounds.width() ) ); } else { p.translate( bounds.left(), bounds.top() + bounds.height() ); p.scale(1.0, -1.0); } int count = _values.count() - startIndex; double spacing, width, yscale; spacing = elastic ? (double) bounds.width() / count : thumbSize.width() + gap; width = elastic ? qMin( spacing, (double) thumbSize.width() ) : thumbSize.width(); yscale = bounds.height(); if( !isFilled ) yscale -= thumbSize.height(); const QColor & fillClr = fillColor(); // selection if( highlight ) { int i = _currentIndex - startIndex; int c = qMin( count - i, _selectionSize ); if(c) { QRect r; r.setHeight( bounds.height() ); r.setWidth( c * spacing ); r.moveLeft( i * spacing ); QColor hlColor = fillClr; hlColor.setAlpha( 70 ); p.fillRect( r, hlColor ); } } p.setPen( strokeColor() ); // lines if( drawLines ) { bool fill = isFilled & !drawRects; p.save(); p.setRenderHint( QPainter::Antialiasing, true ); p.translate( spacing * 0.5, isFilled ? 0.0 : thumbSize.height() * 0.5 ); p.scale( 1.0, (qreal) yscale ); if( fill ) p.setBrush( fillClr ); QPainterPath path; // value line path.moveTo( 0, _values[startIndex] ); for( int i = 1; i < count; ++i ) path.lineTo( (qreal) i * spacing, _values[i + startIndex] ); // reference line int refcount = _ref.count() - startIndex; if( refcount > 0 || fill ) { qreal x, y; int i = count - 1; x = i * spacing; y = i < refcount ? _ref[i + startIndex] : 0.f; if( fill ) path.lineTo(x, y); else path.moveTo(x, y); while( --i >= 0 ) { x = i * spacing; y = i < refcount ? _ref[i + startIndex] : 0.f; path.lineTo(x, y); } if( fill ) path.closeSubpath(); } p.drawPath( path ); p.restore(); } // rects if( drawRects ) { p.setRenderHint( QPainter::Antialiasing, false ); p.translate( (spacing - width) * 0.5, 0 ); p.setBrush( fillClr ); QRectF r; r.setWidth( width ); if( isFilled ) { int refcount = _ref.count() - startIndex; for( int i = 0; i < count; ++i ) { int ref = (i < refcount ? _ref[i + startIndex] : 0.f) * yscale; int val = _values[i + startIndex] * yscale; r.moveLeft( i * spacing ); r.moveTop( ref ); r.setHeight( val - ref ); if(horiz) p.drawRect(r.normalized().adjusted(0,0,-1,-1)); else p.drawRect(r.normalized().adjusted(0,1,-1,0)); } } else { r.setHeight( thumbSize.height() ); for( int i = 0; i < count; ++i ) { r.moveLeft( i * spacing ); r.moveTop( _values[i + startIndex] * yscale ); if(horiz) p.drawRect(r.adjusted(0,0,-1,-1)); else p.drawRect(r.adjusted(0,1,-1,0)); } } } }
void CreateMode::drawControls(QPainter* p) { if (!inItemCreation) return; QPointF topLeft(createObjectPos.x(), createObjectPos.y()); QPointF btRight(canvasCurrCoord.x(), canvasCurrCoord.y()); QColor drawColor = qApp->palette().color(QPalette::Active, QPalette::Highlight); if (createObjectMode != modeDrawLine) { QRectF bounds = QRectF(topLeft, btRight).normalized(); //Lock Height to Width for Control Modifier for region drawing if (modifiers==Qt::ControlModifier) { bounds.setHeight(bounds.width()); if (btRight.y()<topLeft.y()) bounds.moveBottom(topLeft.y()); if (btRight.x()<topLeft.x() && btRight.y()>topLeft.y()) bounds.moveTop(topLeft.y()); } QRect localRect = m_canvas->canvasToLocal(bounds); if (localRect.width() <= 0 || localRect.height() <= 0) return; p->setRenderHint(QPainter::Antialiasing); p->save(); p->setPen(QPen(drawColor, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); drawColor.setAlpha(64); p->setBrush(drawColor); p->drawRect(localRect); drawColor.setAlpha(255); p->setBrush(Qt::NoBrush); p->setPen(QPen(drawColor, 1, Qt::DashLine, Qt::FlatCap, Qt::MiterJoin)); int frameType = 0, itemType = 0; getFrameItemTypes(itemType, frameType); if (frameType == PageItem::Ellipse) { p->drawEllipse(localRect); } else if (createObjectMode == modeDrawArc) { QPainterPath path; path.moveTo(localRect.width() / 2.0, localRect.height() / 2.0); path.arcTo(0.0, 0.0, localRect.width(), localRect.height(), m_doc->itemToolPrefs().arcStartAngle, m_doc->itemToolPrefs().arcSweepAngle); path.closeSubpath(); p->translate(localRect.left(), localRect.top()); p->drawPath(path); } else if (createObjectMode == modeDrawRegularPolygon) { QPainterPath path = RegularPolygonPath(localRect.width(), localRect.height(), m_doc->itemToolPrefs().polyCorners, m_doc->itemToolPrefs().polyUseFactor, m_doc->itemToolPrefs().polyFactor, m_doc->itemToolPrefs().polyRotation, m_doc->itemToolPrefs().polyCurvature, m_doc->itemToolPrefs().polyInnerRot, m_doc->itemToolPrefs().polyOuterCurvature); p->translate(localRect.left(), localRect.top()); p->drawPath(path); } else if (createObjectMode == modeDrawSpiral) { QPainterPath path = SpiralPath(localRect.width(), localRect.height(), m_doc->itemToolPrefs().spiralStartAngle, m_doc->itemToolPrefs().spiralEndAngle, m_doc->itemToolPrefs().spiralFactor); p->translate(localRect.left(), localRect.top()); p->drawPath(path); } else if ((createObjectMode == modeDrawShapes) && (createObjectSubMode > 1)) { FPointArray poly; int valCount = m_doc->ValCount; double *vals = m_doc->ShapeValues; for (int a = 0; a < valCount-3; a += 4) { if (vals[a] < 0) { poly.setMarker(); continue; } double x1 = localRect.width() * vals[a] / 100.0; double y1 = localRect.height() * vals[a+1] / 100.0; double x2 = localRect.width() * vals[a+2] / 100.0; double y2 = localRect.height() * vals[a+3] / 100.0; poly.addPoint(x1, y1); poly.addPoint(x2, y2); } QPainterPath path = poly.toQPainterPath(false); p->translate(localRect.left(), localRect.top()); p->drawPath(path); } p->restore(); } else { QPoint p1 = m_canvas->canvasToLocal(topLeft); QPoint p2 = m_canvas->canvasToLocal(btRight); p->save(); p->setPen(QPen(drawColor, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); p->setBrush(drawColor); p->drawLine(p1, p2); p->restore(); } }
QRectF QgsComposerItem::evalItemRect( const QRectF &newRect, const bool resizeOnly, const QgsExpressionContext* context ) { QRectF result = newRect; //TODO QGIS 3.0 //maintain pre 2.12 API. remove when API break allowed QScopedPointer< QgsExpressionContext > scopedContext; const QgsExpressionContext* evalContext = context; if ( !evalContext ) { scopedContext.reset( createExpressionContext() ); evalContext = scopedContext.data(); } //data defined position or size set? if so, update rect with data defined values QVariant exprVal; //evaulate width and height first, since they may affect position if non-top-left reference point set if ( dataDefinedEvaluate( QgsComposerObject::ItemWidth, exprVal, *evalContext ) ) { bool ok; double width = exprVal.toDouble( &ok ); QgsDebugMsg( QString( "exprVal Width:%1" ).arg( width ) ); if ( ok && !exprVal.isNull() ) { result.setWidth( width ); } } if ( dataDefinedEvaluate( QgsComposerObject::ItemHeight, exprVal, *evalContext ) ) { bool ok; double height = exprVal.toDouble( &ok ); QgsDebugMsg( QString( "exprVal Height:%1" ).arg( height ) ); if ( ok && !exprVal.isNull() ) { result.setHeight( height ); } } double x = result.left(); //initially adjust for position mode to get x coordinate if ( !resizeOnly ) { //adjust x-coordinate if placement is not done to a left point if ( mLastUsedPositionMode == UpperMiddle || mLastUsedPositionMode == Middle || mLastUsedPositionMode == LowerMiddle ) { x += newRect.width() / 2.0; } else if ( mLastUsedPositionMode == UpperRight || mLastUsedPositionMode == MiddleRight || mLastUsedPositionMode == LowerRight ) { x += newRect.width(); } } else { if ( mLastUsedPositionMode == UpperMiddle || mLastUsedPositionMode == Middle || mLastUsedPositionMode == LowerMiddle ) { x += rect().width() / 2.0; } else if ( mLastUsedPositionMode == UpperRight || mLastUsedPositionMode == MiddleRight || mLastUsedPositionMode == LowerRight ) { x += rect().width(); } } if ( dataDefinedEvaluate( QgsComposerObject::PositionX, exprVal, *evalContext ) ) { bool ok; double positionX = exprVal.toDouble( &ok ); QgsDebugMsg( QString( "exprVal Position X:%1" ).arg( positionX ) ); if ( ok && !exprVal.isNull() ) { x = positionX; } } double y = result.top(); //initially adjust for position mode to get y coordinate if ( !resizeOnly ) { //adjust y-coordinate if placement is not done to an upper point if ( mLastUsedPositionMode == MiddleLeft || mLastUsedPositionMode == Middle || mLastUsedPositionMode == MiddleRight ) { y += newRect.height() / 2.0; } else if ( mLastUsedPositionMode == LowerLeft || mLastUsedPositionMode == LowerMiddle || mLastUsedPositionMode == LowerRight ) { y += newRect.height(); } } else { if ( mLastUsedPositionMode == MiddleLeft || mLastUsedPositionMode == Middle || mLastUsedPositionMode == MiddleRight ) { y += rect().height() / 2.0; } else if ( mLastUsedPositionMode == LowerLeft || mLastUsedPositionMode == LowerMiddle || mLastUsedPositionMode == LowerRight ) { y += rect().height(); } } if ( dataDefinedEvaluate( QgsComposerObject::PositionY, exprVal, *evalContext ) ) { bool ok; double positionY = exprVal.toDouble( &ok ); QgsDebugMsg( QString( "exprVal Position Y:%1" ).arg( positionY ) ); if ( ok && !exprVal.isNull() ) { y = positionY; } } //adjust x-coordinate if placement is not done to a left point if ( mLastUsedPositionMode == UpperMiddle || mLastUsedPositionMode == Middle || mLastUsedPositionMode == LowerMiddle ) { x -= result.width() / 2.0; } else if ( mLastUsedPositionMode == UpperRight || mLastUsedPositionMode == MiddleRight || mLastUsedPositionMode == LowerRight ) { x -= result.width(); } //adjust y-coordinate if placement is not done to an upper point if ( mLastUsedPositionMode == MiddleLeft || mLastUsedPositionMode == Middle || mLastUsedPositionMode == MiddleRight ) { y -= result.height() / 2.0; } else if ( mLastUsedPositionMode == LowerLeft || mLastUsedPositionMode == LowerMiddle || mLastUsedPositionMode == LowerRight ) { y -= result.height(); } result.moveLeft( x ); result.moveTop( y ); return result; }
QSGNode* MDeclarativeStatusBar::updatePaintNode(QSGNode* oldNode, UpdatePaintNodeData*) { QSGGeometryNode* node = static_cast<QSGGeometryNode*>(oldNode); if (!node) { node = new QSGGeometryNode; node->setFlags(QSGNode::OwnsGeometry | QSGNode::OwnsMaterial | QSGNode::OwnsOpaqueMaterial); node->setGeometry(new QSGGeometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4)); } if (!sharedPixmapHandle) { node->setMaterial(new QSGFlatColorMaterial); node->setOpaqueMaterial(new QSGFlatColorMaterial); node->markDirty(QSGNode::DirtyMaterial); return node; } if (!sharedTexture || updateSharedTexture) { node->setMaterial(new QSGTextureMaterial); node->setOpaqueMaterial(new QSGTextureMaterial); #if defined(HAVE_XLIB) MDeclarativeScreen* screen = MDeclarativeScreen::instance(); #if defined(QT_OPENGL_ES_2) static PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES"); static PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC) eglGetProcAddress("eglCreateImageKHR"); static PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC) eglGetProcAddress("eglDestroyImageKHR"); static PFNEGLQUERYIMAGENOKPROC eglQueryImageNOK = (PFNEGLQUERYIMAGENOKPROC) eglGetProcAddress("eglQueryImageNOK"); const EGLint attribs[] = { EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE }; EGLDisplay eglDpy = eglGetDisplay((EGLNativeDisplayType)screen->display()); EGLImageKHR img = eglCreateImageKHR(eglDpy, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, (EGLClientBuffer)sharedPixmapHandle, attribs); GLuint textureId; glGenTextures(1, &textureId); glBindTexture(GL_TEXTURE_2D, textureId); glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, (GLeglImageOES)img); GLint width = 0; GLint height = 0; eglQueryImageNOK(eglDpy, img, EGL_WIDTH, &width); eglQueryImageNOK(eglDpy, img, EGL_HEIGHT, &height); sharedTexture.reset(canvas()->createTextureFromId(textureId, QSize(width, height), QQuickCanvas::TextureOwnsGLTexture)); eglDestroyImageKHR(eglDpy, img); #else Display* dpy = screen->display(); Window dummy1; int x, y; unsigned int width, height, borderwidth, depth; XGetGeometry(dpy, sharedPixmapHandle, &dummy1, &x, &y, &width, &height, &borderwidth, &depth); XImage* xi = XGetImage(dpy, sharedPixmapHandle, 0, 0, width, height, ULONG_MAX, ZPixmap); QImage img = MX11Wrapper::qimageFromXImage(xi); XDestroyImage(xi); sharedTexture.reset(canvas()->createTextureFromImage(img)); #endif #endif // HAVE_XLIB static_cast<QSGTextureMaterial*>(node->material())->setTexture(sharedTexture.data()); static_cast<QSGOpaqueTextureMaterial*>(node->opaqueMaterial())->setTexture(sharedTexture.data()); node->markDirty(QSGNode::DirtyMaterial); updateSharedTexture = false; } QRectF sourceRect; sourceRect = QRectF(0, 0, width(), height()); if (mOrientation == MDeclarativeScreen::Portrait || mOrientation == MDeclarativeScreen::PortraitInverted) sourceRect.moveTop(height()); sourceRect = sharedTexture.data()->convertToNormalizedSourceRect(sourceRect); QRect targetRect(x(), y(), width(), height()); QSGGeometry::updateTexturedRectGeometry(node->geometry(), targetRect, sourceRect); node->markDirty(QSGNode::DirtyGeometry); return node; }