mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
Issue #28: Add multiple PDF files at once for merging
This commit is contained in:
@@ -94,7 +94,7 @@ MainWindow::MainWindow(QWidget* parent) :
|
|||||||
ui->actionRegroup_by_Alternating_Pages_Reversed_Order->setData(int(Operation::RegroupAlternatingPagesReversed));
|
ui->actionRegroup_by_Alternating_Pages_Reversed_Order->setData(int(Operation::RegroupAlternatingPagesReversed));
|
||||||
ui->actionPrepare_Icon_Theme->setData(int(Operation::PrepareIconTheme));
|
ui->actionPrepare_Icon_Theme->setData(int(Operation::PrepareIconTheme));
|
||||||
|
|
||||||
m_iconTheme.registerAction(ui->actionAddDocument, ":/pdfdocpage/resources/open.svg");
|
m_iconTheme.registerAction(ui->actionAddDocuments, ":/pdfdocpage/resources/open.svg");
|
||||||
m_iconTheme.registerAction(ui->actionClose, ":/pdfdocpage/resources/close.svg");
|
m_iconTheme.registerAction(ui->actionClose, ":/pdfdocpage/resources/close.svg");
|
||||||
m_iconTheme.registerAction(ui->actionCloneSelection, ":/pdfdocpage/resources/clone-selection.svg");
|
m_iconTheme.registerAction(ui->actionCloneSelection, ":/pdfdocpage/resources/clone-selection.svg");
|
||||||
m_iconTheme.registerAction(ui->actionRemoveSelection, ":/pdfdocpage/resources/remove-selection.svg");
|
m_iconTheme.registerAction(ui->actionRemoveSelection, ":/pdfdocpage/resources/remove-selection.svg");
|
||||||
@@ -139,7 +139,7 @@ MainWindow::MainWindow(QWidget* parent) :
|
|||||||
|
|
||||||
QToolBar* mainToolbar = addToolBar(tr("Main"));
|
QToolBar* mainToolbar = addToolBar(tr("Main"));
|
||||||
mainToolbar->setObjectName("main_toolbar");
|
mainToolbar->setObjectName("main_toolbar");
|
||||||
mainToolbar->addAction(ui->actionAddDocument);
|
mainToolbar->addAction(ui->actionAddDocuments);
|
||||||
mainToolbar->addSeparator();
|
mainToolbar->addSeparator();
|
||||||
mainToolbar->addActions({ ui->actionCloneSelection, ui->actionRemoveSelection });
|
mainToolbar->addActions({ ui->actionCloneSelection, ui->actionRemoveSelection });
|
||||||
mainToolbar->addSeparator();
|
mainToolbar->addSeparator();
|
||||||
@@ -224,12 +224,18 @@ void MainWindow::on_actionClose_triggered()
|
|||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionAddDocument_triggered()
|
void MainWindow::on_actionAddDocuments_triggered()
|
||||||
{
|
{
|
||||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Select PDF document"), m_settings.directory, tr("PDF document (*.pdf)"));
|
QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select PDF document(s)"), m_settings.directory, tr("PDF document (*.pdf)"));
|
||||||
if (!fileName.isEmpty())
|
if (!fileNames.isEmpty())
|
||||||
{
|
{
|
||||||
insertDocument(fileName, QModelIndex());
|
for (const QString& fileName : fileNames)
|
||||||
|
{
|
||||||
|
if (!insertDocument(fileName, QModelIndex()))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -293,16 +299,19 @@ void MainWindow::saveSettings()
|
|||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::insertDocument(const QString& fileName, const QModelIndex& insertIndex)
|
bool MainWindow::insertDocument(const QString& fileName, const QModelIndex& insertIndex)
|
||||||
{
|
{
|
||||||
auto queryPassword = [this](bool* ok)
|
bool isDocumentInserted = true;
|
||||||
|
|
||||||
|
QFileInfo fileInfo(fileName);
|
||||||
|
|
||||||
|
auto queryPassword = [this, &fileInfo](bool* ok)
|
||||||
{
|
{
|
||||||
*ok = false;
|
*ok = false;
|
||||||
return QInputDialog::getText(this, tr("Encrypted document"), tr("Enter password to access document content"), QLineEdit::Password, QString(), ok);
|
return QInputDialog::getText(this, tr("Encrypted document"), tr("Enter password to access document '%1'").arg(fileInfo.fileName()), QLineEdit::Password, QString(), ok);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Mark current directory as this
|
// Mark current directory as this
|
||||||
QFileInfo fileInfo(fileName);
|
|
||||||
m_settings.directory = fileInfo.dir().absolutePath();
|
m_settings.directory = fileInfo.dir().absolutePath();
|
||||||
|
|
||||||
// Try to open a new document
|
// Try to open a new document
|
||||||
@@ -321,15 +330,22 @@ void MainWindow::insertDocument(const QString& fileName, const QModelIndex& inse
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
isDocumentInserted = false;
|
||||||
QMessageBox::critical(this, tr("Error"), tr("Document security doesn't permit to organize pages."));
|
QMessageBox::critical(this, tr("Error"), tr("Document security doesn't permit to organize pages."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (result == pdf::PDFDocumentReader::Result::Failed)
|
else if (result == pdf::PDFDocumentReader::Result::Failed)
|
||||||
{
|
{
|
||||||
|
isDocumentInserted = false;
|
||||||
QMessageBox::critical(this, tr("Error"), errorMessage);
|
QMessageBox::critical(this, tr("Error"), errorMessage);
|
||||||
}
|
}
|
||||||
|
else if (result == pdf::PDFDocumentReader::Result::Cancelled)
|
||||||
|
{
|
||||||
|
isDocumentInserted = false;
|
||||||
|
}
|
||||||
|
|
||||||
updateActions();
|
updateActions();
|
||||||
|
return isDocumentInserted;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MainWindow::canPerformOperation(Operation operation) const
|
bool MainWindow::canPerformOperation(Operation operation) const
|
||||||
@@ -763,23 +779,39 @@ void MainWindow::performOperation(Operation operation)
|
|||||||
filters << QString::fromLatin1(imageFormat).toLower();
|
filters << QString::fromLatin1(imageFormat).toLower();
|
||||||
}
|
}
|
||||||
QString filter = tr("Images (*.%1)").arg(filters.join(" *."));
|
QString filter = tr("Images (*.%1)").arg(filters.join(" *."));
|
||||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Select Image"), m_settings.directory, filter, nullptr);
|
QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select Image(s)"), m_settings.directory, filter, nullptr);
|
||||||
|
|
||||||
if (!fileName.isEmpty())
|
if (!fileNames.isEmpty())
|
||||||
{
|
{
|
||||||
QModelIndexList indexes = ui->documentItemsView->selectionModel()->selection().indexes();
|
QModelIndexList indexes = ui->documentItemsView->selectionModel()->selection().indexes();
|
||||||
m_model->insertImage(fileName, !indexes.isEmpty() ? indexes.front() : QModelIndex());
|
QModelIndex insertIndex = !indexes.isEmpty() ? indexes.front() : QModelIndex();
|
||||||
|
|
||||||
|
for (const QString& fileName : fileNames)
|
||||||
|
{
|
||||||
|
m_model->insertImage(fileName, insertIndex);
|
||||||
|
insertIndex = insertIndex.sibling(insertIndex.row() + 1, insertIndex.column());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case Operation::InsertPDF:
|
case Operation::InsertPDF:
|
||||||
{
|
{
|
||||||
QModelIndexList indexes = ui->documentItemsView->selectionModel()->selection().indexes();
|
QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select PDF document(s)"), m_settings.directory, tr("PDF document (*.pdf)"));
|
||||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Select PDF document"), m_settings.directory, tr("PDF document (*.pdf)"));
|
|
||||||
if (!fileName.isEmpty())
|
if (!fileNames.isEmpty())
|
||||||
{
|
{
|
||||||
insertDocument(fileName, !indexes.isEmpty() ? indexes.back() : QModelIndex());
|
QModelIndexList indexes = ui->documentItemsView->selectionModel()->selection().indexes();
|
||||||
|
QModelIndex insertIndex = !indexes.isEmpty() ? indexes.front() : QModelIndex();
|
||||||
|
|
||||||
|
for (const QString& fileName : fileNames)
|
||||||
|
{
|
||||||
|
if (!insertDocument(fileName, insertIndex))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
insertIndex = insertIndex.sibling(insertIndex.row() + 1, insertIndex.column());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -99,14 +99,14 @@ public:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_actionClose_triggered();
|
void on_actionClose_triggered();
|
||||||
void on_actionAddDocument_triggered();
|
void on_actionAddDocuments_triggered();
|
||||||
void onMappedActionTriggered(int actionId);
|
void onMappedActionTriggered(int actionId);
|
||||||
void updateActions();
|
void updateActions();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void loadSettings();
|
void loadSettings();
|
||||||
void saveSettings();
|
void saveSettings();
|
||||||
void insertDocument(const QString& fileName, const QModelIndex& insertIndex);
|
bool insertDocument(const QString& fileName, const QModelIndex& insertIndex);
|
||||||
|
|
||||||
bool canPerformOperation(Operation operation) const;
|
bool canPerformOperation(Operation operation) const;
|
||||||
void performOperation(Operation operation);
|
void performOperation(Operation operation);
|
||||||
|
@@ -55,7 +55,7 @@
|
|||||||
<property name="title">
|
<property name="title">
|
||||||
<string>File</string>
|
<string>File</string>
|
||||||
</property>
|
</property>
|
||||||
<addaction name="actionAddDocument"/>
|
<addaction name="actionAddDocuments"/>
|
||||||
<addaction name="actionClear"/>
|
<addaction name="actionClear"/>
|
||||||
<addaction name="actionClose"/>
|
<addaction name="actionClose"/>
|
||||||
</widget>
|
</widget>
|
||||||
@@ -145,13 +145,16 @@
|
|||||||
<addaction name="menuHelp"/>
|
<addaction name="menuHelp"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QStatusBar" name="statusbar"/>
|
<widget class="QStatusBar" name="statusbar"/>
|
||||||
<action name="actionAddDocument">
|
<action name="actionAddDocuments">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="resources.qrc">
|
<iconset resource="resources.qrc">
|
||||||
<normaloff>:/pdfdocpage/resources/open.svg</normaloff>:/pdfdocpage/resources/open.svg</iconset>
|
<normaloff>:/pdfdocpage/resources/open.svg</normaloff>:/pdfdocpage/resources/open.svg</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Add Document</string>
|
<string>Add Documents...</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Add Documents</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="shortcut">
|
<property name="shortcut">
|
||||||
<string>Ctrl+O</string>
|
<string>Ctrl+O</string>
|
||||||
|
@@ -3,6 +3,7 @@ CURRENT:
|
|||||||
- Issue #22: Solve compilation warnings
|
- Issue #22: Solve compilation warnings
|
||||||
- Issue #24: Text selection and table selection algorithm improvement
|
- Issue #24: Text selection and table selection algorithm improvement
|
||||||
- Issue #25: Move Qt 6.4, change build system to CMake and VCPKG
|
- Issue #25: Move Qt 6.4, change build system to CMake and VCPKG
|
||||||
|
- Issue #28: Add multiple PDF files at once for merging
|
||||||
|
|
||||||
V: 1.2.1 30.6.2022
|
V: 1.2.1 30.6.2022
|
||||||
- Issue #17: Public key security handler
|
- Issue #17: Public key security handler
|
||||||
|
Reference in New Issue
Block a user