Make the URL hint keyboard modifiers configurable

Instead of hardcoding CTRL which was a bit annoying add checkboxes to
the profile edit dialog to let the user select which keys to use.

REVIEW: 128778
parent 5b11fd59
......@@ -1065,10 +1065,6 @@ void EditProfileDialog::setupMousePage(const Profile::Ptr profile)
void EditProfileDialog::setupAdvancedPage(const Profile::Ptr profile)
{
BooleanOption options[] = {
{
_ui->enableUrlHints , Profile::EnableUrlHints ,
SLOT(toggleEnableUrlHints(bool))
},
{
_ui->enableBlinkingTextButton , Profile::BlinkingTextEnabled ,
SLOT(toggleBlinkingText(bool))
......@@ -1089,6 +1085,19 @@ void EditProfileDialog::setupAdvancedPage(const Profile::Ptr profile)
};
setupCheckBoxes(options , profile);
// Setup the URL hints modifier checkboxes
{
int modifiers = profile->property<int>(Profile::UrlHintsModifiers);
_ui->urlHintsModifierShift->setChecked(modifiers & Qt::ShiftModifier);
_ui->urlHintsModifierCtrl->setChecked(modifiers & Qt::ControlModifier);
_ui->urlHintsModifierAlt->setChecked(modifiers & Qt::AltModifier);
_ui->urlHintsModifierMeta->setChecked(modifiers & Qt::MetaModifier);
connect(_ui->urlHintsModifierShift, &QCheckBox::toggled, this, &EditProfileDialog::updateUrlHintsModifier);
connect(_ui->urlHintsModifierCtrl, &QCheckBox::toggled, this, &EditProfileDialog::updateUrlHintsModifier);
connect(_ui->urlHintsModifierAlt, &QCheckBox::toggled, this, &EditProfileDialog::updateUrlHintsModifier);
connect(_ui->urlHintsModifierMeta, &QCheckBox::toggled, this, &EditProfileDialog::updateUrlHintsModifier);
}
const int lineSpacing = profile->lineSpacing();
_ui->lineSpacingSpinner->setValue(lineSpacing);
......@@ -1197,9 +1206,14 @@ void EditProfileDialog::TripleClickModeChanged(int newValue)
{
updateTempProfileProperty(Profile::TripleClickMode, newValue);
}
void EditProfileDialog::toggleEnableUrlHints(bool enable)
void EditProfileDialog::updateUrlHintsModifier(bool)
{
updateTempProfileProperty(Profile::EnableUrlHints, enable);
Qt::KeyboardModifiers modifiers;
if (_ui->urlHintsModifierShift->isChecked()) modifiers |= Qt::ShiftModifier;
if (_ui->urlHintsModifierCtrl->isChecked()) modifiers |= Qt::ControlModifier;
if (_ui->urlHintsModifierAlt->isChecked()) modifiers |= Qt::AltModifier;
if (_ui->urlHintsModifierMeta->isChecked()) modifiers |= Qt::MetaModifier;
updateTempProfileProperty(Profile::UrlHintsModifiers, int(modifiers));
}
void EditProfileDialog::toggleBlinkingText(bool enable)
{
......
......@@ -174,7 +174,7 @@ private slots:
void togglebidiRendering(bool);
void lineSpacingChanged(int);
void toggleBlinkingCursor(bool);
void toggleEnableUrlHints(bool);
void updateUrlHintsModifier(bool);
void setCursorShape(int);
void autoCursorColor();
......
......@@ -1087,21 +1087,60 @@
</property>
<layout class="QVBoxLayout">
<item>
<widget class="QCheckBox" name="enableUrlHints">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Show URL hint overlays that can be triggered when holding down CTRL.</string>
</property>
<widget class="QLabel" name="urlHintsLabel">
<property name="text">
<string>Enable URL hints</string>
<string>Show URL hints when these keys are pressed:</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="urlHintsModifierSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="urlHintsModifierShift">
<property name="text">
<string>Shift</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="urlHintsModifierCtrl">
<property name="text">
<string>Control</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="urlHintsModifierAlt">
<property name="text">
<string>Alt</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="urlHintsModifierMeta">
<property name="text">
<string>Meta</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="enableBlinkingTextButton">
<property name="sizePolicy">
......
......@@ -91,7 +91,7 @@ const Profile::PropertyInfo Profile::DefaultPropertyNames[] = {
, { ScrollFullPage , "ScrollFullPage" , SCROLLING_GROUP , QVariant::Bool }
// Terminal Features
, { EnableUrlHints , "EnableUrlHints" , TERMINAL_GROUP , QVariant::Bool }
, { UrlHintsModifiers , "UrlHintsModifiers" , TERMINAL_GROUP , QVariant::Int }
, { BlinkingTextEnabled , "BlinkingTextEnabled" , TERMINAL_GROUP , QVariant::Bool }
, { FlowControlEnabled , "FlowControlEnabled" , TERMINAL_GROUP , QVariant::Bool }
, { BidiRenderingEnabled , "BidiRenderingEnabled" , TERMINAL_GROUP , QVariant::Bool }
......@@ -176,7 +176,7 @@ FallbackProfile::FallbackProfile()
setProperty(ScrollFullPage, false);
setProperty(FlowControlEnabled, true);
setProperty(EnableUrlHints, false);
setProperty(UrlHintsModifiers, 0);
setProperty(BlinkingTextEnabled, true);
setProperty(UnderlineLinksEnabled, true);
setProperty(OpenLinksByDirectClickEnabled, false);
......
......@@ -252,10 +252,8 @@ public:
* increases/decreases the terminal font size.
*/
MouseWheelZoomEnabled,
/** (bool) Enables showing a hint for all visible URLs
* which allows activating URLs with the keyboard.
*/
EnableUrlHints
/** (int) Keyboard modifiers to show URL hints */
UrlHintsModifiers
};
/**
......
......@@ -37,6 +37,9 @@ using namespace Konsole;
// FIXME: A dup line from Profile.cpp - redo these
static const char GENERAL_GROUP[] = "General";
static const char FEATURES_GROUP[] = "Terminal Features";
static const char URLHINTS_KEY[] = "EnableUrlHints";
static const char URLHINTSMODIFIERS_KEY[] = "UrlHintsModifiers";
QStringList KDE4ProfileReader::findProfiles()
{
......@@ -94,6 +97,19 @@ bool KDE4ProfileReader::readProfile(const QString& path , Profile::Ptr profile ,
profile->setProperty(Profile::Arguments, shellCommand.arguments());
}
// Check if the user earlier had set the URL hints option, and in that case set the default
// URL hints modifier to the earlier default.
if (config.hasGroup(FEATURES_GROUP)) {
KConfigGroup features = config.group(FEATURES_GROUP);
if (features.hasKey(URLHINTS_KEY)) {
bool enable = features.readEntry(URLHINTS_KEY, false);
if (enable && !features.hasKey(URLHINTSMODIFIERS_KEY)) {
features.writeEntry(URLHINTSMODIFIERS_KEY, int(Qt::ControlModifier));
}
features.deleteEntry(URLHINTS_KEY);
}
}
profile->setProperty(Profile::UntranslatedName, general.readEntryUntranslated("Name"));
// Read remaining properties
......
......@@ -358,8 +358,8 @@ TerminalDisplay::TerminalDisplay(QWidget* parent)
, _textBlinking(false)
, _cursorBlinking(false)
, _hasTextBlinker(false)
, _urlHintsModifiers(Qt::NoModifier)
, _showUrlHint(false)
, _enableShowUrlHint(false)
, _underlineLinks(true)
, _openLinksByDirectClick(false)
, _ctrlRequiredForDrag(true)
......@@ -3115,7 +3115,7 @@ void TerminalDisplay::scrollScreenWindow(enum ScreenWindow::RelativeScrollMode m
void TerminalDisplay::keyPressEvent(QKeyEvent* event)
{
if (_enableShowUrlHint && event->modifiers() & Qt::ControlModifier) {
if (event->modifiers() == _urlHintsModifiers) {
int hintSelected = event->key() - 0x31;
if (hintSelected >= 0 && hintSelected < 10 && hintSelected < _filterChain->hotSpots().count()) {
_filterChain->hotSpots().at(hintSelected)->activate();
......
......@@ -461,17 +461,11 @@ public:
}
/**
* Enables or disables showing hints on URLs when ctrl is pressed
* Sets the modifiers that shows URL hints when they are pressed
* Defaults to disabled.
*/
void setEnableUrlHints(bool on) {
_enableShowUrlHint = on;
}
/**
* Returns the status of the BiDi rendering in this widget.
*/
bool areUrlHintsEnabled() const {
return _enableShowUrlHint;
void setUrlHintsModifiers(int modifiers) {
_urlHintsModifiers = Qt::KeyboardModifiers(modifiers);
}
/**
......@@ -887,8 +881,8 @@ private:
QTimer* _blinkTextTimer;
QTimer* _blinkCursorTimer;
Qt::KeyboardModifiers _urlHintsModifiers;
bool _showUrlHint;
bool _enableShowUrlHint;
bool _underlineLinks; // Underline URL and hosts on mouse hover
bool _openLinksByDirectClick; // Open URL and hosts by single mouse click
......
......@@ -813,7 +813,7 @@ void ViewManager::applyProfileToView(TerminalDisplay* view , const Profile::Ptr
view->setOpenLinksByDirectClick(profile->property<bool>(Profile::OpenLinksByDirectClickEnabled));
view->setEnableUrlHints(profile->property<bool>(Profile::EnableUrlHints));
view->setUrlHintsModifiers(profile->property<int>(Profile::UrlHintsModifiers));
int middleClickPasteMode = profile->property<int>(Profile::MiddleClickPasteMode);
if (middleClickPasteMode == Enum::PasteFromX11Selection)
......
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