Show path to pattern file in a graphical shell.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2016-06-18 16:57:07 +03:00
parent d4abab1029
commit 7b40bc3667
8 changed files with 153 additions and 88 deletions

View file

@ -2031,7 +2031,7 @@ void TMainWindow::InitWindow()
connect(ui->plainTextEditDescription, &QPlainTextEdit::textChanged, this, &TMainWindow::SaveMDescription);
connect(ui->lineEditFullName, &QLineEdit::textEdited, this, &TMainWindow::SaveMFullName);
connect(ui->pushButtonShowInExplorer, &QPushButton::clicked, this, &TMainWindow::ShowInGraphicalShell);
connect(ui->pushButtonShowInExplorer, &QPushButton::clicked, [this](){ShowInGraphicalShell(curFile);});
InitUnits();
@ -2106,12 +2106,14 @@ void TMainWindow::SetCurrentFile(const QString &fileName)
mType == MeasurementsType::Standard ? shownName += QLatin1Literal(".vst") : shownName += QLatin1Literal(".vit");
ui->lineEditPathToFile->setText(tr("<Empty>"));
ui->lineEditPathToFile->setToolTip(tr("File was not saved yet."));
ui->lineEditPathToFile->setCursorPosition(0);
ui->pushButtonShowInExplorer->setEnabled(false);
}
else
{
ui->lineEditPathToFile->setText(QDir::toNativeSeparators(curFile));
ui->lineEditPathToFile->setToolTip(QDir::toNativeSeparators(curFile));
ui->lineEditPathToFile->setCursorPosition(0);
ui->pushButtonShowInExplorer->setEnabled(true);
auto settings = qApp->TapeSettings();
QStringList files = settings->GetRecentFileList();
@ -3001,52 +3003,3 @@ void TMainWindow::InitGender(QComboBox *gender)
gender->addItem(tr("male", "gender"), QVariant(static_cast<int>(GenderType::Male)));
gender->addItem(tr("female", "gender"), QVariant(static_cast<int>(GenderType::Female)));
}
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::ShowInGraphicalShell()
{
#ifdef Q_OS_MAC
QStringList args;
args << "-e";
args << "tell application \"Finder\"";
args << "-e";
args << "activate";
args << "-e";
args << "select POSIX file \""+curFile+"\"";
args << "-e";
args << "end tell";
QProcess::startDetached("osascript", args);
#elif defined(Q_OS_WIN)
QProcess::startDetached(QString("explorer /select, \"%1\"").arg(QDir::toNativeSeparators(curFile)));
#else
const QString app = "xdg-open %d";
QString cmd;
for (int i = 0; i < app.size(); ++i)
{
QChar c = app.at(i);
if (c == QLatin1Char('%') && i < app.size()-1)
{
c = app.at(++i);
QString s;
if (c == QLatin1Char('d'))
{
s = QLatin1Char('"') + QFileInfo(curFile).path() + QLatin1Char('"');
}
else if (c == QLatin1Char('%'))
{
s = c;
}
else
{
s = QLatin1Char('%');
s += c;
}
cmd += s;
continue;
}
cmd += c;
}
QProcess::startDetached(cmd);
#endif
}

View file

@ -116,7 +116,6 @@ private slots:
void ShowMData();
void DeployFormula();
void ShowInGraphicalShell();
void SaveMName();
void SaveMValue();

View file

@ -40,15 +40,26 @@
#define MAX_SIZES 18
//---------------------------------------------------------------------------------------------------------------------
DialogPatternProperties::DialogPatternProperties(VPattern *doc, VContainer *pattern, QWidget *parent) :
QDialog(parent), ui(new Ui::DialogPatternProperties), doc(doc), pattern(pattern), heightsChecked(MAX_HEIGHTS),
sizesChecked(MAX_SIZES), heights (QMap<GHeights, bool>()), sizes(QMap<GSizes, bool>()),
data(QMap<QCheckBox *, int>()), descriptionChanged(false), gradationChanged(false), defaultChanged(false),
securityChanged(false), isInitialized(false),
deleteAction(nullptr),
changeImageAction(nullptr),
saveImageAction(nullptr),
showImageAction(nullptr)
DialogPatternProperties::DialogPatternProperties(const QString &filePath, VPattern *doc, VContainer *pattern,
QWidget *parent)
: QDialog(parent),
ui(new Ui::DialogPatternProperties),
doc(doc),
pattern(pattern),
heightsChecked(MAX_HEIGHTS),
sizesChecked(MAX_SIZES),
heights (QMap<GHeights, bool>()),
sizes(QMap<GSizes, bool>()),
data(QMap<QCheckBox *, int>()),
descriptionChanged(false),
gradationChanged(false),
defaultChanged(false),
securityChanged(false),
deleteAction(nullptr),
changeImageAction(nullptr),
saveImageAction(nullptr),
showImageAction(nullptr),
m_filePath(filePath)
{
ui->setupUi(this);
@ -60,6 +71,25 @@ DialogPatternProperties::DialogPatternProperties(VPattern *doc, VContainer *pat
qApp->ValentinaSettings()->GetOsSeparator() ? setLocale(QLocale::system()) : setLocale(QLocale(QLocale::C));
if (m_filePath.isEmpty())
{
ui->lineEditPathToFile->setText(tr("<Empty>"));
ui->lineEditPathToFile->setToolTip(tr("File was not saved yet."));
ui->pushButtonShowInExplorer->setEnabled(false);
}
else
{
ui->lineEditPathToFile->setText(QDir::toNativeSeparators(m_filePath));
ui->lineEditPathToFile->setToolTip(QDir::toNativeSeparators(m_filePath));
ui->pushButtonShowInExplorer->setEnabled(true);
}
ui->lineEditPathToFile->setCursorPosition(0);
connect(ui->pushButtonShowInExplorer, &QPushButton::clicked, [this](){ShowInGraphicalShell(m_filePath);});
#if defined(Q_OS_MAC)
ui->pushButtonShowInExplorer->setText(tr("Show in Finder"));
#endif //defined(Q_OS_MAC)
ui->lineEditAuthor->setText(doc->GetAuthor());
connect(ui->lineEditAuthor, &QLineEdit::editingFinished, this, &DialogPatternProperties::DescEdited);
@ -329,27 +359,6 @@ void DialogPatternProperties::DescEdited()
descriptionChanged = true;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPatternProperties::showEvent(QShowEvent *event)
{
QDialog::showEvent( event );
if ( event->spontaneous() )
{
return;
}
if (isInitialized)
{
return;
}
// do your init stuff here
setMaximumSize(size());
setMinimumSize(size());
isInitialized = true;//first show windows are held
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPatternProperties::ToggleComboBox()
{

View file

@ -46,7 +46,8 @@ class DialogPatternProperties : public QDialog
{
Q_OBJECT
public:
explicit DialogPatternProperties(VPattern *doc, VContainer *pattern, QWidget *parent = nullptr);
explicit DialogPatternProperties(const QString &filePath, VPattern *doc, VContainer *pattern,
QWidget *parent = nullptr);
virtual ~DialogPatternProperties() Q_DECL_OVERRIDE;
signals:
void UpdateGradation();
@ -59,8 +60,6 @@ public slots:
void DescEdited();
void ChangeImage();
void ShowContextMenu();
protected:
virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE;
private slots:
void ToggleComboBox();
void DefValueChanged();
@ -82,11 +81,11 @@ private:
bool gradationChanged;
bool defaultChanged;
bool securityChanged;
bool isInitialized;
QAction *deleteAction;
QAction *changeImageAction;
QAction *saveImageAction;
QAction *showImageAction;
const QString &m_filePath;
void SetHeightsChecked(bool enabled);
void SetSizesChecked(bool enabled);

View file

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>657</width>
<height>532</height>
<width>757</width>
<height>692</height>
</rect>
</property>
<property name="windowTitle">
@ -28,6 +28,58 @@
<string>Description</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayoutPath">
<item>
<widget class="QLabel" name="label_9">
<property name="text">
<string>Path:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEditPathToFile">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background: transparent;</string>
</property>
<property name="frame">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string notr="true">Path to the pattern file.</string>
</property>
</widget>
</item>
<item alignment="Qt::AlignRight">
<widget class="QPushButton" name="pushButtonShowInExplorer">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Show in Explorer</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>

View file

@ -1212,7 +1212,7 @@ void MainWindow::OpenRecentFile()
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::PatternProperties()
{
DialogPatternProperties proper(doc, pattern, this);
DialogPatternProperties proper(curFile, doc, pattern, this);
connect(&proper, &DialogPatternProperties::UpdateGradation, this, &MainWindow::UpdateGradation);
proper.exec();
}

View file

@ -34,6 +34,7 @@
#include <QDir>
#include <QPrinterInfo>
#include <QDebug>
#include <QProcess>
// Keep synchronize all names with initialization in VTranslateVars class!!!!!
//measurements
@ -1796,3 +1797,53 @@ QPixmap darkenPixmap(const QPixmap &pixmap)
}
return QPixmap::fromImage(img);
}
//---------------------------------------------------------------------------------------------------------------------
void ShowInGraphicalShell(const QString &filePath)
{
#ifdef Q_OS_MAC
QStringList args;
args << "-e";
args << "tell application \"Finder\"";
args << "-e";
args << "activate";
args << "-e";
args << "select POSIX file \""+filePath+"\"";
args << "-e";
args << "end tell";
QProcess::startDetached("osascript", args);
#elif defined(Q_OS_WIN)
QProcess::startDetached(QString("explorer /select, \"%1\"").arg(QDir::toNativeSeparators(filePath)));
#else
const QString app = "xdg-open %d";
QString cmd;
for (int i = 0; i < app.size(); ++i)
{
QChar c = app.at(i);
if (c == QLatin1Char('%') && i < app.size()-1)
{
c = app.at(++i);
QString s;
if (c == QLatin1Char('d'))
{
s = QLatin1Char('"') + QFileInfo(filePath).path() + QLatin1Char('"');
}
else if (c == QLatin1Char('%'))
{
s = c;
}
else
{
s = QLatin1Char('%');
s += c;
}
cmd += s;
continue;
}
cmd += c;
}
QProcess::startDetached(cmd);
#endif
}

View file

@ -615,6 +615,8 @@ QSharedPointer<QPrinter> DefaultPrinter(QPrinter::PrinterMode mode = QPrinter::S
QPixmap darkenPixmap(const QPixmap &pixmap) Q_REQUIRED_RESULT;
void ShowInGraphicalShell(const QString &filePath);
static inline bool VFuzzyComparePossibleNulls(double p1, double p2) Q_REQUIRED_RESULT;
static inline bool VFuzzyComparePossibleNulls(double p1, double p2)
{