Commit c5f9059d authored by Hans-Christian Ebke's avatar Hans-Christian Ebke

Viewer snapshot dialog usability improvements.

The viewer snapshot dialog now automatically suggests file names that don't
exist yet. If names of existing files are entered, a warning is displayed in
real time. If non-writable paths are entered, a warning is displayed as well.


git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@20952 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 25ace02a
......@@ -390,35 +390,107 @@ void CoreWidget::slotExaminerSnapshot() {
}
}
///Take a snapshot of the whole application
void CoreWidget::applicationSnapshotDialog() {
static QString suggestSnapshotFilename(QString mostRecentPath) {
if (mostRecentPath.isEmpty()) {
mostRecentPath = QStringLiteral("%1%2snap.000000.png")
.arg(OpenFlipperSettings().value("Core/CurrentDir").toString())
.arg(QDir::separator());
}
QFileInfo fi(snapshotName_);
if (snapshotName_ == "")
fi.setFile( OpenFlipperSettings().value("Core/CurrentDir").toString() + QDir::separator() + "snap.png" );
QFileInfo fi(mostRecentPath);
QString path = fi.path();
// Add leading zeros
QString number = QString::number(snapshotCounter_);
while ( number.size() < 7 )
number = "0" + number;
if (!fi.exists() && QFileInfo(path).isWritable()) {
#ifndef NDEBUG
std::cout << "suggestSnapshotFilename(): mostRecentPath feasible as "
"file name. Using it." << std::endl;
#endif
return mostRecentPath;
}
QString suggest = fi.path() + QDir::separator() + fi.baseName() + "." + number + ".";
if (!QFileInfo(path).isWritable()) {
#ifndef NDEBUG
std::cout << "suggestSnapshotFilename(): Most recent path invalid. "
"Doesn't exist. Returning empty string." << std::endl;
#endif
return QString::null;
}
QString format="png";
QString base_name = fi.completeBaseName();
QString suffix = fi.suffix();
if (fi.completeSuffix() == "ppm")
format="ppmraw";
if (suffix.isEmpty())
suffix = "png";
if (fi.completeSuffix() == "jpg")
format="jpg";
QRegExp base_name_re("(\\D*)(\\d+)?(.*)");
base_name_re.setPatternSyntax(QRegExp::RegExp2);
if (!base_name_re.exactMatch(base_name)) {
#ifndef NDEBUG
std::cout << "suggestSnapshotFilename(): Regexp didn't match. This "
"should be impossible." << std::endl;
#endif
return QString::null;
}
suggest += format;
QString pre = base_name_re.cap(1),
num = base_name_re.cap(2),
post = base_name_re.cap(3);
#ifndef NDEBUG
std::cout << (QStringLiteral("suggestSnapshotFilename(): Decomposition of "
"\"%1\": \"%2\", \"%3\", \"%4\"")
.arg(base_name)
.arg(pre)
.arg(num)
.arg(post)).toStdString() << std::endl;
#endif
if (pre.isEmpty() && num.isEmpty() && post.isEmpty()) {
pre = "snap.";
}
size_t num_len = num.length();
bool num_is_int;
int file_no = num.toInt(&num_is_int);
if (!num_is_int) {
file_no = 0;
num_len = 6;
}
size_t sanity_counter = 0;
for (; sanity_counter < 100000; ++file_no, ++sanity_counter) {
QString suggested_file_name =
QStringLiteral("%1%2%3%4%5.%6")
.arg(path)
.arg(QDir::separator())
.arg(pre)
.arg(file_no, num_len, 10, QLatin1Char('0'))
.arg(post)
.arg(suffix)
;
QFileInfo suggested_fi(suggested_file_name);
if (!suggested_fi.exists()){
#ifndef NDEBUG
std::cout << "suggestSnapshotFilename(): Found a feasible file "
"name. Returning it." << std::endl;
#endif
return suggested_file_name;
}
}
#ifndef NDEBUG
std::cout << "suggestSnapshotFilename(): No luck incrementing file_no. "
"Aborting, returning empty string." << std::endl;
#endif
return QString::null;
}
///Take a snapshot of the whole application
void CoreWidget::applicationSnapshotDialog() {
int w = width();
int h = height();
SnapshotDialog dialog(suggest, false, w, h, 0);
SnapshotDialog dialog(suggestSnapshotFilename(snapshotName_), false, w, h, 0);
connect(&dialog, SIGNAL(resizeApplication(int,int)), this, SIGNAL(resizeApplication(int,int)) );
......@@ -427,14 +499,9 @@ void CoreWidget::applicationSnapshotDialog() {
if ( ok ){
QString newName = dialog.filename->text();
if (newName != suggest){
OpenFlipperSettings().setValue("Core/CurrentDir", QFileInfo(newName).absolutePath() );
OpenFlipperSettings().setValue("Core/CurrentDir", QFileInfo(newName).absolutePath() );
snapshotName_ = newName;
snapshotCounter_ = 1;
}else
snapshotCounter_++;
snapshotName_ = newName;
//grabs only the widget (espacially in windows)
//todo: deprecated in QT 5.0, use QScreen instead
......@@ -465,61 +532,17 @@ void CoreWidget::applicationSnapshotDialog() {
///Take a snapshot of the whole application
void CoreWidget::applicationSnapshot() {
QFileInfo fi(snapshotName_);
// Add leading zeros
QString number = QString::number(snapshotCounter_++);
while ( number.size() < 7 )
number = "0" + number;
QString suggest = fi.path() + QDir::separator() +fi.baseName() + "." + number + ".";
QString format="png";
if (fi.completeSuffix() == "ppm")
format="ppmraw";
if (fi.completeSuffix() == "jpg")
format="jpg";
suggest += format;
// Write image asynchronously
QImage* pic = new QImage(QPixmap::grabWindow( winId() ).toImage());
writeImageAsynchronously(pic, suggest);
writeImageAsynchronously(pic, suggestSnapshotFilename(snapshotName_));
}
///Take a snapshot of all viewers
void CoreWidget::viewerSnapshotDialog() {
QFileInfo fi(snapshotName_);
if (snapshotName_ == "")
fi.setFile( OpenFlipperSettings().value("Core/CurrentDir").toString() + QDir::separator() + "snap.png" );
// Add leading zeros
QString number = QString::number(snapshotCounter_);
while ( number.size() < 7 )
number = "0" + number;
QString suggest = fi.path() + QDir::separator() + fi.baseName() + "." + number + ".";
QString format="png";
if (fi.completeSuffix() == "ppm")
format="ppmraw";
if (fi.completeSuffix() == "jpg")
format="jpg";
suggest += format;
int w = glView_->width();
int h = glView_->height();
SnapshotDialog dialog(suggest, true, w, h, 0);
SnapshotDialog dialog(suggestSnapshotFilename(snapshotName_), true, w, h, 0);
if (!ACG::SceneGraph::Material::support_json_serialization())
dialog.metaData_storeMatInfo_cb->setVisible(false);
......@@ -529,16 +552,10 @@ void CoreWidget::viewerSnapshotDialog() {
if (ok){
QString newName = dialog.filename->text();
if (newName != suggest){
OpenFlipperSettings().setValue("Core/CurrentDir", QFileInfo(newName).absolutePath() );
OpenFlipperSettings().setValue("Core/CurrentDir", QFileInfo(newName).absolutePath() );
snapshotName_ = newName;
snapshotCounter_ = 1;
snapshotName_ = newName;
}else
snapshotCounter_++;
QString comments;
if (dialog.metaData_storeComments_cb->isChecked()) {
comments = PluginFunctions::collectObjectComments(
......@@ -719,27 +736,7 @@ void CoreWidget::viewerSnapshotDialog() {
///Take a snapshot of all viewers
void CoreWidget::viewerSnapshot() {
QFileInfo fi(snapshotName_);
// Add leading zeros
QString number = QString::number(snapshotCounter_++);
while ( number.size() < 7 )
number = "0" + number;
QString suggest = fi.path() + QDir::separator() +fi.baseName() + "." + number + ".";
QString format="png";
if (fi.completeSuffix() == "ppm")
format="ppmraw";
if (fi.completeSuffix() == "jpg")
format="jpg";
suggest += format;
switch ( baseLayout_->mode() ){
switch ( baseLayout_->mode() ){
case QtMultiViewLayout::SingleView:
{
......@@ -747,7 +744,7 @@ void CoreWidget::viewerSnapshot() {
examiner_widgets_[PluginFunctions::activeExaminer()]->snapshot(*finalImage);
writeImageAsynchronously(finalImage, suggest);
writeImageAsynchronously(finalImage, suggestSnapshotFilename(snapshotName_));
break;
}
......@@ -769,7 +766,7 @@ void CoreWidget::viewerSnapshot() {
painter.drawImage(QRectF(img[0].width()+2, 0, img[1].width(), img[1].height()),img[1],
QRectF( 0, 0, img[1].width(), img[1].height()) );
writeImageAsynchronously(finalImage, suggest);
writeImageAsynchronously(finalImage, suggestSnapshotFilename(snapshotName_));
break;
}
......@@ -798,7 +795,7 @@ void CoreWidget::viewerSnapshot() {
painter.drawImage(QRectF(img0.width()+2, img0.height()+2, img3.width(), img3.height()),img3,
QRectF( 0, 0, img3.width(), img3.height()) );
writeImageAsynchronously(finalImage, suggest);
writeImageAsynchronously(finalImage, suggestSnapshotFilename(snapshotName_));
break;
}
......@@ -826,7 +823,7 @@ void CoreWidget::viewerSnapshot() {
painter.drawImage(QRectF(img0.width()+2, img1.height()+img2.height()+4, img3.width(),img3.height()),img3,
QRectF( 0, 0, img3.width(), img3.height()) );
writeImageAsynchronously(finalImage, suggest);
writeImageAsynchronously(finalImage, suggestSnapshotFilename(snapshotName_));
break;
}
......@@ -836,9 +833,7 @@ void CoreWidget::viewerSnapshot() {
}
void CoreWidget::applicationSnapshotName(QString _name) {
snapshotName_ = _name;
snapshotCounter_ = 0;
}
......
......@@ -69,6 +69,8 @@ SnapshotDialog::SnapshotDialog(QString _suggest, bool _captureViewers, int _w, i
snapWidth->setValue(_w);
snapHeight->setValue(_h);
warning_lb->setText("");
// Load button states
loadStates();
......@@ -81,6 +83,8 @@ SnapshotDialog::SnapshotDialog(QString _suggest, bool _captureViewers, int _w, i
connect(findButton, SIGNAL(clicked()), this, SLOT(findFile()) );
connect(resButton, SIGNAL(clicked()), this, SLOT(slotChangeResolution()) );
connect(okButton, SIGNAL(clicked()), this, SLOT(slotOk()) );
connect(filename, SIGNAL(textChanged(const QString &)), this, SLOT(filenameChanged(const QString &)));
}
void SnapshotDialog::saveStates() {
......@@ -185,3 +189,21 @@ void SnapshotDialog::findFile()
if (ok)
filename->setText( dialog.selectedFiles()[0] );
}
void SnapshotDialog::filenameChanged(const QString &new_filename) {
QFileInfo fi(new_filename);
if (!QFileInfo(fi.path()).isWritable()) {
static const char *style = "background: #ffffcc;";
filename->setStyleSheet(style);
warning_lb->setText(trUtf8("Warning: Folder not writable."));
} else if (fi.exists()) {
static const char *style = "background: #ffcccc;";
filename->setStyleSheet(style);
warning_lb->setText(trUtf8("Warning: File exists and will be "
"overwritten without further warning."));
} else {
static const char *style = "";
filename->setStyleSheet(style);
warning_lb->setText("");
}
}
......@@ -74,6 +74,8 @@ class SnapshotDialog : public QDialog, public Ui::SnapshotDialog
void saveStates();
void loadStates();
void filenameChanged(const QString &new_filename);
signals:
void resizeApplication(int _width, int _height);
};
......
......@@ -21,7 +21,14 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLineEdit" name="filename"/>
<widget class="QLineEdit" name="filename">
<property name="minimumSize">
<size>
<width>400</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="findButton">
......@@ -34,6 +41,16 @@
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="warning_lb">
<property name="styleSheet">
<string notr="true">color:red</string>
</property>
<property name="text">
<string>Warning: &lt;will state warnings about the selected file name&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
......@@ -119,24 +136,6 @@
</property>
</spacer>
</item>
<item row="3" column="2">
<widget class="QPushButton" name="resButton">
<property name="toolTip">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Changes the resolution of the application window and thus of the snapshot taken. It will be reset to its original value when this dialog is closed.&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;This will not work when the application is maximized or fullscreen.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Only available when taking application snapshots.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Change Resolution</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QCheckBox" name="keepAspect">
<property name="text">
......@@ -146,6 +145,48 @@ p, li { white-space: pre-wrap; }
</item>
</layout>
</item>
<item>
<widget class="QWidget" name="widget_2" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_7">
<property name="margin">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>544</width>
<height>23</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="resButton">
<property name="toolTip">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Changes the resolution of the application window and thus of the snapshot taken. It will be reset to its original value when this dialog is closed.&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;This will not work when the application is maximized or fullscreen.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Only available when taking application snapshots.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Change Resolution</string>
</property>
</widget>
</item>
</layout>
<zorder>horizontalSpacer_4</zorder>
<zorder>resButton</zorder>
</widget>
</item>
</layout>
</widget>
</item>
......@@ -325,6 +366,19 @@ Allowed values: any number between 2 and 16.</string>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
......@@ -359,19 +413,6 @@ Allowed values: any number between 2 and 16.</string>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<tabstops>
......@@ -388,6 +429,8 @@ Allowed values: any number between 2 and 16.</string>
<tabstop>metaData_storeComments_cb</tabstop>
<tabstop>metaData_comments_visibleOnly_cb</tabstop>
<tabstop>metaData_comments_targetedOnly_cb</tabstop>
<tabstop>metaData_storeView_cb</tabstop>
<tabstop>metaData_storeMatInfo_cb</tabstop>
<tabstop>cancelButton</tabstop>
<tabstop>okButton</tabstop>
</tabstops>
......@@ -400,12 +443,12 @@ Allowed values: any number between 2 and 16.</string>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>34</x>
<y>363</y>
<x>54</x>
<y>338</y>
</hint>
<hint type="destinationlabel">
<x>26</x>
<y>390</y>
<x>46</x>
<y>363</y>
</hint>
</hints>
</connection>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment