Allow for showing line numbers

As with semantic hints, the line numbers may be displayed always, never
or when URL hints are shown.
wilder
Matan Ziv-Av 4 years ago committed by Tomaz Canabrava
parent 274ebb9887
commit 24cc94d5fb
  1. 22
      src/ViewManager.cpp
  2. 2
      src/ViewManager.h
  3. 1
      src/profile/Profile.cpp
  4. 9
      src/profile/Profile.h
  5. 11
      src/terminalDisplay/TerminalPainter.cpp

@ -294,6 +294,12 @@ void ViewManager::setupActions()
connect(action, &QAction::triggered, this, &ViewManager::toggleSemanticHints);
_viewContainer->addAction(action);
action = new QAction(i18nc("@action Shortcut entry", "Toggle line numbers display"), this);
collection->addAction(QStringLiteral("toggle-line-numbers"), action);
collection->setDefaultShortcut(action, Qt::CTRL | Qt::ALT | Qt::Key_Backslash);
connect(action, &QAction::triggered, this, &ViewManager::toggleLineNumbers);
_viewContainer->addAction(action);
action = new QAction(this);
action->setText(i18nc("@action:inmenu", "Equal size to all views"));
collection->setDefaultShortcut(action, Konsole::ACCEL | Qt::SHIFT | Qt::Key_Backslash);
@ -522,6 +528,22 @@ void ViewManager::toggleSemanticHints()
activeTerminalDisplay->update();
}
void ViewManager::toggleLineNumbers()
{
int currentSessionId = currentSession();
Q_ASSERT(currentSessionId >= 0);
Session *activeSession = SessionManager::instance()->idToSession(currentSessionId);
Q_ASSERT(activeSession);
auto profile = SessionManager::instance()->sessionProfile(activeSession);
profile->setProperty(Profile::LineNumbers, (profile->lineNumbers() + 1) % 3);
auto activeTerminalDisplay = _viewContainer->activeViewSplitter()->activeTerminalDisplay();
const char *names[3] = {"Never", "Sometimes", "Always"};
activeTerminalDisplay->showNotification(i18n("Line numbers ") + i18n(names[profile->lineNumbers()]));
activeTerminalDisplay->update();
}
QHash<TerminalDisplay *, Session *> ViewManager::forgetAll(ViewSplitter *splitter)
{
splitter->setParent(nullptr);

@ -404,6 +404,8 @@ private Q_SLOTS:
void toggleSemanticHints();
void toggleLineNumbers();
private:
Q_DISABLE_COPY(ViewManager)

@ -120,6 +120,7 @@ const std::vector<Profile::PropertyInfo> Profile::DefaultProperties = {
{VerticalLine, "VerticalLine", TERMINAL_GROUP, false},
{VerticalLineAtChar, "VerticalLineAtChar", TERMINAL_GROUP, 80},
{PeekPrimaryKeySequence, "PeekPrimaryKeySequence", TERMINAL_GROUP, QString()},
{LineNumbers, "LineNumbers", TERMINAL_GROUP, 0},
// Cursor
{UseCustomCursorColor, "UseCustomCursorColor", CURSOR_GROUP, false},

@ -374,6 +374,10 @@ public:
/** (QFont) Emoji font override
*/
EmojiFont,
/** When to show line numbers.
* 0 for Never, 1 when showing URL hints, 2 for always
*/
LineNumbers,
};
Q_ENUM(Property)
@ -805,6 +809,11 @@ public:
return property<int>(Profile::SemanticHints);
}
int lineNumbers() const
{
return property<int>(Profile::LineNumbers);
}
bool semanticUpDown() const
{
return property<bool>(Profile::SemanticUpDown);

@ -78,6 +78,7 @@ void TerminalPainter::drawContents(Character *image,
auto currentProfile = SessionManager::instance()->sessionProfile(m_parentDisplay->session());
const bool invertedRendition = currentProfile ? currentProfile->property<bool>(Profile::InvertSelectionColors) : false;
const Enum::Hints semanticHints = currentProfile ? static_cast<Enum::Hints>(currentProfile->semanticHints()) : Enum::HintsNever;
const Enum::Hints lineNumbers = currentProfile ? static_cast<Enum::Hints>(currentProfile->lineNumbers()) : Enum::HintsNever;
QVector<uint> univec;
univec.reserve(m_parentDisplay->usedColumns());
@ -250,6 +251,16 @@ void TerminalPainter::drawContents(Character *image,
paint.setPen(pen);
paint.drawLine(leftPadding, textY, m_parentDisplay->contentRect().right(), textY);
}
if ((lineNumbers == Enum::HintsURL && m_parentDisplay->filterChain()->showUrlHint()) || lineNumbers == Enum::HintsAlways) {
QRect rect(m_parentDisplay->contentRect().right() - 4 * fontWidth, textY, m_parentDisplay->contentRect().right(), textY + fontHeight);
QPen pen(QColor(0xC00000));
paint.setPen(pen);
QFont currentFont = paint.font();
currentFont.setWeight(normalWeight);
currentFont.setItalic(false);
paint.setFont(currentFont);
paint.drawText(rect, Qt::AlignLeft, QString::number(y + m_parentDisplay->screenWindow()->currentLine()));
}
if (doubleHeightLinePair) {
y++;

Loading…
Cancel
Save