|
@@ -36,6 +36,8 @@ ctkScreenshotDialogPrivate::ctkScreenshotDialogPrivate(ctkScreenshotDialog& obje
|
|
|
{
|
|
|
this->CaptureButton = 0;
|
|
|
this->CountDownValue = 0;
|
|
|
+ this->AspectRatio = 1.0;
|
|
|
+ this->AllowTransparency = true;
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
@@ -68,11 +70,20 @@ void ctkScreenshotDialogPrivate::setupUi(QDialog * widget)
|
|
|
connect(this->ImageVersionNumberSpinBox, SIGNAL(valueChanged(int)), SLOT(updateFullNameLabel()));
|
|
|
connect(this->DelaySpinBox, SIGNAL(valueChanged(int)), SLOT(resetCountDownValue()));
|
|
|
connect(&this->CountDownTimer, SIGNAL(timeout()), SLOT(updateCountDown()));
|
|
|
+ connect(this->ScaleFactorRadioButton, SIGNAL(toggled(bool)), SLOT(selectScaleFactor(bool)));
|
|
|
+ connect(this->OutputResolutionRadioButton, SIGNAL(toggled(bool)), SLOT(selectOutputResolution(bool)));
|
|
|
+ connect(this->LockAspectToolButton, SIGNAL(toggled(bool)), SLOT(lockAspectRatio(bool)));
|
|
|
+ connect(this->WidthSpinBox, SIGNAL(editingFinished()), SLOT(onWidthEdited()));
|
|
|
+ connect(this->HeightSpinBox, SIGNAL(editingFinished()), SLOT(onHeightEdited()));
|
|
|
|
|
|
this->CaptureButton = okButton;
|
|
|
|
|
|
// Called to enable/disable buttons
|
|
|
q->setWidgetToGrab(0);
|
|
|
+ // Set a sufficient range (1, 2^16) on the spin boxes
|
|
|
+ this->WidthSpinBox->setRange(1, 65536);
|
|
|
+ this->HeightSpinBox->setRange(1, 65536);
|
|
|
+ this->DirectoryPathLineEdit->setFilters(ctkPathLineEdit::Dirs);
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
@@ -123,6 +134,113 @@ void ctkScreenshotDialogPrivate::updateCountDown()
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
+void ctkScreenshotDialogPrivate::useScalarFactor(bool scale)
|
|
|
+{
|
|
|
+ this->ScaleFactorSpinBox->setEnabled(scale);
|
|
|
+ this->WidthSpinBox->setEnabled(!scale);
|
|
|
+ this->HeightSpinBox->setEnabled(!scale);
|
|
|
+ this->xLabel->setEnabled(!scale);
|
|
|
+ this->LockAspectToolButton->setEnabled(!scale);
|
|
|
+}
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+void ctkScreenshotDialogPrivate::selectScaleFactor(bool scale)
|
|
|
+{
|
|
|
+ this->useScalarFactor(scale);
|
|
|
+}
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+void ctkScreenshotDialogPrivate::selectOutputResolution(bool scale)
|
|
|
+{
|
|
|
+ this->useScalarFactor(!scale);
|
|
|
+}
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+void ctkScreenshotDialogPrivate::lockAspectRatio(bool lock)
|
|
|
+{
|
|
|
+ Q_Q(ctkScreenshotDialog);
|
|
|
+ if(lock)
|
|
|
+ {
|
|
|
+ QSize curSize = q->widgetSize();
|
|
|
+ if(curSize.height() > 0)
|
|
|
+ {
|
|
|
+ this->AspectRatio = curSize.width()/static_cast<double>(curSize.height());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ QString message = QString("Height of widget: ") + curSize.height() +\
|
|
|
+ QString(" is invalid. Check widget dimensions. Using default aspect\
|
|
|
+ ratio (1.0).");
|
|
|
+ QMessageBox::warning(q, "Invalid widget dimensions", message,
|
|
|
+ QMessageBox::Ok);
|
|
|
+ this->AspectRatio = 1.0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+void ctkScreenshotDialogPrivate::onWidthEdited()
|
|
|
+{
|
|
|
+ Q_Q(ctkScreenshotDialog);
|
|
|
+ if(this->LockAspectToolButton->isChecked())
|
|
|
+ {
|
|
|
+ if(this->AspectRatio > 0)
|
|
|
+ {
|
|
|
+ this->HeightSpinBox->setValue(static_cast<int>(this->WidthSpinBox->value()/this->AspectRatio));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ QString message = QString("Aspect ratio: ") + this->AspectRatio +\
|
|
|
+ QString(" is invalid. Check widget dimensions.");
|
|
|
+ QMessageBox::warning(q, "Invalid aspect ratio", message, QMessageBox::Ok);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+void ctkScreenshotDialogPrivate::onHeightEdited()
|
|
|
+{
|
|
|
+ if(this->LockAspectToolButton->isChecked())
|
|
|
+ {
|
|
|
+ this->WidthSpinBox->setValue(static_cast<int>(this->HeightSpinBox->value()*this->AspectRatio));
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+void ctkScreenshotDialog::enforceResolution(int width, int height)
|
|
|
+{
|
|
|
+ Q_D(ctkScreenshotDialog);
|
|
|
+ d->OutputResolutionRadioButton->setChecked(true);
|
|
|
+ d->useScalarFactor(true);
|
|
|
+ d->ScaleFactorRadioButton->setEnabled(false);
|
|
|
+ d->OutputResolutionRadioButton->setEnabled(false);
|
|
|
+ d->ScaleFactorSpinBox->setEnabled(false);
|
|
|
+ d->WidthSpinBox->setValue(width);
|
|
|
+ d->HeightSpinBox->setValue(height);
|
|
|
+}
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+void ctkScreenshotDialog::enforceResolution(QSize size)
|
|
|
+{
|
|
|
+ this->enforceResolution(size.width(), size.height());
|
|
|
+}
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+QSize ctkScreenshotDialog::widgetSize()
|
|
|
+{
|
|
|
+ Q_D(ctkScreenshotDialog);
|
|
|
+ QPixmap viewportPixmap = QPixmap::grabWidget(d->WidgetToGrab.data());
|
|
|
+ return viewportPixmap.size();
|
|
|
+}
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+void ctkScreenshotDialog::enableTransparency(bool enable)
|
|
|
+{
|
|
|
+ Q_D(ctkScreenshotDialog);
|
|
|
+ d->AllowTransparency = enable;
|
|
|
+}
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
void ctkScreenshotDialogPrivate::saveScreenshot(int delayInSeconds)
|
|
|
{
|
|
|
Q_Q(ctkScreenshotDialog);
|
|
@@ -140,7 +258,7 @@ void ctkScreenshotDialogPrivate::saveScreenshot(int delayInSeconds)
|
|
|
this->setWaitingForScreenshot(true);
|
|
|
this->CountDownValue = delayInSeconds;
|
|
|
this->CountDownTimer.start(1000);
|
|
|
- // Add 1ms to give time to set the countdown at 0.
|
|
|
+ // Add 1ms to give time to set the countdown at 0.
|
|
|
QTimer::singleShot(delayInSeconds * 1000 + 1, q, SLOT(instantScreenshot()));
|
|
|
}
|
|
|
|
|
@@ -170,6 +288,9 @@ void ctkScreenshotDialog::setWidgetToGrab(QWidget* newWidgetToGrab)
|
|
|
d->CaptureButton->setEnabled(newWidgetToGrab != 0);
|
|
|
|
|
|
d->WidgetToGrab = newWidgetToGrab;
|
|
|
+ QSize curSize = this->widgetSize();
|
|
|
+ d->HeightSpinBox->setValue(curSize.height());
|
|
|
+ d->WidthSpinBox->setValue(curSize.width());
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
@@ -197,14 +318,14 @@ QString ctkScreenshotDialog::baseFileName() const
|
|
|
void ctkScreenshotDialog::setDirectory(const QString& newDirectory)
|
|
|
{
|
|
|
Q_D(ctkScreenshotDialog);
|
|
|
- d->DirectoryButton->setDirectory(newDirectory);
|
|
|
+ d->DirectoryPathLineEdit->setCurrentPath(newDirectory);
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
QString ctkScreenshotDialog::directory()const
|
|
|
{
|
|
|
Q_D(const ctkScreenshotDialog);
|
|
|
- return d->DirectoryButton->directory();
|
|
|
+ return d->DirectoryPathLineEdit->currentPath();
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
@@ -247,12 +368,22 @@ void ctkScreenshotDialog::instantScreenshot()
|
|
|
d->setWaitingForScreenshot(false);
|
|
|
d->resetCountDownValue();
|
|
|
|
|
|
- // Rescale
|
|
|
- QPixmap rescaledViewportPixmap = viewportPixmap.scaled(
|
|
|
+ // Rescale based on scale factor or output resolution specified
|
|
|
+ QPixmap rescaledViewportPixmap = viewportPixmap;
|
|
|
+ if(d->ScaleFactorRadioButton->isChecked())
|
|
|
+ {
|
|
|
+ rescaledViewportPixmap = viewportPixmap.scaled(
|
|
|
viewportPixmap.size().width() * d->ScaleFactorSpinBox->value(),
|
|
|
viewportPixmap.size().height() * d->ScaleFactorSpinBox->value());
|
|
|
+ }
|
|
|
+ else if(d->OutputResolutionRadioButton->isChecked())
|
|
|
+ {
|
|
|
+ rescaledViewportPixmap = viewportPixmap.scaled(
|
|
|
+ d->WidthSpinBox->value(),
|
|
|
+ d->HeightSpinBox->value());
|
|
|
+ }
|
|
|
|
|
|
- QString filename = QString("%1/%2_%3.png").arg(d->DirectoryButton->directory())
|
|
|
+ QString filename = QString("%1/%2_%3.png").arg(d->DirectoryPathLineEdit->currentPath())
|
|
|
.arg(d->ImageNameLineEdit->text())
|
|
|
.arg(d->ImageVersionNumberSpinBox->value());
|
|
|
|
|
@@ -278,7 +409,13 @@ void ctkScreenshotDialog::instantScreenshot()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- rescaledViewportPixmap.save(filename);
|
|
|
+ QImage img = rescaledViewportPixmap.toImage();
|
|
|
+ if( !d->AllowTransparency &&
|
|
|
+ img.hasAlphaChannel())
|
|
|
+ {
|
|
|
+ img = img.convertToFormat(QImage::Format_RGB32);
|
|
|
+ }
|
|
|
+ img.save(filename);
|
|
|
|
|
|
d->ImageVersionNumberSpinBox->setValue(d->ImageVersionNumberSpinBox->value() + 1);
|
|
|
}
|