From cc2f552d7471adde14880dd61e68da0a2ef697f2 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Wed, 5 Aug 2020 16:25:15 +0000 Subject: [PATCH] Add a new option in the profile: Vertical line at Column This patch introduces a new profile option, a vertical line at a specific column, to help writting emails, and git commits in editors that doesn't support line columns such as nano --- src/profile/Profile.cpp | 5 +- src/profile/Profile.h | 14 +++ src/widgets/EditProfileAppearancePage.ui | 120 ++++++++++++++--------- src/widgets/EditProfileDialog.cpp | 17 ++++ src/widgets/EditProfileDialog.h | 3 +- src/widgets/TerminalDisplay.cpp | 11 +++ src/widgets/TerminalDisplay.h | 2 + 7 files changed, 122 insertions(+), 50 deletions(-) diff --git a/src/profile/Profile.cpp b/src/profile/Profile.cpp index 1ae4e437..0ea2833d 100644 --- a/src/profile/Profile.cpp +++ b/src/profile/Profile.cpp @@ -105,7 +105,8 @@ const Profile::PropertyInfo Profile::DefaultPropertyNames[] = { , { BidiRenderingEnabled , "BidiRenderingEnabled" , TERMINAL_GROUP , QVariant::Bool } , { BlinkingCursorEnabled , "BlinkingCursorEnabled" , TERMINAL_GROUP , QVariant::Bool } , { BellMode , "BellMode" , TERMINAL_GROUP , QVariant::Int } - + , { VerticalLine, "VerticalLine", TERMINAL_GROUP, QVariant::Bool } + , { VerticalLineAtChar, "VerticalLineAtChar", TERMINAL_GROUP, QVariant::Int } // Cursor , { UseCustomCursorColor , "UseCustomCursorColor" , CURSOR_GROUP , QVariant::Bool} , { CursorShape , "CursorShape" , CURSOR_GROUP , QVariant::Int} @@ -233,6 +234,8 @@ void Profile::useFallback() setProperty(TabColor, QColor(QColor::Invalid)); setProperty(AllowEscapedLinks, true); setProperty(EscapedLinksSchema, QStringLiteral("http://;https://;file://")); + setProperty(VerticalLine, false); + setProperty(VerticalLineAtChar, 80); // Fallback should not be shown in menus setHidden(true); } diff --git a/src/profile/Profile.h b/src/profile/Profile.h index 576f7a84..7f58eeb1 100644 --- a/src/profile/Profile.h +++ b/src/profile/Profile.h @@ -319,6 +319,10 @@ public: * some weird ones like git:// and ssh:// but if the user wants he can enable. */ EscapedLinksSchema, + /** Use Vertical Line At */ + VerticalLine, + /** Vertical Line Pixel at */ + VerticalLineAtChar }; Q_ENUM(Property) @@ -669,6 +673,16 @@ public: return property(Profile::MenuIndex); } + bool verticalLine() const + { + return property(Profile::VerticalLine); + } + + int verticalLineAtChar() const + { + return property(Profile::VerticalLineAtChar); + } + int menuIndexAsInt() const; /** Return a list of all properties names and their type diff --git a/src/widgets/EditProfileAppearancePage.ui b/src/widgets/EditProfileAppearancePage.ui index 5f5dd3b0..5b82a8a0 100644 --- a/src/widgets/EditProfileAppearancePage.ui +++ b/src/widgets/EditProfileAppearancePage.ui @@ -471,47 +471,55 @@ - + 6 - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 16 - - - - Window: - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - + + - Indicate whether the window is active by dimming the colors + Show terminal size in columns and lines in the center of window after resizing - Darken + Show hint for terminal size after resizing - + + + + + + Darkening strength: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 255 + + + Qt::Horizontal + + + QSlider::NoTicks + + + + + + Inactive Terminals: @@ -521,7 +529,7 @@ - + Terminal contents @@ -663,7 +671,17 @@ - + + + + Indicate whether the window is active by dimming the colors + + + Darken + + + + @@ -680,40 +698,46 @@ - - - - Show terminal size in columns and lines in the center of window after resizing + + + + Qt::Vertical - - Show hint for terminal size after resizing + + QSizePolicy::Fixed - + + + 20 + 16 + + + - - + + - + - Darkening strength: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Display Vertical line at column: - - - 255 - + + + + Qt::Horizontal - - QSlider::NoTicks + + + 40 + 20 + - + diff --git a/src/widgets/EditProfileDialog.cpp b/src/widgets/EditProfileDialog.cpp index 4e11bca5..183b6f87 100644 --- a/src/widgets/EditProfileDialog.cpp +++ b/src/widgets/EditProfileDialog.cpp @@ -784,6 +784,14 @@ void EditProfileDialog::setupAppearancePage(const Profile::Ptr &profile) _appearanceUi->dimLabel->setEnabled(profile->dimWhenInactive()); connect(_appearanceUi->dimValue, &QSlider::valueChanged, this, &Konsole::EditProfileDialog::setDimValue); + + _appearanceUi->displayVerticalLine->setChecked(profile->verticalLine()); + connect(_appearanceUi->displayVerticalLine, &QCheckBox::toggled, + this, &EditProfileDialog::setVerticalLine); + + _appearanceUi->displayVerticalLineAtColumn->setValue(profile->verticalLineAtChar()); + connect(_appearanceUi->displayVerticalLineAtColumn, QOverload::of(&QSpinBox::valueChanged), + this, &EditProfileDialog::setVerticalLineColumn); } void EditProfileDialog::setAntialiasText(bool enable) @@ -804,6 +812,15 @@ void EditProfileDialog::linkEscapeSequenceTextsChanged() { updateTempProfileProperty(Profile::EscapedLinksSchema, _mouseUi->linkEscapeSequenceTexts->text()); } +void EditProfileDialog::setVerticalLine(bool value) +{ + updateTempProfileProperty(Profile::VerticalLine, value); +} + +void EditProfileDialog::setVerticalLineColumn(int value) +{ + updateTempProfileProperty(Profile::VerticalLineAtChar, value); +} void EditProfileDialog::setBoldIntense(bool enable) { diff --git a/src/widgets/EditProfileDialog.h b/src/widgets/EditProfileDialog.h index cb83fbeb..4b8ad02d 100644 --- a/src/widgets/EditProfileDialog.h +++ b/src/widgets/EditProfileDialog.h @@ -144,7 +144,8 @@ private Q_SLOTS: void saveColorScheme(const ColorScheme &scheme, bool isNewScheme); void removeColorScheme(); void gotNewColorSchemes(const KNS3::Entry::List &changedEntries); - + void setVerticalLine(bool); + void setVerticalLineColumn(int); void toggleBlinkingCursor(bool); void setCursorShape(int); void autoCursorColor(); diff --git a/src/widgets/TerminalDisplay.cpp b/src/widgets/TerminalDisplay.cpp index 82388f40..c6268b3f 100644 --- a/src/widgets/TerminalDisplay.cpp +++ b/src/widgets/TerminalDisplay.cpp @@ -1345,6 +1345,14 @@ void TerminalDisplay::paintEvent(QPaintEvent* pe) drawBackground(paint, rect, getBackgroundColor(), true /* use opacity setting */); } + if (_displayVerticalLine) { + const int x = (_fontWidth/2) + (_fontWidth * _displayVerticalLineAtChar); + const QColor lineColor = getForegroundColor(); + + paint.setPen(lineColor); + paint.drawLine(QPoint(x, 0), QPoint(x, height())); + } + // only turn on text anti-aliasing, never turn on normal antialiasing // set https://bugreports.qt.io/browse/QTBUG-66036 paint.setRenderHint(QPainter::TextAntialiasing, _antialiasText); @@ -4147,6 +4155,9 @@ void TerminalDisplay::applyProfile(const Profile::Ptr &profile) // mouse wheel zoom _mouseWheelZoom = profile->mouseWheelZoomEnabled(); + + _displayVerticalLine = profile->verticalLine(); + _displayVerticalLineAtChar = profile->verticalLineAtChar(); setAlternateScrolling(profile->property(Profile::AlternateScrolling)); _dimValue = profile->dimValue(); } diff --git a/src/widgets/TerminalDisplay.h b/src/widgets/TerminalDisplay.h index 22aabfde..6017eb17 100644 --- a/src/widgets/TerminalDisplay.h +++ b/src/widgets/TerminalDisplay.h @@ -915,6 +915,8 @@ private: static const int HIGHLIGHT_SCROLLED_LINES_WIDTH = 3; bool _hasCompositeFocus; + bool _displayVerticalLine; + int _displayVerticalLineAtChar; QSharedPointer _currentlyHoveredHotspot; }; -- GitLab