Commit e788b2a8 authored by Gustavo Carneiro's avatar Gustavo Carneiro Committed by Kurt Hindenburg
Browse files

Konsole: Add a color tabs support in Konsole


Signed-off-by: Gustavo Carneiro's avatarGustavo Carneiro <gcarneiroa@hotmail.com>
parent 25112583
......@@ -336,6 +336,7 @@ void Application::createTabFromArgs(MainWindow *window, const QHash<QString, QSt
const QString &command = tokens[QStringLiteral("command")];
const QString &profile = tokens[QStringLiteral("profile")];
const QString &workdir = tokens[QStringLiteral("workdir")];
const QColor &color = tokens[QStringLiteral("tabcolor")];
Profile::Ptr baseProfile;
if (!profile.isEmpty()) {
......@@ -365,6 +366,12 @@ void Application::createTabFromArgs(MainWindow *window, const QHash<QString, QSt
shouldUseNewProfile = true;
}
// For tab color support
if (color.isValid()) {
newProfile->setProperty(Profile::TabColor, color);
shouldUseNewProfile = true;
}
if (m_parser->isSet(QStringLiteral("workdir"))) {
newProfile->setProperty(Profile::Directory, m_parser->value(QStringLiteral("workdir")));
shouldUseNewProfile = true;
......
......@@ -27,6 +27,9 @@
#include <KAcceleratorManager>
#include <QPainter>
#include <QColor>
namespace Konsole {
DetachableTabBar::DetachableTabBar(QWidget *parent) :
......@@ -40,6 +43,16 @@ DetachableTabBar::DetachableTabBar(QWidget *parent) :
KAcceleratorManager::setNoAccel(this);
}
void DetachableTabBar::setColor(int idx, const QColor &color)
{
setTabData(idx, QColor(color));
}
void DetachableTabBar::removeColor(int idx)
{
setTabData(idx, QVariant());
}
void DetachableTabBar::middleMouseButtonClickAt(const QPoint& pos)
{
tabId = tabAt(pos);
......@@ -140,4 +153,24 @@ void DetachableTabBar::dragMoveEvent(QDragMoveEvent* event)
}
}
void DetachableTabBar::paintEvent(QPaintEvent *event)
{
QTabBar::paintEvent(event);
if (!event->isAccepted()) return; // Reduces repainting
QPainter painter(this);
painter.setPen(Qt::NoPen);
for (int tabIndex = 0; tabIndex <= count(); tabIndex++) {
QColor varColor = tabData(tabIndex).value<QColor>();
if (!varColor.isValid()) {
continue;
}
varColor.setAlpha(tabIndex == currentIndex() ? 180 : 125);
painter.setBrush(varColor);
painter.drawRect(tabRect(tabIndex));
}
}
}
......@@ -23,6 +23,9 @@
#include <QTabBar>
#include <QCursor>
class QColor;
class QPaintEvent;
namespace Konsole {
class TabbedViewContainer;
class DetachableTabBar : public QTabBar {
......@@ -31,6 +34,9 @@ public:
enum class DragType : unsigned char {NONE, OUTSIDE, WINDOW};
explicit DetachableTabBar(QWidget *parent = nullptr);
void setColor(int idx, const QColor &color);
void removeColor(int idx);
Q_SIGNALS:
void detachTab(int index);
void moveTabToWindow(int tabIndex, QWidget *otherWindow);
......@@ -43,6 +49,7 @@ protected:
void mouseReleaseEvent(QMouseEvent *event) override;
void dragEnterEvent(QDragEnterEvent *event) override;
void dragMoveEvent(QDragMoveEvent * event) override;
void paintEvent(QPaintEvent *event) override;
private:
DragType dragType;
......
......@@ -528,11 +528,14 @@ void EditProfileDialog::setupTabsPage(const Profile::Ptr &profile)
// tab title format
_tabsUi->renameTabWidget->setTabTitleText(profile->localTabTitleFormat());
_tabsUi->renameTabWidget->setRemoteTabTitleText(profile->remoteTabTitleFormat());
_tabsUi->renameTabWidget->setColor(profile->tabColor());
connect(_tabsUi->renameTabWidget, &Konsole::RenameTabWidget::tabTitleFormatChanged, this,
&Konsole::EditProfileDialog::tabTitleFormatChanged);
connect(_tabsUi->renameTabWidget, &Konsole::RenameTabWidget::remoteTabTitleFormatChanged, this,
&Konsole::EditProfileDialog::remoteTabTitleFormatChanged);
connect(_tabsUi->renameTabWidget, &Konsole::RenameTabWidget::tabColorChanged, this,
&Konsole::EditProfileDialog::tabColorChanged);
// tab monitoring
const int silenceSeconds = profile->silenceSeconds();
......@@ -577,6 +580,11 @@ void EditProfileDialog::remoteTabTitleFormatChanged(const QString &format)
updateTempProfileProperty(Profile::RemoteTabTitleFormat, format);
}
void EditProfileDialog::tabColorChanged(const QColor &color)
{
updateTempProfileProperty(Profile::TabColor, color);
}
void EditProfileDialog::silenceSecondsChanged(int seconds)
{
updateTempProfileProperty(Profile::SilenceSeconds, seconds);
......
......@@ -124,15 +124,18 @@ private Q_SLOTS:
void initialDirChanged(const QString &dir);
void startInSameDir(bool);
void commandChanged(const QString &command);
// tab page
void tabTitleFormatChanged(const QString &format);
void remoteTabTitleFormatChanged(const QString &format);
void tabColorChanged(const QColor &color);
void silenceSecondsChanged(int);
void terminalColumnsEntryChanged(int);
void terminalRowsEntryChanged(int);
void showTerminalSizeHint(bool);
void setDimWhenInactive(bool);
void showEnvironmentEditor();
void silenceSecondsChanged(int);
// appearance page
void setAntialiasText(bool enable);
......
......@@ -83,6 +83,7 @@ const Profile::PropertyInfo Profile::DefaultPropertyNames[] = {
, { BoldIntense, "BoldIntense", APPEARANCE_GROUP, QVariant::Bool }
, { UseFontLineCharacters, "UseFontLineChararacters", APPEARANCE_GROUP, QVariant::Bool }
, { LineSpacing , "LineSpacing" , APPEARANCE_GROUP , QVariant::Int }
, { TabColor, "TabColor", APPEARANCE_GROUP, QVariant::Color }
// Keyboard
, { KeyBindings , "KeyBindings" , KEYBOARD_GROUP , QVariant::String }
......@@ -222,15 +223,19 @@ void Profile::useFallback()
setProperty(WordCharacters, QStringLiteral(":@-./_~?&=%+#"));
setProperty(TabColor, QColor(QColor::Invalid));
// Fallback should not be shown in menus
setHidden(true);
}
Profile::Profile(const Profile::Ptr &parent)
: _propertyValues(QHash<Property, QVariant>())
, _parent(parent)
, _hidden(false)
{
}
void Profile::clone(Profile::Ptr profile, bool differentOnly)
{
const PropertyInfo* properties = DefaultPropertyNames;
......@@ -275,14 +280,17 @@ bool Profile::isEmpty() const
{
return _propertyValues.isEmpty();
}
QHash<Profile::Property, QVariant> Profile::setProperties() const
{
return _propertyValues;
}
void Profile::setProperty(Property p, const QVariant& value)
{
_propertyValues.insert(p, value);
}
bool Profile::isPropertySet(Property p) const
{
return _propertyValues.contains(p);
......@@ -383,6 +391,7 @@ void ProfileGroup::updateValues()
properties++;
}
}
void ProfileGroup::setProperty(Property p, const QVariant& value)
{
if (_profiles.count() > 1 && !canInheritProperty(p)) {
......@@ -394,4 +403,3 @@ void ProfileGroup::setProperty(Property p, const QVariant& value)
profile->setProperty(p, value);
}
}
......@@ -300,7 +300,9 @@ public:
/** (int) Keyboard modifiers to show URL hints */
UrlHintsModifiers,
/** (bool) Reverse the order of URL hints */
ReverseUrlHints
ReverseUrlHints,
/** (QColor) used in tab color */
TabColor
};
Q_ENUM(Property)
......@@ -445,6 +447,12 @@ public:
return property<QString>(Profile::RemoteTabTitleFormat);
}
/** Convenience method for property<QColor>(Profile::TabColor) */
QColor tabColor() const
{
return property<QColor>(Profile::TabColor);
}
/** Convenience method for property<bool>(Profile::ShowTerminalSizeHint) */
bool showTerminalSizeHint() const
{
......
......@@ -78,6 +78,11 @@ void RenameTabDialog::setRemoteTabTitleText(const QString &text)
_ui->renameTabWidget->setRemoteTabTitleText(text);
}
void RenameTabDialog::setColor(const QColor &color)
{
_ui->renameTabWidget->setColor(color);
}
QString RenameTabDialog::tabTitleText() const
{
return _ui->renameTabWidget->tabTitleText();
......@@ -87,3 +92,8 @@ QString RenameTabDialog::remoteTabTitleText() const
{
return _ui->renameTabWidget->remoteTabTitleText();
}
QColor RenameTabDialog::color() const
{
return _ui->renameTabWidget->color();
}
......@@ -38,8 +38,10 @@ public:
QString tabTitleText() const;
QString remoteTabTitleText() const;
QColor color() const;
void setTabTitleText(const QString &);
void setRemoteTabTitleText(const QString &);
void setColor(const QColor &);
void focusTabTitleText();
void focusRemoteTabTitleText();
......
......@@ -23,6 +23,12 @@
// Konsole
#include "ui_RenameTabWidget.h"
// KDE
#include <KColorCombo>
// Qt
#include <QColor>
using Konsole::RenameTabWidget;
RenameTabWidget::RenameTabWidget(QWidget *parent) :
......@@ -35,10 +41,17 @@ RenameTabWidget::RenameTabWidget(QWidget *parent) :
_ui->tabTitleEdit->setClearButtonEnabled(true);
_ui->remoteTabTitleEdit->setClearButtonEnabled(true);
QList<QColor> listColors(_ui->tabColorCombo->colors());
listColors.insert(0, QColor(QColor::Invalid));
_ui->tabColorCombo->setColors(listColors);
_ui->tabColorCombo->setItemText(1, i18n("Color from theme"));
connect(_ui->tabTitleEdit, &QLineEdit::textChanged, this,
&Konsole::RenameTabWidget::tabTitleFormatChanged);
connect(_ui->remoteTabTitleEdit, &QLineEdit::textChanged, this,
&Konsole::RenameTabWidget::remoteTabTitleFormatChanged);
connect(_ui->tabColorCombo, &KColorCombo::activated, this,
&Konsole::RenameTabWidget::tabColorChanged);
_ui->tabTitleFormatButton->setContext(Session::LocalTabTitle);
connect(_ui->tabTitleFormatButton, &Konsole::TabTitleFormatButton::dynamicElementSelected, this,
......@@ -74,6 +87,11 @@ void RenameTabWidget::setRemoteTabTitleText(const QString &text)
_ui->remoteTabTitleEdit->setText(text);
}
void RenameTabWidget::setColor(const QColor &color)
{
_ui->tabColorCombo->setColor(color);
}
QString RenameTabWidget::tabTitleText() const
{
return _ui->tabTitleEdit->text();
......@@ -84,6 +102,11 @@ QString RenameTabWidget::remoteTabTitleText() const
return _ui->remoteTabTitleEdit->text();
}
QColor RenameTabWidget::color() const
{
return _ui->tabColorCombo->color();
}
void RenameTabWidget::insertTabTitleText(const QString &text)
{
_ui->tabTitleEdit->insert(text);
......
......@@ -23,6 +23,8 @@
// Qt
#include <QWidget>
class QColor;
namespace Ui {
class RenameTabWidget;
}
......@@ -38,8 +40,10 @@ public:
QString tabTitleText() const;
QString remoteTabTitleText() const;
QColor color() const;
void setTabTitleText(const QString &);
void setRemoteTabTitleText(const QString &);
void setColor(const QColor &);
void focusTabTitleText();
void focusRemoteTabTitleText();
......@@ -47,6 +51,7 @@ public:
Q_SIGNALS:
void tabTitleFormatChanged(const QString &);
void remoteTabTitleFormatChanged(const QString &);
void tabColorChanged(const QColor &);
public Q_SLOTS:
void insertTabTitleText(const QString &text);
......
......@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>400</width>
<height>70</height>
<height>119</height>
</rect>
</property>
<property name="sizePolicy">
......@@ -29,6 +29,44 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item row="1" column="1">
<widget class="QLineEdit" name="remoteTabTitleEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Tab title format used when a remote command (e.g. connection to another computer via SSH) is being executed</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="Konsole::TabTitleFormatButton" name="remoteTabTitleFormatButton"/>
</item>
<item row="0" column="2">
<widget class="Konsole::TabTitleFormatButton" name="tabTitleFormatButton"/>
</item>
<item row="1" column="0" alignment="Qt::AlignRight">
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Remote tab title format:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>remoteTabTitleEdit</cstring>
</property>
</widget>
</item>
<item row="0" column="0" alignment="Qt::AlignRight">
<widget class="QLabel" name="label">
<property name="sizePolicy">
......@@ -61,47 +99,37 @@
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="Konsole::TabTitleFormatButton" name="tabTitleFormatButton"/>
</item>
<item row="1" column="0" alignment="Qt::AlignRight">
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Remote tab title format:</string>
<string>Tab Color:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>remoteTabTitleEdit</cstring>
<cstring>tabColorCombo</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="remoteTabTitleEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<item row="2" column="1">
<widget class="KColorCombo" name="tabColorCombo">
<property name="editable">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Tab title format used when a remote command (e.g. connection to another computer via SSH) is being executed</string>
<property name="currentIndex">
<number>0</number>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="Konsole::TabTitleFormatButton" name="remoteTabTitleFormatButton"/>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KColorCombo</class>
<extends>QComboBox</extends>
<header>kcolorcombo.h</header>
</customwidget>
<customwidget>
<class>Konsole::TabTitleFormatButton</class>
<extends>QPushButton</extends>
......
......@@ -88,6 +88,7 @@ Session::Session(QObject* parent) :
, _localTabTitleFormat(QString())
, _remoteTabTitleFormat(QString())
, _tabTitleSetByUser(false)
, _tabColorSetByUser(false)
, _iconName(QString())
, _iconText(QString())
, _addToUtmp(true)
......@@ -587,6 +588,7 @@ QString Session::userTitle() const
{
return _userTitle;
}
void Session::setTabTitleFormat(TabTitleContext context , const QString& format)
{
if (context == LocalTabTitle) {
......@@ -597,6 +599,7 @@ void Session::setTabTitleFormat(TabTitleContext context , const QString& format)
_remoteTabTitleFormat = format;
}
}
QString Session::tabTitleFormat(TabTitleContext context) const
{
if (context == LocalTabTitle) {
......@@ -618,6 +621,16 @@ bool Session::isTabTitleSetByUser() const
return _tabTitleSetByUser;
}
void Session::tabColorSetByUser(bool set)
{
_tabColorSetByUser = set;
}
bool Session::isTabColorSetByUser() const
{
return _tabColorSetByUser;
}
void Session::silenceTimerDone()
{
//FIXME: The idea here is that the notification popup will appear to tell the user than output from
......@@ -684,10 +697,10 @@ void Session::changeTabTextColor(int i)
void Session::onPrimaryScreenInUse(bool use)
{
_isPrimaryScreen = use;
emit primaryScreenInUse(use);
}
bool Session::isPrimaryScreen()
{
return _isPrimaryScreen;
......@@ -1641,6 +1654,7 @@ void Session::saveSession(KConfigGroup& group)
group.writePathEntry("WorkingDir", currentWorkingDirectory());
group.writeEntry("LocalTab", tabTitleFormat(LocalTabTitle));
group.writeEntry("RemoteTab", tabTitleFormat(RemoteTabTitle));
group.writeEntry("TabColor", QString(color().name(QColor::HexArgb)));
group.writeEntry("SessionGuid", _uniqueIdentifier.toString());
group.writeEntry("Encoding", QString::fromUtf8(codec()));
}
......@@ -1661,6 +1675,10 @@ void Session::restoreSession(KConfigGroup& group)
if (!value.isEmpty()) {
setTabTitleFormat(RemoteTabTitle, value);
}
value = group.readEntry("TabColor");
if (!value.isEmpty()) {
setColor(QColor(value));
}
value = group.readEntry("SessionGuid");
if (!value.isEmpty()) {
_uniqueIdentifier = QUuid(value);
......@@ -1746,6 +1764,17 @@ void Session::setReadOnly(bool readOnly)
}
}
void Session::setColor(const QColor &color)
{
_tabColor = color;
emit sessionAttributeChanged();
}
QColor Session::color() const
{
return _tabColor;
}
SessionGroup::SessionGroup(QObject* parent)
: QObject(parent), _masterMode(0)
{
......
......@@ -174,12 +174,27 @@ public:
/** Returns the format used by this session for tab titles. */
QString tabTitleFormat(TabTitleContext context) const;
/**
* Sets the color user by this session for tab.
*
* @param color The background color for the tab.
*/
void setColor(const QColor &color);
/** Returns the color used by this session for tab. */
QColor color() const;
/**
* Returns true if the tab title has been changed by the user via the
* rename-tab dialog.
*/
bool isTabTitleSetByUser() const;
/**
* Returns true if the tab color has been changed by the user via the
* rename-tab dialog.
*/
bool isTabColorSetByUser() const;
/** Returns the arguments passed to the shell process when run() is called. */
QStringList arguments() const;
/** Returns the program name of the shell process started when run() is called. */
......@@ -385,6 +400,7 @@ public:
// or false if it's the primary/normal buffer
bool isPrimaryScreen();
void tabTitleSetByUser(bool set);
void tabColorSetByUser(bool set);
enum Notification {
NoNotification = 0,
......@@ -808,8 +824,10 @@ private:
QString _localTabTitleFormat;
QString _remoteTabTitleFormat;
QColor _tabColor;
bool _tabTitleSetByUser;
bool _tabColorSetByUser;
QString _iconName;
QString _iconText; // not actually used
......
......@@ -164,7 +164,8 @@ SessionController::SessionController(Session* session , TerminalDisplay* view, Q
connect(_session.data(), &Konsole::Session::sessionAttributeChanged, this, &Konsole::SessionController::sessionAttributeChanged);
connect(_session.data(), &Konsole::Session::readOnlyChanged, this, &Konsole::SessionController::sessionReadOnlyChanged);
connect(this, &Konsole::SessionController::tabRenamedByUser, _session, &Konsole::Session::tabTitleSetByUser);
connect(this, &Konsole::SessionController::tabRenamedByUser, _session, &Konsole::Session::tabTitleSetByUser);
connect(this, &Konsole::SessionController::tabColoredByUser, _session, &Konsole::Session::tabColorSetByUser);
connect(_session.data() , &Konsole::Session::currentDirectoryChanged , this , &Konsole::SessionController::currentDirectoryChanged);
......@@ -310,10 +311,19 @@ void SessionController::snapshot()
if (title.isEmpty()) {
title = _session->title(Session::NameRole);
}
QColor color = _session->color();
// use the fallback color if needed
if (!color.isValid()) {
color = QColor(QColor::Invalid);
}
// apply new title
_session->setTitle(Session::DisplayedTitleRole, title);
// apply new color
_session->setColor(color);
// do not forget icon
updateSessionIcon();
}
......@@ -859,10 +869,12 @@ void SessionController::renameSession()