Commit 340d8fc0 authored by Mariusz Glebocki's avatar Mariusz Glebocki Committed by Kurt Hindenburg
Browse files

Show separate status icons in view (split) headers

parent fc660b0b
......@@ -44,45 +44,75 @@ namespace Konsole {
TerminalHeaderBar::TerminalHeaderBar(QWidget *parent)
: QWidget(parent)
{
m_closeBtn = new QToolButton(this);
m_closeBtn->setIcon(QIcon::fromTheme(QStringLiteral("tab-close")));
m_closeBtn->setToolTip(i18nc("@info:tooltip", "Close terminal"));
m_closeBtn->setText(i18nc("@info:tooltip", "Close terminal"));
m_closeBtn->setObjectName(QStringLiteral("close-terminal-button"));
m_closeBtn->setAutoRaise(true);
m_toggleExpandedMode = new QToolButton(this);
m_toggleExpandedMode->setIcon(QIcon::fromTheme(QStringLiteral("view-fullscreen"))); // fake 'expand' icon. VDG input?
m_toggleExpandedMode->setAutoRaise(true);
m_toggleExpandedMode->setCheckable(true);
m_toggleExpandedMode->setToolTip(i18nc("@info:tooltip", "Maximize terminal"));
m_boxLayout = new QBoxLayout(QBoxLayout::LeftToRight);
m_boxLayout->setSpacing(0);
m_boxLayout->setContentsMargins(0, 0, 0, 0);
m_terminalTitle = new QLabel(this);
m_terminalTitle->setFont(QApplication::font());
// Session icon
m_terminalIcon = new QLabel(this);
m_terminalIcon->setAlignment(Qt::AlignCenter);
m_terminalIcon->setFixedSize(m_toggleExpandedMode->sizeHint());
m_terminalActivity = new QLabel(this);
m_terminalIcon->setFixedSize(20, 20);
m_boxLayout = new QBoxLayout(QBoxLayout::LeftToRight);
m_boxLayout->setSpacing(0);
m_boxLayout->setContentsMargins(0, 0, 0, 0);
// Layout Setup
m_boxLayout->addWidget(m_terminalIcon);
m_boxLayout->addWidget(m_terminalActivity);
// Status icons
QLabel ** statusIcons[] = {&m_statusIconReadOnly, &m_statusIconCopyInput, &m_statusIconSilence, &m_statusIconActivity, &m_statusIconBell};
for (auto **statusIcon: statusIcons) {
*statusIcon = new QLabel(this);
(*statusIcon)->setAlignment(Qt::AlignCenter);
(*statusIcon)->setFixedSize(20, 20);
(*statusIcon)->setVisible(false);
m_boxLayout->addWidget(*statusIcon);
}
m_statusIconReadOnly->setPixmap(QIcon::fromTheme(QStringLiteral("object-locked")).pixmap(QSize(16,16)));
m_statusIconCopyInput->setPixmap(QIcon::fromTheme(QStringLiteral("irc-voice")).pixmap(QSize(16,16)));
m_statusIconSilence->setPixmap(QIcon::fromTheme(QStringLiteral("system-suspend")).pixmap(QSize(16,16)));
m_statusIconActivity->setPixmap(QIcon::fromTheme(QStringLiteral("dialog-information")).pixmap(QSize(16,16)));
m_statusIconBell->setPixmap(QIcon::fromTheme(QStringLiteral("notifications")).pixmap(QSize(16,16)));
// Title
m_terminalTitle = new QLabel(this);
m_terminalTitle->setFont(QApplication::font());
m_boxLayout->addStretch();
m_boxLayout->addWidget(m_terminalTitle);
m_boxLayout->addStretch();
// Expand button
m_toggleExpandedMode = new QToolButton(this);
m_toggleExpandedMode->setIcon(QIcon::fromTheme(QStringLiteral("view-fullscreen"))); // fake 'expand' icon. VDG input?
m_toggleExpandedMode->setAutoRaise(true);
m_toggleExpandedMode->setCheckable(true);
m_toggleExpandedMode->setToolTip(i18nc("@info:tooltip", "Maximize terminal"));
connect(m_toggleExpandedMode, &QToolButton::clicked,
this, &TerminalHeaderBar::requestToggleExpansion);
m_boxLayout->addWidget(m_toggleExpandedMode);
// Close button
m_closeBtn = new QToolButton(this);
m_closeBtn->setIcon(QIcon::fromTheme(QStringLiteral("tab-close")));
m_closeBtn->setToolTip(i18nc("@info:tooltip", "Close terminal"));
m_closeBtn->setText(i18nc("@info:tooltip", "Close terminal"));
m_closeBtn->setObjectName(QStringLiteral("close-terminal-button"));
m_closeBtn->setAutoRaise(true);
m_boxLayout->addWidget(m_closeBtn);
setLayout(m_boxLayout);
// The widget itself
setLayout(m_boxLayout);
setAutoFillBackground(true);
setFocusIndicatorState(false);
connect(m_toggleExpandedMode, &QToolButton::clicked,
this, &TerminalHeaderBar::requestToggleExpansion);
}
// Hack untill I can detangle the creation of the TerminalViews
......@@ -99,9 +129,14 @@ void TerminalHeaderBar::finishHeaderSetup(ViewProperties *properties)
});
m_terminalIcon->setPixmap(properties->icon().pixmap(QSize(22,22)));
connect(properties, &Konsole::ViewProperties::activity, this, [this]{
m_terminalActivity->setPixmap(QPixmap());
});
connect(properties, &Konsole::ViewProperties::notificationChanged, this,
&Konsole::TerminalHeaderBar::updateNotification);
connect(properties, &Konsole::ViewProperties::readOnlyChanged, this,
&Konsole::TerminalHeaderBar::updateSpecialState);
connect(properties, &Konsole::ViewProperties::copyInputChanged, this,
&Konsole::TerminalHeaderBar::updateSpecialState);
connect(m_closeBtn, &QToolButton::clicked, controller, &SessionController::closeSession);
}
......@@ -112,6 +147,33 @@ void TerminalHeaderBar::setFocusIndicatorState(bool focused)
update();
}
void TerminalHeaderBar::updateNotification(ViewProperties *item, Session::Notification notification, bool enabled)
{
Q_UNUSED(item);
switch(notification) {
case Session::Notification::Silence:
m_statusIconSilence->setVisible(enabled);
break;
case Session::Notification::Activity:
m_statusIconActivity->setVisible(enabled);
break;
case Session::Notification::Bell:
m_statusIconBell->setVisible(enabled);
break;
default:
break;
}
}
void TerminalHeaderBar::updateSpecialState(ViewProperties *item)
{
auto controller = dynamic_cast<SessionController*>(item);
m_statusIconReadOnly->setVisible(controller->isReadOnly());
m_statusIconCopyInput->setVisible(controller->isCopyInputActive());
}
void TerminalHeaderBar::paintEvent(QPaintEvent *paintEvent)
{
/* Try to get the widget that's 10px above this one.
......@@ -175,3 +237,9 @@ void TerminalHeaderBar::mouseReleaseEvent(QMouseEvent* ev)
}
}
QSize Konsole::TerminalHeaderBar::minimumSizeHint() const
{
auto height = sizeHint().height();
return QSize(height, height);
}
\ No newline at end of file
......@@ -24,6 +24,7 @@
#include <QWidget>
#include <QPoint>
#include "Session.h"
class QLabel;
class QToolButton;
......@@ -38,9 +39,14 @@ public:
// TODO: Verify if the terminalDisplay is needed, or some other thing like SessionController.
explicit TerminalHeaderBar(QWidget *parent = nullptr);
void finishHeaderSetup(ViewProperties *properties);
QSize minimumSizeHint() const override;
public Q_SLOTS:
void setFocusIndicatorState(bool focused);
/** Shows/hide notification status icon */
void updateNotification(ViewProperties *item, Konsole::Session::Notification notification, bool enabled);
/** Shows/hide special state status icon (copy input or read-only) */
void updateSpecialState(ViewProperties *item);
protected:
void paintEvent(QPaintEvent* paintEvent) override;
......@@ -56,7 +62,11 @@ private:
TerminalDisplay *m_terminalDisplay;
QLabel *m_terminalTitle;
QLabel *m_terminalIcon;
QLabel *m_terminalActivity; // Bell icon.
QLabel *m_statusIconReadOnly;
QLabel *m_statusIconCopyInput;
QLabel *m_statusIconSilence;
QLabel *m_statusIconActivity;
QLabel *m_statusIconBell;
QToolButton *m_closeBtn;
QToolButton *m_toggleExpandedMode;
bool m_terminalIsFocused;
......
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