Screenshot tool - finishing, fixing bugs

This commit is contained in:
Jakub Melka 2020-02-29 11:25:23 +01:00
parent 13bfbd7095
commit 9de47cc183
6 changed files with 28 additions and 13 deletions

View File

@ -238,6 +238,14 @@ qt_plugin_platform.files = $$[QT_INSTALL_PLUGINS]/platforms/qwindows$${SUFFIX}.d
qt_plugin_platform.path = $$DESTDIR/install/platforms qt_plugin_platform.path = $$DESTDIR/install/platforms
INSTALLS += qt_plugin_platform INSTALLS += qt_plugin_platform
qt_plugin_style.files = $$[QT_INSTALL_PLUGINS]/styles/qwindowsvistastyle$${SUFFIX}.dll
qt_plugin_style.path = $$DESTDIR/install/styles
INSTALLS += qt_plugin_style
qt_plugin_imageformat.files = $$[QT_INSTALL_PLUGINS]/imageformats/q*$${SUFFIX}.dll
qt_plugin_imageformat.path = $$DESTDIR/install/imageformats
INSTALLS += qt_plugin_imageformat
qt_plugin_iconengine.files = $$[QT_INSTALL_PLUGINS]/iconengines/qsvgicon$${SUFFIX}.dll qt_plugin_iconengine.files = $$[QT_INSTALL_PLUGINS]/iconengines/qsvgicon$${SUFFIX}.dll
qt_plugin_iconengine.path = $$DESTDIR/install/iconengines qt_plugin_iconengine.path = $$DESTDIR/install/iconengines
INSTALLS += qt_plugin_iconengine INSTALLS += qt_plugin_iconengine

View File

@ -647,7 +647,7 @@ QMatrix PDFDrawWidgetProxy::createPagePointToDevicePointMatrix(const PDFPage* pa
void PDFDrawWidgetProxy::draw(QPainter* painter, QRect rect) void PDFDrawWidgetProxy::draw(QPainter* painter, QRect rect)
{ {
drawPages(painter, rect); drawPages(painter, rect, m_features);
for (IDocumentDrawInterface* drawInterface : m_drawInterfaces) for (IDocumentDrawInterface* drawInterface : m_drawInterfaces)
{ {
@ -668,7 +668,7 @@ QColor PDFDrawWidgetProxy::getPaperColor()
return paperColor; return paperColor;
} }
void PDFDrawWidgetProxy::drawPages(QPainter* painter, QRect rect) void PDFDrawWidgetProxy::drawPages(QPainter* painter, QRect rect, PDFRenderer::Features features)
{ {
painter->fillRect(rect, Qt::lightGray); painter->fillRect(rect, Qt::lightGray);
QMatrix baseMatrix = painter->worldMatrix(); QMatrix baseMatrix = painter->worldMatrix();
@ -696,11 +696,11 @@ void PDFDrawWidgetProxy::drawPages(QPainter* painter, QRect rect)
const PDFPage* page = m_controller->getDocument()->getCatalog()->getPage(item.pageIndex); const PDFPage* page = m_controller->getDocument()->getCatalog()->getPage(item.pageIndex);
QMatrix matrix = createPagePointToDevicePointMatrix(page, placedRect) * baseMatrix; QMatrix matrix = createPagePointToDevicePointMatrix(page, placedRect) * baseMatrix;
compiledPage->draw(painter, page->getCropBox(), matrix, m_features); compiledPage->draw(painter, page->getCropBox(), matrix, features);
PDFTextLayoutGetter layoutGetter = m_textLayoutCompiler->getTextLayoutLazy(item.pageIndex); PDFTextLayoutGetter layoutGetter = m_textLayoutCompiler->getTextLayoutLazy(item.pageIndex);
// Draw text blocks/text lines, if it is enabled // Draw text blocks/text lines, if it is enabled
if (m_features.testFlag(PDFRenderer::DebugTextBlocks)) if (features.testFlag(PDFRenderer::DebugTextBlocks))
{ {
m_textLayoutCompiler->makeTextLayout(); m_textLayoutCompiler->makeTextLayout();
const PDFTextLayout& layout = layoutGetter; const PDFTextLayout& layout = layoutGetter;
@ -723,7 +723,7 @@ void PDFDrawWidgetProxy::drawPages(QPainter* painter, QRect rect)
painter->restore(); painter->restore();
} }
if (m_features.testFlag(PDFRenderer::DebugTextLines)) if (features.testFlag(PDFRenderer::DebugTextLines))
{ {
m_textLayoutCompiler->makeTextLayout(); m_textLayoutCompiler->makeTextLayout();
const PDFTextLayout& layout = layoutGetter; const PDFTextLayout& layout = layoutGetter;
@ -750,17 +750,20 @@ void PDFDrawWidgetProxy::drawPages(QPainter* painter, QRect rect)
painter->restore(); painter->restore();
} }
for (IDocumentDrawInterface* drawInterface : m_drawInterfaces) if (!features.testFlag(PDFRenderer::DenyExtraGraphics))
{ {
painter->save(); for (IDocumentDrawInterface* drawInterface : m_drawInterfaces)
drawInterface->drawPage(painter, item.pageIndex, compiledPage, layoutGetter, matrix); {
painter->restore(); painter->save();
drawInterface->drawPage(painter, item.pageIndex, compiledPage, layoutGetter, matrix);
painter->restore();
}
} }
const qint64 drawTimeNS = timer.nsecsElapsed(); const qint64 drawTimeNS = timer.nsecsElapsed();
// Draw rendering times // Draw rendering times
if (m_features.testFlag(PDFRenderer::DisplayTimes)) if (features.testFlag(PDFRenderer::DisplayTimes))
{ {
QFont font = m_widget->font(); QFont font = m_widget->font();
font.setPointSize(12); font.setPointSize(12);
@ -868,6 +871,7 @@ PDFInteger PDFDrawWidgetProxy::getPageUnderPoint(QPoint point, QPointF* pagePoin
// topleft point of the block. But block maybe doesn't start at (0, 0), // topleft point of the block. But block maybe doesn't start at (0, 0),
// so we must also use translation from the block beginning. // so we must also use translation from the block beginning.
QRect placedRect = item.pageRect.translated(m_horizontalOffset - m_layout.blockRect.left(), m_verticalOffset - m_layout.blockRect.top()); QRect placedRect = item.pageRect.translated(m_horizontalOffset - m_layout.blockRect.left(), m_verticalOffset - m_layout.blockRect.top());
placedRect.adjust(0, 0, 1, 1);
if (placedRect.contains(point)) if (placedRect.contains(point))
{ {
if (pagePoint) if (pagePoint)

View File

@ -244,7 +244,8 @@ public:
/// Rectangle is space in the widget, which is used for painting the PDF. /// Rectangle is space in the widget, which is used for painting the PDF.
/// \param painter Painter to paint the PDF pages /// \param painter Painter to paint the PDF pages
/// \param rect Rectangle in which the content is painted /// \param rect Rectangle in which the content is painted
void drawPages(QPainter* painter, QRect rect); /// \param features Rendering features
void drawPages(QPainter* painter, QRect rect, PDFRenderer::Features features);
/// Draws thumbnail image of the given size (so larger of the page size /// Draws thumbnail image of the given size (so larger of the page size
/// width or height equals to pixel size and the latter size is rescaled /// width or height equals to pixel size and the latter size is rescaled

View File

@ -501,6 +501,7 @@ void PDFPrecompiledPage::draw(QPainter* painter, const QRectF& cropBox, const QM
Q_ASSERT(pagePointToDevicePointMatrix.isInvertible()); Q_ASSERT(pagePointToDevicePointMatrix.isInvertible());
painter->save(); painter->save();
painter->setWorldMatrix(QMatrix());
if (features.testFlag(PDFRenderer::ClipToCropBox)) if (features.testFlag(PDFRenderer::ClipToCropBox))
{ {

View File

@ -56,6 +56,7 @@ public:
DebugTextBlocks = 0x0040, ///< Debug text block layout algorithm DebugTextBlocks = 0x0040, ///< Debug text block layout algorithm
DebugTextLines = 0x0080, ///< Debug text line layout algorithm DebugTextLines = 0x0080, ///< Debug text line layout algorithm
InvertColors = 0x0100, ///< Invert colors InvertColors = 0x0100, ///< Invert colors
DenyExtraGraphics = 0x0200, ///< Do not display additional graphics, for example from tools
}; };
Q_DECLARE_FLAGS(Features, Feature) Q_DECLARE_FLAGS(Features, Feature)

View File

@ -908,7 +908,7 @@ void PDFMagnifierTool::drawPostRendering(QPainter* painter, QRect rect) const
// because origin at (100, 100) is now at position (50, 50) after scale. So, if it has to remain // because origin at (100, 100) is now at position (50, 50) after scale. So, if it has to remain
// the same, we must translate by -(50, 50). // the same, we must translate by -(50, 50).
painter->translate(m_mousePos * (1.0 / m_magnifierZoom - 1.0)); painter->translate(m_mousePos * (1.0 / m_magnifierZoom - 1.0));
getProxy()->drawPages(painter, rect); getProxy()->drawPages(painter, rect, getProxy()->getFeatures());
painter->restore(); painter->restore();
painter->setPen(Qt::black); painter->setPen(Qt::black);
@ -1135,7 +1135,7 @@ void PDFScreenshotTool::onRectanglePicked(PDFInteger pageIndex, QRectF pageRecta
{ {
QPainter painter(&image); QPainter painter(&image);
painter.translate(-selectedRectangle.topLeft()); painter.translate(-selectedRectangle.topLeft());
getProxy()->drawPages(&painter, getProxy()->getWidget()->rect()); getProxy()->drawPages(&painter, getProxy()->getWidget()->rect(), getProxy()->getFeatures() | PDFRenderer::DenyExtraGraphics);
} }
QApplication::clipboard()->setImage(image, QClipboard::Clipboard); QApplication::clipboard()->setImage(image, QClipboard::Clipboard);