Use default close button of KMessageWidget

Summary:
D10935 introduced KMessageWidgets in TerminalDisplay for the "resume"
and "read-only" messages. This patch restores the default close button
and makes use of animateShow/animateHide. A nice plus is that I also
removed some code which has become obsolete AND that the messages
are now animated.

{F5749781}

Test Plan:
Show/hide works like before.
Also still works if readonly and suspended at the same time.
Detaching works.

Reviewers: ach, #konsole, hindenburg

Reviewed By: #konsole, hindenburg

Subscribers: hindenburg, ach, #konsole

Tags: #konsole

Differential Revision: https://phabricator.kde.org/D11241
wilder-portage
Joshua Noack 8 years ago committed by Kurt Hindenburg
parent 5eb9952b8c
commit c442d22313
  1. 34
      src/TerminalDisplay.cpp
  2. 4
      src/TerminalDisplay.h

@ -3355,25 +3355,19 @@ void TerminalDisplay::outputSuspended(bool suspended)
//all terminal emulators.
//If there isn't a suitable article available in the target language the link
//can simply be removed.
auto linkHandler = [this](const QString &url) {
if (url == QLatin1String("#close")) {
_outputSuspendedMessageWidget->hide();
} else {
QDesktopServices::openUrl(QUrl(url));
}
};
_outputSuspendedMessageWidget = createMessageWidget(i18n("<qt>Output has been "
"<a href=\"http://en.wikipedia.org/wiki/Software_flow_control\">suspended</a>"
" by pressing Ctrl+S."
" Press <b>Ctrl+Q</b> to resume."
" Click <a href=\"#close\">here</a> to dismiss this message.</qt>"), linkHandler);
" Press <b>Ctrl+Q</b> to resume.</qt>"));
connect(_outputSuspendedMessageWidget, &KMessageWidget::linkActivated, this, [this](const QString &url) {
QDesktopServices::openUrl(QUrl(url));
});
_outputSuspendedMessageWidget->setMessageType(KMessageWidget::Warning);
_outputSuspendedMessageWidget->hide();
}
_outputSuspendedMessageWidget->setVisible(suspended);
suspended ? _outputSuspendedMessageWidget->animatedShow() : _outputSuspendedMessageWidget->animatedHide();
}
void TerminalDisplay::dismissOutputSuspendedMessage()
@ -3381,15 +3375,12 @@ void TerminalDisplay::dismissOutputSuspendedMessage()
outputSuspended(false);
}
KMessageWidget* TerminalDisplay::createMessageWidget(const QString &text, std::function<void (const QString&)> linkHandler) {
KMessageWidget* TerminalDisplay::createMessageWidget(const QString &text) {
auto widget = new KMessageWidget(text);
widget->setWordWrap(true);
widget->setFocusProxy(this);
widget->setCloseButtonVisible(false);
widget->setCursor(Qt::ArrowCursor);
connect(widget, &KMessageWidget::linkActivated, this, linkHandler);
_verticalLayout->insertWidget(0, widget);
return widget;
}
@ -3399,20 +3390,13 @@ void TerminalDisplay::updateReadOnlyState(bool readonly) {
if (readonly) {
// Lazy create the readonly messagewidget
if (_readOnlyMessageWidget == nullptr) {
auto linkHandler = [this](const QString &url) {
if (url == QLatin1String("#close")) {
_readOnlyMessageWidget->hide();
}
};
_readOnlyMessageWidget = createMessageWidget(i18n("<qt>This terminal is read-only. <a href=\"#close\">Dismiss</a></qt>"), linkHandler);
_readOnlyMessageWidget = createMessageWidget(i18n("This terminal is read-only."));
_readOnlyMessageWidget->setIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
}
}
if (_readOnlyMessageWidget != nullptr) {
_readOnlyMessageWidget->setVisible(readonly);
readonly ? _readOnlyMessageWidget->animatedShow() : _readOnlyMessageWidget->animatedHide();
}
}

@ -21,8 +21,6 @@
#ifndef TERMINALDISPLAY_H
#define TERMINALDISPLAY_H
#include <functional>
// Qt
#include <QColor>
#include <QPointer>
@ -882,7 +880,7 @@ private:
Screen::DecodingOptions currentDecodingOptions();
// Boilerplate setup for MessageWidget
KMessageWidget* createMessageWidget(const QString &text, std::function<void (const QString&)> linkHandler);
KMessageWidget* createMessageWidget(const QString &text);
// the window onto the terminal screen which this display
// is currently showing.

Loading…
Cancel
Save