Add keyboard shortcut for toggling display of semantic hints

wilder
Matan Ziv-Av 4 years ago committed by Tomaz Canabrava
parent 660b78f70c
commit 274ebb9887
  1. 8
      src/Enumeration.h
  2. 22
      src/ViewManager.cpp
  3. 2
      src/ViewManager.h
  4. 1
      src/terminalDisplay/TerminalDisplay.cpp
  5. 6
      src/terminalDisplay/TerminalDisplay.h
  6. 13
      src/terminalDisplay/TerminalPainter.cpp
  7. 6
      src/widgets/EditProfileDialog.cpp

@ -61,10 +61,10 @@ public:
/** This enum describes semantic hints appearance /** This enum describes semantic hints appearance
*/ */
enum SemanticHints { enum Hints {
SemanticHintsNever = 0, HintsNever = 0,
SemanticHintsURL = 1, HintsURL = 1,
SemanticHintsAlways = 2, HintsAlways = 2,
}; };
/** This enum describes the shapes used to draw the cursor in terminal /** This enum describes the shapes used to draw the cursor in terminal

@ -288,6 +288,12 @@ void ViewManager::setupActions()
connect(action, &QAction::triggered, this, &ViewManager::semanticSetupBash); connect(action, &QAction::triggered, this, &ViewManager::semanticSetupBash);
_viewContainer->addAction(action); _viewContainer->addAction(action);
action = new QAction(i18nc("@action Shortcut entry", "Toggle semantic hints display"), this);
collection->addAction(QStringLiteral("toggle-semantic-hints"), action);
collection->setDefaultShortcut(action, Qt::CTRL | Qt::ALT | Qt::Key_BracketLeft);
connect(action, &QAction::triggered, this, &ViewManager::toggleSemanticHints);
_viewContainer->addAction(action);
action = new QAction(this); action = new QAction(this);
action->setText(i18nc("@action:inmenu", "Equal size to all views")); action->setText(i18nc("@action:inmenu", "Equal size to all views"));
collection->setDefaultShortcut(action, Konsole::ACCEL | Qt::SHIFT | Qt::Key_Backslash); collection->setDefaultShortcut(action, Konsole::ACCEL | Qt::SHIFT | Qt::Key_Backslash);
@ -500,6 +506,22 @@ void ViewManager::semanticSetupBash()
QChar()); QChar());
} }
void ViewManager::toggleSemanticHints()
{
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::SemanticHints, (profile->semanticHints() + 1) % 3);
auto activeTerminalDisplay = _viewContainer->activeViewSplitter()->activeTerminalDisplay();
const char *names[3] = {"Never", "Sometimes", "Always"};
activeTerminalDisplay->showNotification(i18n("Semantic hints ") + i18n(names[profile->semanticHints()]));
activeTerminalDisplay->update();
}
QHash<TerminalDisplay *, Session *> ViewManager::forgetAll(ViewSplitter *splitter) QHash<TerminalDisplay *, Session *> ViewManager::forgetAll(ViewSplitter *splitter)
{ {
splitter->setParent(nullptr); splitter->setParent(nullptr);

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

@ -2867,7 +2867,6 @@ void TerminalDisplay::applyProfile(const Profile::Ptr &profile)
_bidiLineLTR = profile->bidiLineLTR(); _bidiLineLTR = profile->bidiLineLTR();
_bidiTableDirOverride = profile->bidiTableDirOverride(); _bidiTableDirOverride = profile->bidiTableDirOverride();
_semanticUpDown = profile->semanticUpDown(); _semanticUpDown = profile->semanticUpDown();
_semanticHints = profile->semanticHints();
_semanticInputClick = profile->semanticInputClick(); _semanticInputClick = profile->semanticInputClick();
_trimLeadingSpaces = profile->property<bool>(Profile::TrimLeadingSpacesInSelectedText); _trimLeadingSpaces = profile->property<bool>(Profile::TrimLeadingSpacesInSelectedText);
_trimTrailingSpaces = profile->property<bool>(Profile::TrimTrailingSpacesInSelectedText); _trimTrailingSpaces = profile->property<bool>(Profile::TrimTrailingSpacesInSelectedText);

@ -340,11 +340,6 @@ public:
return _semanticUpDown; return _semanticUpDown;
} }
int semanticHints() const
{
return _semanticHints;
}
ColorSchemeWallpaper::Ptr wallpaper() const ColorSchemeWallpaper::Ptr wallpaper() const
{ {
return _wallpaper; return _wallpaper;
@ -790,7 +785,6 @@ private:
std::unique_ptr<KonsolePrintManager> _printManager; std::unique_ptr<KonsolePrintManager> _printManager;
int _semanticHints;
bool _semanticUpDown; bool _semanticUpDown;
bool _semanticInputClick; bool _semanticInputClick;
}; };

@ -66,12 +66,6 @@ static inline bool isLineCharString(const QString &string)
return LineBlockCharacters::isLegacyComputingSymbol(ucs4); return LineBlockCharacters::isLegacyComputingSymbol(ucs4);
} }
bool isInvertedRendition(const TerminalDisplay *display)
{
auto currentProfile = SessionManager::instance()->sessionProfile(display->session());
return currentProfile ? currentProfile->property<bool>(Profile::InvertSelectionColors) : false;
}
void TerminalPainter::drawContents(Character *image, void TerminalPainter::drawContents(Character *image,
QPainter &paint, QPainter &paint,
const QRect &rect, const QRect &rect,
@ -81,7 +75,9 @@ void TerminalPainter::drawContents(Character *image,
QVector<LineProperty> lineProperties, QVector<LineProperty> lineProperties,
CharacterColor const *ulColorTable) CharacterColor const *ulColorTable)
{ {
const bool invertedRendition = isInvertedRendition(m_parentDisplay); 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;
QVector<uint> univec; QVector<uint> univec;
univec.reserve(m_parentDisplay->usedColumns()); univec.reserve(m_parentDisplay->usedColumns());
@ -249,8 +245,7 @@ void TerminalPainter::drawContents(Character *image,
paint.setRenderHint(QPainter::Antialiasing, false); paint.setRenderHint(QPainter::Antialiasing, false);
paint.setWorldTransform(textScale.inverted(), true); paint.setWorldTransform(textScale.inverted(), true);
if ((lineProperty & LINE_PROMPT_START) if ((lineProperty & LINE_PROMPT_START)
&& ((m_parentDisplay->semanticHints() == Enum::SemanticHintsURL && m_parentDisplay->filterChain()->showUrlHint()) && ((semanticHints == Enum::HintsURL && m_parentDisplay->filterChain()->showUrlHint()) || semanticHints == Enum::HintsAlways)) {
|| m_parentDisplay->semanticHints() == Enum::SemanticHintsAlways)) {
QPen pen(m_parentDisplay->terminalColor()->foregroundColor()); QPen pen(m_parentDisplay->terminalColor()->foregroundColor());
paint.setPen(pen); paint.setPen(pen);
paint.drawLine(leftPadding, textY, m_parentDisplay->contentRect().right(), textY); paint.drawLine(leftPadding, textY, m_parentDisplay->contentRect().right(), textY);

@ -489,9 +489,9 @@ void EditProfileDialog::setupGeneralPage(const Profile::Ptr &profile)
false, // preview false, // preview
{ {
// buttons // buttons
{_generalUi->semanticHintsNever, Enum::SemanticHintsNever}, {_generalUi->semanticHintsNever, Enum::HintsNever},
{_generalUi->semanticHintsURL, Enum::SemanticHintsURL}, {_generalUi->semanticHintsURL, Enum::HintsURL},
{_generalUi->semanticHintsAlways, Enum::SemanticHintsAlways}, {_generalUi->semanticHintsAlways, Enum::HintsAlways},
}, },
}; };
setupButtonGroup(semanticHints, profile); setupButtonGroup(semanticHints, profile);

Loading…
Cancel
Save