Files
PDF4QT/Pdf4QtEditor/main.cpp
2025-04-27 12:39:06 +02:00

112 lines
3.8 KiB
C++

// MIT License
//
// Copyright (c) 2018-2025 Jakub Melka and Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include "pdfeditormainwindow.h"
#include "pdfconstants.h"
#include "pdfsecurityhandler.h"
#include "pdfwidgetutils.h"
#include "pdfviewersettings.h"
#include "pdfapplicationtranslator.h"
#include <QSettings>
#include <QApplication>
#include <QCommandLineParser>
#include "pdfdbgheap.h"
int main(int argc, char *argv[])
{
#if defined(PDF4QT_USE_DBG_HEAP)
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
QApplication::setAttribute(Qt::AA_CompressHighFrequencyEvents, true);
QApplication application(argc, argv);
QCoreApplication::setOrganizationName("MelkaJ");
QCoreApplication::setApplicationName("PDF4QT Editor");
QCoreApplication::setApplicationVersion(pdf::PDF_LIBRARY_VERSION);
QApplication::setApplicationDisplayName(QApplication::translate("Application", "PDF4QT Editor"));
QCommandLineOption noDrm("no-drm", "Disable DRM settings of documents.");
QCommandLineOption lightGui("theme-light", "Use a light theme for the GUI.");
QCommandLineOption darkGui("theme-dark", "Use a dark theme for the GUI.");
QCommandLineParser parser;
parser.setApplicationDescription(QCoreApplication::applicationName());
parser.addOption(noDrm);
parser.addOption(lightGui);
parser.addOption(darkGui);
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument("file", "The PDF file to open.");
parser.process(application);
if (parser.isSet(noDrm))
{
pdf::PDFSecurityHandler::setNoDRMMode();
}
pdf::PDFApplicationTranslator translator;
translator.loadSettings();
translator.installTranslator();
bool isLightGui = false;
bool isDarkGui = false;
const pdfviewer::PDFViewerSettings::ColorScheme colorScheme = pdfviewer::PDFViewerSettings::getColorSchemeStatic();
switch (colorScheme)
{
case pdfviewer::PDFViewerSettings::AutoScheme:
isLightGui = parser.isSet(lightGui);
isDarkGui = parser.isSet(darkGui);
break;
case pdfviewer::PDFViewerSettings::LightScheme:
isLightGui = true;
break;
case pdfviewer::PDFViewerSettings::DarkScheme:
isDarkGui = true;
break;
default:
Q_ASSERT(false);
break;
}
pdf::PDFWidgetUtils::setDarkTheme(isLightGui, isDarkGui);
QIcon appIcon(":/app-icon.svg");
QApplication::setWindowIcon(appIcon);
pdfviewer::PDFEditorMainWindow mainWindow;
mainWindow.show();
QStringList arguments = parser.positionalArguments();
if (!arguments.isEmpty())
{
mainWindow.getProgramController()->openDocument(arguments.front());
}
return application.exec();
}