Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 248f2c3c authored by Jekyll Wu's avatar Jekyll Wu

Add profile option for opening URL by direct click(off by default)

Thanks to Asko Eronen<asko.eronen@gmail.com> for the idea and patch

REVIEW: 105282
FEATURE:
DIGEST:
parent 5ae5bc50
......@@ -993,6 +993,10 @@ void EditProfileDialog::setupMousePage(const Profile::Ptr profile)
_ui->copyTextToClipboardButton , Profile::AutoCopySelectedText,
SLOT(toggleCopyTextToClipboard(bool))
},
{
_ui->openLinksByDirectClickButton , Profile::OpenLinksByDirectClickEnabled,
SLOT(toggleOpenLinksByDirectClick(bool))
},
{ 0 , Profile::Property(0) , 0 }
};
setupCheckBoxes(options , profile);
......@@ -1017,6 +1021,8 @@ void EditProfileDialog::setupMousePage(const Profile::Ptr profile)
connect(_ui->tripleClickModeCombo, SIGNAL(activated(int)), this,
SLOT(TripleClickModeChanged(int)));
_ui->openLinksByDirectClickButton->setEnabled(_ui->underlineLinksButton->isChecked());
}
void EditProfileDialog::setupAdvancedPage(const Profile::Ptr profile)
{
......@@ -1116,11 +1122,16 @@ void EditProfileDialog::toggleBlinkingCursor(bool enable)
void EditProfileDialog::toggleUnderlineLinks(bool enable)
{
updateTempProfileProperty(Profile::UnderlineLinksEnabled, enable);
_ui->openLinksByDirectClickButton->setEnabled(enable);
}
void EditProfileDialog::toggleCtrlRequiredForDrag(bool enable)
{
updateTempProfileProperty(Profile::CtrlRequiredForDrag, enable);
}
void EditProfileDialog::toggleOpenLinksByDirectClick(bool enable)
{
updateTempProfileProperty(Profile::OpenLinksByDirectClickEnabled, enable);
}
void EditProfileDialog::toggleCopyTextToClipboard(bool enable)
{
updateTempProfileProperty(Profile::AutoCopySelectedText, enable);
......
......@@ -150,6 +150,7 @@ private slots:
// mouse page
void toggleUnderlineLinks(bool);
void toggleOpenLinksByDirectClick(bool);
void toggleCtrlRequiredForDrag(bool);
void toggleCopyTextToClipboard(bool);
void pasteFromX11Selection();
......
......@@ -838,6 +838,39 @@
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="openLinksByDirectClickButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Text recognized as a link or an email address can be opened by direct mouse click.</string>
</property>
<property name="text">
<string>Open links by direct click</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="ctrlRequiredForDragButton">
<property name="toolTip">
......
......@@ -104,6 +104,7 @@ const Profile::PropertyInfo Profile::DefaultPropertyNames[] = {
, { WordCharacters , "WordCharacters" , INTERACTION_GROUP , QVariant::String }
, { TripleClickMode , "TripleClickMode" , INTERACTION_GROUP , QVariant::Int }
, { UnderlineLinksEnabled , "UnderlineLinksEnabled" , INTERACTION_GROUP , QVariant::Bool }
, { OpenLinksByDirectClickEnabled , "OpenLinksByDirectClickEnabled" , INTERACTION_GROUP , QVariant::Bool }
, { CtrlRequiredForDrag, "CtrlRequiredForDrag" , INTERACTION_GROUP , QVariant::Bool }
, { AutoCopySelectedText , "AutoCopySelectedText" , INTERACTION_GROUP , QVariant::Bool }
, { PasteFromSelectionEnabled , "PasteFromSelectionEnabled" , INTERACTION_GROUP , QVariant::Bool }
......@@ -169,6 +170,7 @@ FallbackProfile::FallbackProfile()
setProperty(FlowControlEnabled, true);
setProperty(BlinkingTextEnabled, true);
setProperty(UnderlineLinksEnabled, true);
setProperty(OpenLinksByDirectClickEnabled, false);
setProperty(CtrlRequiredForDrag, true);
setProperty(AutoCopySelectedText, false);
setProperty(PasteFromSelectionEnabled, true);
......
......@@ -199,6 +199,8 @@ public:
* underlined when hovered by the mouse pointer.
*/
UnderlineLinksEnabled,
/** (bool) If true, links can be opened by direct mouse click.*/
OpenLinksByDirectClickEnabled,
/** (bool) If true, control key must be pressed to click and drag selected text. */
CtrlRequiredForDrag,
/** (bool) If true, automatically copy selected text into the clipboard */
......
......@@ -313,6 +313,7 @@ TerminalDisplay::TerminalDisplay(QWidget* parent)
, _cursorBlinking(false)
, _hasTextBlinker(false)
, _underlineLinks(true)
, _openLinksByDirectClick(false)
, _isFixedSize(false)
, _ctrlRequiredForDrag(true)
, _tripleClickMode(Enum::SelectWholeLine)
......@@ -1800,6 +1801,15 @@ void TerminalDisplay::mousePressEvent(QMouseEvent* ev)
} else {
emit mouseSignal(0, charColumn + 1, charLine + 1 + _scrollBar->value() - _scrollBar->maximum() , 0);
}
if (_underlineLinks && _openLinksByDirectClick) {
Filter::HotSpot* spot = _filterChain->hotSpotAt(charLine,charColumn);
if (spot && spot->type() == Filter::HotSpot::Link) {
QObject action;
action.setObjectName("open-action");
spot->activate(&action);
}
}
}
} else if (ev->button() == Qt::MidButton) {
processMidButtonClick(ev);
......@@ -1832,38 +1842,46 @@ void TerminalDisplay::mouseMoveEvent(QMouseEvent* ev)
// handle filters
// change link hot-spot appearance on mouse-over
Filter::HotSpot* spot = _filterChain->hotSpotAt(charLine, charColumn);
if (_underlineLinks && spot && spot->type() == Filter::HotSpot::Link) {
QRegion previousHotspotArea = _mouseOverHotspotArea;
_mouseOverHotspotArea = QRegion();
QRect r;
if (spot->startLine() == spot->endLine()) {
r.setCoords(spot->startColumn()*_fontWidth + scrollBarWidth,
spot->startLine()*_fontHeight,
spot->endColumn()*_fontWidth + scrollBarWidth,
(spot->endLine() + 1)*_fontHeight - 1);
_mouseOverHotspotArea |= r;
} else {
r.setCoords(spot->startColumn()*_fontWidth + scrollBarWidth,
spot->startLine()*_fontHeight,
_columns * _fontWidth - 1 + scrollBarWidth,
(spot->startLine() + 1)*_fontHeight);
_mouseOverHotspotArea |= r;
for (int line = spot->startLine() + 1 ; line < spot->endLine() ; line++) {
if (spot && spot->type() == Filter::HotSpot::Link) {
if (_underlineLinks) {
QRegion previousHotspotArea = _mouseOverHotspotArea;
_mouseOverHotspotArea = QRegion();
QRect r;
if (spot->startLine() == spot->endLine()) {
r.setCoords(spot->startColumn()*_fontWidth + scrollBarWidth,
spot->startLine()*_fontHeight,
spot->endColumn()*_fontWidth + scrollBarWidth,
(spot->endLine() + 1)*_fontHeight - 1);
_mouseOverHotspotArea |= r;
} else {
r.setCoords(spot->startColumn()*_fontWidth + scrollBarWidth,
spot->startLine()*_fontHeight,
_columns * _fontWidth - 1 + scrollBarWidth,
(spot->startLine() + 1)*_fontHeight);
_mouseOverHotspotArea |= r;
for (int line = spot->startLine() + 1 ; line < spot->endLine() ; line++) {
r.setCoords(0 * _fontWidth + scrollBarWidth,
line * _fontHeight,
_columns * _fontWidth + scrollBarWidth,
(line + 1)*_fontHeight);
_mouseOverHotspotArea |= r;
}
r.setCoords(0 * _fontWidth + scrollBarWidth,
line * _fontHeight,
_columns * _fontWidth + scrollBarWidth,
(line + 1)*_fontHeight);
spot->endLine()*_fontHeight,
spot->endColumn()*_fontWidth + scrollBarWidth,
(spot->endLine() + 1)*_fontHeight);
_mouseOverHotspotArea |= r;
}
r.setCoords(0 * _fontWidth + scrollBarWidth,
spot->endLine()*_fontHeight,
spot->endColumn()*_fontWidth + scrollBarWidth,
(spot->endLine() + 1)*_fontHeight);
_mouseOverHotspotArea |= r;
}
update(_mouseOverHotspotArea | previousHotspotArea);
if (_openLinksByDirectClick && (cursor().shape() != Qt::PointingHandCursor))
setCursor(Qt::PointingHandCursor);
update(_mouseOverHotspotArea | previousHotspotArea);
}
} else if (!_mouseOverHotspotArea.isEmpty()) {
if (_underlineLinks && _openLinksByDirectClick)
setCursor(_mouseMarks ? Qt::IBeamCursor : Qt::ArrowCursor);
update(_mouseOverHotspotArea);
// set hotspot area to an invalid rectangle
_mouseOverHotspotArea = QRegion();
......
......@@ -181,6 +181,18 @@ public:
return _underlineLinks;
}
/**
* Specifies whether links and email addresses should be opened when
* clicked with the mouse. Defaults to false.
*/
void setOpenLinksByDirectClick(bool value) { _openLinksByDirectClick = value; }
/**
* Returns true if links and email addresses should be opened when
* clicked with the mouse.
*/
bool getOpenLinksByDirectClick() const { return _openLinksByDirectClick; }
void setLineSpacing(uint);
uint lineSpacing() const;
......@@ -756,6 +768,7 @@ private:
QTimer* _blinkCursorTimer;
bool _underlineLinks; // Underline URL and hosts on mouse hover
bool _openLinksByDirectClick; // Open URL and hosts by single mouse click
bool _isFixedSize; // columns/lines are locked.
bool _ctrlRequiredForDrag; // require Ctrl key for drag selected text
......
......@@ -807,6 +807,8 @@ void ViewManager::applyProfileToView(TerminalDisplay* view , const Profile::Ptr
view->setBidiEnabled(profile->bidiRenderingEnabled());
view->setLineSpacing(profile->lineSpacing());
view->setOpenLinksByDirectClick(profile->property<bool>(Profile::OpenLinksByDirectClickEnabled));
int middleClickPasteMode = profile->property<int>(Profile::MiddleClickPasteMode);
if (middleClickPasteMode == Enum::PasteFromX11Selection)
view->setMiddleClickPasteMode(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