mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
Some basic action functionality for application DocPage Organizer
This commit is contained in:
63
Pdf4QtLib/sources/pdfpainterutils.cpp
Normal file
63
Pdf4QtLib/sources/pdfpainterutils.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
// 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 "pdfpainterutils.h"
|
||||
|
||||
#include <QFontMetrics>
|
||||
|
||||
namespace pdf
|
||||
{
|
||||
|
||||
QRect PDFPainterHelper::drawBubble(QPainter* painter, QPoint point, QColor color, QString text, Qt::Alignment alignment)
|
||||
{
|
||||
QFontMetrics fontMetrics = painter->fontMetrics();
|
||||
|
||||
const int lineSpacing = fontMetrics.lineSpacing();
|
||||
const int bubbleHeight = lineSpacing* 2;
|
||||
const int bubbleWidth = lineSpacing + fontMetrics.horizontalAdvance(text);
|
||||
|
||||
QRect rectangle(point, QSize(bubbleWidth, bubbleHeight));
|
||||
|
||||
if (alignment.testFlag(Qt::AlignVCenter))
|
||||
{
|
||||
rectangle.translate(0, -rectangle.height() / 2);
|
||||
}
|
||||
else if (alignment.testFlag(Qt::AlignTop))
|
||||
{
|
||||
rectangle.translate(0, -rectangle.height());
|
||||
}
|
||||
|
||||
if (alignment.testFlag(Qt::AlignHCenter))
|
||||
{
|
||||
rectangle.translate(-rectangle.width() / 2, 0);
|
||||
}
|
||||
else if (alignment.testFlag(Qt::AlignLeft))
|
||||
{
|
||||
rectangle.translate(-rectangle.width(), 0);
|
||||
}
|
||||
|
||||
PDFPainterStateGuard guard(painter);
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setBrush(QBrush(color));
|
||||
painter->drawRoundedRect(rectangle, rectangle.height() / 2, rectangle.height() / 2, Qt::AbsoluteSize);
|
||||
painter->setPen(Qt::black);
|
||||
painter->drawText(rectangle, Qt::AlignCenter, text);
|
||||
|
||||
return rectangle;
|
||||
}
|
||||
|
||||
} // namespace pdf
|
@@ -18,6 +18,8 @@
|
||||
#ifndef PDFPAINTERUTILS_H
|
||||
#define PDFPAINTERUTILS_H
|
||||
|
||||
#include "pdfglobal.h"
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
namespace pdf
|
||||
@@ -42,6 +44,19 @@ private:
|
||||
QPainter* m_painter;
|
||||
};
|
||||
|
||||
class Pdf4QtLIBSHARED_EXPORT PDFPainterHelper
|
||||
{
|
||||
public:
|
||||
/// Draws bubble using painter. Bubble is aligned to the point, colored with color
|
||||
/// and inside bubble, text is being paint. Bubble bounding box is being returned.
|
||||
/// \param painter Painter
|
||||
/// \param point Position of the bubble
|
||||
/// \param color Color of the bubble
|
||||
/// \param text Text inside the bubble
|
||||
/// \param alignment Bubble alignment relative to the bubble position point
|
||||
static QRect drawBubble(QPainter* painter, QPoint point, QColor color, QString text, Qt::Alignment alignment);
|
||||
};
|
||||
|
||||
} // namespace pdf
|
||||
|
||||
#endif // PDFPAINTERUTILS_H
|
||||
|
Reference in New Issue
Block a user