mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
Snapper, some code for screenshot tool
This commit is contained in:
@@ -44,8 +44,7 @@ SOURCES += \
|
||||
pdftexttospeech.cpp \
|
||||
pdfviewermainwindow.cpp \
|
||||
pdfviewersettings.cpp \
|
||||
pdfviewersettingsdialog.cpp \
|
||||
pdfwidgetutils.cpp
|
||||
pdfviewersettingsdialog.cpp
|
||||
|
||||
HEADERS += \
|
||||
pdfaboutdialog.h \
|
||||
@@ -58,8 +57,7 @@ HEADERS += \
|
||||
pdftexttospeech.h \
|
||||
pdfviewermainwindow.h \
|
||||
pdfviewersettings.h \
|
||||
pdfviewersettingsdialog.h \
|
||||
pdfwidgetutils.h
|
||||
pdfviewersettingsdialog.h
|
||||
|
||||
FORMS += \
|
||||
pdfaboutdialog.ui \
|
||||
|
@@ -48,7 +48,7 @@ PDFAboutDialog::PDFAboutDialog(QWidget* parent) :
|
||||
ui->tableWidget->setItem(i, 3, new QTableWidgetItem(info.url));
|
||||
}
|
||||
|
||||
PDFWidgetUtils::scaleWidget(this, QSize(750, 600));
|
||||
pdf::PDFWidgetUtils::scaleWidget(this, QSize(750, 600));
|
||||
}
|
||||
|
||||
PDFAboutDialog::~PDFAboutDialog()
|
||||
|
@@ -48,13 +48,13 @@ PDFDocumentPropertiesDialog::PDFDocumentPropertiesDialog(const pdf::PDFDocument*
|
||||
initializeFonts(document);
|
||||
initializeDisplayAndPrintSettings(document);
|
||||
|
||||
const int minimumSectionSize = PDFWidgetUtils::scaleDPI_x(this, 300);
|
||||
const int minimumSectionSize = pdf::PDFWidgetUtils::scaleDPI_x(this, 300);
|
||||
for (QTreeWidget* widget : findChildren<QTreeWidget*>(QString(), Qt::FindChildrenRecursively))
|
||||
{
|
||||
widget->header()->setMinimumSectionSize(minimumSectionSize);
|
||||
}
|
||||
|
||||
PDFWidgetUtils::scaleWidget(this, QSize(750, 600));
|
||||
pdf::PDFWidgetUtils::scaleWidget(this, QSize(750, 600));
|
||||
}
|
||||
|
||||
PDFDocumentPropertiesDialog::~PDFDocumentPropertiesDialog()
|
||||
|
@@ -41,5 +41,6 @@
|
||||
<file>resources/play.svg</file>
|
||||
<file>resources/stop.svg</file>
|
||||
<file>resources/magnifier.svg</file>
|
||||
<file>resources/screenshot-tool.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@@ -80,7 +80,7 @@ PDFRenderToImagesDialog::PDFRenderToImagesDialog(const pdf::PDFDocument* documen
|
||||
loadImageWriterSettings();
|
||||
loadImageExportSettings();
|
||||
|
||||
PDFWidgetUtils::scaleWidget(this, QSize(1000, 600));
|
||||
pdf::PDFWidgetUtils::scaleWidget(this, QSize(1000, 600));
|
||||
}
|
||||
|
||||
PDFRenderToImagesDialog::~PDFRenderToImagesDialog()
|
||||
|
@@ -356,7 +356,7 @@ void PDFSidebarWidget::onOutlineItemClicked(const QModelIndex& index)
|
||||
|
||||
void PDFSidebarWidget::onThumbnailsSizeChanged(int size)
|
||||
{
|
||||
const int thumbnailsSize = PDFWidgetUtils::getPixelSize(this, size * 10.0);
|
||||
const int thumbnailsSize = pdf::PDFWidgetUtils::getPixelSize(this, size * 10.0);
|
||||
Q_ASSERT(thumbnailsSize > 0);
|
||||
m_thumbnailsModel->setThumbnailsSize(thumbnailsSize);
|
||||
}
|
||||
|
@@ -94,7 +94,7 @@ PDFViewerMainWindow::PDFViewerMainWindow(QWidget* parent) :
|
||||
ui->setupUi(this);
|
||||
|
||||
// Initialize toolbar icon size
|
||||
QSize iconSize = PDFWidgetUtils::scaleDPI(this, QSize(24, 24));
|
||||
QSize iconSize = pdf::PDFWidgetUtils::scaleDPI(this, QSize(24, 24));
|
||||
ui->mainToolBar->setIconSize(iconSize);
|
||||
|
||||
// Initialize task bar progress
|
||||
@@ -190,6 +190,7 @@ PDFViewerMainWindow::PDFViewerMainWindow(QWidget* parent) :
|
||||
// Tools
|
||||
ui->mainToolBar->addAction(ui->actionSelectText);
|
||||
ui->mainToolBar->addAction(ui->actionMagnifier);
|
||||
ui->mainToolBar->addAction(ui->actionScreenshot);
|
||||
|
||||
connect(ui->actionZoom_In, &QAction::triggered, this, [this] { m_pdfWidget->getDrawWidgetProxy()->performOperation(pdf::PDFDrawWidgetProxy::ZoomIn); });
|
||||
connect(ui->actionZoom_Out, &QAction::triggered, this, [this] { m_pdfWidget->getDrawWidgetProxy()->performOperation(pdf::PDFDrawWidgetProxy::ZoomOut); });
|
||||
@@ -253,6 +254,7 @@ PDFViewerMainWindow::PDFViewerMainWindow(QWidget* parent) :
|
||||
actions.deselectAction = ui->actionDeselectText;
|
||||
actions.copyTextAction = ui->actionCopyText;
|
||||
actions.magnifierAction = ui->actionMagnifier;
|
||||
actions.screenshotToolAction = ui->actionScreenshot;
|
||||
m_toolManager = new pdf::PDFToolManager(m_pdfWidget->getDrawWidgetProxy(), actions, this, this);
|
||||
m_pdfWidget->setToolManager(m_toolManager);
|
||||
updateMagnifierToolSettings();
|
||||
@@ -1129,7 +1131,7 @@ void PDFViewerMainWindow::on_actionRendering_Errors_triggered()
|
||||
void PDFViewerMainWindow::updateMagnifierToolSettings()
|
||||
{
|
||||
pdf::PDFMagnifierTool* magnifierTool = m_toolManager->getMagnifierTool();
|
||||
magnifierTool->setMagnifierSize(PDFWidgetUtils::scaleDPI_x(this, m_settings->getSettings().m_magnifierSize));
|
||||
magnifierTool->setMagnifierSize(pdf::PDFWidgetUtils::scaleDPI_x(this, m_settings->getSettings().m_magnifierSize));
|
||||
magnifierTool->setMagnifierZoom(m_settings->getSettings().m_magnifierZoom);
|
||||
}
|
||||
|
||||
|
@@ -87,6 +87,7 @@
|
||||
<string>Tools</string>
|
||||
</property>
|
||||
<addaction name="actionMagnifier"/>
|
||||
<addaction name="actionScreenshot"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionRendering_Errors"/>
|
||||
<addaction name="separator"/>
|
||||
@@ -473,6 +474,18 @@
|
||||
<string>Magnifier Tool</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionScreenshot">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="pdfforqtviewer.qrc">
|
||||
<normaloff>:/resources/screenshot-tool.svg</normaloff>:/resources/screenshot-tool.svg</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Screenshot</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources>
|
||||
|
@@ -1,79 +0,0 @@
|
||||
// Copyright (C) 2019-2020 Jakub Melka
|
||||
//
|
||||
// This file is part of PdfForQt.
|
||||
//
|
||||
// PdfForQt 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// PdfForQt 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 PDFForQt. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#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
|
||||
{
|
||||
|
||||
int PDFWidgetUtils::getPixelSize(QWidget* widget, pdf::PDFReal sizeMM)
|
||||
{
|
||||
const int width = widget->width();
|
||||
const int height = widget->height();
|
||||
|
||||
if (width > height)
|
||||
{
|
||||
return pdf::PDFReal(width) * sizeMM / pdf::PDFReal(widget->widthMM());
|
||||
}
|
||||
else
|
||||
{
|
||||
return pdf::PDFReal(height) * sizeMM / pdf::PDFReal(widget->heightMM());
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
QSize PDFWidgetUtils::scaleDPI(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();
|
||||
|
||||
return QSize(width, height);
|
||||
}
|
||||
|
||||
} // namespace pdfviewer
|
@@ -1,52 +0,0 @@
|
||||
// Copyright (C) 2019-2020 Jakub Melka
|
||||
//
|
||||
// This file is part of PdfForQt.
|
||||
//
|
||||
// PdfForQt 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// PdfForQt 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 PDFForQt. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef PDFWIDGETUTILS_H
|
||||
#define PDFWIDGETUTILS_H
|
||||
|
||||
#include "pdfglobal.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace pdfviewer
|
||||
{
|
||||
|
||||
class PDFWidgetUtils
|
||||
{
|
||||
public:
|
||||
PDFWidgetUtils() = delete;
|
||||
|
||||
/// Converts size in MM to pixel size
|
||||
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);
|
||||
|
||||
/// Scales size based on DPI
|
||||
/// \param widget Widget, from which we get DPI
|
||||
/// \param unscaledSize Unscaled size
|
||||
static QSize scaleDPI(QWidget* widget, QSize unscaledSize);
|
||||
};
|
||||
|
||||
} // namespace pdfviewer
|
||||
|
||||
#endif // PDFWIDGETUTILS_H
|
135
PdfForQtViewer/resources/screenshot-tool.svg
Normal file
135
PdfForQtViewer/resources/screenshot-tool.svg
Normal file
@@ -0,0 +1,135 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="30mm"
|
||||
height="30mm"
|
||||
viewBox="0 0 30 30"
|
||||
version="1.1"
|
||||
id="svg5291"
|
||||
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
|
||||
sodipodi:docname="screenshot-tool.svg">
|
||||
<defs
|
||||
id="defs5285">
|
||||
<inkscape:perspective
|
||||
sodipodi:type="inkscape:persp3d"
|
||||
inkscape:vp_x="0 : 15 : 1"
|
||||
inkscape:vp_y="0 : 1000 : 0"
|
||||
inkscape:vp_z="30 : 15 : 1"
|
||||
inkscape:persp3d-origin="15 : 10 : 1"
|
||||
id="perspective5921" />
|
||||
</defs>
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="0.35355338"
|
||||
inkscape:cx="813.01344"
|
||||
inkscape:cy="-622.0065"
|
||||
inkscape:document-units="mm"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="false"
|
||||
inkscape:window-width="3840"
|
||||
inkscape:window-height="2035"
|
||||
inkscape:window-x="-13"
|
||||
inkscape:window-y="-13"
|
||||
inkscape:window-maximized="1" />
|
||||
<metadata
|
||||
id="metadata5288">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
<dc:creator>
|
||||
<cc:Agent>
|
||||
<dc:title>Jakub Melka</dc:title>
|
||||
</cc:Agent>
|
||||
</dc:creator>
|
||||
<cc:license
|
||||
rdf:resource="http://creativecommons.org/licenses/by-sa/4.0/" />
|
||||
</cc:Work>
|
||||
<cc:License
|
||||
rdf:about="http://creativecommons.org/licenses/by-sa/4.0/">
|
||||
<cc:permits
|
||||
rdf:resource="http://creativecommons.org/ns#Reproduction" />
|
||||
<cc:permits
|
||||
rdf:resource="http://creativecommons.org/ns#Distribution" />
|
||||
<cc:requires
|
||||
rdf:resource="http://creativecommons.org/ns#Notice" />
|
||||
<cc:requires
|
||||
rdf:resource="http://creativecommons.org/ns#Attribution" />
|
||||
<cc:permits
|
||||
rdf:resource="http://creativecommons.org/ns#DerivativeWorks" />
|
||||
<cc:requires
|
||||
rdf:resource="http://creativecommons.org/ns#ShareAlike" />
|
||||
</cc:License>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Vrstva 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(0,-267)">
|
||||
<flowRoot
|
||||
xml:space="preserve"
|
||||
id="flowRoot5913"
|
||||
style="font-style:normal;font-weight:normal;font-size:40px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none"><flowRegion
|
||||
id="flowRegion5915"><rect
|
||||
id="rect5917"
|
||||
width="129.22377"
|
||||
height="91.747108"
|
||||
x="-13.788582"
|
||||
y="-33.515606" /></flowRegion><flowPara
|
||||
id="flowPara5919" /></flowRoot> <flowRoot
|
||||
xml:space="preserve"
|
||||
id="flowRoot843"
|
||||
style="font-style:italic;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:40px;line-height:1.25;font-family:sans-serif;-inkscape-font-specification:'sans-serif Italic';letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none"><flowRegion
|
||||
id="flowRegion845"><rect
|
||||
id="rect847"
|
||||
width="159.09903"
|
||||
height="129.04698"
|
||||
x="-37.123108"
|
||||
y="-35.460152" /></flowRegion><flowPara
|
||||
id="flowPara849" /></flowRoot> <rect
|
||||
style="fill:none;fill-opacity:1;stroke:#000000;stroke-width:1.39999998;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers"
|
||||
id="rect851"
|
||||
width="24.789249"
|
||||
height="16.884754"
|
||||
x="2.5958552"
|
||||
y="275.43802" />
|
||||
<rect
|
||||
style="fill:none;fill-opacity:1;stroke:#000000;stroke-width:1.78122473;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers"
|
||||
id="rect853"
|
||||
width="2.7173724"
|
||||
height="1.2168522"
|
||||
x="4.1575332"
|
||||
y="273.02496" />
|
||||
<ellipse
|
||||
style="fill:none;fill-opacity:1;stroke:#000000;stroke-width:1.39999998;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers"
|
||||
id="path855"
|
||||
cx="14.84974"
|
||||
cy="283.91141"
|
||||
rx="5.589323"
|
||||
ry="5.4322267" />
|
||||
<ellipse
|
||||
style="fill:none;fill-opacity:1;stroke:#000000;stroke-width:1.39999998;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers"
|
||||
id="path857"
|
||||
cx="14.896935"
|
||||
cy="283.81024"
|
||||
rx="3.0401912"
|
||||
ry="2.9934189" />
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 5.0 KiB |
Reference in New Issue
Block a user