Merge remote-tracking branch 'origin/release/22.08'

remotes/origin/work/numberformattest
Albert Astals Cid 4 years ago
commit b2c56a0a71
  1. 8
      core/textdocumentgenerator_p.h
  2. 61
      generators/epub/converter.cpp
  3. 11
      part/part.cpp
  4. 15
      part/toggleactionmenu.cpp
  5. 8
      part/toggleactionmenu.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();

@ -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

@ -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 {

@ -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);

@ -88,6 +88,14 @@ protected:
QPointer<QAction> m_defaultAction;
QList<QPointer<QToolButton>> m_buttons;
QHash<const QToolButton *, Qt::ToolButtonStyle> 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.
*

Loading…
Cancel
Save