Pencil2D Animation
Download Community News Docs Contribute
  • Overview
  • Articles
  • Code
  •  
  • Class List
  • Class Index
  • Class Hierarchy
  • Class Members
  • File List
Loading...
Searching...
No Matches
  • app
  • src
importexportdialog.cpp
1/*
2
3Pencil2D - Traditional Animation Software
4Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5Copyright (C) 2012-2020 Matthew Chiawen Chang
6
7This program is free software; you can redistribute it and/or
8modify it under the terms of the GNU General Public License
9as published by the Free Software Foundation; version 2 of the License.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16*/
17
18#include "importexportdialog.h"
19#include "ui_importexportdialog.h"
20#include <QFileInfo>
21#include <QDialogButtonBox>
22#include "filedialog.h"
23
24ImportExportDialog::ImportExportDialog(QWidget* parent, Mode eMode, FileType eFileType) : QDialog(parent)
25{
26 mMode = eMode;
27 mFileType = eFileType;
28
29 ui = new Ui::ImportExportDialog;
30 ui->setupUi(this);
31 hidePreviewGroupBox(true);
32 connect(ui->browseButton, &QPushButton::clicked, this, &ImportExportDialog::browse);
33
34 Qt::WindowFlags eFlags = Qt::Dialog | Qt::WindowTitleHint | Qt::WindowCloseButtonHint;
35 setWindowFlags(eFlags);
36}
37
38ImportExportDialog::~ImportExportDialog()
39{
40 delete ui;
41}
42
43QDialogButtonBox* ImportExportDialog::getDialogButtonBox()
44{
45 return ui->buttonBox;
46}
47
48QString ImportExportDialog::getFilePath() const
49{
50 return m_filePaths.isEmpty() ? QString() : m_filePaths.first();
51}
52
53QStringList ImportExportDialog::getFilePaths()
54{
55 return m_filePaths;
56}
57
58QString ImportExportDialog::getAbsolutePath()
59{
60 QFileInfo info(m_filePaths.first());
61 return info.absolutePath();
62}
63
64void ImportExportDialog::hideInstructionsLabel(bool hide)
65{
66 ui->instructionsLabel->setHidden(hide);
67}
68
69void ImportExportDialog::setInstructionsLabel(const QString& text)
70{
71 ui->instructionsLabel->setText(text);
72}
73
74void ImportExportDialog::setOkButtonEnabled(const bool enabled)
75{
76 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(enabled);
77}
78
79void ImportExportDialog::init()
80{
81 switch (mMode)
82 {
83 case Import:
84 m_filePaths = QStringList(FileDialog::getLastOpenPath(mFileType));
85 break;
86 case Export:
87 m_filePaths = QStringList(FileDialog::getLastSavePath(mFileType));
88 break;
89 default:
90 Q_ASSERT(false);
91 }
92 ui->fileEdit->setText("\"" + m_filePaths.first() + "\"");
93
94 emit filePathsChanged(m_filePaths);
95}
96
97QGroupBox* ImportExportDialog::getOptionsGroupBox()
98{
99 return ui->optionsGroupBox;
100}
101
102void ImportExportDialog::hideOptionsGroupBox(bool hide)
103{
104 ui->optionsGroupBox->setHidden(hide);
105}
106
107void ImportExportDialog::hidePreviewGroupBox(bool hide)
108{
109 ui->previewGroupBox->setHidden(hide);
110}
111
112QGroupBox* ImportExportDialog::getPreviewGroupBox()
113{
114 return ui->previewGroupBox;
115}
116
117void ImportExportDialog::setFileExtension(const QString& extension)
118{
119 for (int i = 0; i < m_filePaths.size(); i++)
120 {
121 QFileInfo info(m_filePaths.at(i));
122 m_filePaths.replace(i, info.path() + "/" + info.completeBaseName() + "." + extension);
123 }
124 ui->fileEdit->setText("\"" + m_filePaths.join("\" \"") + "\"");
125
126 emit filePathsChanged(m_filePaths);
127}
128
129void ImportExportDialog::browse()
130{
131 QStringList filePaths;
132 switch (mMode)
133 {
134 case Import:
135 if (mFileType == FileType::IMAGE_SEQUENCE)
136 {
137 filePaths = FileDialog::getOpenFileNames(this, FileType::IMAGE_SEQUENCE);
138 break;
139 }
140 filePaths = QStringList(FileDialog::getOpenFileName(this, mFileType));
141 break;
142 case Export:
143 filePaths = QStringList(FileDialog::getSaveFileName(this, mFileType));
144 break;
145 default:
146 Q_ASSERT(false);
147 }
148
149 if (filePaths.isEmpty() || filePaths.first().isEmpty())
150 {
151 return;
152 }
153
154 m_filePaths = filePaths;
155 ui->fileEdit->setText("\"" + filePaths.join("\" \"") + "\"");
156
157 emit filePathsChanged(m_filePaths);
158}
FileDialog::getLastSavePath
static QString getLastSavePath(FileType fileType)
Retrieves the last used save path for a given file type.
Definition: filedialog.cpp:146
FileDialog::getOpenFileNames
static QStringList getOpenFileNames(QWidget *parent, FileType fileType, const QString &caption=QString())
Shows a file dialog which allows the user to select multiple files to open.
Definition: filedialog.cpp:53
FileDialog::getSaveFileName
static QString getSaveFileName(QWidget *parent, FileType fileType, const QString &caption=QString())
Shows a file dialog which allows the user to select a file save path.
Definition: filedialog.cpp:84
FileDialog::getOpenFileName
static QString getOpenFileName(QWidget *parent, FileType fileType, const QString &caption=QString())
Shows a file dialog which allows the user to select a file to open.
Definition: filedialog.cpp:28
FileDialog::getLastOpenPath
static QString getLastOpenPath(FileType fileType)
Retrieves the last opened file of a given type.
Definition: filedialog.cpp:131
QAbstractButton::clicked
void clicked(bool checked)
QDialog::extension
QWidget * extension() const const
QDialog
QDialogButtonBox
QDialogButtonBox::Ok
Ok
QFileInfo
QGroupBox
QList::at
const T & at(int i) const const
QList::first
T & first()
QList::isEmpty
bool isEmpty() const const
QList::replace
void replace(int i, const T &value)
QList::size
int size() const const
QString
QStringList
QStringList::join
QString join(const QString &separator) const const
Qt::WindowFlags
typedef WindowFlags
QWidget
QWidget::enabled
enabled
QWidget::hide
void hide()
QWidget::setupUi
void setupUi(QWidget *widget)
Generated on Thu May 8 2025 04:47:53 for Pencil2D by doxygen 1.9.6 based on revision 4513250b1d5b1a3676ec0e67b06b7a885ceaae39