MCPcopy Index your code
hub / github.com/DreamSourceLab/DSView / on_screenShot

Method on_screenShot

DSView/pv/mainwindow.cpp:525–593  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

523 }
524
525 void MainWindow::on_screenShot()
526 {
527 AppConfig &app = AppConfig::Instance();
528 QString default_name = app.userHistory.screenShotPath + "/" + APP_NAME + QDateTime::currentDateTime().toString("-yyMMdd-hhmmss");
529
530 int x = parentWidget()->pos().x();
531 int y = parentWidget()->pos().y();
532 int w = parentWidget()->frameGeometry().width();
533 int h = parentWidget()->frameGeometry().height();
534
535 (void)h;
536 (void)w;
537 (void)x;
538 (void)y;
539
540#ifdef _WIN32
541 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
542 QPixmap pixmap = QGuiApplication::primaryScreen()->grabWindow(QApplication::desktop->winId(), x, y, w, h);
543 #else
544 QPixmap pixmap = QPixmap::grabWidget(parentWidget());
545 #endif
546#elif __APPLE__
547 x += MainFrame::Margin;
548 y += MainFrame::Margin;
549 w -= MainFrame::Margin * 2;
550 h -= MainFrame::Margin * 2;
551
552 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
553 QPixmap pixmap = QGuiApplication::primaryScreen()->grabWindow(winId(), x, y, w, h);
554 #else
555 QDesktopWidget *desktop = QApplication::desktop();
556 int curMonitor = desktop->screenNumber(this);
557 QPixmap pixmap = QGuiApplication::screens().at(curMonitor)->grabWindow(winId(), x, y, w, h);
558 #endif
559#else
560 QPixmap pixmap = QGuiApplication::primaryScreen()->grabWindow(winId());
561#endif
562
563 QString format = "png";
564 QString fileName = QFileDialog::getSaveFileName(
565 this,
566 L_S(STR_PAGE_DLG, S_ID(IDS_DLG_SAVE_AS), "Save As"),
567 default_name,
568 "png file(*.png);;jpeg file(*.jpeg)",
569 &format);
570
571 if (!fileName.isEmpty())
572 {
573 QStringList list = format.split('.').last().split(')');
574 QString suffix = list.first();
575
576 QFileInfo f(fileName);
577 if (f.suffix().compare(suffix))
578 {
579 //tr
580 fileName += "." + suffix;
581 }
582

Callers

nothing calls this directly

Calls 2

GetDirectoryNameFunction · 0.85
SaveHistoryMethod · 0.80

Tested by

no test coverage detected