Commit 1dc81340 authored by Albert Astals Cid's avatar Albert Astals Cid
Browse files

okularkirigami: Show document error/warning/notice

parent 1f84075c
Pipeline #79658 passed with stage
in 9 minutes and 33 seconds
......@@ -10,6 +10,8 @@ import org.kde.okular 2.0 as Okular
import org.kde.kirigami 2.10 as Kirigami
Kirigami.Page {
id: root
property alias document: pageArea.document
leftPadding: 0
topPadding: 0
......@@ -34,6 +36,47 @@ Kirigami.Page {
onClicked: fileBrowserRoot.controlsVisible = !fileBrowserRoot.controlsVisible
}
Connections {
target: root.document
onError: (text, duration) => {
inlineMessage.showMessage(Kirigami.MessageType.Error, text, duration);
}
onWarning: (text, duration) => {
inlineMessage.showMessage(Kirigami.MessageType.Warning, text, duration);
}
onNotice: (text, duration) => {
inlineMessage.showMessage(Kirigami.MessageType.Information, text, duration);
}
}
Kirigami.InlineMessage {
id: inlineMessage
width: parent.width
function showMessage(type, text, duration) {
inlineMessage.type = type;
inlineMessage.text = text;
inlineMessage.visible = true;
inlineMessageTimer.interval = duration > 0 ? duration : 500 + 100 * text.length;
}
onVisibleChanged: {
if (visible) {
inlineMessageTimer.start()
} else {
inlineMessageTimer.stop()
}
}
Timer {
id: inlineMessageTimer
onTriggered: inlineMessage.visible = false
}
}
// TODO KF 5.64 replace usage by upstream PlaceholderMessage
PlaceholderMessage {
visible: documentItem.url.toString().length === 0
......
......@@ -34,6 +34,9 @@ DocumentItem::DocumentItem(QObject *parent)
connect(m_document, &Okular::Document::searchFinished, this, &DocumentItem::searchFinished);
connect(m_document->bookmarkManager(), &Okular::BookmarkManager::bookmarksChanged, this, &DocumentItem::bookmarkedPagesChanged);
connect(m_document->bookmarkManager(), &Okular::BookmarkManager::bookmarksChanged, this, &DocumentItem::bookmarksChanged);
connect(m_document, &Okular::Document::error, this, &DocumentItem::error);
connect(m_document, &Okular::Document::warning, this, &DocumentItem::warning);
connect(m_document, &Okular::Document::notice, this, &DocumentItem::notice);
}
DocumentItem::~DocumentItem()
......
......@@ -139,6 +139,30 @@ Q_SIGNALS:
void bookmarksChanged();
void windowTitleForDocumentChanged();
/**
* This signal is emitted whenever an error occurred.
*
* @param text The description of the error.
* @param duration The time in milliseconds the message should be shown to the user.
*/
void error(const QString &text, int duration);
/**
* This signal is emitted to signal a warning.
*
* @param text The description of the warning.
* @param duration The time in milliseconds the message should be shown to the user.
*/
void warning(const QString &text, int duration);
/**
* This signal is emitted to signal a notice.
*
* @param text The description of the notice.
* @param duration The time in milliseconds the message should be shown to the user.
*/
void notice(const QString &text, int duration);
private Q_SLOTS:
void searchFinished(int id, Okular::Document::SearchStatus endStatus);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment