Commit cf2c8a03 authored by Tomaz  Canabrava's avatar Tomaz Canabrava
Browse files

Move Url hints code to The HotSpot rework

parent b6cb1540
......@@ -26,6 +26,7 @@
#include <QRect>
#include <QEvent>
#include <QKeyEvent>
#include <QPainter>
#include <algorithm>
......@@ -151,18 +152,53 @@ QList<QSharedPointer<HotSpot>> FilterChain::filterBy(HotSpot::Type type) const
void FilterChain::leaveEvent(TerminalDisplay *td, QEvent *ev)
{
Q_UNUSED(td);
Q_UNUSED(ev);
_showUrlHint = false;
}
void FilterChain::keyReleaseEvent(TerminalDisplay *td, QKeyEvent *ev, int charLine, int charColumn)
{
if (_showUrlHint) {
_showUrlHint = false;
td->update();
}
auto spot = hotSpotAt(charLine, charColumn);
if (spot) {
spot->keyReleaseEvent(td, ev);
}
}
static int ascii_to_int(int c) {
return c - '0';
}
void FilterChain::keyPressEvent(TerminalDisplay *td, QKeyEvent *ev, int charLine, int charColumn)
{
if ((_urlHintsModifiers != 0u) && ev->modifiers() == _urlHintsModifiers) {
QList<QSharedPointer<HotSpot>> hotspots = filterBy(HotSpot::Link);
int nHotSpots = hotspots.count();
int hintSelected = ascii_to_int(ev->key());
// Triggered a Hotspot via shortcut.
if (hintSelected >= 0 && hintSelected < 10 && hintSelected < nHotSpots) {
if (_reverseUrlHints) {
hintSelected = nHotSpots - hintSelected - 1;
}
hotspots.at(hintSelected)->activate();
_showUrlHint = false;
td->update();
return;
}
if (!_showUrlHint) {
td->processFilters();
_showUrlHint = true;
td->update();
}
}
auto spot = hotSpotAt(charLine, charColumn);
if (spot) {
spot->keyPressEvent(td, ev);
......@@ -216,7 +252,7 @@ void FilterChain::paint(TerminalDisplay* td, QPainter& painter)
int urlNumInc;
// TODO: Remove _reverseUrllHints from TerminalDisplay.
if (false) { // TODO: Access reverseUrlHints from the profile, here.
if (_reverseUrlHints) { // TODO: Access reverseUrlHints from the profile, here.
urlNumber = count(HotSpot::Link);
urlNumInc = -1;
} else {
......@@ -233,15 +269,16 @@ void FilterChain::paint(TerminalDisplay* td, QPainter& painter)
// TODO: Move this paint code to HotSpot->drawHint();
// TODO: Fix the Url Hints access from the Profile.
if (/* _showUrlHint */ false && urlNumber >= 0 && urlNumber < 10 && spot->type() == HotSpot::Link) {
// Position at the beginning of the URL
QRect hintRect(*region.begin());
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));
if (_showUrlHint && spot->type() == HotSpot::Link) {
if (urlNumber >= 0 && urlNumber < 10) {
// Position at the beginning of the URL
QRect hintRect(*region.begin());
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));
}
urlNumber += urlNumInc;
}
}
......@@ -298,7 +335,7 @@ void FilterChain::paint(TerminalDisplay* td, QPainter& painter)
// TODO: Fix accessing the urlHint here.
// TODO: Move this code to UrlFilterHotSpot.
const bool hasMouse = region.contains(td->mapFromGlobal(QCursor::pos()));
if ((spot->type() == HotSpot::Link && /*_showUrlHint*/ false) || hasMouse) {
if ((spot->type() == HotSpot::Link && _showUrlHint) || hasMouse) {
QFontMetrics metrics(td->font());
// find the baseline (which is the invisible line that the characters in the font sit on,
......@@ -320,3 +357,12 @@ void FilterChain::paint(TerminalDisplay* td, QPainter& painter)
}
}
void FilterChain::setReverseUrlHints(bool value)
{
_reverseUrlHints = value;
}
void FilterChain::setUrlHintsModifiers(Qt::KeyboardModifiers value)
{
_urlHintsModifiers = value;
}
......@@ -96,10 +96,21 @@ public:
void leaveEvent(TerminalDisplay *td, QEvent *ev);
void paint(TerminalDisplay *td, QPainter &painter);
void setReverseUrlHints(bool value);
void setUrlHintsModifiers(Qt::KeyboardModifiers value);
protected:
QList<Filter *> _filters;
TerminalDisplay *_terminalDisplay;
QSharedPointer<HotSpot> _hotSpotUnderMouse;
/* TODO: this should be profile related, not here. but
* currently this removes a bit of code from TerminalDisplay,
* so it's a good compromise
* */
bool _showUrlHint;
bool _reverseUrlHints;
Qt::KeyboardModifiers _urlHintsModifiers;
};
}
......
......@@ -488,9 +488,6 @@ TerminalDisplay::TerminalDisplay(QWidget* parent)
, _textBlinking(false)
, _cursorBlinking(false)
, _hasTextBlinker(false)
, _urlHintsModifiers(Qt::NoModifier)
, _showUrlHint(false)
, _reverseUrlHints(false)
, _openLinksByDirectClick(false)
, _ctrlRequiredForDrag(true)
, _dropUrlsAsText(false)
......@@ -1790,8 +1787,6 @@ void TerminalDisplay::focusOutEvent(QFocusEvent*)
// suppress further text blinking
_blinkTextTimer->stop();
Q_ASSERT(!_textBlinking);
_showUrlHint = false;
}
void TerminalDisplay::focusInEvent(QFocusEvent*)
......@@ -3050,7 +3045,7 @@ void TerminalDisplay::setUsesMouseTracking(bool on)
resetCursor();
}
void TerminalDisplay::resetCursor()
void TerminalDisplay::resetCursor()
{
setCursor(_usesMouseTracking ? Qt::ArrowCursor : Qt::IBeamCursor);
}
......@@ -3490,28 +3485,6 @@ void TerminalDisplay::scrollScreenWindow(enum ScreenWindow::RelativeScrollMode m
void TerminalDisplay::keyPressEvent(QKeyEvent* event)
{
// TODO: Move this code to HotSpot too.
if ((_urlHintsModifiers != 0u) && event->modifiers() == _urlHintsModifiers) {
QList<QSharedPointer<HotSpot>> hotspots = _filterChain->filterBy(HotSpot::Link);
int nHotSpots = hotspots.count();
int hintSelected = event->key() - 0x31;
if (hintSelected >= 0 && hintSelected < 10 && hintSelected < nHotSpots) {
if (_reverseUrlHints) {
hintSelected = nHotSpots - hintSelected - 1;
}
hotspots.at(hintSelected)->activate();
_showUrlHint = false;
update();
return;
}
if (!_showUrlHint) {
processFilters();
_showUrlHint = true;
update();
}
}
{ // C++17: change getCharacterPosition to return a tuple and use auto [charLine, charColumn] to extract the values.
int charLine;
int charColumn;
......@@ -3553,11 +3526,6 @@ void TerminalDisplay::keyPressEvent(QKeyEvent* event)
void TerminalDisplay::keyReleaseEvent(QKeyEvent *event)
{
if (_showUrlHint) {
_showUrlHint = false;
update();
}
if (_readOnly) {
event->accept();
return;
......@@ -3905,8 +3873,6 @@ void TerminalDisplay::applyProfile(const Profile::Ptr &profile)
_trimLeadingSpaces = profile->property<bool>(Profile::TrimLeadingSpacesInSelectedText);
_trimTrailingSpaces = profile->property<bool>(Profile::TrimTrailingSpacesInSelectedText);
_openLinksByDirectClick = profile->property<bool>(Profile::OpenLinksByDirectClickEnabled);
_urlHintsModifiers = Qt::KeyboardModifiers(profile->property<int>(Profile::UrlHintsModifiers));
_reverseUrlHints = profile->property<bool>(Profile::ReverseUrlHints);
setMiddleClickPasteMode(Enum::MiddleClickPasteModeEnum(profile->property<int>(Profile::MiddleClickPasteMode)));
setCopyTextAsHTML(profile->property<bool>(Profile::CopyTextAsHTML));
......@@ -3940,6 +3906,10 @@ void TerminalDisplay::applyProfile(const Profile::Ptr &profile)
_displayVerticalLineAtChar = profile->verticalLineAtChar();
setAlternateScrolling(profile->property<bool>(Profile::AlternateScrolling));
_dimValue = profile->dimValue();
_filterChain->setUrlHintsModifiers(Qt::KeyboardModifiers(profile->property<int>(Profile::UrlHintsModifiers)));
_filterChain->setReverseUrlHints(profile->property<bool>(Profile::ReverseUrlHints));
}
void TerminalDisplay::printScreen()
......
......@@ -346,7 +346,7 @@ public:
* Selects everything in the terminal
*/
void selectAll();
// TODO: Move this code to KonsolePrintManager
void printContent(QPainter &painter, bool friendly);
......@@ -818,9 +818,6 @@ private:
QTimer *_blinkTextTimer;
QTimer *_blinkCursorTimer;
Qt::KeyboardModifiers _urlHintsModifiers;
bool _showUrlHint;
bool _reverseUrlHints;
bool _openLinksByDirectClick; // Open URL and hosts by single mouse click
bool _ctrlRequiredForDrag; // require Ctrl key for drag selected text
......
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