Commit 80d3c06c authored by Waqar Ahmed's avatar Waqar Ahmed Committed by Christoph Cullmann
Browse files

Add a new msg indicator for output toolview tab button

When a new message arrives that is not a "Log" message, the indicator
starts blinking.

If the toolview will show afterwards automatically, the blink happens
only once, otherwise if its a warn or error msg and the toolview is not
visible, it will blink till the button is clicked.
parent 4da1665e
......@@ -281,7 +281,7 @@ void KateMainWindow::setupMainWindow()
KTextEditor::MainWindow::Bottom,
QIcon::fromTheme(QStringLiteral("output_win")),
i18n("Output"));
m_outputView = new KateOutputView(this, m_toolViewOutput);
m_outputView = new KateOutputView(this, m_toolViewOutput, toolviewToggleButton(static_cast<KateMDI::ToolView *>(m_toolViewOutput)));
}
void KateMainWindow::setupActions()
......
......@@ -1482,6 +1482,14 @@ bool MainWindow::hideToolView(ToolView *widget)
return ret;
}
QWidget *MainWindow::toolviewToggleButton(ToolView *tv)
{
if (tv && tv->sidebar()) {
return tv->sidebar()->tabButtonForToolview(tv);
}
return nullptr;
}
void MainWindow::hideToolViews()
{
for (const auto &tv : m_toolviews) {
......
......@@ -266,6 +266,18 @@ public:
bool isCollapsed();
QWidget *tabButtonForToolview(ToolView *widget) const
{
auto it = m_widgetToId.find(widget);
if (it == m_widgetToId.end()) {
return nullptr;
}
if (auto tabbar = kmTabBar(widget)) {
return tabbar->tab(it->second);
}
return nullptr;
}
/**
* Will the sidebar expand when some tool has to be visible in any section,
* or calling collapseSidebar() if non such tool is found
......@@ -546,6 +558,8 @@ public:
*/
bool hideToolView(ToolView *widget);
QWidget *toolviewToggleButton(ToolView *tv);
/**
* session saving and restore stuff
*/
......
......@@ -20,6 +20,7 @@
#include <QMenu>
#include <QPainter>
#include <QSortFilterProxyModel>
#include <QTimeLine>
#include <QToolButton>
#include <QTreeView>
#include <QVBoxLayout>
......@@ -27,8 +28,64 @@
#include <KFuzzyMatcher>
#include <ktexteditor_utils.h>
class NewMsgIndicator : public QWidget
{
Q_OBJECT
public:
NewMsgIndicator(QWidget *parent)
: QWidget(parent)
, m_timeline(1000, this)
{
setAttribute(Qt::WA_TransparentForMouseEvents, true);
setGeometry(parent->geometry().adjusted(-2, -2, 2, 2));
m_timeline.setDirection(QTimeLine::Forward);
m_timeline.setEasingCurve(QEasingCurve::SineCurve);
m_timeline.setFrameRange(0, 92);
auto update = QOverload<>::of(&QWidget::update);
connect(&m_timeline, &QTimeLine::valueChanged, this, update);
connect(&m_timeline, &QTimeLine::finished, this, &QObject::deleteLater);
}
void run(int c)
{
// If parent is not visible, do nothing
if (parentWidget() && !parentWidget()->isVisible()) {
return;
}
show();
raise();
m_timeline.setLoopCount(c);
m_timeline.start();
}
Q_SLOT void stop()
{
m_timeline.stop();
deleteLater();
}
protected:
void paintEvent(QPaintEvent *) override
{
if (m_timeline.state() == QTimeLine::Running) {
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);
QColor c = Qt::red;
c.setAlpha(m_timeline.currentFrame());
p.setBrush(c);
p.setPen(Qt::NoPen);
p.drawRoundedRect(rect(), 15, 15);
}
}
private:
QTimeLine m_timeline;
};
class KateOutputTreeView : public QTreeView
{
Q_OBJECT
public:
KateOutputTreeView(QWidget *parent)
: QTreeView(parent)
......@@ -110,6 +167,7 @@ private:
class OutputSortFilterProxyModel final : public QSortFilterProxyModel
{
Q_OBJECT
public:
OutputSortFilterProxyModel(QObject *parent = nullptr)
: QSortFilterProxyModel(parent)
......@@ -159,10 +217,13 @@ private:
static constexpr int WeightRole = Qt::UserRole + 1;
};
KateOutputView::KateOutputView(KateMainWindow *mainWindow, QWidget *parent)
KateOutputView::KateOutputView(KateMainWindow *mainWindow, QWidget *parent, QWidget *tabButton)
: QWidget(parent)
, m_mainWindow(mainWindow)
, tabButton(tabButton)
{
Q_ASSERT(tabButton);
m_proxyModel = new OutputSortFilterProxyModel(this);
m_proxyModel->setSourceModel(&m_messagesModel);
m_proxyModel->setRecursiveFilteringEnabled(true);
......@@ -284,6 +345,7 @@ void KateOutputView::slotMessage(const QVariantMap &message)
*/
bool shouldShowOutputToolView = false;
auto typeColumn = new QStandardItem();
int indicatorLoopCount = 0; // for warning/error infinite loop
const auto typeString = message.value(QStringLiteral("type")).toString();
if (typeString == QLatin1String("Error")) {
shouldShowOutputToolView = (m_showOutputViewForMessageType >= 1);
......@@ -297,10 +359,23 @@ void KateOutputView::slotMessage(const QVariantMap &message)
shouldShowOutputToolView = (m_showOutputViewForMessageType >= 3);
typeColumn->setText(i18nc("@info", "Info"));
typeColumn->setIcon(QIcon::fromTheme(QStringLiteral("data-information")));
indicatorLoopCount = 2;
} else {
shouldShowOutputToolView = (m_showOutputViewForMessageType >= 4);
typeColumn->setText(i18nc("@info", "Log"));
typeColumn->setIcon(QIcon::fromTheme(QStringLiteral("dialog-messages")));
indicatorLoopCount = -1; // no FadingIndicator for log messages
}
if (shouldShowOutputToolView || isVisible()) {
// if we are going to show the output toolview afterwards
indicatorLoopCount = 1;
}
if (!m_fadingIndicator && indicatorLoopCount >= 0) {
m_fadingIndicator = new NewMsgIndicator(tabButton);
m_fadingIndicator->run(indicatorLoopCount);
connect(tabButton, SIGNAL(clicked()), m_fadingIndicator, SLOT(stop()));
}
/**
......@@ -369,3 +444,5 @@ void KateOutputView::slotMessage(const QVariantMap &message)
m_mainWindow->showToolView(parentWidget());
}
}
#include "kateoutputview.moc"
......@@ -8,6 +8,7 @@
#define KATE_OUTPUT_VIEW_H
#include <QLineEdit>
#include <QPointer>
#include <QStandardItemModel>
#include <QWidget>
......@@ -34,7 +35,7 @@ public:
* @param mainWindow parent main window
* @param parent parent widget (e.g. the tool view in the main window)
*/
KateOutputView(KateMainWindow *mainWindow, QWidget *parent);
KateOutputView(KateMainWindow *mainWindow, QWidget *parent, QWidget *tabButton);
public Q_SLOTS:
/**
......@@ -131,6 +132,10 @@ private:
* history size limit, < 0 is unlimited
*/
int m_historyLimit = -1;
QPointer<QWidget> tabButton;
QPointer<class NewMsgIndicator> m_fadingIndicator;
};
#endif
Supports Markdown
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