summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin T. H. Sandsmark <martin.sandsmark@kde.org>2016-09-04 12:12:02 (GMT)
committerMartin T. H. Sandsmark <martin.sandsmark@kde.org>2016-10-18 22:11:06 (GMT)
commitb2b044cf2ad3b7a400fd032650acfa37c4e440b9 (patch)
tree3c0e75601b00c3f4d2a9ad7f4095fa33b3bd1fca
parentf173cb4e103b37b507ede1fe607081831c3965db (diff)
Make the config of file filters and url filters separate
REVIEW: 128828 BUG: 368234
-rw-r--r--src/EditProfileDialog.cpp21
-rw-r--r--src/EditProfileDialog.h1
-rw-r--r--src/EditProfileDialog.ui14
-rw-r--r--src/Profile.cpp4
-rw-r--r--src/Profile.h9
-rw-r--r--src/SessionController.cpp40
-rw-r--r--src/SessionController.h6
-rw-r--r--src/TerminalDisplay.cpp67
-rw-r--r--src/TerminalDisplay.h16
-rw-r--r--src/ViewManager.cpp1
10 files changed, 117 insertions, 62 deletions
diff --git a/src/EditProfileDialog.cpp b/src/EditProfileDialog.cpp
index cfca11e..5fff767 100644
--- a/src/EditProfileDialog.cpp
+++ b/src/EditProfileDialog.cpp
@@ -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,11 +1012,16 @@ 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)
{
diff --git a/src/EditProfileDialog.h b/src/EditProfileDialog.h
index bb2896f..37713ff 100644
--- a/src/EditProfileDialog.h
+++ b/src/EditProfileDialog.h
@@ -156,6 +156,7 @@ private slots:
void removeKeyBinding();
// mouse page
+ void toggleUnderlineFiles(bool enable);
void toggleUnderlineLinks(bool);
void toggleOpenLinksByDirectClick(bool);
void toggleCtrlRequiredForDrag(bool);
diff --git a/src/EditProfileDialog.ui b/src/EditProfileDialog.ui
index 8358bd3..228704f 100644
--- a/src/EditProfileDialog.ui
+++ b/src/EditProfileDialog.ui
@@ -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>
diff --git a/src/Profile.cpp b/src/Profile.cpp
index a7866da..096c909 100644
--- a/src/Profile.cpp
+++ b/src/Profile.cpp
@@ -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);
diff --git a/src/Profile.h b/src/Profile.h
index 3e3aebf..db6c9fd 100644
--- a/src/Profile.h
+++ b/src/Profile.h
@@ -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);
}
diff --git a/src/SessionController.cpp b/src/SessionController.cpp
index 929a6d2..0e286e4 100644
--- a/src/SessionController.cpp
+++ b/src/SessionController.cpp
@@ -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);
diff --git a/src/SessionController.h b/src/SessionController.h
index 3ac06f5..30f07e4 100644
--- a/src/SessionController.h
+++ b/src/SessionController.h
@@ -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;
diff --git a/src/TerminalDisplay.cpp b/src/TerminalDisplay.cpp
index 39a8b84..3ef9ddb 100644
--- a/src/TerminalDisplay.cpp
+++ b/src/TerminalDisplay.cpp
@@ -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);
diff --git a/src/TerminalDisplay.h b/src/TerminalDisplay.h
index b3ffba7..aeee129 100644
--- a/src/TerminalDisplay.h
+++ b/src/TerminalDisplay.h
@@ -180,21 +180,6 @@ public:
}
/**
- * 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
diff --git a/src/ViewManager.cpp b/src/ViewManager.cpp
index 0f14ca0..81ccab1 100644
--- a/src/ViewManager.cpp
+++ b/src/ViewManager.cpp
@@ -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());