Implement URL hints

Implements a feature from e. g. good old Konqueror/KHTML, where you got
a number overlaid all links when pressing ctrl, and then you could press
ctrl+number to activate that link.

REVIEW: 128348
parent bb6abc0b
......@@ -1041,7 +1041,12 @@ void EditProfileDialog::setupMousePage(const Profile::Ptr profile)
}
void EditProfileDialog::setupAdvancedPage(const Profile::Ptr profile)
{
BooleanOption options[] = { {
BooleanOption options[] = {
{
_ui->enableUrlHints , Profile::EnableUrlHints ,
SLOT(toggleEnableUrlHints(bool))
},
{
_ui->enableBlinkingTextButton , Profile::BlinkingTextEnabled ,
SLOT(toggleBlinkingText(bool))
},
......@@ -1169,6 +1174,10 @@ void EditProfileDialog::TripleClickModeChanged(int newValue)
{
updateTempProfileProperty(Profile::TripleClickMode, newValue);
}
void EditProfileDialog::toggleEnableUrlHints(bool enable)
{
updateTempProfileProperty(Profile::EnableUrlHints, enable);
}
void EditProfileDialog::toggleBlinkingText(bool enable)
{
updateTempProfileProperty(Profile::BlinkingTextEnabled, enable);
......
......@@ -172,6 +172,7 @@ private slots:
void togglebidiRendering(bool);
void lineSpacingChanged(int);
void toggleBlinkingCursor(bool);
void toggleEnableUrlHints(bool);
void setCursorShape(int);
void autoCursorColor();
......
......@@ -1066,6 +1066,22 @@
<bool>true</bool>
</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>
<property name="text">
<string>Enable URL hints</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="enableBlinkingTextButton">
<property name="sizePolicy">
......
......@@ -89,6 +89,7 @@ const Profile::PropertyInfo Profile::DefaultPropertyNames[] = {
, { ScrollFullPage , "ScrollFullPage" , SCROLLING_GROUP , QVariant::Bool }
// Terminal Features
, { EnableUrlHints , "EnableUrlHints" , TERMINAL_GROUP , QVariant::Bool }
, { BlinkingTextEnabled , "BlinkingTextEnabled" , TERMINAL_GROUP , QVariant::Bool }
, { FlowControlEnabled , "FlowControlEnabled" , TERMINAL_GROUP , QVariant::Bool }
, { BidiRenderingEnabled , "BidiRenderingEnabled" , TERMINAL_GROUP , QVariant::Bool }
......@@ -173,6 +174,7 @@ FallbackProfile::FallbackProfile()
setProperty(ScrollFullPage, false);
setProperty(FlowControlEnabled, true);
setProperty(EnableUrlHints, false);
setProperty(BlinkingTextEnabled, true);
setProperty(UnderlineLinksEnabled, true);
setProperty(OpenLinksByDirectClickEnabled, false);
......
......@@ -248,7 +248,11 @@ public:
/** (bool) If true, mouse wheel scroll with Ctrl key pressed
* increases/decreases the terminal font size.
*/
MouseWheelZoomEnabled
MouseWheelZoomEnabled,
/** (bool) Enables showing a hint for all visible URLs
* which allows activating URLs with the keyboard.
*/
EnableUrlHints
};
/**
......
......@@ -351,6 +351,8 @@ TerminalDisplay::TerminalDisplay(QWidget* parent)
, _textBlinking(false)
, _cursorBlinking(false)
, _hasTextBlinker(false)
, _showUrlHint(false)
, _enableShowUrlHint(false)
, _underlineLinks(true)
, _openLinksByDirectClick(false)
, _ctrlRequiredForDrag(true)
......@@ -1335,8 +1337,11 @@ void TerminalDisplay::paintFilters(QPainter& painter)
// iterate over hotspots identified by the display's currently active filters
// and draw appropriate visuals to indicate the presence of the hotspot
int urlNumber = 0;
QList<Filter::HotSpot*> spots = _filterChain->hotSpots();
foreach(Filter::HotSpot* spot, spots) {
urlNumber++;
QRegion region;
if (_underlineLinks && spot->type() == Filter::HotSpot::Link) {
QRect r;
......@@ -1365,6 +1370,16 @@ void TerminalDisplay::paintFilters(QPainter& painter)
(spot->endLine() + 1)*_fontHeight + _contentRect.top() - 1);
region |= r;
}
if (_showUrlHint) {
// Position at the beginning of the URL
QRect hintRect(region.rects().first());
hintRect.setWidth(r.height());
painter.fillRect(hintRect, QColor(0, 0, 0, 128));
painter.setPen(Qt::white);
painter.drawRect(hintRect.adjusted(0, 0, -1, -1));
painter.drawText(hintRect, Qt::AlignCenter, QString::number(urlNumber));
}
}
for (int line = spot->startLine() ; line <= spot->endLine() ; line++) {
......@@ -1418,6 +1433,7 @@ void TerminalDisplay::paintFilters(QPainter& painter)
painter.drawLine(r.left() , underlinePos ,
r.right() , underlinePos);
}
// Marker hotspots simply have a transparent rectangular shape
// drawn on top of them
} else if (spot->type() == Filter::HotSpot::Marker) {
......@@ -3062,6 +3078,22 @@ void TerminalDisplay::scrollScreenWindow(enum ScreenWindow::RelativeScrollMode m
void TerminalDisplay::keyPressEvent(QKeyEvent* event)
{
if (_enableShowUrlHint && event->modifiers() & Qt::ControlModifier) {
int hintSelected = event->key() - 0x31;
if (hintSelected >= 0 && hintSelected < _filterChain->hotSpots().count()) {
_filterChain->hotSpots().at(hintSelected)->activate();
_showUrlHint = false;
update();
return;
}
if (!_showUrlHint) {
processFilters();
_showUrlHint = true;
update();
}
}
_screenWindow->screen()->setCurrentTerminalDisplay(this);
_actSel = 0; // Key stroke implies a screen update, so TerminalDisplay won't
......@@ -3085,6 +3117,16 @@ void TerminalDisplay::keyPressEvent(QKeyEvent* event)
event->accept();
}
void TerminalDisplay::keyReleaseEvent(QKeyEvent *event)
{
if (_showUrlHint) {
_showUrlHint = false;
update();
}
QWidget::keyReleaseEvent(event);
}
bool TerminalDisplay::handleShortcutOverrideEvent(QKeyEvent* keyEvent)
{
const int modifiers = keyEvent->modifiers();
......
......@@ -445,6 +445,20 @@ public:
return _bidiEnabled;
}
/**
* Enables or disables showing hints on URLs when ctrl is 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;
}
/**
* Sets the terminal screen section which is displayed in this widget.
* When updateImage() is called, the display fetches the latest character image from the
......@@ -638,6 +652,7 @@ protected:
virtual void focusInEvent(QFocusEvent* event);
virtual void focusOutEvent(QFocusEvent* event);
virtual void keyPressEvent(QKeyEvent* event);
virtual void keyReleaseEvent(QKeyEvent* event);
virtual void leaveEvent(QEvent* event);
virtual void mouseDoubleClickEvent(QMouseEvent* event);
virtual void mousePressEvent(QMouseEvent* event);
......@@ -857,6 +872,8 @@ private:
QTimer* _blinkTextTimer;
QTimer* _blinkCursorTimer;
bool _showUrlHint;
bool _enableShowUrlHint;
bool _underlineLinks; // Underline URL and hosts on mouse hover
bool _openLinksByDirectClick; // Open URL and hosts by single mouse click
......
......@@ -812,6 +812,8 @@ void ViewManager::applyProfileToView(TerminalDisplay* view , const Profile::Ptr
view->setOpenLinksByDirectClick(profile->property<bool>(Profile::OpenLinksByDirectClickEnabled));
view->setEnableUrlHints(profile->property<bool>(Profile::EnableUrlHints));
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