Pencil2D  ff90c0872e88be3bf81c548cd60f01983012ec49
Pencil2D is an animation software for both bitmap and vector graphics. It is free, multi-platform, and open source.
 All Classes Functions
importexportdialog.cpp
1 /*
2 
3 Pencil - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2013-2017 Matt Chiawen Chang
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; version 2 of the License.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 */
17 
18 #include "importexportdialog.h"
19 #include "ui_importexportdialog.h"
20 #include <QFileInfo>
21 
22 ImportExportDialog::ImportExportDialog(QWidget *parent) :
23  QDialog(parent),
24  ui(new Ui::ImportExportDialog),
25  m_fileDialog(new FileDialog(this)),
26  m_filePaths(QStringList())
27 {
28  ui->setupUi(this);
29 
30  connect(ui->browseButton, &QPushButton::clicked, this, &ImportExportDialog::browse);
31 
32  Qt::WindowFlags eFlags = Qt::Dialog | Qt::WindowTitleHint | Qt::WindowCloseButtonHint;
33  setWindowFlags(eFlags);
34 }
35 
36 ImportExportDialog::~ImportExportDialog()
37 {
38  delete ui;
39 }
40 
41 QString ImportExportDialog::getFilePath()
42 {
43  return m_filePaths.isEmpty() ? QString() : m_filePaths.first();
44 }
45 
46 QStringList ImportExportDialog::getFilePaths()
47 {
48  return m_filePaths;
49 }
50 
51 void ImportExportDialog::init()
52 {
53  switch (getMode())
54  {
55  case Import:
56  m_filePaths = QStringList(m_fileDialog->getLastOpenPath(getFileType()));
57  break;
58  case Export:
59  m_filePaths = QStringList(m_fileDialog->getLastSavePath(getFileType()));
60  break;
61  default:
62  Q_ASSERT(false);
63  }
64  ui->fileEdit->setText("\"" + m_filePaths.first() + "\"");
65 }
66 
67 QGroupBox *ImportExportDialog::getOptionsGroupBox()
68 {
69  return ui->optionsGroupBox;
70 }
71 
72 void ImportExportDialog::setFileExtension(QString extension)
73 {
74  for (int i = 0; i < m_filePaths.size(); i++)
75  {
76  QFileInfo info(m_filePaths.at(i));
77  m_filePaths.replace(i, info.path() + "/" + info.baseName() + "." + extension);
78  }
79  ui->fileEdit->setText("\"" + m_filePaths.join("\" \"") + "\"");
80 }
81 
82 void ImportExportDialog::browse()
83 {
84  QStringList filePaths;
85  switch (getMode())
86  {
87  case Import:
88  if (getFileType() == FileType::IMAGE_SEQUENCE)
89  {
90  filePaths = m_fileDialog->openFiles( FileType::IMAGE_SEQUENCE );
91  break;
92  }
93 
94  filePaths = QStringList(m_fileDialog->openFile(getFileType()));
95  break;
96  case Export:
97  filePaths = QStringList(m_fileDialog->saveFile(getFileType()));
98  break;
99  default:
100  Q_ASSERT(false);
101  }
102 
103  if (filePaths.isEmpty() || filePaths.first().isEmpty())
104  {
105  return;
106  }
107 
108  m_filePaths = filePaths;
109  ui->fileEdit->setText("\"" + filePaths.join("\" \"") + "\"");
110 }