Showing the changes to interface/src/Application.cpp (1 of 1 file). Show all
Unified · Split
| @@ -5444,51 +5444,65 @@ void Application::takeSnapshot(bool notify, const QString& format, float aspectR · 5443 unmodified lines | ||
| 5444 | 5444 | player->setMedia(QUrl::fromLocalFile(inf.absoluteFilePath())); |
| 5445 | 5445 | player->play(); |
| 5446 | 5446 | |
| 5447 | − GifWriter _animatedSnapshotGifWriter; | |
| 5448 | − uint8_t _currentAnimatedSnapshotFrame = 0; | |
| 5449 | − QString path; | |
| 5450 | 5447 | |
| 5451 | 5448 | // If this is a still snapshot... |
| 5452 | 5449 | if (!format.compare("still")) |
| 5453 | 5450 | { |
| 5454 | − // Get a screenshot and save it. and - this part of the code has been around for a while | |
| 5455 | − path = Snapshot::saveSnapshot(getActiveDisplayPlugin()->getScreenshot(aspectRatio)); | |
| 5451 | + // Get a screenshot and save it | |
| 5452 | + QString path = Snapshot::saveSnapshot(getActiveDisplayPlugin()->getScreenshot(aspectRatio)); | |
| 5453 | + // Notify the window scripting interface that we've taken a Snapshot | |
| 5454 | + emit DependencyManager::get<WindowScriptingInterface>()->snapshotTaken(path, notify); | |
| 5456 | 5455 | } |
| 5457 | 5456 | // If this is an animated snapshot (GIF)... |
| 5458 | 5457 | else if (!format.compare("animated")) |
| 5459 | 5458 | { |
| 5459 | + GifWriter _animatedSnapshotGifWriter; | |
| 5460 | + uint8_t _currentAnimatedSnapshotFrame = 0; | |
| 5461 | + // File path stuff -- lots of this is temporary | |
| 5462 | + // until I figure out how to save the .GIF to the same location as the still .JPG | |
| 5460 | 5463 | char* cstr; |
| 5461 | − // File path stuff | |
| 5462 | − path = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); | |
| 5463 | − path.append(QDir::separator()); | |
| 5464 | − path.append("test.gif"); | |
| 5465 | − string fname = path.toStdString(); | |
| 5466 | − cstr = new char[fname.size() + 1]; | |
| 5467 | − strcpy(cstr, fname.c_str()); | |
| 5468 | − | |
| 5469 | − connect(&animatedSnapshotTimer, &QTimer::timeout, [&] { | |
| 5464 | + QString path = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); // Get the desktop | |
| 5465 | + path.append(QDir::separator()); // Add the dir separator to the desktop location | |
| 5466 | + path.append("test.gif"); // Add "test.gif" to the path | |
| 5467 | + string fname = path.toStdString(); // Turn the QString into a regular string | |
| 5468 | + cstr = new char[fname.size() + 1]; // Create a new character array to hold the .GIF file location | |
| 5469 | + strcpy(cstr, fname.c_str()); // Copy the string into a character array | |
| 5470 | + | |
| 5471 | + // Connect the animatedSnapshotTimer QTimer to the lambda slot function | |
| 5472 | + connect(&animatedSnapshotTimer, &QTimer::timeout, [&]() { | |
| 5473 | + // If this is the last frame... | |
| 5470 | 5474 | if (_currentAnimatedSnapshotFrame == SNAPSNOT_ANIMATED_NUM_FRAMES) |
| 5471 | 5475 | { |
| 5476 | + // Stop the snapshot QTimer | |
| 5472 | 5477 | animatedSnapshotTimer.stop(); |
| 5478 | + // Write out the end of the GIF | |
| 5473 | 5479 | GifEnd(&_animatedSnapshotGifWriter); |
| 5480 | + // Notify the Window Scripting Interface that the snapshot was taken | |
| 5474 | 5481 | emit DependencyManager::get<WindowScriptingInterface>()->snapshotTaken(path, false); |
| 5475 | 5482 | return; |
| 5476 | 5483 | } |
| 5477 | 5484 | |
| 5478 | − QImage frame = (getActiveDisplayPlugin()->getScreenshot(aspectRatio)).scaledToWidth(SNAPSNOT_ANIMATED_WIDTH).convertToFormat(QImage::Format_RGBA8888); | |
| 5485 | + // Get a screenshot from the display, then scale the screenshot down, | |
| 5486 | + // then convert it to the image format the GIF library needs, | |
| 5487 | + // then save all that to the QImage named "frame" | |
| 5488 | + QImage frame = (qApp->getActiveDisplayPlugin()->getScreenshot(aspectRatio)).scaledToWidth(SNAPSNOT_ANIMATED_WIDTH).convertToFormat(QImage::Format_RGBA8888); | |
| 5489 | + | |
| 5490 | + // If this is the first frame... | |
| 5479 | 5491 | if (_currentAnimatedSnapshotFrame == 0) |
| 5480 | 5492 | { |
| 5493 | + // Write out the header and beginning of the GIF file | |
| 5481 | 5494 | GifBegin(&_animatedSnapshotGifWriter, cstr, frame.width(), frame.height(), SNAPSNOT_ANIMATED_FRAME_DELAY); |
| 5482 | 5495 | } |
| 5483 | 5496 | |
| 5497 | + // Write the frame to the gif | |
| 5484 | 5498 | GifWriteFrame(&_animatedSnapshotGifWriter, (uint8_t*)frame.bits(), frame.width(), frame.height(), SNAPSNOT_ANIMATED_FRAME_DELAY); |
| 5499 | + // Increment the current snapshot frame count | |
| 5485 | 5500 | _currentAnimatedSnapshotFrame++; |
| 5486 | 5501 | }); |
| 5502 | + | |
| 5503 | + // Start the animatedSnapshotTimer QTimer | |
| 5487 | 5504 | animatedSnapshotTimer.start(SNAPSNOT_ANIMATED_FRAME_DELAY * 10); |
| 5488 | 5505 | } |
| 5489 | − | |
| 5490 | − // Notify the window scripting interface that we've taken a Snapshot | |
| 5491 | − emit DependencyManager::get<WindowScriptingInterface>()->snapshotTaken(path, notify); | |
| 5492 | 5506 | }); |
| 5493 | 5507 | } |
| 5494 | 5508 | void Application::shareSnapshot(const QString& path) { |