mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-02-15 03:00:40 +01:00
Icon theme for DocPage Organizer
This commit is contained in:
parent
8ed4259fe0
commit
5cbcb4485f
@ -93,6 +93,50 @@ MainWindow::MainWindow(QWidget* parent) :
|
||||
ui->actionRegroup_by_Bookmarks->setData(int(Operation::RegroupBookmarks));
|
||||
ui->actionRegroup_by_Alternating_Pages->setData(int(Operation::RegroupAlternatingPages));
|
||||
ui->actionRegroup_by_Alternating_Pages_Reversed_Order->setData(int(Operation::RegroupAlternatingPagesReversed));
|
||||
ui->actionPrepare_Icon_Theme->setData(int(Operation::PrepareIconTheme));
|
||||
|
||||
m_iconTheme.registerAction(ui->actionAddDocument, ":/pdfdocpage/resources/open.svg");
|
||||
m_iconTheme.registerAction(ui->actionClose, ":/pdfdocpage/resources/close.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->actionRestoreRemovedItems, ":/pdfdocpage/resources/restore-removed-items.svg");
|
||||
m_iconTheme.registerAction(ui->actionInsert_PDF, ":/pdfdocpage/resources/insert-page-from-pdf.svg");
|
||||
m_iconTheme.registerAction(ui->actionInsert_Image, ":/pdfdocpage/resources/insert-image.svg");
|
||||
m_iconTheme.registerAction(ui->actionInsert_Empty_Page, ":/pdfdocpage/resources/insert-empty-page.svg");
|
||||
m_iconTheme.registerAction(ui->actionCut, ":/pdfdocpage/resources/cut.svg");
|
||||
m_iconTheme.registerAction(ui->actionCopy, ":/pdfdocpage/resources/copy.svg");
|
||||
m_iconTheme.registerAction(ui->actionPaste, ":/pdfdocpage/resources/paste.svg");
|
||||
m_iconTheme.registerAction(ui->actionReplaceSelection, ":/pdfdocpage/resources/replace-selection.svg");
|
||||
m_iconTheme.registerAction(ui->actionSelect_None, ":/pdfdocpage/resources/select-none.svg");
|
||||
m_iconTheme.registerAction(ui->actionSelect_All, ":/pdfdocpage/resources/select-all.svg");
|
||||
m_iconTheme.registerAction(ui->actionSelect_Even, ":/pdfdocpage/resources/select-even.svg");
|
||||
m_iconTheme.registerAction(ui->actionSelect_Odd, ":/pdfdocpage/resources/select-odd.svg");
|
||||
m_iconTheme.registerAction(ui->actionSelect_Portrait, ":/pdfdocpage/resources/select-portrait.svg");
|
||||
m_iconTheme.registerAction(ui->actionSelect_Landscape, ":/pdfdocpage/resources/select-landscape.svg");
|
||||
m_iconTheme.registerAction(ui->actionRotate_Right, ":/pdfdocpage/resources/rotate-right.svg");
|
||||
m_iconTheme.registerAction(ui->actionRotate_Left, ":/pdfdocpage/resources/rotate-left.svg");
|
||||
m_iconTheme.registerAction(ui->actionZoom_In, ":/pdfdocpage/resources/zoom-in.svg");
|
||||
m_iconTheme.registerAction(ui->actionZoom_Out, ":/pdfdocpage/resources/zoom-out.svg");
|
||||
m_iconTheme.registerAction(ui->actionGet_Source, ":/pdfdocpage/resources/get-source.svg");
|
||||
m_iconTheme.registerAction(ui->actionAbout, ":/pdfdocpage/resources/about.svg");
|
||||
m_iconTheme.registerAction(ui->actionUnited_Document, ":/pdfdocpage/resources/make-united-document.svg");
|
||||
m_iconTheme.registerAction(ui->actionSeparate_to_Multiple_Documents, ":/pdfdocpage/resources/make-separated-document.svg");
|
||||
m_iconTheme.registerAction(ui->actionSeparate_to_Multiple_Documents_Grouped, ":/pdfdocpage/resources/make-separated-document-from-groups.svg");
|
||||
m_iconTheme.registerAction(ui->actionGroup, ":/pdfdocpage/resources/group.svg");
|
||||
m_iconTheme.registerAction(ui->actionUngroup, ":/pdfdocpage/resources/ungroup.svg");
|
||||
m_iconTheme.registerAction(ui->actionClear, ":/pdfdocpage/resources/clear.svg");
|
||||
m_iconTheme.registerAction(ui->actionRegroup_Even_Odd, ":/pdfdocpage/resources/regroup-even-odd.svg");
|
||||
m_iconTheme.registerAction(ui->actionRegroup_by_Page_Pairs, ":/pdfdocpage/resources/regroup-pairs.svg");
|
||||
m_iconTheme.registerAction(ui->actionRegroup_by_Bookmarks, ":/pdfdocpage/resources/regroup-bookmarks.svg");
|
||||
m_iconTheme.registerAction(ui->actionRegroup_by_Alternating_Pages, ":/pdfdocpage/resources/regroup-alternating.svg");
|
||||
m_iconTheme.registerAction(ui->actionRegroup_by_Alternating_Pages_Reversed_Order, ":/pdfdocpage/resources/regroup-alternating-reversed.svg");
|
||||
m_iconTheme.registerAction(ui->actionInvert_Selection, ":/pdfdocpage/resources/invert-selection.svg");
|
||||
m_iconTheme.registerAction(ui->actionUndo, ":/pdfdocpage/resources/undo.svg");
|
||||
m_iconTheme.registerAction(ui->actionRedo, ":/pdfdocpage/resources/redo.svg");
|
||||
|
||||
m_iconTheme.setDirectory("pdfdocpage_theme");
|
||||
m_iconTheme.setPrefix(":/pdfdocpage/resources/");
|
||||
m_iconTheme.loadTheme();
|
||||
|
||||
QToolBar* mainToolbar = addToolBar(tr("Main"));
|
||||
mainToolbar->setObjectName("main_toolbar");
|
||||
@ -360,6 +404,7 @@ bool MainWindow::canPerformOperation(Operation operation) const
|
||||
case Operation::InsertPDF:
|
||||
case Operation::GetSource:
|
||||
case Operation::About:
|
||||
case Operation::PrepareIconTheme:
|
||||
return true;
|
||||
|
||||
case Operation::InvertSelection:
|
||||
@ -561,6 +606,10 @@ void MainWindow::performOperation(Operation operation)
|
||||
break;
|
||||
}
|
||||
|
||||
case Operation::PrepareIconTheme:
|
||||
m_iconTheme.prepareTheme();
|
||||
break;
|
||||
|
||||
case Operation::Unite:
|
||||
case Operation::Separate:
|
||||
case Operation::SeparateGrouped:
|
||||
|
@ -18,11 +18,12 @@
|
||||
#ifndef PDFDOCPAGEORGANIZER_MAINWINDOW_H
|
||||
#define PDFDOCPAGEORGANIZER_MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include "pdficontheme.h"
|
||||
|
||||
#include "pageitemmodel.h"
|
||||
#include "pageitemdelegate.h"
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QSignalMapper>
|
||||
|
||||
namespace Ui
|
||||
@ -92,7 +93,8 @@ public:
|
||||
RegroupAlternatingPagesReversed,
|
||||
|
||||
GetSource,
|
||||
About
|
||||
About,
|
||||
PrepareIconTheme
|
||||
};
|
||||
|
||||
private slots:
|
||||
@ -116,6 +118,7 @@ private:
|
||||
|
||||
Ui::MainWindow* ui;
|
||||
|
||||
pdf::PDFIconTheme m_iconTheme;
|
||||
PageItemModel* m_model;
|
||||
PageItemDelegate* m_delegate;
|
||||
Settings m_settings;
|
||||
|
@ -118,6 +118,7 @@
|
||||
</property>
|
||||
<addaction name="actionGet_Source"/>
|
||||
<addaction name="actionAbout"/>
|
||||
<addaction name="actionPrepare_Icon_Theme"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuToolbars">
|
||||
<property name="title">
|
||||
@ -582,6 +583,11 @@
|
||||
<string>Ctrl+Y</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionPrepare_Icon_Theme">
|
||||
<property name="text">
|
||||
<string>Prepare Icon Theme</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="resources.qrc"/>
|
||||
|
@ -57,6 +57,7 @@ SOURCES += \
|
||||
sources/pdfexecutionpolicy.cpp \
|
||||
sources/pdffile.cpp \
|
||||
sources/pdfform.cpp \
|
||||
sources/pdficontheme.cpp \
|
||||
sources/pdfitemmodels.cpp \
|
||||
sources/pdfjavascriptscanner.cpp \
|
||||
sources/pdfjbig2decoder.cpp \
|
||||
@ -123,6 +124,7 @@ HEADERS += \
|
||||
sources/pdfexecutionpolicy.h \
|
||||
sources/pdffile.h \
|
||||
sources/pdfform.h \
|
||||
sources/pdficontheme.h \
|
||||
sources/pdfitemmodels.h \
|
||||
sources/pdfjavascriptscanner.h \
|
||||
sources/pdfjbig2decoder.h \
|
||||
|
123
Pdf4QtLib/sources/pdficontheme.cpp
Normal file
123
Pdf4QtLib/sources/pdficontheme.cpp
Normal file
@ -0,0 +1,123 @@
|
||||
// Copyright (C) 2021 Jakub Melka
|
||||
//
|
||||
// This file is part of PDF4QT.
|
||||
//
|
||||
// PDF4QT is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// with the written consent of the copyright owner, any later version.
|
||||
//
|
||||
// PDF4QT is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "pdficontheme.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
namespace pdf
|
||||
{
|
||||
|
||||
void PDFIconTheme::registerAction(QAction* action, QString iconFileName)
|
||||
{
|
||||
m_actionInfos.emplace_back(action, std::move(iconFileName));
|
||||
}
|
||||
|
||||
QString PDFIconTheme::getDirectory() const
|
||||
{
|
||||
return m_directory;
|
||||
}
|
||||
|
||||
void PDFIconTheme::setDirectory(const QString& directory)
|
||||
{
|
||||
m_directory = directory;
|
||||
}
|
||||
|
||||
QString PDFIconTheme::getPrefix() const
|
||||
{
|
||||
return m_prefix;
|
||||
}
|
||||
|
||||
void PDFIconTheme::setPrefix(const QString& prefix)
|
||||
{
|
||||
m_prefix = prefix;
|
||||
}
|
||||
|
||||
void PDFIconTheme::prepareTheme()
|
||||
{
|
||||
QString directory = getThemeDirectory();
|
||||
QDir dir(directory);
|
||||
|
||||
if (!dir.exists())
|
||||
{
|
||||
dir.mkpath(directory);
|
||||
|
||||
QStringList infoList;
|
||||
|
||||
for (const ActionInfo& actionInfo : m_actionInfos)
|
||||
{
|
||||
QString fileName = formatFileName(actionInfo, directory);
|
||||
if (!QFile::exists(fileName))
|
||||
{
|
||||
QFile::copy(actionInfo.fileName, fileName);
|
||||
QFile::setPermissions(fileName, QFile::Permissions(0xFFFF));
|
||||
}
|
||||
|
||||
infoList << QString("%1;%2").arg(actionInfo.action->text(), fileName);
|
||||
}
|
||||
|
||||
if (!infoList.isEmpty())
|
||||
{
|
||||
QFile file(directory + "/icons.txt");
|
||||
if (file.open(QFile::WriteOnly | QFile::Text | QFile::Truncate))
|
||||
{
|
||||
{
|
||||
QTextStream stream(&file);
|
||||
stream.setCodec("UTF8");
|
||||
stream.setGenerateByteOrderMark(true);
|
||||
for (const QString& text : infoList)
|
||||
{
|
||||
stream << text << endl;
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PDFIconTheme::loadTheme()
|
||||
{
|
||||
QString directory = getThemeDirectory();
|
||||
QDir dir(directory);
|
||||
|
||||
if (dir.exists())
|
||||
{
|
||||
for (const ActionInfo& actionInfo : m_actionInfos)
|
||||
{
|
||||
QString fileName = formatFileName(actionInfo, directory);
|
||||
if (QFile::exists(fileName))
|
||||
{
|
||||
actionInfo.action->setIcon(QIcon(fileName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString PDFIconTheme::getThemeDirectory() const
|
||||
{
|
||||
return QApplication::applicationDirPath() + "/" + m_directory;
|
||||
}
|
||||
|
||||
QString PDFIconTheme::formatFileName(const ActionInfo& info, const QString& themeDirectory) const
|
||||
{
|
||||
QString fileName = info.fileName;
|
||||
fileName.remove(m_prefix);
|
||||
return QString("%1/%2").arg(themeDirectory, fileName);
|
||||
}
|
||||
|
||||
} // namespace pdf
|
72
Pdf4QtLib/sources/pdficontheme.h
Normal file
72
Pdf4QtLib/sources/pdficontheme.h
Normal file
@ -0,0 +1,72 @@
|
||||
// Copyright (C) 2021 Jakub Melka
|
||||
//
|
||||
// This file is part of PDF4QT.
|
||||
//
|
||||
// PDF4QT is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// with the written consent of the copyright owner, any later version.
|
||||
//
|
||||
// PDF4QT is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef PDFICONTHEME_H
|
||||
#define PDFICONTHEME_H
|
||||
|
||||
#include "pdfglobal.h"
|
||||
|
||||
#include <QAction>
|
||||
|
||||
namespace pdf
|
||||
{
|
||||
|
||||
/// Theme icon provider. Can provide icons from custom directory,
|
||||
/// so user can use their own icon theme.
|
||||
class PDF4QTLIBSHARED_EXPORT PDFIconTheme
|
||||
{
|
||||
public:
|
||||
explicit PDFIconTheme() = default;
|
||||
|
||||
void registerAction(QAction* action, QString iconFileName);
|
||||
|
||||
QString getDirectory() const;
|
||||
void setDirectory(const QString& directory);
|
||||
|
||||
QString getPrefix() const;
|
||||
void setPrefix(const QString& prefix);
|
||||
|
||||
void prepareTheme();
|
||||
void loadTheme();
|
||||
|
||||
QString getThemeDirectory() const;
|
||||
|
||||
private:
|
||||
struct ActionInfo
|
||||
{
|
||||
ActionInfo(QAction* action = nullptr, QString fileName = QString()) :
|
||||
action(action),
|
||||
fileName(std::move(fileName))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QAction* action = nullptr;
|
||||
QString fileName;
|
||||
};
|
||||
|
||||
QString m_directory;
|
||||
QString m_prefix;
|
||||
|
||||
QString formatFileName(const ActionInfo& info, const QString& themeDirectory) const;
|
||||
|
||||
std::vector<ActionInfo> m_actionInfos;
|
||||
};
|
||||
|
||||
} // namespace pdf
|
||||
|
||||
#endif // PDFICONTHEME_H
|
Loading…
x
Reference in New Issue
Block a user