mirror of
https://invent.kde.org/graphics/okular
synced 2024-10-02 22:23:43 +00:00
Merge remote-tracking branch 'origin/release/20.12'
This commit is contained in:
commit
6f761b9e3a
|
@ -64,12 +64,6 @@ void ShellTest::testUrlArgs_data()
|
|||
|
||||
// non-local files
|
||||
QTest::newRow("http://kde.org/foo.pdf") << "http://kde.org/foo.pdf" << true << QUrl(QStringLiteral("http://kde.org/foo.pdf"));
|
||||
// make sure we don't have a fragment
|
||||
QUrl hashInName(QStringLiteral("http://kde.org"));
|
||||
QVERIFY(hashInName.path().isEmpty());
|
||||
hashInName.setPath(QStringLiteral("/foo#bar.pdf"));
|
||||
QVERIFY(hashInName.fragment().isEmpty());
|
||||
QTest::newRow("http://kde.org/foo#bar.pdf") << "http://kde.org/foo#bar.pdf" << true << hashInName;
|
||||
QUrl withAnchor(QStringLiteral("http://kde.org/foo.pdf"));
|
||||
withAnchor.setFragment(QStringLiteral("anchor"));
|
||||
QTest::newRow("http://kde.org/foo.pdf#anchor") << "http://kde.org/foo.pdf#anchor" << true << withAnchor;
|
||||
|
|
|
@ -422,7 +422,7 @@ const QIcon AnnotationActionHandlerPrivate::stampIcon(const QString &stampIconNa
|
|||
void AnnotationActionHandlerPrivate::selectTool(int toolId)
|
||||
{
|
||||
selectedTool = toolId;
|
||||
annotator->selectTool(toolId);
|
||||
annotator->selectTool(toolId, PageViewAnnotator::ShowTip::Yes);
|
||||
parseTool(toolId);
|
||||
}
|
||||
|
||||
|
|
|
@ -863,7 +863,7 @@ QRect PageViewAnnotator::performRouteMouseOrTabletEvent(const AnnotatorEngine::E
|
|||
}
|
||||
|
||||
if (m_continuousMode)
|
||||
selectTool(m_lastToolId);
|
||||
selectTool(m_lastToolId, ShowTip::No);
|
||||
else
|
||||
detachAnnotation();
|
||||
}
|
||||
|
@ -950,7 +950,7 @@ void PageViewAnnotator::routePaint(QPainter *painter, const QRect paintRect)
|
|||
painter->restore();
|
||||
}
|
||||
|
||||
void PageViewAnnotator::selectTool(int toolId)
|
||||
void PageViewAnnotator::selectTool(int toolId, ShowTip showTip)
|
||||
{
|
||||
// ask for Author's name if not already set
|
||||
if (toolId > 0 && Okular::Settings::identityAuthor().isEmpty()) {
|
||||
|
@ -1012,39 +1012,41 @@ void PageViewAnnotator::selectTool(int toolId)
|
|||
else
|
||||
qCWarning(OkularUiDebug).nospace() << "tools.xml: engine type:'" << type << "' is not defined!";
|
||||
|
||||
// display the tooltip
|
||||
const QString annotType = toolElement.attribute(QStringLiteral("type"));
|
||||
QString tip;
|
||||
if (showTip == ShowTip::Yes) {
|
||||
// display the tooltip
|
||||
const QString annotType = toolElement.attribute(QStringLiteral("type"));
|
||||
QString tip;
|
||||
|
||||
if (annotType == QLatin1String("ellipse"))
|
||||
tip = i18nc("Annotation tool", "Draw an ellipse (drag to select a zone)");
|
||||
else if (annotType == QLatin1String("highlight"))
|
||||
tip = i18nc("Annotation tool", "Highlight text");
|
||||
else if (annotType == QLatin1String("ink"))
|
||||
tip = i18nc("Annotation tool", "Draw a freehand line");
|
||||
else if (annotType == QLatin1String("note-inline"))
|
||||
tip = i18nc("Annotation tool", "Inline Text Annotation (drag to select a zone)");
|
||||
else if (annotType == QLatin1String("note-linked"))
|
||||
tip = i18nc("Annotation tool", "Put a pop-up note");
|
||||
else if (annotType == QLatin1String("polygon"))
|
||||
tip = i18nc("Annotation tool", "Draw a polygon (click on the first point to close it)");
|
||||
else if (annotType == QLatin1String("rectangle"))
|
||||
tip = i18nc("Annotation tool", "Draw a rectangle");
|
||||
else if (annotType == QLatin1String("squiggly"))
|
||||
tip = i18nc("Annotation tool", "Squiggle text");
|
||||
else if (annotType == QLatin1String("stamp"))
|
||||
tip = i18nc("Annotation tool", "Put a stamp symbol");
|
||||
else if (annotType == QLatin1String("straight-line"))
|
||||
tip = i18nc("Annotation tool", "Draw a straight line");
|
||||
else if (annotType == QLatin1String("strikeout"))
|
||||
tip = i18nc("Annotation tool", "Strike out text");
|
||||
else if (annotType == QLatin1String("underline"))
|
||||
tip = i18nc("Annotation tool", "Underline text");
|
||||
else if (annotType == QLatin1String("typewriter"))
|
||||
tip = i18nc("Annotation tool", "Typewriter Annotation (drag to select a zone)");
|
||||
if (annotType == QLatin1String("ellipse"))
|
||||
tip = i18nc("Annotation tool", "Draw an ellipse (drag to select a zone)");
|
||||
else if (annotType == QLatin1String("highlight"))
|
||||
tip = i18nc("Annotation tool", "Highlight text");
|
||||
else if (annotType == QLatin1String("ink"))
|
||||
tip = i18nc("Annotation tool", "Draw a freehand line");
|
||||
else if (annotType == QLatin1String("note-inline"))
|
||||
tip = i18nc("Annotation tool", "Inline Text Annotation (drag to select a zone)");
|
||||
else if (annotType == QLatin1String("note-linked"))
|
||||
tip = i18nc("Annotation tool", "Put a pop-up note");
|
||||
else if (annotType == QLatin1String("polygon"))
|
||||
tip = i18nc("Annotation tool", "Draw a polygon (click on the first point to close it)");
|
||||
else if (annotType == QLatin1String("rectangle"))
|
||||
tip = i18nc("Annotation tool", "Draw a rectangle");
|
||||
else if (annotType == QLatin1String("squiggly"))
|
||||
tip = i18nc("Annotation tool", "Squiggle text");
|
||||
else if (annotType == QLatin1String("stamp"))
|
||||
tip = i18nc("Annotation tool", "Put a stamp symbol");
|
||||
else if (annotType == QLatin1String("straight-line"))
|
||||
tip = i18nc("Annotation tool", "Draw a straight line");
|
||||
else if (annotType == QLatin1String("strikeout"))
|
||||
tip = i18nc("Annotation tool", "Strike out text");
|
||||
else if (annotType == QLatin1String("underline"))
|
||||
tip = i18nc("Annotation tool", "Underline text");
|
||||
else if (annotType == QLatin1String("typewriter"))
|
||||
tip = i18nc("Annotation tool", "Typewriter Annotation (drag to select a zone)");
|
||||
|
||||
if (!tip.isEmpty() && !m_continuousMode)
|
||||
m_pageView->displayMessage(tip, QString(), PageViewMessage::Annotation);
|
||||
if (!tip.isEmpty())
|
||||
m_pageView->displayMessage(tip, QString(), PageViewMessage::Annotation);
|
||||
}
|
||||
}
|
||||
|
||||
// consistency warning
|
||||
|
@ -1067,12 +1069,12 @@ void PageViewAnnotator::selectStampTool(const QString &stampSymbol)
|
|||
engineElement.setAttribute(QStringLiteral("hoverIcon"), stampSymbol);
|
||||
annotationElement.setAttribute(QStringLiteral("icon"), stampSymbol);
|
||||
saveBuiltinAnnotationTools();
|
||||
selectTool(STAMP_TOOL_ID);
|
||||
selectTool(STAMP_TOOL_ID, ShowTip::Yes);
|
||||
}
|
||||
|
||||
void PageViewAnnotator::detachAnnotation()
|
||||
{
|
||||
selectTool(-1);
|
||||
selectTool(-1, ShowTip::No);
|
||||
if (m_actionHandler)
|
||||
m_actionHandler->deselectAllAnnotationActions();
|
||||
}
|
||||
|
@ -1333,7 +1335,7 @@ void PageViewAnnotator::setAnnotationWidth(double width)
|
|||
{
|
||||
currentAnnotationElement().setAttribute(QStringLiteral("width"), QString::number(width));
|
||||
saveBuiltinAnnotationTools();
|
||||
selectTool(m_lastToolId);
|
||||
selectTool(m_lastToolId, ShowTip::No);
|
||||
}
|
||||
|
||||
void PageViewAnnotator::setAnnotationColor(const QColor &color)
|
||||
|
@ -1347,7 +1349,7 @@ void PageViewAnnotator::setAnnotationColor(const QColor &color)
|
|||
annotationElement.setAttribute(QStringLiteral("color"), color.name(QColor::HexRgb));
|
||||
}
|
||||
saveBuiltinAnnotationTools();
|
||||
selectTool(m_lastToolId);
|
||||
selectTool(m_lastToolId, ShowTip::No);
|
||||
}
|
||||
|
||||
void PageViewAnnotator::setAnnotationInnerColor(const QColor &color)
|
||||
|
@ -1359,21 +1361,21 @@ void PageViewAnnotator::setAnnotationInnerColor(const QColor &color)
|
|||
annotationElement.setAttribute(QStringLiteral("innerColor"), color.name(QColor::HexRgb));
|
||||
}
|
||||
saveBuiltinAnnotationTools();
|
||||
selectTool(m_lastToolId);
|
||||
selectTool(m_lastToolId, ShowTip::No);
|
||||
}
|
||||
|
||||
void PageViewAnnotator::setAnnotationOpacity(double opacity)
|
||||
{
|
||||
currentAnnotationElement().setAttribute(QStringLiteral("opacity"), QString::number(opacity));
|
||||
saveBuiltinAnnotationTools();
|
||||
selectTool(m_lastToolId);
|
||||
selectTool(m_lastToolId, ShowTip::No);
|
||||
}
|
||||
|
||||
void PageViewAnnotator::setAnnotationFont(const QFont &font)
|
||||
{
|
||||
currentAnnotationElement().setAttribute(QStringLiteral("font"), font.toString());
|
||||
saveBuiltinAnnotationTools();
|
||||
selectTool(m_lastToolId);
|
||||
selectTool(m_lastToolId, ShowTip::No);
|
||||
}
|
||||
|
||||
void PageViewAnnotator::addToQuickAnnotations()
|
||||
|
@ -1409,7 +1411,7 @@ void PageViewAnnotator::slotAdvancedSettings()
|
|||
int toolId = toolElement.attribute(QStringLiteral("id")).toInt();
|
||||
m_builtinToolsDefinition->updateTool(toolElementUpdated, toolId);
|
||||
saveBuiltinAnnotationTools();
|
||||
selectTool(m_lastToolId);
|
||||
selectTool(m_lastToolId, ShowTip::No);
|
||||
}
|
||||
|
||||
#include "moc_pageviewannotator.cpp"
|
||||
|
|
|
@ -102,8 +102,9 @@ public:
|
|||
// enable/disable the text-selection annotation actions
|
||||
void setTextToolsEnabled(bool enabled);
|
||||
|
||||
enum class ShowTip { Yes, No };
|
||||
// selects the active tool
|
||||
void selectTool(int toolId);
|
||||
void selectTool(int toolId, ShowTip showTip);
|
||||
// selects a stamp tool and sets the stamp symbol
|
||||
void selectStampTool(const QString &stampSymbol);
|
||||
// makes a quick annotation the active tool
|
||||
|
|
|
@ -1142,7 +1142,9 @@ void Part::loadCancelled(const QString &reason)
|
|||
// so we don't want to show an ugly messagebox just because the document is
|
||||
// taking more than usual to be recreated
|
||||
if (m_viewportDirty.pageNumber == -1) {
|
||||
if (!reason.isEmpty()) {
|
||||
if (m_urlWithFragment.isValid() && !m_urlWithFragment.isLocalFile()) {
|
||||
tryOpeningUrlWithFragmentAsName();
|
||||
} else if (!reason.isEmpty()) {
|
||||
KMessageBox::error(widget(), i18n("Could not open %1. Reason: %2", url().toDisplayString(), reason));
|
||||
}
|
||||
}
|
||||
|
@ -1460,7 +1462,7 @@ bool Part::openFile()
|
|||
mimes << pathMime << argMime;
|
||||
}
|
||||
|
||||
if (mimes[0].name() == QLatin1String("text/plain")) {
|
||||
if (mimes[0].inherits(QStringLiteral("text/plain"))) {
|
||||
QMimeType contentMime = db.mimeTypeForFile(fileNameToOpen, QMimeDatabase::MatchContent);
|
||||
mimes.prepend(contentMime);
|
||||
}
|
||||
|
@ -1675,6 +1677,7 @@ bool Part::openUrl(const QUrl &_url, bool swapInsteadOfOpening)
|
|||
|
||||
QUrl url(_url);
|
||||
if (url.hasFragment()) {
|
||||
m_urlWithFragment = _url;
|
||||
const QString dest = url.fragment(QUrl::FullyDecoded);
|
||||
bool ok = true;
|
||||
int page = dest.toInt(&ok);
|
||||
|
@ -1699,6 +1702,8 @@ bool Part::openUrl(const QUrl &_url, bool swapInsteadOfOpening)
|
|||
m_document->setNextDocumentDestination(dest);
|
||||
}
|
||||
url.setFragment(QString());
|
||||
} else {
|
||||
m_urlWithFragment.clear();
|
||||
}
|
||||
|
||||
// this calls in sequence the 'closeUrl' and 'openFile' methods
|
||||
|
@ -1709,15 +1714,27 @@ bool Part::openUrl(const QUrl &_url, bool swapInsteadOfOpening)
|
|||
|
||||
setWindowTitleFromDocument();
|
||||
} else {
|
||||
resetStartArguments();
|
||||
/* TRANSLATORS: Adding the reason (%2) why the opening failed (if any). */
|
||||
QString errorMessage = i18n("Could not open %1. %2", url.toDisplayString(), QStringLiteral("\n%1").arg(m_document->openError()));
|
||||
KMessageBox::error(widget(), errorMessage);
|
||||
if (m_urlWithFragment.isValid() && m_urlWithFragment.isLocalFile()) {
|
||||
openOk = tryOpeningUrlWithFragmentAsName();
|
||||
} else {
|
||||
resetStartArguments();
|
||||
/* TRANSLATORS: Adding the reason (%2) why the opening failed (if any). */
|
||||
QString errorMessage = i18n("Could not open %1. %2", url.toDisplayString(), QStringLiteral("\n%1").arg(m_document->openError()));
|
||||
KMessageBox::error(widget(), errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
return openOk;
|
||||
}
|
||||
|
||||
bool Part::tryOpeningUrlWithFragmentAsName()
|
||||
{
|
||||
QUrl url = m_urlWithFragment;
|
||||
url.setPath(url.path() + QLatin1Char('#') + url.fragment());
|
||||
url.setFragment(QString());
|
||||
return openUrl(url);
|
||||
}
|
||||
|
||||
bool Part::queryClose()
|
||||
{
|
||||
if (!isReadWrite() || !isModified())
|
||||
|
|
|
@ -295,6 +295,8 @@ private:
|
|||
void slotShareActionFinished(const QJsonObject &output, int error, const QString &message);
|
||||
#endif
|
||||
|
||||
bool tryOpeningUrlWithFragmentAsName();
|
||||
|
||||
static int numberOfParts;
|
||||
|
||||
QTemporaryFile *m_tempfile;
|
||||
|
@ -420,6 +422,10 @@ private:
|
|||
// String to search in document startup
|
||||
QString m_textToFindOnOpen;
|
||||
|
||||
// Set when opening an url that had fragment so that if it fails opening we try adding the fragment to the filename
|
||||
// if we're opening http://localhost/foo#bar.pdf and the filename contains an # we can open it after trying to open foo fails
|
||||
QUrl m_urlWithFragment;
|
||||
|
||||
private Q_SLOTS:
|
||||
void slotAnnotationPreferences();
|
||||
void slotHandleActivatedSourceReference(const QString &absFileName, int line, int col, bool *handled);
|
||||
|
|
|
@ -45,13 +45,6 @@ QUrl urlFromArg(const QString &_arg, FileExistFunc exist_func, const QString &pa
|
|||
url.setPath(path.left(hashIndex));
|
||||
url.setFragment(path.mid(hashIndex + 1));
|
||||
}
|
||||
} else if (!url.fragment().isEmpty()) {
|
||||
// make sure something like http://example.org/foo#bar.pdf is treated as a path name
|
||||
// but something like http://example.org/foo.pdf#bar is foo.pdf plus an anchor "bar"
|
||||
if (url.fragment().contains(QLatin1Char('.'))) {
|
||||
url.setPath(url.path() + QLatin1Char('#') + url.fragment());
|
||||
url.setFragment(QString());
|
||||
}
|
||||
}
|
||||
if (!pageArg.isEmpty()) {
|
||||
url.setFragment(pageArg);
|
||||
|
|
Loading…
Reference in a new issue