2021-05-24 07:25:56 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2004-2005 Enrico Ros <eros.kde@email.it>
|
2021-06-03 18:33:18 +00:00
|
|
|
|
|
|
|
Work sponsored by the LiMux project of the city of Munich:
|
2021-05-24 11:41:08 +00:00
|
|
|
SPDX-FileCopyrightText: 2017 Klarälvdalens Datakonsult AB a KDAB Group company <info@kdab.com>
|
2021-05-24 07:25:56 +00:00
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2004-10-20 16:41:13 +00:00
|
|
|
|
2007-04-19 18:30:20 +00:00
|
|
|
#include "pageviewutils.h"
|
|
|
|
|
2004-10-20 16:41:13 +00:00
|
|
|
// qt/kde includes
|
2020-07-08 11:54:37 +00:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QTimer>
|
2004-10-20 16:41:13 +00:00
|
|
|
|
|
|
|
// local includes
|
2015-07-20 16:55:35 +00:00
|
|
|
#include "core/form.h"
|
2005-01-02 14:37:49 +00:00
|
|
|
#include "core/page.h"
|
2007-02-25 00:07:59 +00:00
|
|
|
#include "formwidgets.h"
|
2006-03-28 22:22:10 +00:00
|
|
|
#include "settings.h"
|
2008-08-25 01:59:23 +00:00
|
|
|
#include "videowidget.h"
|
2004-10-20 16:41:13 +00:00
|
|
|
|
2005-02-26 18:05:01 +00:00
|
|
|
/*********************/
|
|
|
|
/** PageViewItem */
|
|
|
|
/*********************/
|
2005-02-12 17:42:54 +00:00
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
PageViewItem::PageViewItem(const Okular::Page *page)
|
2007-12-31 22:22:38 +00:00
|
|
|
: m_page(page)
|
|
|
|
, m_zoomFactor(1.0)
|
|
|
|
, m_visible(true)
|
2008-05-19 00:37:14 +00:00
|
|
|
, m_formsVisible(false)
|
|
|
|
, m_crop(0., 0., 1., 1.)
|
2005-02-12 17:42:54 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-02-25 00:07:59 +00:00
|
|
|
PageViewItem::~PageViewItem()
|
|
|
|
{
|
2017-10-25 12:51:58 +00:00
|
|
|
qDeleteAll(m_formWidgets);
|
2008-08-25 01:59:23 +00:00
|
|
|
qDeleteAll(m_videoWidgets);
|
2007-02-25 00:07:59 +00:00
|
|
|
}
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
const Okular::Page *PageViewItem::page() const
|
2005-02-12 17:42:54 +00:00
|
|
|
{
|
|
|
|
return m_page;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PageViewItem::pageNumber() const
|
|
|
|
{
|
|
|
|
return m_page->number();
|
|
|
|
}
|
|
|
|
|
2008-05-19 00:37:14 +00:00
|
|
|
const QRect &PageViewItem::croppedGeometry() const
|
2005-02-12 17:42:54 +00:00
|
|
|
{
|
2008-05-19 00:37:14 +00:00
|
|
|
return m_croppedGeometry;
|
2005-02-12 17:42:54 +00:00
|
|
|
}
|
|
|
|
|
2008-05-19 00:37:14 +00:00
|
|
|
int PageViewItem::croppedWidth() const
|
2005-02-12 17:42:54 +00:00
|
|
|
{
|
2008-05-19 00:37:14 +00:00
|
|
|
return m_croppedGeometry.width();
|
2005-02-12 17:42:54 +00:00
|
|
|
}
|
|
|
|
|
2008-05-19 00:37:14 +00:00
|
|
|
int PageViewItem::croppedHeight() const
|
2005-02-12 17:42:54 +00:00
|
|
|
{
|
2008-05-19 00:37:14 +00:00
|
|
|
return m_croppedGeometry.height();
|
|
|
|
}
|
|
|
|
|
|
|
|
const QRect &PageViewItem::uncroppedGeometry() const
|
|
|
|
{
|
|
|
|
return m_uncroppedGeometry;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PageViewItem::uncroppedWidth() const
|
|
|
|
{
|
|
|
|
return m_uncroppedGeometry.width();
|
|
|
|
}
|
|
|
|
|
|
|
|
int PageViewItem::uncroppedHeight() const
|
|
|
|
{
|
|
|
|
return m_uncroppedGeometry.height();
|
|
|
|
}
|
|
|
|
|
|
|
|
const Okular::NormalizedRect &PageViewItem::crop() const
|
|
|
|
{
|
|
|
|
return m_crop;
|
2005-02-12 17:42:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double PageViewItem::zoomFactor() const
|
|
|
|
{
|
|
|
|
return m_zoomFactor;
|
|
|
|
}
|
|
|
|
|
2008-07-31 09:26:11 +00:00
|
|
|
double PageViewItem::absToPageX(double absX) const
|
2008-05-19 00:37:14 +00:00
|
|
|
{
|
|
|
|
return (absX - m_uncroppedGeometry.left()) / m_uncroppedGeometry.width();
|
|
|
|
}
|
|
|
|
|
2008-07-31 09:26:11 +00:00
|
|
|
double PageViewItem::absToPageY(double absY) const
|
2008-05-19 00:37:14 +00:00
|
|
|
{
|
|
|
|
return (absY - m_uncroppedGeometry.top()) / m_uncroppedGeometry.height();
|
|
|
|
}
|
|
|
|
|
2007-12-31 17:17:54 +00:00
|
|
|
bool PageViewItem::isVisible() const
|
|
|
|
{
|
|
|
|
return m_visible;
|
|
|
|
}
|
|
|
|
|
2017-10-25 12:51:58 +00:00
|
|
|
QSet<FormWidgetIface *> &PageViewItem::formWidgets()
|
2007-02-25 00:07:59 +00:00
|
|
|
{
|
|
|
|
return m_formWidgets;
|
|
|
|
}
|
|
|
|
|
2008-08-25 01:59:23 +00:00
|
|
|
QHash<Okular::Movie *, VideoWidget *> &PageViewItem::videoWidgets()
|
|
|
|
{
|
|
|
|
return m_videoWidgets;
|
|
|
|
}
|
|
|
|
|
2008-05-19 00:37:14 +00:00
|
|
|
void PageViewItem::setWHZC(int w, int h, double z, const Okular::NormalizedRect &c)
|
2005-02-12 17:42:54 +00:00
|
|
|
{
|
2008-05-19 00:37:14 +00:00
|
|
|
m_croppedGeometry.setWidth(w);
|
|
|
|
m_croppedGeometry.setHeight(h);
|
2005-02-12 17:42:54 +00:00
|
|
|
m_zoomFactor = z;
|
2008-05-19 00:37:14 +00:00
|
|
|
m_crop = c;
|
|
|
|
m_uncroppedGeometry.setWidth(qRound(w / (c.right - c.left)));
|
|
|
|
m_uncroppedGeometry.setHeight(qRound(h / (c.bottom - c.top)));
|
2019-12-09 13:39:47 +00:00
|
|
|
for (FormWidgetIface *fwi : qAsConst(m_formWidgets)) {
|
2007-08-13 22:25:27 +00:00
|
|
|
Okular::NormalizedRect r = fwi->rect();
|
2008-05-19 00:37:14 +00:00
|
|
|
fwi->setWidthHeight(qRound(fabs(r.right - r.left) * m_uncroppedGeometry.width()), qRound(fabs(r.bottom - r.top) * m_uncroppedGeometry.height()));
|
2007-02-25 00:07:59 +00:00
|
|
|
}
|
2019-12-09 13:39:47 +00:00
|
|
|
for (VideoWidget *vw : qAsConst(m_videoWidgets)) {
|
2008-08-25 01:59:23 +00:00
|
|
|
const Okular::NormalizedRect r = vw->normGeometry();
|
|
|
|
vw->resize(qRound(fabs(r.right - r.left) * m_uncroppedGeometry.width()), qRound(fabs(r.bottom - r.top) * m_uncroppedGeometry.height()));
|
|
|
|
}
|
2005-02-12 17:42:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PageViewItem::moveTo(int x, int y)
|
2008-05-19 00:37:14 +00:00
|
|
|
// Assumes setWHZC() has already been called
|
2005-02-12 17:42:54 +00:00
|
|
|
{
|
2008-05-19 00:37:14 +00:00
|
|
|
m_croppedGeometry.moveLeft(x);
|
|
|
|
m_croppedGeometry.moveTop(y);
|
|
|
|
m_uncroppedGeometry.moveLeft(qRound(x - m_crop.left * m_uncroppedGeometry.width()));
|
|
|
|
m_uncroppedGeometry.moveTop(qRound(y - m_crop.top * m_uncroppedGeometry.height()));
|
2017-10-25 12:51:58 +00:00
|
|
|
QSet<FormWidgetIface *>::iterator it = m_formWidgets.begin(), itEnd = m_formWidgets.end();
|
2007-02-25 00:07:59 +00:00
|
|
|
for (; it != itEnd; ++it) {
|
|
|
|
Okular::NormalizedRect r = (*it)->rect();
|
2008-05-19 00:37:14 +00:00
|
|
|
(*it)->moveTo(qRound(x + m_uncroppedGeometry.width() * r.left) + 1, qRound(y + m_uncroppedGeometry.height() * r.top) + 1);
|
2007-02-25 00:07:59 +00:00
|
|
|
}
|
2019-12-09 13:39:47 +00:00
|
|
|
for (VideoWidget *vw : qAsConst(m_videoWidgets)) {
|
2008-08-25 01:59:23 +00:00
|
|
|
const Okular::NormalizedRect r = vw->normGeometry();
|
|
|
|
vw->move(qRound(x + m_uncroppedGeometry.width() * r.left) + 1, qRound(y + m_uncroppedGeometry.height() * r.top) + 1);
|
|
|
|
}
|
2005-02-12 17:42:54 +00:00
|
|
|
}
|
|
|
|
|
2007-12-31 17:17:54 +00:00
|
|
|
void PageViewItem::setVisible(bool visible)
|
|
|
|
{
|
2007-12-31 22:22:38 +00:00
|
|
|
setFormWidgetsVisible(visible && m_formsVisible);
|
2007-12-31 17:17:54 +00:00
|
|
|
m_visible = visible;
|
|
|
|
}
|
|
|
|
|
2006-04-23 12:44:10 +00:00
|
|
|
void PageViewItem::invalidate()
|
|
|
|
{
|
2008-05-19 00:37:14 +00:00
|
|
|
m_croppedGeometry.setRect(0, 0, 0, 0);
|
|
|
|
m_uncroppedGeometry.setRect(0, 0, 0, 0);
|
2006-04-23 12:44:10 +00:00
|
|
|
}
|
2005-02-12 17:42:54 +00:00
|
|
|
|
2007-02-25 14:59:26 +00:00
|
|
|
bool PageViewItem::setFormWidgetsVisible(bool visible)
|
2007-02-25 00:07:59 +00:00
|
|
|
{
|
2007-12-31 22:22:38 +00:00
|
|
|
m_formsVisible = visible;
|
|
|
|
|
|
|
|
if (!m_visible) {
|
|
|
|
return false;
|
2022-03-08 10:10:43 +00:00
|
|
|
}
|
2007-12-31 22:22:38 +00:00
|
|
|
|
2007-02-25 14:59:26 +00:00
|
|
|
bool somehadfocus = false;
|
2017-10-25 12:51:58 +00:00
|
|
|
QSet<FormWidgetIface *>::iterator it = m_formWidgets.begin(), itEnd = m_formWidgets.end();
|
2007-02-25 00:07:59 +00:00
|
|
|
for (; it != itEnd; ++it) {
|
2018-03-20 21:58:58 +00:00
|
|
|
bool hadfocus = (*it)->setVisibility(visible && (*it)->formField()->isVisible() && FormWidgetsController::shouldFormWidgetBeShown((*it)->formField()));
|
2007-10-18 20:35:34 +00:00
|
|
|
somehadfocus = somehadfocus || hadfocus;
|
|
|
|
}
|
2007-02-25 14:59:26 +00:00
|
|
|
return somehadfocus;
|
2007-02-25 00:07:59 +00:00
|
|
|
}
|
|
|
|
|
2015-07-20 16:55:35 +00:00
|
|
|
void PageViewItem::reloadFormWidgetsState()
|
|
|
|
{
|
2019-12-09 13:39:47 +00:00
|
|
|
for (FormWidgetIface *fwi : qAsConst(m_formWidgets)) {
|
2019-01-05 22:30:25 +00:00
|
|
|
fwi->setVisibility(fwi->formField()->isVisible() && FormWidgetsController::shouldFormWidgetBeShown(fwi->formField()));
|
2015-07-20 16:55:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-26 18:05:01 +00:00
|
|
|
/*********************/
|
|
|
|
/** PageViewMessage */
|
|
|
|
/*********************/
|
2005-02-12 17:42:54 +00:00
|
|
|
|
2004-10-20 16:41:13 +00:00
|
|
|
PageViewMessage::PageViewMessage(QWidget *parent)
|
2017-09-05 21:27:18 +00:00
|
|
|
: QWidget(parent)
|
|
|
|
, m_timer(nullptr)
|
2010-08-21 10:40:22 +00:00
|
|
|
, m_lineSpacing(0)
|
2004-10-20 16:41:13 +00:00
|
|
|
{
|
2015-10-29 12:37:11 +00:00
|
|
|
setObjectName(QStringLiteral("pageViewMessage"));
|
2006-03-23 20:43:38 +00:00
|
|
|
setFocusPolicy(Qt::NoFocus);
|
2006-05-27 15:44:30 +00:00
|
|
|
QPalette pal = palette();
|
|
|
|
pal.setColor(QPalette::Active, QPalette::Window, QApplication::palette().color(QPalette::Active, QPalette::Window));
|
|
|
|
setPalette(pal);
|
2006-09-20 13:58:28 +00:00
|
|
|
// if the layout is LtR, we can safely place it in the right position
|
2007-12-14 22:08:22 +00:00
|
|
|
if (layoutDirection() == Qt::LeftToRight) {
|
2006-09-20 13:58:28 +00:00
|
|
|
move(10, 10);
|
2022-03-08 10:10:43 +00:00
|
|
|
}
|
2004-10-20 16:41:13 +00:00
|
|
|
resize(0, 0);
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
2010-08-21 10:40:22 +00:00
|
|
|
void PageViewMessage::display(const QString &message, const QString &details, Icon icon, int durationMs)
|
2005-02-26 18:05:01 +00:00
|
|
|
// give Caesar what belongs to Caesar: code taken from Amarok's osd.h/.cpp
|
2005-07-15 18:20:57 +00:00
|
|
|
// "redde (reddite, pl.) cesari quae sunt cesaris", just btw. :)
|
2014-02-15 22:40:36 +00:00
|
|
|
// The code has been heavily modified since then.
|
2004-10-20 16:41:13 +00:00
|
|
|
{
|
2006-09-21 08:45:36 +00:00
|
|
|
if (!Okular::Settings::showOSD()) {
|
2004-11-03 17:35:48 +00:00
|
|
|
hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-01-02 18:41:31 +00:00
|
|
|
// set text
|
|
|
|
m_message = message;
|
2010-08-21 10:40:22 +00:00
|
|
|
m_details = details;
|
|
|
|
// reset vars
|
|
|
|
m_lineSpacing = 0;
|
2007-12-14 22:08:22 +00:00
|
|
|
|
2014-02-15 22:40:36 +00:00
|
|
|
// load icon (if set)
|
2021-11-23 20:45:23 +00:00
|
|
|
m_symbol = QIcon();
|
2004-10-20 16:41:13 +00:00
|
|
|
if (icon != None) {
|
|
|
|
switch (icon) {
|
2005-02-18 18:24:45 +00:00
|
|
|
case Annotation:
|
2021-11-23 20:45:23 +00:00
|
|
|
m_symbol = QIcon::fromTheme(QStringLiteral("draw-freehand"));
|
2005-02-18 18:24:45 +00:00
|
|
|
break;
|
2005-01-20 17:33:05 +00:00
|
|
|
case Find:
|
2021-11-23 20:45:23 +00:00
|
|
|
m_symbol = QIcon::fromTheme(QStringLiteral("zoom-original"));
|
2005-01-20 17:33:05 +00:00
|
|
|
break;
|
2004-10-20 16:41:13 +00:00
|
|
|
case Error:
|
2021-11-23 20:45:23 +00:00
|
|
|
m_symbol = QIcon::fromTheme(QStringLiteral("dialog-error"));
|
2004-10-20 16:41:13 +00:00
|
|
|
break;
|
|
|
|
case Warning:
|
2021-11-23 20:45:23 +00:00
|
|
|
m_symbol = QIcon::fromTheme(QStringLiteral("dialog-warning"));
|
2004-10-20 16:41:13 +00:00
|
|
|
break;
|
|
|
|
default:
|
2021-11-23 20:45:23 +00:00
|
|
|
m_symbol = QIcon::fromTheme(QStringLiteral("dialog-information"));
|
2004-10-20 16:41:13 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-01-02 18:41:31 +00:00
|
|
|
}
|
2004-10-20 16:41:13 +00:00
|
|
|
|
2014-02-15 22:40:36 +00:00
|
|
|
computeSizeAndResize();
|
2004-10-20 16:41:13 +00:00
|
|
|
// show widget and schedule a repaint
|
|
|
|
show();
|
|
|
|
update();
|
|
|
|
|
|
|
|
// close the message window after given mS
|
|
|
|
if (durationMs > 0) {
|
|
|
|
if (!m_timer) {
|
|
|
|
m_timer = new QTimer(this);
|
2006-05-27 22:07:29 +00:00
|
|
|
m_timer->setSingleShot(true);
|
2014-10-01 17:40:48 +00:00
|
|
|
connect(m_timer, &QTimer::timeout, this, &PageViewMessage::hide);
|
2004-10-20 16:41:13 +00:00
|
|
|
}
|
2006-05-27 22:07:29 +00:00
|
|
|
m_timer->start(durationMs);
|
2004-11-03 17:35:48 +00:00
|
|
|
} else if (m_timer) {
|
|
|
|
m_timer->stop();
|
2022-03-08 10:10:43 +00:00
|
|
|
}
|
2014-02-15 22:40:36 +00:00
|
|
|
|
|
|
|
qobject_cast<QAbstractScrollArea *>(parentWidget())->viewport()->installEventFilter(this);
|
2004-10-20 16:41:13 +00:00
|
|
|
}
|
|
|
|
|
2014-02-15 22:40:36 +00:00
|
|
|
QRect PageViewMessage::computeTextRect(const QString &message, int extra_width) const
|
|
|
|
// Return the QRect which embeds the text
|
2004-10-20 16:41:13 +00:00
|
|
|
{
|
2014-02-15 22:40:36 +00:00
|
|
|
int charSize = fontMetrics().averageCharWidth();
|
|
|
|
/* width of the viewport, minus 20 (~ size removed by further resizing),
|
|
|
|
minus the extra size (usually the icon width), minus (a bit empirical)
|
|
|
|
twice the mean width of a character to ensure that the bounding box is
|
|
|
|
really smaller than the container.
|
|
|
|
*/
|
|
|
|
const int boundingWidth = qobject_cast<QAbstractScrollArea *>(parentWidget())->viewport()->width() - 20 - (extra_width > 0 ? 2 + extra_width : 0) - 2 * charSize;
|
|
|
|
QRect textRect = fontMetrics().boundingRect(0, 0, boundingWidth, 0, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, message);
|
2008-01-02 18:41:31 +00:00
|
|
|
textRect.translate(-textRect.left(), -textRect.top());
|
|
|
|
textRect.adjust(0, 0, 2, 2);
|
|
|
|
|
2014-02-15 22:40:36 +00:00
|
|
|
return textRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PageViewMessage::computeSizeAndResize()
|
|
|
|
{
|
2021-11-23 20:45:23 +00:00
|
|
|
const auto symbolSize = !m_symbol.isNull() ? style()->pixelMetric(QStyle::PM_SmallIconSize) : 0;
|
|
|
|
|
2014-02-15 22:40:36 +00:00
|
|
|
// determine text rectangle
|
2021-11-23 20:45:23 +00:00
|
|
|
const QRect textRect = computeTextRect(m_message, symbolSize);
|
2014-02-15 22:40:36 +00:00
|
|
|
int width = textRect.width(), height = textRect.height();
|
|
|
|
|
|
|
|
if (!m_details.isEmpty()) {
|
|
|
|
// determine details text rectangle
|
2021-11-23 20:45:23 +00:00
|
|
|
const QRect detailsRect = computeTextRect(m_details, symbolSize);
|
2014-02-15 22:40:36 +00:00
|
|
|
width = qMax(width, detailsRect.width());
|
|
|
|
height += detailsRect.height();
|
|
|
|
|
|
|
|
// plus add a ~60% line spacing
|
|
|
|
m_lineSpacing = static_cast<int>(fontMetrics().height() * 0.6);
|
|
|
|
height += m_lineSpacing;
|
|
|
|
}
|
|
|
|
|
|
|
|
// update geometry with icon information
|
|
|
|
if (!m_symbol.isNull()) {
|
2021-11-23 20:45:23 +00:00
|
|
|
width += 2 + symbolSize;
|
|
|
|
height = qMax(height, symbolSize);
|
2014-02-15 22:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// resize widget
|
|
|
|
resize(QRect(0, 0, width + 10, height + 8).size());
|
|
|
|
|
|
|
|
// if the layout is RtL, we can move it to the right place only after we
|
|
|
|
// know how much size it will take
|
|
|
|
if (layoutDirection() == Qt::RightToLeft) {
|
|
|
|
move(parentWidget()->width() - geometry().width() - 10 - 1, 10);
|
2022-03-08 10:10:43 +00:00
|
|
|
}
|
2014-02-15 22:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool PageViewMessage::eventFilter(QObject *obj, QEvent *event)
|
|
|
|
{
|
|
|
|
/* if the parent object (scroll area) resizes, the message should
|
|
|
|
resize as well */
|
|
|
|
if (event->type() == QEvent::Resize) {
|
|
|
|
QResizeEvent *resizeEvent = static_cast<QResizeEvent *>(event);
|
|
|
|
if (resizeEvent->oldSize() != resizeEvent->size()) {
|
|
|
|
computeSizeAndResize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// standard event processing
|
|
|
|
return QObject::eventFilter(obj, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PageViewMessage::paintEvent(QPaintEvent * /* e */)
|
|
|
|
{
|
2021-11-23 20:45:23 +00:00
|
|
|
const auto symbolSize = !m_symbol.isNull() ? style()->pixelMetric(QStyle::PM_SmallIconSize) : 0;
|
|
|
|
const QRect textRect = computeTextRect(m_message, symbolSize);
|
2014-02-15 22:40:36 +00:00
|
|
|
|
2010-08-21 10:40:22 +00:00
|
|
|
QRect detailsRect;
|
|
|
|
if (!m_details.isEmpty()) {
|
2021-11-23 20:45:23 +00:00
|
|
|
detailsRect = computeTextRect(m_details, symbolSize);
|
2010-08-21 10:40:22 +00:00
|
|
|
}
|
|
|
|
|
2008-01-02 18:41:31 +00:00
|
|
|
int textXOffset = 0,
|
2020-09-24 14:10:59 +00:00
|
|
|
// add 2 to account for the reduced drawRoundedRect later
|
2021-11-23 20:45:23 +00:00
|
|
|
textYOffset = (geometry().height() - textRect.height() - detailsRect.height() - m_lineSpacing + 2) / 2, iconXOffset = 0, iconYOffset = !m_symbol.isNull() ? (geometry().height() - symbolSize) / 2 : 0, shadowOffset = 1;
|
2008-01-02 18:41:31 +00:00
|
|
|
|
|
|
|
if (layoutDirection() == Qt::RightToLeft) {
|
|
|
|
iconXOffset = 2 + textRect.width();
|
|
|
|
} else {
|
2021-11-23 20:45:23 +00:00
|
|
|
textXOffset = 2 + symbolSize;
|
2022-03-08 10:10:43 +00:00
|
|
|
}
|
2008-01-02 18:41:31 +00:00
|
|
|
|
|
|
|
// draw background
|
|
|
|
QPainter painter(this);
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
|
|
|
painter.setPen(Qt::black);
|
|
|
|
painter.setBrush(palette().color(QPalette::Window));
|
2008-01-02 21:52:25 +00:00
|
|
|
painter.translate(0.5, 0.5);
|
2022-03-08 16:38:19 +00:00
|
|
|
painter.drawRoundedRect(1, 1, width() - 2, height() - 2, 600.0 / width(), 600.0 / height(), Qt::RelativeSize);
|
2008-01-02 18:41:31 +00:00
|
|
|
|
|
|
|
// draw icon if present
|
|
|
|
if (!m_symbol.isNull()) {
|
2021-11-23 20:45:23 +00:00
|
|
|
painter.drawPixmap(5 + iconXOffset, iconYOffset, m_symbol.pixmap(symbolSize));
|
2022-03-08 10:10:43 +00:00
|
|
|
}
|
2008-01-02 18:41:31 +00:00
|
|
|
|
2014-02-15 22:40:36 +00:00
|
|
|
const int xStartPoint = 5 + textXOffset;
|
|
|
|
const int yStartPoint = textYOffset;
|
|
|
|
const int textDrawingFlags = Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap;
|
|
|
|
|
2008-01-02 18:41:31 +00:00
|
|
|
// draw shadow and text
|
2019-03-13 05:58:11 +00:00
|
|
|
painter.setPen(palette().color(QPalette::Window).darker(115));
|
2014-02-15 22:40:36 +00:00
|
|
|
painter.drawText(xStartPoint + shadowOffset, yStartPoint + shadowOffset, textRect.width(), textRect.height(), textDrawingFlags, m_message);
|
2010-08-21 10:40:22 +00:00
|
|
|
if (!m_details.isEmpty()) {
|
2014-02-15 22:40:36 +00:00
|
|
|
painter.drawText(xStartPoint + shadowOffset, yStartPoint + textRect.height() + m_lineSpacing + shadowOffset, textRect.width(), detailsRect.height(), textDrawingFlags, m_details);
|
2022-03-08 10:10:43 +00:00
|
|
|
}
|
2008-01-02 18:41:31 +00:00
|
|
|
painter.setPen(palette().color(QPalette::WindowText));
|
2014-02-15 22:40:36 +00:00
|
|
|
painter.drawText(xStartPoint, yStartPoint, textRect.width(), textRect.height(), textDrawingFlags, m_message);
|
2010-08-21 10:40:22 +00:00
|
|
|
if (!m_details.isEmpty()) {
|
2014-02-15 22:40:36 +00:00
|
|
|
painter.drawText(xStartPoint + shadowOffset, yStartPoint + textRect.height() + m_lineSpacing, textRect.width(), detailsRect.height(), textDrawingFlags, m_details);
|
2022-03-08 10:10:43 +00:00
|
|
|
}
|
2004-10-20 16:41:13 +00:00
|
|
|
}
|
|
|
|
|
2004-10-31 17:04:04 +00:00
|
|
|
void PageViewMessage::mousePressEvent(QMouseEvent * /*e*/)
|
2004-10-20 16:41:13 +00:00
|
|
|
{
|
|
|
|
if (m_timer) {
|
|
|
|
m_timer->stop();
|
2022-03-08 10:10:43 +00:00
|
|
|
}
|
2004-10-20 16:41:13 +00:00
|
|
|
hide();
|
|
|
|
}
|