12#include "ui_recorderdocker.h"
18#include <klocalizedstring.h>
38#include <QRegularExpression>
48const QString keyActionRecordToggle =
"recorder_record_toggle";
49const QString keyActionExport =
"recorder_export";
51#if QT_VERSION > QT_VERSION_CHECK(6, 0, 0)
52QString activeColorPositive;
53QString activeColorNeutral;
54QString activeColorNegative;
56QString inactiveColorPositive;
57QString inactiveColorNeutral;
58QString inactiveColorNegative;
60QColor textColorNeutral;
61QColor buttonColorNeutral;
62QColor textColorNegative;
63QColor buttonColorNegative;
65const QString activeColorPositive(
"#5cab25");
66const QString activeColorNeutral(
"#ca8f14");
67const QString activeColorNegative(
"#da4453");
68const QString colorNormal(
"#3e3e3e");
69const QString inactiveColorPositive(
"#b4e196");
70const QString inactiveColorNeutral(
"#ffe5af");
71const QString inactiveColorNegative(
"#f2c4c9");
73const QColor textColorNeutral(0xff, 0xe5, 0xaf);
74const QColor buttonColorNeutral(0xca, 0x8f, 0x14);
75const QColor textColorNegative(0xf2, 0xc4, 0xc9);
76const QColor buttonColorNegative(0xda, 0x44, 0x53);
86 QScopedPointer<Ui::RecorderDocker>
ui;
110 bool internalMoveInProgress{
false};
122 ,
ui(new
Ui::RecorderDocker())
141 QSize imageSize =
canvas->image()->size();
144 quint64 totalSize = (quint64)imageSize.width() * (quint64)imageSize.height() * 4;
146 return totalSize <= 2147483647;
154 fixInternalSnapshotDirectory();
191 title = i18nc(
"Title for label. JPEG Quality level",
"Quality:");
192 hint = i18nc(
"@tooltip",
"Greater value will produce a larger file and a better quality. Doesn't affect CPU consumption.\nValues lower than 50 are not recommended due to high artifacts.");
200 title = i18nc(
"Title for label. PNG Compression level",
"Compression:");
201 hint = i18nc(
"@tooltip",
"Greater value will produce a smaller file but will require more from your CPU. Doesn't affect quality.\nCompression set to 0 is not recommended due to high disk space consumption.\nValues above 3 are not recommended due to high performance impact.");
209 ui->comboFormat->setCurrentIndex(index);
210 ui->labelQuality->setText(title);
211 ui->spinQuality->setToolTip(hint);
212 QSignalBlocker blocker(
ui->spinQuality);
213 ui->spinQuality->setMinimum(minValue);
214 ui->spinQuality->setMaximum(maxValue);
215 ui->spinQuality->setValue(factor);
216 ui->spinQuality->setSuffix(suffix);
226 QSignalBlocker blocker(
ui->spinRate);
229 title = i18nc(
"Title for label. Video frames per second",
"Video FPS:");
238 title = i18nc(
"Title for label. Capture rate",
"Capture interval:");
248 ui->labelRate->setText(title);
249 ui->spinRate->setDecimals(decimals);
250 ui->spinRate->setMinimum(minValue);
251 ui->spinRate->setMaximum(maxValue);
252 ui->spinRate->setSuffix(suffix);
274 :
canvas->imageView()->document()->documentInfo()->aboutInfo(
"creation-date").remove(QRegularExpression(
"[^0-9]"));
280 i18nc(
"Use original resolution for the frames when recording the canvas",
"Original"),
281 i18nc(
"Use the resolution two times smaller than the original resolution for the frames when recording the canvas",
"Half"),
282 i18nc(
"Use the resolution four times smaller than the original resolution for the frames when recording the canvas",
"Quarter")
286 for (
int index = 0, len = titles.length(); index < len; ++index) {
287 int divider = 1 << index;
288 items += QString(
"%1 (%2x%3)").arg(titles[index])
289 .arg((width / divider) & ~1)
290 .arg((height / divider) & ~1);
292 QSignalBlocker blocker(
ui->comboResolution);
293 const int currentIndex =
ui->comboResolution->currentIndex();
294 ui->comboResolution->clear();
295 ui->comboResolution->addItems(items);
296 ui->comboResolution->setCurrentIndex(currentIndex);
301 QSignalBlocker blocker(
ui->buttonRecordToggle);
305 ui->buttonRecordToggle->setChecked(isRecording);
307 ui->buttonRecordToggle->setText(isRecording ? i18nc(
"Stop recording the canvas",
"Stop")
308 : i18nc(
"Start recording the canvas",
"Record"));
311 ui->buttonRecordToggle->setEnabled(
true);
312 ui->buttonRecordToggle->setToolTip(
"");
314 ui->buttonRecordToggle->setEnabled(
false);
315 ui->buttonRecordToggle->setToolTip(i18n(
"Image too large to be recorded"));
317 ui->widgetSettings->setEnabled(!isRecording);
339 QString label(
"<font style='letter-spacing:-4px'>");
343 if (threadNr > threads) {
344 threadColor = colorNormal;
346 threadColor = threadNr <= threadsInUse ? activeColorNegative : inactiveColorNegative;
348 threadColor = threadNr <= threadsInUse ? activeColorNeutral : inactiveColorNeutral;
350 threadColor = threadNr <= threadsInUse ? activeColorPositive : inactiveColorPositive;
352 label.append(QString(
"<font color='%1'>▍</font>").arg(threadColor));
355 label.append(QString(
"</font><font> %1 </font><font color='%2'>●</font>")
356 .arg(i18nc(
"Recording symbol",
"REC"))
357 .arg(
paused ?
"" : activeColorNegative));
359 statusBarLabel->setToolTip(
paused ? i18n(
"Recorder is paused") : QString(i18n(
"Active recording with %1 of %2 available threads")).arg(threadsInUse).arg(threads));
378 pal.setColor(QPalette::Text, textColorNegative);
379 pal.setColor(QPalette::Button, buttonColorNegative);
380 ui->spinThreads->setPalette(pal);
381 ui->sliderThreads->setPalette(pal);
382 toolTipText = QString(
383 i18n(
"Set the number of recording threads.\nThe number of threads exceeds the ideal max number of your hardware setup.\nPlease be aware, that a number greater than %1 probably won't give you any performance boost.")
389 pal.setColor(QPalette::Text, textColorNeutral);
390 pal.setColor(QPalette::Button, buttonColorNeutral);
391 ui->spinThreads->setPalette(pal);
392 ui->sliderThreads->setPalette(pal);
393 toolTipText = QString(
394 i18n(
"Set the number of recording threads.\nAccording to your hardware setup you should record with no more than %1 threads.\nYou can play around with one or two more threads, but keep an eye on your overall system performance.")
399 toolTipText = i18n(
"Set the number of threads to be used for recording.");
401 ui->spinThreads->setToolTip(toolTipText);
402 ui->sliderThreads->setToolTip(toolTipText);
406 void fixInternalSnapshotDirectory()
418 q->moveFilesFromInternalSnapshotDirectory();
425 : QDockWidget(i18nc(
"Title of the docker",
"Recorder"))
427 , d(new
Private(*exportSettings, this))
429 QWidget* page =
new QWidget(
this);
430 d->
ui->setupUi(page);
436 d->
ui->sliderThreads->setTickPosition(QSlider::TickPosition::TicksBelow);
437 d->
ui->sliderThreads->setMinimum(1);
439 d->
ui->spinThreads->setMinimum(1);
462 connect(
d->
exportAction, SIGNAL(triggered()),
d->
ui->buttonExport, SIGNAL(clicked()));
463 connect(
d->
ui->buttonRecordToggle, SIGNAL(toggled(
bool)),
d->
ui->buttonExport, SLOT(setDisabled(
bool)));
465 d->
ui->buttonExport->setDisabled(
true);
474 connect(
d->
ui->comboFormat, SIGNAL(currentIndexChanged(
int)),
this, SLOT(
onFormatChanged(
int)));
497 connect(scroller, SIGNAL(stateChanged(QScroller::State)),
504 d->
ui->checkBoxRealTimeCaptureMode->setCheckState(Qt::Unchecked);
505 d->
ui->checkBoxRealTimeCaptureMode->setDisabled(
true);
506 d->
ui->checkBoxRealTimeCaptureMode->setToolTip(
507 i18n(
"Your system is not efficient enough for this feature"));
544 setEnabled(canvas !=
nullptr);
555 connect(
d->
canvas->imageView(),
559 Qt::UniqueConnection);
565 bool wasToggled =
false;
576 bool enabled =
d->
enabledIds.value(document->linkedResourcesStorageId(),
false);
599#if QT_VERSION > QT_VERSION_CHECK(6, 0, 0)
600 connect(window, SIGNAL(themeChanged()),
this, SLOT(
onThemeChanged()));
607#if QT_VERSION > QT_VERSION_CHECK(6, 0, 0)
631 QSignalBlocker blocker(
d->
ui->buttonRecordToggle);
639 d->
ui->buttonRecordToggle->setChecked(
false);
651 const QString &
id =
d->
canvas->imageView()->document()->linkedResourcesStorageId();
653 bool wasEmpty = !
d->
enabledIds.values().contains(
true);
657 bool isEmpty = !
d->
enabledIds.values().contains(
true);
661 if (isEmpty == wasEmpty) {
672 d->
ui->buttonRecordToggle->setEnabled(
false);
714 exportDialog.
setup();
730 dialog.setCaption(i18n(
"Select a Directory for Recordings"));
731 dialog.setDefaultDir(
d->
ui->editDirectory->text());
732 QString directory = dialog.filename();
733 if (!directory.isEmpty()) {
734 d->
ui->editDirectory->setText(directory);
843 if (!valueWasIncreased)
858 QMessageBox::warning(
this, i18nc(
"@title:window",
"Recorder"),
859 i18n(
"The recorder has been stopped due to failure while writing a frame. Please check free disk space and start the recorder again."));
864 QMessageBox::warning(
this, i18nc(
"@title:window",
"Recorder"),
865 i18n(
"Krita was unable to stop the recorder probably. Please try to restart Krita."));
870 d->
showWarning(i18n(
"Low performance warning. The recorder is not able to write all the frames in time during Real Time Capture mode.\nTry to reduce the frame rate for the ffmpeg export or reduce the scaling filtering in the canvas acceleration settings."));
872 d->
showWarning(i18n(
"Low performance warning. The recorder is not able to write all the frames in time.\nTry to increase the capture interval or reduce the scaling filtering in the canvas acceleration settings."));
887void RecorderDockerDock::moveFilesFromInternalSnapshotDirectory()
889 if (!
d->internalMoveInProgress) {
890 const QString &internalPath = RecorderConfig::defaultInternalSnapshotDirectory();
899 qWarning().nospace() <<
"Moving recordings stuck in internal directory '" << internalPath
901 RecorderDockerInternalSnapshotsMover *mover =
904 &RecorderDockerInternalSnapshotsMover::sigMoveFinished,
906 &RecorderDockerDock::slotInternalSnapshotMoveFinished,
907 Qt::QueuedConnection);
908 d->internalMoveInProgress =
true;
909 QThreadPool::globalInstance()->start(mover);
914void RecorderDockerDock::slotInternalSnapshotMoveFinished(
const QString &srcRoot)
916 d->internalMoveInProgress =
false;
919 moveFilesFromInternalSnapshotDirectory();
923RecorderDockerInternalSnapshotsMover::RecorderDockerInternalSnapshotsMover(
const QString &srcRoot,
924 const QString &dstRoot)
930void RecorderDockerInternalSnapshotsMover::run()
932 moveFromInternalSnapshotDirectory(QDir(m_srcRoot), QDir(m_dstRoot));
933 if (!QDir().rmdir(m_srcRoot)) {
934 qWarning().nospace() <<
"Failed to remove root directory '" << m_srcRoot <<
"'";
936 Q_EMIT sigMoveFinished(m_srcRoot);
939void RecorderDockerInternalSnapshotsMover::moveFromInternalSnapshotDirectory(
const QDir &src,
const QDir &dst)
941 for (
const QFileInfo &srcInfo :
src.entryInfoList(FILTERS)) {
942 QString srcName = srcInfo.fileName();
943 QString dstPath = dst.filePath(srcName);
945 if (srcInfo.isDir()) {
947 if (dst.mkpath(dstPath)) {
948 moveFromInternalSnapshotDirectory(QDir(srcInfo.filePath()), QDir(dstPath));
950 qWarning().nospace() <<
"Failed to create directory '" << dstPath <<
"' in '" << dst.path() <<
"'";
955 if (!
src.rmdir(srcName)) {
956 qWarning().nospace() <<
"Failed to remove directory '" << srcName <<
"' in '" <<
src.path() <<
"'";
960 QFile srcFile(srcInfo.filePath());
965 QFile::remove(dstPath);
966 if (!srcFile.rename(dstPath)) {
967 qWarning().nospace() <<
"Error " << srcFile.error() <<
" moving '" << srcFile.fileName() <<
"' to '"
968 << dstPath <<
"': " << srcFile.errorString();
float value(const T *src, size_t ch)
QBrush background(BackgroundRole=NormalBackground) const
QBrush foreground(ForegroundRole=NormalText) const
QAction * makeQAction(const QString &name, QObject *parent=0)
static KisActionRegistry * instance()
A container for a set of QAction objects.
Q_INVOKABLE QAction * addAction(const QString &name, QAction *action)
KisViewManager * viewManager
static KisPart * instance()
void removeExtraWidget(QWidget *widget)
void addExtraWidget(QWidget *widget)
virtual KisKActionCollection * actionCollection() const
double captureInterval() const
QString snapshotDirectory() const
void setFormat(RecorderFormat value)
void setRealTimeCaptureMode(bool value)
bool recordIsolateLayerMode() const
RecorderFormat format() const
void setRecordAutomatically(bool value)
void setResolution(int value)
void setCaptureInterval(double value)
void setSnapshotDirectory(const QString &value)
void setRecordIsolateLayerMode(bool value)
void setFocusedRecord(bool value)
void setCompression(int value)
bool recordAutomatically() const
void setQuality(int value)
bool realTimeCaptureMode() const
bool focusedRecord() const
void setThreads(int value)
bool recordIsolateLayerMode
QPointer< KisCanvas2 > canvas
void showWarning(const QString &hint)
QString snapshotDirectory
void loadRelevantExportSettings()
QPalette threadsSpinPalette
RecorderWriterManager writer
QMap< QString, bool > enabledIds
Private(const RecorderExportSettings &es, RecorderDockerDock *q_ptr)
void updateUiForRealTimeMode()
QScopedPointer< Ui::RecorderDocker > ui
void updateWriterSettings()
void updateRecIndicator()
void updateRecordStatus(bool isRecording)
QAction * recordToggleAction
QLabel * statusBarWarningLabel
RecorderDockerDock *const q
void updateComboResolution(quint32 width, quint32 height)
QPalette threadsSliderPalette
void onDocumentAboutToClose(KoCanvasBase *canvas)
void slotScrollerStateChanged(QScroller::State state)
RecorderExportSettings *const exportSettings
void onManageRecordingsButtonClicked()
void onCaptureIntervalChanged(double interval)
void setCanvas(KoCanvasBase *canvas) override
void onThreadsChanged(int threads)
void onVideoFPSChanged(double interval)
void slotSelectSnapshotDirectory()
void onFocusedCaptureToggled(bool checked)
void onQualityChanged(int value)
void onWriterFrameWriteFailed()
void onRecordIsolateLayerModeToggled(bool checked)
void onUpdateRecIndicator()
void onRealTimeCaptureModeToggled(bool checked)
void unsetCanvas() override
void onResolutionChanged(int resolution)
bool onRecordButtonToggled(bool checked)
void onAutoRecordToggled(bool checked)
void onRecorderStopWarning()
void onActiveRecording(bool valueWasIncreased)
void onMainWindowIsBeingCreated(KisMainWindow *window)
void onLowPerformanceWarning()
void onExportButtonClicked()
void onFormatChanged(int format)
void execFor(const QString &snapshotsDirectory)
void saveState()
Generate a tail and save the recording region.
void start(bool toggleEnabled, bool restoreState)
bool stop(bool toggleEnabled, bool saveState)
void restoreState()
Remove the tail and restore region from a file.
void setCanvas(QPointer< KisCanvas2 > canvas)
void setEnabled(bool enabled)
void setup(const RecorderWriterSettings &settings)
ThreadCounter recorderThreads
unsigned int getUsed() const
QIcon loadIcon(const QString &name)
const unsigned int IdealRecordThreadCount
const unsigned int MaxThreadCount
const unsigned int MaxRecordThreadCount
bool realTimeCaptureModeWasSet