Commit b2b044cf authored by Martin Tobias Holmedahl Sandsmark's avatar Martin Tobias Holmedahl Sandsmark
Browse files

Make the config of file filters and url filters separate

REVIEW: 128828
BUG: 368234
parent f173cb4e
......@@ -857,6 +857,7 @@ void EditProfileDialog::removeKeyBinding()
_ui->keyBindingList->model()->removeRow(selected.first().row());
}
}
void EditProfileDialog::showKeyBindingEditor(bool isNewTranslator)
{
QModelIndexList selected = _ui->keyBindingList->selectionModel()->selectedIndexes();
......@@ -1011,10 +1012,15 @@ void EditProfileDialog::scrollHalfPage()
}
void EditProfileDialog::setupMousePage(const Profile::Ptr profile)
{
BooleanOption options[] = { {
BooleanOption options[] = {
{
_ui->underlineLinksButton , Profile::UnderlineLinksEnabled,
SLOT(toggleUnderlineLinks(bool))
},
{
_ui->underlineFilesButton , Profile::UnderlineFilesEnabled,
SLOT(toggleUnderlineFiles(bool))
},
{
_ui->ctrlRequiredForDragButton, Profile::CtrlRequiredForDrag,
SLOT(toggleCtrlRequiredForDrag(bool))
......@@ -1058,7 +1064,7 @@ void EditProfileDialog::setupMousePage(const Profile::Ptr profile)
connect(_ui->tripleClickModeCombo, static_cast<void(KComboBox::*)(int)>(&KComboBox::activated), this, &Konsole::EditProfileDialog::TripleClickModeChanged);
_ui->openLinksByDirectClickButton->setEnabled(_ui->underlineLinksButton->isChecked());
_ui->openLinksByDirectClickButton->setEnabled(_ui->underlineLinksButton->isChecked() || _ui->underlineFilesButton->isChecked());
_ui->enableMouseWheelZoomButton->setChecked(profile->mouseWheelZoomEnabled());
connect(_ui->enableMouseWheelZoomButton, &QCheckBox::toggled, this, &Konsole::EditProfileDialog::toggleMouseWheelZoom);
......@@ -1173,7 +1179,16 @@ void EditProfileDialog::toggleBlinkingCursor(bool enable)
void EditProfileDialog::toggleUnderlineLinks(bool enable)
{
updateTempProfileProperty(Profile::UnderlineLinksEnabled, enable);
_ui->openLinksByDirectClickButton->setEnabled(enable);
bool enableClick = _ui->underlineFilesButton->isChecked() || enable;
_ui->openLinksByDirectClickButton->setEnabled(enableClick);
}
void EditProfileDialog::toggleUnderlineFiles(bool enable)
{
updateTempProfileProperty(Profile::UnderlineFilesEnabled, enable);
bool enableClick = _ui->underlineLinksButton->isChecked() || enable;
_ui->openLinksByDirectClickButton->setEnabled(enableClick);
}
void EditProfileDialog::toggleCtrlRequiredForDrag(bool enable)
{
......
......@@ -156,6 +156,7 @@ private slots:
void removeKeyBinding();
// mouse page
void toggleUnderlineFiles(bool enable);
void toggleUnderlineLinks(bool);
void toggleOpenLinksByDirectClick(bool);
void toggleCtrlRequiredForDrag(bool);
......
......@@ -984,10 +984,20 @@
<item>
<widget class="QCheckBox" name="underlineLinksButton">
<property name="toolTip">
<string>Text recognized as a file, link or an email address will be underlined when hovered by the mouse pointer.</string>
<string>Text recognized as a link or an email address will be underlined when hovered by the mouse pointer.</string>
</property>
<property name="text">
<string>Underline files and links</string>
<string>Underline links</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="underlineFilesButton">
<property name="toolTip">
<string>Text recognized as a file will be underlined when hovered by the mouse pointer.</string>
</property>
<property name="text">
<string>Underline files</string>
</property>
</widget>
</item>
......
......@@ -109,6 +109,7 @@ const Profile::PropertyInfo Profile::DefaultPropertyNames[] = {
, { WordCharacters , "WordCharacters" , INTERACTION_GROUP , QVariant::String }
, { TripleClickMode , "TripleClickMode" , INTERACTION_GROUP , QVariant::Int }
, { UnderlineLinksEnabled , "UnderlineLinksEnabled" , INTERACTION_GROUP , QVariant::Bool }
, { UnderlineFilesEnabled , "UnderlineFilesEnabled" , INTERACTION_GROUP , QVariant::Bool }
, { OpenLinksByDirectClickEnabled , "OpenLinksByDirectClickEnabled" , INTERACTION_GROUP , QVariant::Bool }
, { CtrlRequiredForDrag, "CtrlRequiredForDrag" , INTERACTION_GROUP , QVariant::Bool }
, { DropUrlsAsText , "DropUrlsAsText" , INTERACTION_GROUP , QVariant::Bool }
......@@ -182,7 +183,8 @@ FallbackProfile::FallbackProfile()
setProperty(FlowControlEnabled, true);
setProperty(UrlHintsModifiers, 0);
setProperty(BlinkingTextEnabled, true);
setProperty(UnderlineLinksEnabled, false);
setProperty(UnderlineLinksEnabled, true);
setProperty(UnderlineFilesEnabled, false);
setProperty(OpenLinksByDirectClickEnabled, false);
setProperty(CtrlRequiredForDrag, true);
setProperty(AutoCopySelectedText, false);
......
......@@ -196,6 +196,10 @@ public:
* underlined when hovered by the mouse pointer.
*/
UnderlineLinksEnabled,
/** (bool) If true, text that matches a file is
* underlined when hovered by the mouse pointer.
*/
UnderlineFilesEnabled,
/** (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. */
......@@ -465,6 +469,11 @@ public:
return property<bool>(Profile::UnderlineLinksEnabled);
}
/** Convenience method for property<bool>(Profile::UnderlineFilesEnabled) */
bool underlineFilesEnabled() const {
return property<bool>(Profile::UnderlineFilesEnabled);
}
bool autoCopySelectedText() const {
return property<bool>(Profile::AutoCopySelectedText);
}
......
......@@ -20,6 +20,7 @@
// Own
#include "SessionController.h"
#include "ProfileManager.h"
// Qt
#include <QApplication>
......@@ -99,6 +100,8 @@ SessionController::SessionController(Session* session , TerminalDisplay* view, Q
, _profileList(0)
, _previousState(-1)
, _searchFilter(0)
, _urlFilter(0)
, _fileFilter(0)
, _copyInputToAllTabsAction(0)
, _findAction(0)
, _findNextAction(0)
......@@ -140,11 +143,11 @@ SessionController::SessionController(Session* session , TerminalDisplay* view, Q
view->installEventFilter(this);
view->setSessionController(this);
// install filter on the view to highlight URLs
_view->filterChain()->addFilter(new UrlFilter);
// install filter on the view to highlight URLs and files
updateFilterList(SessionManager::instance()->sessionProfile(_session));
// install filter on the view to highlight Files
_view->filterChain()->addFilter(new FileFilter(_session));
// listen for changes in session, we might need to change the enabled filters
connect(ProfileManager::instance(), &Konsole::ProfileManager::profileChanged, this, &Konsole::SessionController::updateFilterList);
// listen for session resize requests
connect(_session.data(), &Konsole::Session::resizeRequest, this, &Konsole::SessionController::sessionResizeRequest);
......@@ -740,6 +743,7 @@ void SessionController::setupExtraActions()
void SessionController::switchProfile(Profile::Ptr profile)
{
SessionManager::instance()->setSessionProfile(_session, profile);
updateFilterList(profile);
}
void SessionController::prepareSwitchProfileMenu()
......@@ -1064,6 +1068,34 @@ void SessionController::searchClosed()
searchHistory(false);
}
void SessionController::updateFilterList(Profile::Ptr profile)
{
if (profile != SessionManager::instance()->sessionProfile(_session)) {
return;
}
bool underlineFiles = profile->underlineFilesEnabled();
if (!underlineFiles && _fileFilter) {
_view->filterChain()->removeFilter(_fileFilter);
delete _fileFilter;
_fileFilter = nullptr;
} else if (underlineFiles && !_fileFilter) {
_fileFilter = new FileFilter(_session);
_view->filterChain()->addFilter(_fileFilter);
}
bool underlineLinks = profile->underlineLinksEnabled();
if (!underlineLinks && _urlFilter) {
_view->filterChain()->removeFilter(_urlFilter);
delete _urlFilter;
_urlFilter = nullptr;
} else if (underlineLinks && !_urlFilter) {
_urlFilter = new UrlFilter();
_view->filterChain()->addFilter(_urlFilter);
}
}
void SessionController::setSearchStartToWindowCurrentLine()
{
setSearchStartTo(-1);
......
......@@ -61,6 +61,8 @@ class TerminalDisplay;
class IncrementalSearchBar;
class ProfileList;
class RegExpFilter;
class UrlFilter;
class FileFilter;
class EditProfileDialog;
// SaveHistoryTask
......@@ -265,6 +267,8 @@ private slots:
void searchClosed(); // called when the user clicks on the
// history search bar's close button
void updateFilterList(Profile::Ptr profile); // Called when the profile has changed, so we might need to change the list of filters
void interactionHandler();
void snapshot(); // called periodically as the user types
// to take a snapshot of the state of the
......@@ -317,6 +321,8 @@ private:
int _previousState;
RegExpFilter* _searchFilter;
UrlFilter* _urlFilter;
FileFilter* _fileFilter;
QAction* _copyInputToAllTabsAction;
......
......@@ -360,7 +360,6 @@ TerminalDisplay::TerminalDisplay(QWidget* parent)
, _hasTextBlinker(false)
, _urlHintsModifiers(Qt::NoModifier)
, _showUrlHint(false)
, _underlineLinks(true)
, _openLinksByDirectClick(false)
, _ctrlRequiredForDrag(true)
, _tripleClickMode(Enum::SelectWholeLine)
......@@ -1364,7 +1363,7 @@ void TerminalDisplay::paintFilters(QPainter& painter)
urlNumber++;
QRegion region;
if (_underlineLinks && spot->type() == Filter::HotSpot::Link) {
if (spot->type() == Filter::HotSpot::Link) {
QRect r;
if (spot->startLine() == spot->endLine()) {
r.setCoords(spot->startColumn()*_fontWidth + _contentRect.left(),
......@@ -1442,7 +1441,7 @@ void TerminalDisplay::paintFilters(QPainter& painter)
endColumn * _fontWidth + _contentRect.left() - 1,
(line + 1)*_fontHeight + _contentRect.top() - 1);
// Underline link hotspots
if (_underlineLinks && spot->type() == Filter::HotSpot::Link) {
if (spot->type() == Filter::HotSpot::Link) {
QFontMetrics metrics(font());
// find the baseline (which is the invisible line that the characters in the font sit on,
......@@ -2041,7 +2040,7 @@ void TerminalDisplay::mousePressEvent(QMouseEvent* ev)
emit mouseSignal(0, charColumn + 1, charLine + 1 + _scrollBar->value() - _scrollBar->maximum() , 0);
}
if (_underlineLinks && (_openLinksByDirectClick || (ev->modifiers() & Qt::ControlModifier))) {
if ((_openLinksByDirectClick || (ev->modifiers() & Qt::ControlModifier))) {
Filter::HotSpot* spot = _filterChain->hotSpotAt(charLine, charColumn);
if (spot && spot->type() == Filter::HotSpot::Link) {
QObject action;
......@@ -2081,43 +2080,41 @@ void TerminalDisplay::mouseMoveEvent(QMouseEvent* ev)
// change link hot-spot appearance on mouse-over
Filter::HotSpot* spot = _filterChain->hotSpotAt(charLine, charColumn);
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 + _contentRect.left(),
spot->startLine()*_fontHeight + _contentRect.top(),
(spot->endColumn())*_fontWidth + _contentRect.left() - 1,
(spot->endLine() + 1)*_fontHeight + _contentRect.top() - 1);
_mouseOverHotspotArea |= r;
} else {
r.setCoords(spot->startColumn()*_fontWidth + _contentRect.left(),
spot->startLine()*_fontHeight + _contentRect.top(),
(_columns)*_fontWidth + _contentRect.left() - 1,
(spot->startLine() + 1)*_fontHeight + _contentRect.top() - 1);
_mouseOverHotspotArea |= r;
for (int line = spot->startLine() + 1 ; line < spot->endLine() ; line++) {
r.setCoords(0 * _fontWidth + _contentRect.left(),
line * _fontHeight + _contentRect.top(),
(_columns)*_fontWidth + _contentRect.left() - 1,
(line + 1)*_fontHeight + _contentRect.top() - 1);
_mouseOverHotspotArea |= r;
}
QRegion previousHotspotArea = _mouseOverHotspotArea;
_mouseOverHotspotArea = QRegion();
QRect r;
if (spot->startLine() == spot->endLine()) {
r.setCoords(spot->startColumn()*_fontWidth + _contentRect.left(),
spot->startLine()*_fontHeight + _contentRect.top(),
(spot->endColumn())*_fontWidth + _contentRect.left() - 1,
(spot->endLine() + 1)*_fontHeight + _contentRect.top() - 1);
_mouseOverHotspotArea |= r;
} else {
r.setCoords(spot->startColumn()*_fontWidth + _contentRect.left(),
spot->startLine()*_fontHeight + _contentRect.top(),
(_columns)*_fontWidth + _contentRect.left() - 1,
(spot->startLine() + 1)*_fontHeight + _contentRect.top() - 1);
_mouseOverHotspotArea |= r;
for (int line = spot->startLine() + 1 ; line < spot->endLine() ; line++) {
r.setCoords(0 * _fontWidth + _contentRect.left(),
spot->endLine()*_fontHeight + _contentRect.top(),
(spot->endColumn())*_fontWidth + _contentRect.left() - 1,
(spot->endLine() + 1)*_fontHeight + _contentRect.top() - 1);
line * _fontHeight + _contentRect.top(),
(_columns)*_fontWidth + _contentRect.left() - 1,
(line + 1)*_fontHeight + _contentRect.top() - 1);
_mouseOverHotspotArea |= r;
}
r.setCoords(0 * _fontWidth + _contentRect.left(),
spot->endLine()*_fontHeight + _contentRect.top(),
(spot->endColumn())*_fontWidth + _contentRect.left() - 1,
(spot->endLine() + 1)*_fontHeight + _contentRect.top() - 1);
_mouseOverHotspotArea |= r;
}
if ((_openLinksByDirectClick || (ev->modifiers() & Qt::ControlModifier)) && (cursor().shape() != Qt::PointingHandCursor))
setCursor(Qt::PointingHandCursor);
if ((_openLinksByDirectClick || (ev->modifiers() & Qt::ControlModifier)) && (cursor().shape() != Qt::PointingHandCursor))
setCursor(Qt::PointingHandCursor);
update(_mouseOverHotspotArea | previousHotspotArea);
}
update(_mouseOverHotspotArea | previousHotspotArea);
} else if (!_mouseOverHotspotArea.isEmpty()) {
if ((_underlineLinks && (_openLinksByDirectClick || (ev->modifiers() & Qt::ControlModifier))) || (cursor().shape() == Qt::PointingHandCursor))
if ((_openLinksByDirectClick || (ev->modifiers() & Qt::ControlModifier)) || (cursor().shape() == Qt::PointingHandCursor))
setCursor(_mouseMarks ? Qt::IBeamCursor : Qt::ArrowCursor);
update(_mouseOverHotspotArea);
......
......@@ -179,21 +179,6 @@ public:
return _tripleClickMode;
}
/**
* Specifies whether links and email addresses should be underlined when
* hovered by the mouse. Defaults to true.
*/
void setUnderlineLinks(bool value) {
_underlineLinks = value;
}
/**
* Returns true if links and email addresses should be underlined when
* hovered by the mouse.
*/
bool getUnderlineLinks() const {
return _underlineLinks;
}
/**
* Specifies whether links and email addresses should be opened when
* clicked with the mouse. Defaults to false.
......@@ -883,7 +868,6 @@ private:
Qt::KeyboardModifiers _urlHintsModifiers;
bool _showUrlHint;
bool _underlineLinks; // Underline URL and hosts on mouse hover
bool _openLinksByDirectClick; // Open URL and hosts by single mouse click
bool _ctrlRequiredForDrag; // require Ctrl key for drag selected text
......
......@@ -804,7 +804,6 @@ void ViewManager::applyProfileToView(TerminalDisplay* view , const Profile::Ptr
view->setTripleClickMode(Enum::TripleClickModeEnum(tripleClickMode));
view->setAutoCopySelectedText(profile->autoCopySelectedText());
view->setUnderlineLinks(profile->underlineLinksEnabled());
view->setControlDrag(profile->property<bool>(Profile::CtrlRequiredForDrag));
view->setDropUrlsAsText(profile->property<bool>(Profile::DropUrlsAsText));
view->setBidiEnabled(profile->bidiRenderingEnabled());
......
Supports Markdown
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