mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-02-20 21:50:38 +01:00
Finishing of document properties
This commit is contained in:
parent
f48709c8c5
commit
1fafd3835c
@ -23,6 +23,8 @@
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
QApplication::setAttribute(Qt::AA_CompressHighFrequencyEvents, true);
|
||||||
|
QApplication::setAttribute(Qt::AA_DisableHighDpiScaling, true);
|
||||||
QApplication application(argc, argv);
|
QApplication application(argc, argv);
|
||||||
|
|
||||||
QCoreApplication::setOrganizationName("MelkaJ");
|
QCoreApplication::setOrganizationName("MelkaJ");
|
||||||
|
@ -19,8 +19,12 @@
|
|||||||
#include "ui_pdfaboutdialog.h"
|
#include "ui_pdfaboutdialog.h"
|
||||||
|
|
||||||
#include "pdfutils.h"
|
#include "pdfutils.h"
|
||||||
|
#include "pdfwidgetutils.h"
|
||||||
|
|
||||||
PDFAboutDialog::PDFAboutDialog(QWidget *parent) :
|
namespace pdfviewer
|
||||||
|
{
|
||||||
|
|
||||||
|
PDFAboutDialog::PDFAboutDialog(QWidget* parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
ui(new Ui::PDFAboutDialog)
|
ui(new Ui::PDFAboutDialog)
|
||||||
{
|
{
|
||||||
@ -43,9 +47,13 @@ PDFAboutDialog::PDFAboutDialog(QWidget *parent) :
|
|||||||
ui->tableWidget->setItem(i, 2, new QTableWidgetItem(info.license));
|
ui->tableWidget->setItem(i, 2, new QTableWidgetItem(info.license));
|
||||||
ui->tableWidget->setItem(i, 3, new QTableWidgetItem(info.url));
|
ui->tableWidget->setItem(i, 3, new QTableWidgetItem(info.url));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PDFWidgetUtils::scaleWidget(this, QSize(750, 600));
|
||||||
}
|
}
|
||||||
|
|
||||||
PDFAboutDialog::~PDFAboutDialog()
|
PDFAboutDialog::~PDFAboutDialog()
|
||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace viewer
|
||||||
|
@ -25,16 +25,21 @@ namespace Ui
|
|||||||
class PDFAboutDialog;
|
class PDFAboutDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace pdfviewer
|
||||||
|
{
|
||||||
|
|
||||||
class PDFAboutDialog : public QDialog
|
class PDFAboutDialog : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit PDFAboutDialog(QWidget* parent = nullptr);
|
explicit PDFAboutDialog(QWidget* parent = nullptr);
|
||||||
~PDFAboutDialog();
|
virtual ~PDFAboutDialog() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::PDFAboutDialog* ui;
|
Ui::PDFAboutDialog* ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace pdfviewer
|
||||||
|
|
||||||
#endif // PDFABOUTDIALOG_H
|
#endif // PDFABOUTDIALOG_H
|
||||||
|
@ -45,10 +45,15 @@ PDFDocumentPropertiesDialog::PDFDocumentPropertiesDialog(const pdf::PDFDocument*
|
|||||||
initializeFileInfoProperties(fileInfo);
|
initializeFileInfoProperties(fileInfo);
|
||||||
initializeSecurity(document);
|
initializeSecurity(document);
|
||||||
initializeFonts(document);
|
initializeFonts(document);
|
||||||
|
initializeDisplayAndPrintSettings(document);
|
||||||
|
|
||||||
const int defaultWidth = PDFWidgetUtils::getPixelSize(this, 240.0);
|
const int minimumSectionSize = PDFWidgetUtils::scaleDPI_x(this, 300);
|
||||||
const int defaultHeight = PDFWidgetUtils::getPixelSize(this, 200.0);
|
for (QTreeWidget* widget : findChildren<QTreeWidget*>(QString(), Qt::FindChildrenRecursively))
|
||||||
resize(defaultWidth, defaultHeight);
|
{
|
||||||
|
widget->header()->setMinimumSectionSize(minimumSectionSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
PDFWidgetUtils::scaleWidget(this, QSize(750, 600));
|
||||||
}
|
}
|
||||||
|
|
||||||
PDFDocumentPropertiesDialog::~PDFDocumentPropertiesDialog()
|
PDFDocumentPropertiesDialog::~PDFDocumentPropertiesDialog()
|
||||||
@ -212,8 +217,12 @@ void PDFDocumentPropertiesDialog::initializeSecurity(const pdf::PDFDocument* doc
|
|||||||
|
|
||||||
new QTreeWidgetItem(securityRoot, { tr("Document encryption"), modeString });
|
new QTreeWidgetItem(securityRoot, { tr("Document encryption"), modeString });
|
||||||
new QTreeWidgetItem(securityRoot, { tr("Authorized as"), authorizationMode });
|
new QTreeWidgetItem(securityRoot, { tr("Authorized as"), authorizationMode });
|
||||||
new QTreeWidgetItem(securityRoot, { tr("Metadata encrypted"), securityHandler->isMetadataEncrypted() ? tr("Yes") : tr("No") });
|
|
||||||
new QTreeWidgetItem(securityRoot, { tr("Version"), locale.toString(securityHandler->getVersion()) });
|
if (securityHandler->getAuthorizationResult() != pdf::PDFSecurityHandler::AuthorizationResult::NoAuthorizationRequired)
|
||||||
|
{
|
||||||
|
new QTreeWidgetItem(securityRoot, { tr("Metadata encrypted"), securityHandler->isMetadataEncrypted() ? tr("Yes") : tr("No") });
|
||||||
|
new QTreeWidgetItem(securityRoot, { tr("Version"), locale.toString(securityHandler->getVersion()) });
|
||||||
|
}
|
||||||
|
|
||||||
QTreeWidgetItem* permissionsRoot = new QTreeWidgetItem({ tr("Permissions") });
|
QTreeWidgetItem* permissionsRoot = new QTreeWidgetItem({ tr("Permissions") });
|
||||||
|
|
||||||
@ -367,6 +376,152 @@ void PDFDocumentPropertiesDialog::initializeFonts(const pdf::PDFDocument* docume
|
|||||||
m_futureWatcher.setFuture(m_future);
|
m_futureWatcher.setFuture(m_future);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PDFDocumentPropertiesDialog::initializeDisplayAndPrintSettings(const pdf::PDFDocument* document)
|
||||||
|
{
|
||||||
|
const pdf::PDFCatalog* catalog = document->getCatalog();
|
||||||
|
pdf::PageLayout pageLayout = catalog->getPageLayout();
|
||||||
|
pdf::PageMode pageMode = catalog->getPageMode();
|
||||||
|
const pdf::PDFViewerPreferences* viewerPreferences = catalog->getViewerPreferences();
|
||||||
|
|
||||||
|
QTreeWidgetItem* viewerSettingsRoot = new QTreeWidgetItem({ tr("Viewer settings") });
|
||||||
|
QTreeWidgetItem* printerSettingsRoot = new QTreeWidgetItem({ tr("Default printer settings") });
|
||||||
|
|
||||||
|
QString pageLayoutString;
|
||||||
|
switch (pageLayout)
|
||||||
|
{
|
||||||
|
case pdf::PageLayout::SinglePage:
|
||||||
|
pageLayoutString = tr("Single page");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case pdf::PageLayout::OneColumn:
|
||||||
|
pageLayoutString = tr("Continuous column");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case pdf::PageLayout::TwoColumnLeft:
|
||||||
|
case pdf::PageLayout::TwoColumnRight:
|
||||||
|
pageLayoutString = tr("Two continuous columns");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case pdf::PageLayout::TwoPagesLeft:
|
||||||
|
case pdf::PageLayout::TwoPagesRight:
|
||||||
|
pageLayoutString = tr("Two pages");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Q_ASSERT(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString pageModeString;
|
||||||
|
switch (pageMode)
|
||||||
|
{
|
||||||
|
case pdf::PageMode::UseNone:
|
||||||
|
pageModeString = tr("Default");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case pdf::PageMode::UseOutlines:
|
||||||
|
pageModeString = tr("Show outlines");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case pdf::PageMode::UseThumbnails:
|
||||||
|
pageModeString = tr("Show thumbnails");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case pdf::PageMode::Fullscreen:
|
||||||
|
pageModeString = tr("Fullscreen");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case pdf::PageMode::UseOptionalContent:
|
||||||
|
pageModeString = tr("Show optional content");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case pdf::PageMode::UseAttachments:
|
||||||
|
pageModeString = tr("Show attachments");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Q_ASSERT(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString directionString;
|
||||||
|
switch (viewerPreferences->getDirection())
|
||||||
|
{
|
||||||
|
case pdf::PDFViewerPreferences::Direction::LeftToRight:
|
||||||
|
directionString = tr("Left to right");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case pdf::PDFViewerPreferences::Direction::RightToLeft:
|
||||||
|
directionString = tr("Right to left");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Q_ASSERT(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
new QTreeWidgetItem(viewerSettingsRoot, { tr("Page layout"), pageLayoutString });
|
||||||
|
new QTreeWidgetItem(viewerSettingsRoot, { tr("View mode"), pageModeString });
|
||||||
|
new QTreeWidgetItem(viewerSettingsRoot, { tr("Writing direction"), directionString });
|
||||||
|
|
||||||
|
QString printScalingString;
|
||||||
|
switch (viewerPreferences->getPrintScaling())
|
||||||
|
{
|
||||||
|
case pdf::PDFViewerPreferences::PrintScaling::None:
|
||||||
|
printScalingString = tr("None");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case pdf::PDFViewerPreferences::PrintScaling::AppDefault:
|
||||||
|
printScalingString = tr("Application default");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Q_ASSERT(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
new QTreeWidgetItem(printerSettingsRoot, { tr("Scale"), printScalingString });
|
||||||
|
|
||||||
|
QString duplexString;
|
||||||
|
switch (viewerPreferences->getDuplex())
|
||||||
|
{
|
||||||
|
case pdf::PDFViewerPreferences::Duplex::None:
|
||||||
|
duplexString = tr("None");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case pdf::PDFViewerPreferences::Duplex::Simplex:
|
||||||
|
duplexString = tr("Simplex");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case pdf::PDFViewerPreferences::Duplex::DuplexFlipLongEdge:
|
||||||
|
duplexString = tr("Duplex (flip long edge)");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case pdf::PDFViewerPreferences::Duplex::DuplexFlipShortEdge:
|
||||||
|
duplexString = tr("Duplex (flip long edge)");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Q_ASSERT(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
new QTreeWidgetItem(printerSettingsRoot, { tr("Duplex mode"), duplexString });
|
||||||
|
new QTreeWidgetItem(printerSettingsRoot, { tr("Pick tray by page size"), viewerPreferences->getOptions().testFlag(pdf::PDFViewerPreferences::PickTrayByPDFSize) ? tr("Yes") : tr("No") });
|
||||||
|
|
||||||
|
QStringList pageRanges;
|
||||||
|
for (const std::pair<pdf::PDFInteger, pdf::PDFInteger>& pageRange : viewerPreferences->getPrintPageRanges())
|
||||||
|
{
|
||||||
|
pageRanges << QString("%1-%2").arg(pageRange.first).arg(pageRange.second);
|
||||||
|
}
|
||||||
|
QString pageRangesString = pageRanges.join(",");
|
||||||
|
new QTreeWidgetItem(printerSettingsRoot, { tr("Default print page ranges"), pageRangesString });
|
||||||
|
new QTreeWidgetItem(printerSettingsRoot, { tr("Number of copies"), QString::number(viewerPreferences->getNumberOfCopies()) });
|
||||||
|
|
||||||
|
ui->displayAndPrintTreeWidget->addTopLevelItem(viewerSettingsRoot);
|
||||||
|
ui->displayAndPrintTreeWidget->addTopLevelItem(printerSettingsRoot);
|
||||||
|
ui->displayAndPrintTreeWidget->expandAll();
|
||||||
|
ui->displayAndPrintTreeWidget->resizeColumnToContents(0);
|
||||||
|
}
|
||||||
|
|
||||||
void PDFDocumentPropertiesDialog::onFontsFinished()
|
void PDFDocumentPropertiesDialog::onFontsFinished()
|
||||||
{
|
{
|
||||||
if (!m_fontTreeWidgetItems.empty())
|
if (!m_fontTreeWidgetItems.empty())
|
||||||
|
@ -73,6 +73,7 @@ private:
|
|||||||
void initializeFileInfoProperties(const PDFFileInfo* fileInfo);
|
void initializeFileInfoProperties(const PDFFileInfo* fileInfo);
|
||||||
void initializeSecurity(const pdf::PDFDocument* document);
|
void initializeSecurity(const pdf::PDFDocument* document);
|
||||||
void initializeFonts(const pdf::PDFDocument* document);
|
void initializeFonts(const pdf::PDFDocument* document);
|
||||||
|
void initializeDisplayAndPrintSettings(const pdf::PDFDocument* document);
|
||||||
|
|
||||||
void onFontsFinished();
|
void onFontsFinished();
|
||||||
|
|
||||||
|
@ -156,6 +156,42 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QWidget" name="displayAndPrintTab">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Display && Print</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QVBoxLayout" name="displayAndPrintPageLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="displayAndPrintGroupBox">
|
||||||
|
<property name="title">
|
||||||
|
<string>Display && Print Settings</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QTreeWidget" name="displayAndPrintTreeWidget">
|
||||||
|
<property name="columnCount">
|
||||||
|
<number>2</number>
|
||||||
|
</property>
|
||||||
|
<attribute name="headerVisible">
|
||||||
|
<bool>false</bool>
|
||||||
|
</attribute>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true">1</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true">2</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
@ -17,6 +17,13 @@
|
|||||||
|
|
||||||
#include "pdfwidgetutils.h"
|
#include "pdfwidgetutils.h"
|
||||||
|
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
int qt_default_dpi_x() { return 72; }
|
||||||
|
int qt_default_dpi_y() { return 72; }
|
||||||
|
#else
|
||||||
|
int qt_default_dpi_x() { return 96; }
|
||||||
|
int qt_default_dpi_y() { return 96; }
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace pdfviewer
|
namespace pdfviewer
|
||||||
{
|
{
|
||||||
@ -36,4 +43,24 @@ int PDFWidgetUtils::getPixelSize(QWidget* widget, pdf::PDFReal sizeMM)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int PDFWidgetUtils::scaleDPI_x(QWidget* widget, int unscaledSize)
|
||||||
|
{
|
||||||
|
const double logicalDPI_x = widget->logicalDpiX();
|
||||||
|
const double defaultDPI_x = qt_default_dpi_x();
|
||||||
|
return (logicalDPI_x / defaultDPI_x) * unscaledSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PDFWidgetUtils::scaleWidget(QWidget* widget, QSize unscaledSize)
|
||||||
|
{
|
||||||
|
const double logicalDPI_x = widget->logicalDpiX();
|
||||||
|
const double logicalDPI_y = widget->logicalDpiY();
|
||||||
|
const double defaultDPI_x = qt_default_dpi_x();
|
||||||
|
const double defaultDPI_y = qt_default_dpi_y();
|
||||||
|
|
||||||
|
const int width = (logicalDPI_x / defaultDPI_x) * unscaledSize.width();
|
||||||
|
const int height = (logicalDPI_y / defaultDPI_y) * unscaledSize.height();
|
||||||
|
|
||||||
|
widget->resize(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace pdfviewer
|
} // namespace pdfviewer
|
||||||
|
@ -32,6 +32,14 @@ public:
|
|||||||
|
|
||||||
/// Converts size in MM to pixel size
|
/// Converts size in MM to pixel size
|
||||||
static int getPixelSize(QWidget* widget, pdf::PDFReal sizeMM);
|
static int getPixelSize(QWidget* widget, pdf::PDFReal sizeMM);
|
||||||
|
|
||||||
|
/// Scale horizontal DPI value
|
||||||
|
static int scaleDPI_x(QWidget* widget, int unscaledSize);
|
||||||
|
|
||||||
|
/// Scales widget based on DPI
|
||||||
|
/// \param widget Widget to be scaled
|
||||||
|
/// \param unscaledSize Unscaled size of the widget
|
||||||
|
static void scaleWidget(QWidget* widget, QSize unscaledSize);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace pdfviewer
|
} // namespace pdfviewer
|
||||||
|
Loading…
x
Reference in New Issue
Block a user