From e13128122c127a5e937d8950ed05ec5e18cb940d Mon Sep 17 00:00:00 2001 From: Mark Watkins Date: Thu, 10 Apr 2014 02:14:41 +1000 Subject: [PATCH] Fixed F12 screenshot ability for Mac --- sleepyhead/docs/update_notes.html | 2 +- sleepyhead/mainwindow.cpp | 29 ++++++++++++----------------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/sleepyhead/docs/update_notes.html b/sleepyhead/docs/update_notes.html index 81fabc8a..9a74779e 100644 --- a/sleepyhead/docs/update_notes.html +++ b/sleepyhead/docs/update_notes.html @@ -7,7 +7,7 @@ Changes in this version
-
  • Added ability to pin Event and Flow waveform graphs
  • +
  • Added ability to pin graphs
  • Fixed tranlation loading on Mac
  • Updated Dutch Tranlsations (Thanks Arie)
  • Fixed overview graph legends showing wrong details
  • diff --git a/sleepyhead/mainwindow.cpp b/sleepyhead/mainwindow.cpp index b4ef8900..901493e5 100644 --- a/sleepyhead/mainwindow.cpp +++ b/sleepyhead/mainwindow.cpp @@ -95,7 +95,7 @@ MainWindow::MainWindow(QWidget *parent) : // Disable Screenshot on Mac Platform,as it doesn't work, and the system provides this functionality anyway. #ifdef Q_OS_MAC - ui->action_Screenshot->setVisible(false); + // ui->action_Screenshot->setVisible(false); #endif overview=NULL; @@ -736,31 +736,26 @@ void MainWindow::on_action_Screenshot_triggered() } void MainWindow::DelayedScreenshot() { -//#ifdef Q_OS_MAC -// CGImageRef windowImage = CGWindowListCreateImage(imageBounds, singleWindowListOptions, windowID, imageOptions); -// originalPixmap = new QPixmap(QPixmap::fromMacCGImageRef(windowImage)); + int w=width(); + int h=height(); + // Scale for high resolution displays (like Retina) + qreal pr=devicePixelRatio(); + w/=pr; + h/=pr; + + QPixmap pixmap=QPixmap::grabWindow(this->winId(),x(),y(),w,h); -// CGImageRef img = CGDisplayCreateImageForRect(displayID, *rect); -// CFMutableDataRef imgData = CFDataCreateMutable(0, 0); -// CGImageDestinationRef imgDst = CGImageDestinationCreateWithData(imgData, kUTTypeJPEG2000, 1, 0); -// CGImageDestinationAddImage(imgDst, img, 0); -// CGImageDestinationFinalize(imgDst); -// CFRelease(imgDst); -// QPixmap pixmap=QPixmap::fromMacCGImageRef(img); -//#else - QPixmap pixmap = QPixmap::grabWindow(this->winId()); -//#endif QString a=PREF.Get("{home}/Screenshots"); QDir dir(a); if (!dir.exists()){ dir.mkdir(a); } - a+="/screenshot-"+QDateTime::currentDateTime().toString(Qt::ISODate)+".jpg"; + a+="/screenshot-"+QDateTime::currentDateTime().toString(Qt::ISODate)+".png"; + qDebug() << "Saving screenshot to" << a; - if (pixmap.save(a)) { - Notify(tr("There was an error saving screenshot to file \"%1\"").arg(QDir::toNativeSeparators(a))); + if (!pixmap.save(a)) { Notify(tr("There was an error saving screenshot to file \"%1\"").arg(QDir::toNativeSeparators(a))); } }