diff --git a/core/textdocumentgenerator_p.h b/core/textdocumentgenerator_p.h index 955ea303f..fb1a5e395 100644 --- a/core/textdocumentgenerator_p.h +++ b/core/textdocumentgenerator_p.h @@ -136,8 +136,12 @@ static Okular::DocumentViewport calculateViewport(QTextDocument *document, const const QSizeF pageSize = document->pageSize(); const QRectF rect = document->documentLayout()->blockBoundingRect(block); - const int page = qRound(rect.y()) / qRound(pageSize.height()); - const int offset = qRound(rect.y()) % qRound(pageSize.height()); + int page = qRound(rect.y()) / qRound(pageSize.height()); + int offset = qRound(rect.y()) % qRound(pageSize.height()); + if (rect.y() + rect.height() > pageSize.height()) { + page = page + 1; + offset = 0; + } Okular::DocumentViewport viewport(page); viewport.rePos.normalizedX = (double)rect.x() / (double)pageSize.width(); diff --git a/generators/epub/converter.cpp b/generators/epub/converter.cpp index 78d3b9424..b48c5d850 100644 --- a/generators/epub/converter.cpp +++ b/generators/epub/converter.cpp @@ -380,37 +380,42 @@ QTextDocument *Converter::convert(const QString &fileName) if (mSectionMap.contains(link)) { block = mSectionMap.value(link); - } else { // load missing resource - char *data = nullptr; - // epub_get_data can't handle whitespace url encodings - QByteArray ba = link.replace(QLatin1String("%20"), QLatin1String(" ")).toLatin1(); - const char *clinkClean = ba.data(); - int size = epub_get_data(mTextDocument->getEpub(), clinkClean, &data); - - if (data) { - _cursor->insertBlock(); - - // try to load as image and if not load as html - block = _cursor->block(); - QImage image; - mSectionMap.insert(link, block); - if (image.loadFromData((unsigned char *)data, size)) { - mTextDocument->addResource(QTextDocument::ImageResource, QUrl(link), image); - _cursor->insertImage(link); - } else { - _cursor->insertHtml(QString::fromUtf8(data)); - // Add anchors to hashes - _handle_anchors(block, link); + } else { + const QString percentDecodedLink = QUrl::fromPercentEncoding(link.toUtf8()); + if (mSectionMap.contains(percentDecodedLink)) { + block = mSectionMap.value(percentDecodedLink); + } else { // load missing resource + char *data = nullptr; + // epub_get_data can't handle whitespace url encodings + QByteArray ba = link.replace(QLatin1String("%20"), QLatin1String(" ")).toLatin1(); + const char *clinkClean = ba.data(); + int size = epub_get_data(mTextDocument->getEpub(), clinkClean, &data); + + if (data) { + _cursor->insertBlock(); + + // try to load as image and if not load as html + block = _cursor->block(); + QImage image; + mSectionMap.insert(link, block); + if (image.loadFromData((unsigned char *)data, size)) { + mTextDocument->addResource(QTextDocument::ImageResource, QUrl(link), image); + _cursor->insertImage(link); + } else { + _cursor->insertHtml(QString::fromUtf8(data)); + // Add anchors to hashes + _handle_anchors(block, link); + } + + // Start new file in a new page + int page = mTextDocument->pageCount(); + while (mTextDocument->pageCount() == page) { + _cursor->insertText(QStringLiteral("\n")); + } } - // Start new file in a new page - int page = mTextDocument->pageCount(); - while (mTextDocument->pageCount() == page) { - _cursor->insertText(QStringLiteral("\n")); - } + free(data); } - - free(data); } if (block.isValid()) { // be sure we actually got a block diff --git a/part/part.cpp b/part/part.cpp index 9f355146d..c7a0c7ebf 100644 --- a/part/part.cpp +++ b/part/part.cpp @@ -1578,10 +1578,19 @@ bool Part::openFile() mimes << pathMime << argMime; } + // text is super annoying because it always succeeds when opening so try to make sure + // that we don't set it as first mime unless we're really sure it is that. + // If it could be something else based on the content we try that first but only if that content itself + // is not text or if it's a supported text child like markdown if (mimes[0].inherits(QStringLiteral("text/plain"))) { const QMimeType contentMime = db.mimeTypeForFile(fileNameToOpen, QMimeDatabase::MatchContent); - if (contentMime.name() != QLatin1String("text/plain")) { + if (!contentMime.inherits(QStringLiteral("text/plain"))) { mimes.prepend(contentMime); + } else if (contentMime.name() != QLatin1String("text/plain")) { + const QStringList supportedMimes = m_document->supportedMimeTypes(); + if (supportedMimes.contains(contentMime.name())) { + mimes.prepend(contentMime); + } } } } else { diff --git a/part/toggleactionmenu.cpp b/part/toggleactionmenu.cpp index 0ccff3fb2..453c67b25 100644 --- a/part/toggleactionmenu.cpp +++ b/part/toggleactionmenu.cpp @@ -52,6 +52,7 @@ QWidget *ToggleActionMenu::createWidget(QWidget *parent) // END QToolButton hack m_buttons.append(button); + m_originalToolButtonStyle[button] = button->toolButtonStyle(); // Apply other properties to the button. updateButtons(); @@ -74,11 +75,25 @@ void ToggleActionMenu::setDefaultAction(QAction *action) updateButtons(); } +Qt::ToolButtonStyle ToggleActionMenu::styleFor(QToolButton *button) const +{ + Qt::ToolButtonStyle style = m_originalToolButtonStyle[button]; + + if (style == Qt::ToolButtonTextBesideIcon && priority() < QAction::NormalPriority) { + style = Qt::ToolButtonIconOnly; + } + + return style; +} + void ToggleActionMenu::updateButtons() { for (QToolButton *button : qAsConst(m_buttons)) { if (button) { button->setDefaultAction(this->defaultAction()); + // If *this action* is low priority we need to tell the button + // so that it hides the text + button->setToolButtonStyle(styleFor(button)); if (delayed()) { // TODO deprecated interface. button->setPopupMode(QToolButton::DelayedPopup); diff --git a/part/toggleactionmenu.h b/part/toggleactionmenu.h index 1a7c56263..54eabb976 100644 --- a/part/toggleactionmenu.h +++ b/part/toggleactionmenu.h @@ -88,6 +88,14 @@ protected: QPointer m_defaultAction; QList> m_buttons; + QHash m_originalToolButtonStyle; + + /** + * Returns the aproppriate style for @p button. + * Respects both toolbar settings and settings for this menu action. + */ + Qt::ToolButtonStyle styleFor(QToolButton *button) const; + /** * Updates the toolbar buttons by setting the current defaultAction() on them. *