MCPcopy Create free account
hub / github.com/KDE/labplot / exportToClipboard

Method exportToClipboard

src/frontend/worksheet/WorksheetView.cpp:2256–2285  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2254}
2255
2256void WorksheetView::exportToClipboard() {
2257 QRectF sourceRect;
2258
2259 if (m_selectedItems.size() == 0) {
2260 sourceRect = scene()->itemsBoundingRect();
2261 sourceRect = QRect(0, 0, sourceRect.width() + sourceRect.x(), sourceRect.height());
2262 } else {
2263 // export selection
2264 // Union the bounding rectangles of selected items
2265 for (const auto* item : m_selectedItems) {
2266 QRectF itemRect = item->mapToScene(item->boundingRect()).boundingRect();
2267 sourceRect = sourceRect.united(itemRect);
2268 }
2269 }
2270 int w = Worksheet::convertFromSceneUnits(sourceRect.width(), Worksheet::Unit::Millimeter);
2271 int h = Worksheet::convertFromSceneUnits(sourceRect.height(), Worksheet::Unit::Millimeter);
2272 w = w * GuiTools::dpi(this).first / (GSL_CONST_CGS_INCH * Worksheet::convertToSceneUnits(1, Worksheet::Unit::Millimeter));
2273 h = h * GuiTools::dpi(this).second / (GSL_CONST_CGS_INCH * Worksheet::convertToSceneUnits(1, Worksheet::Unit::Millimeter));
2274 QImage image(QSize(w, h), QImage::Format_ARGB32_Premultiplied);
2275 image.fill(Qt::transparent);
2276 QRectF targetRect(0, 0, w, h);
2277
2278 QPainter painter;
2279 painter.begin(&image);
2280 painter.setRenderHint(QPainter::Antialiasing);
2281 exportPaint(&painter, targetRect, sourceRect, true);
2282 painter.end();
2283
2284 QApplication::clipboard()->setImage(image, QClipboard::Clipboard);
2285}
2286
2287void WorksheetView::exportPaint(QPainter* painter, const QRectF& targetRect, const QRectF& sourceRect, const bool background, const bool selection) {
2288 // hide the magnification window, shouldn't be exported

Callers

nothing calls this directly

Calls 8

xMethod · 0.80
heightMethod · 0.80
setImageMethod · 0.80
sizeMethod · 0.45
widthMethod · 0.45
boundingRectMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected