Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Utilities
Konsole
Commits
69865507
Commit
69865507
authored
Jul 19, 2020
by
Tomaz Canabrava
Browse files
Move mouseMoveEvent handling to hotSpot
parent
83de7c45
Changes
8
Hide whitespace changes
Inline
Side-by-side
src/filterHotSpots/FileFilterHotspot.cpp
View file @
69865507
...
...
@@ -27,6 +27,7 @@
#include <QMenu>
#include <QTimer>
#include <QToolTip>
#include <QMouseEvent>
#include <KRun>
#include <KLocalizedString>
...
...
@@ -34,6 +35,7 @@
#include "konsoledebug.h"
#include "KonsoleSettings.h"
#include "widgets/TerminalDisplay.h"
using
namespace
Konsole
;
...
...
@@ -194,3 +196,12 @@ KFileItem FileFilterHotSpot::fileItem() const
{
return
KFileItem
(
QUrl
::
fromLocalFile
(
_filePath
));
}
void
FileFilterHotSpot
::
mouseMoveEvent
(
TerminalDisplay
*
td
,
QMouseEvent
*
ev
)
{
HotSpot
::
mouseMoveEvent
(
td
,
ev
);
if
(
this
!=
HotSpot
::
currentlyHoveredHotSpot
)
{
HotSpot
::
currentlyHoveredHotSpot
.
reset
(
this
);
requestThumbnail
(
ev
->
modifiers
(),
ev
->
globalPos
());
}
}
src/filterHotSpots/FileFilterHotspot.h
View file @
69865507
...
...
@@ -35,10 +35,11 @@ class QAction;
class
QPixmap
;
namespace
Konsole
{
class
TerminalDisplay
;
/**
* Hotspot type created by FileFilter instances.
*/
class
FileFilterHotSpot
:
public
RegExpFilterHotSpot
{
public:
...
...
@@ -59,6 +60,8 @@ public:
void
thumbnailRequested
();
static
void
stopThumbnailGeneration
();
void
mouseMoveEvent
(
TerminalDisplay
*
td
,
QMouseEvent
*
ev
);
private:
void
showThumbnail
(
const
KFileItem
&
item
,
const
QPixmap
&
preview
);
QString
_filePath
;
...
...
src/filterHotSpots/FilterChain.cpp
View file @
69865507
...
...
@@ -25,7 +25,7 @@
#include "widgets/TerminalDisplay.h"
#include <QRect>
#include <QEvent>
#include <algorithm>
using
namespace
Konsole
;
...
...
@@ -135,3 +135,13 @@ int FilterChain::count(HotSpot::Type type)
return
s
->
type
()
==
type
;
});
}
void
FilterChain
::
leaveEvent
(
TerminalDisplay
*
td
,
QEvent
*
ev
)
{
Q_UNUSED
(
ev
);
if
(
!
HotSpot
::
mouseOverHotSpotArea
.
isEmpty
())
{
td
->
update
(
HotSpot
::
mouseOverHotSpotArea
);
HotSpot
::
mouseOverHotSpotArea
=
QRegion
();
td
->
setCursor
(
Qt
::
IBeamCursor
);
}
}
src/filterHotSpots/FilterChain.h
View file @
69865507
...
...
@@ -28,6 +28,8 @@
#include "HotSpot.h"
class
QLeaveEvent
;
namespace
Konsole
{
class
Filter
;
...
...
@@ -84,6 +86,8 @@ public:
/* Returns the amount of hotspots of the given type */
int
count
(
HotSpot
::
Type
type
);
void
leaveEvent
(
TerminalDisplay
*
td
,
QEvent
*
ev
);
protected:
QList
<
Filter
*>
_filters
;
TerminalDisplay
*
_terminalDisplay
;
...
...
src/filterHotSpots/HotSpot.cpp
View file @
69865507
...
...
@@ -20,8 +20,16 @@
#include "HotSpot.h"
#include <QMouseEvent>
#include "widgets/TerminalDisplay.h"
#include "FileFilterHotspot.h"
using
namespace
Konsole
;
QSharedPointer
<
HotSpot
>
HotSpot
::
currentlyHoveredHotSpot
;
QRegion
HotSpot
::
mouseOverHotSpotArea
;
HotSpot
::~
HotSpot
()
=
default
;
HotSpot
::
HotSpot
(
int
startLine
,
int
startColumn
,
int
endLine
,
int
endColumn
)
:
...
...
@@ -107,3 +115,34 @@ QPair<QRegion, QRect> HotSpot::region(int fontWidth, int fontHeight, int columns
}
return
{
region
,
r
};
}
void
HotSpot
::
mouseMoveEvent
(
TerminalDisplay
*
td
,
QMouseEvent
*
ev
)
{
//TODO: Move this to HotSpot::mouseMoveEvent
QCursor
cursor
=
td
->
cursor
();
if
((
type
()
==
HotSpot
::
Link
||
type
()
==
HotSpot
::
EMailAddress
||
type
()
==
HotSpot
::
EscapedUrl
))
{
QRegion
previousHotspotArea
=
_mouseOverHotspotArea
;
_mouseOverHotspotArea
=
region
(
td
->
fontWidth
(),
td
->
fontHeight
(),
td
->
columns
(),
td
->
contentRect
()).
first
;
if
((
td
->
openLinksByDirectClick
()
||
((
ev
->
modifiers
()
&
Qt
::
ControlModifier
)
!=
0u
))
&&
(
cursor
.
shape
()
!=
Qt
::
PointingHandCursor
))
{
td
->
setCursor
(
Qt
::
PointingHandCursor
);
}
td
->
update
(
_mouseOverHotspotArea
|
previousHotspotArea
);
}
else
if
(
!
_mouseOverHotspotArea
.
isEmpty
())
{
if
((
td
->
openLinksByDirectClick
()
||
((
ev
->
modifiers
()
&
Qt
::
ControlModifier
)
!=
0u
))
||
(
cursor
.
shape
()
==
Qt
::
PointingHandCursor
))
{
td
->
setCursor
(
td
->
usesMouseTracking
()
?
Qt
::
ArrowCursor
:
Qt
::
IBeamCursor
);
}
td
->
update
(
_mouseOverHotspotArea
);
// set hotspot area to an invalid rectangle
_mouseOverHotspotArea
=
QRegion
();
// TODO: We need to move this to a `mouseLeaveEvent`
// HACK: Special case, if we move away from a FileFilterHotSpot, we need to stop the thumbnail.
FileFilterHotSpot
::
stopThumbnailGeneration
();
HotSpot
::
currentlyHoveredHotSpot
.
clear
();
}
}
src/filterHotSpots/HotSpot.h
View file @
69865507
...
...
@@ -26,11 +26,15 @@
#include <QList>
#include <QRegion>
#include <QRect>
#include <QSharedPointer>
class
QAction
;
class
QMenu
;
class
QMouseEvent
;
namespace
Konsole
{
class
TerminalDisplay
;
/**
* Represents an area of text which matched the pattern a particular filter has been looking for.
*
...
...
@@ -57,6 +61,8 @@ public:
HotSpot
(
int
startLine
,
int
startColumn
,
int
endLine
,
int
endColumn
);
virtual
~
HotSpot
();
static
QSharedPointer
<
HotSpot
>
currentlyHoveredHotSpot
;
static
QRegion
mouseOverHotSpotArea
;
enum
Type
{
// the type of the hotspot is not specified
NotSpecified
,
...
...
@@ -104,6 +110,9 @@ public:
virtual
void
setupMenu
(
QMenu
*
menu
);
QPair
<
QRegion
,
QRect
>
region
(
int
fontWidth
,
int
fontHeight
,
int
columns
,
QRect
terminalDisplayRect
)
const
;
void
mouseMoveEvent
(
TerminalDisplay
*
td
,
QMouseEvent
*
ev
);
protected:
/** Sets the type of a hotspot. This should only be set once */
void
setType
(
Type
type
);
...
...
@@ -114,6 +123,7 @@ private:
int
_endLine
;
int
_endColumn
;
Type
_type
;
QRegion
_mouseOverHotspotArea
;
};
}
...
...
src/widgets/TerminalDisplay.cpp
View file @
69865507
...
...
@@ -498,7 +498,6 @@ TerminalDisplay::TerminalDisplay(QWidget* parent)
,
_blendColor
(
qRgba
(
0
,
0
,
0
,
0xff
))
,
_wallpaper
(
nullptr
)
,
_filterChain
(
new
TerminalImageFilterChain
(
this
))
,
_mouseOverHotspotArea
(
QRegion
())
,
_filterUpdateRequired
(
true
)
,
_cursorShape
(
Enum
::
BlockCursor
)
,
_cursorColor
(
QColor
())
...
...
@@ -2358,35 +2357,10 @@ void TerminalDisplay::mouseMoveEvent(QMouseEvent* ev)
processFilters
();
// handle filters
// change link hot-spot appearance on mouse-over
// TODO: Move this to filterChain::mouseMoveEvent
auto
spot
=
_filterChain
->
hotSpotAt
(
charLine
,
charColumn
);
if
((
spot
!=
nullptr
)
&&
(
spot
->
type
()
==
HotSpot
::
Link
||
spot
->
type
()
==
HotSpot
::
EMailAddress
||
spot
->
type
()
==
HotSpot
::
EscapedUrl
))
{
QRegion
previousHotspotArea
=
_mouseOverHotspotArea
;
_mouseOverHotspotArea
=
spot
->
region
(
_fontWidth
,
_fontHeight
,
_columns
,
_contentRect
).
first
;
if
((
_openLinksByDirectClick
||
((
ev
->
modifiers
()
&
Qt
::
ControlModifier
)
!=
0u
))
&&
(
cursor
().
shape
()
!=
Qt
::
PointingHandCursor
))
{
setCursor
(
Qt
::
PointingHandCursor
);
}
/* can't use qobject_cast because moc is broken for inner classes */
auto
fileSpot
=
spot
.
dynamicCast
<
FileFilterHotSpot
>
();
if
(
fileSpot
!=
_currentlyHoveredHotspot
)
{
_currentlyHoveredHotspot
=
fileSpot
;
if
(
fileSpot
!=
nullptr
)
{
fileSpot
->
requestThumbnail
(
ev
->
modifiers
(),
ev
->
globalPos
());
}
}
update
(
_mouseOverHotspotArea
|
previousHotspotArea
);
}
else
if
(
!
_mouseOverHotspotArea
.
isEmpty
())
{
if
((
_openLinksByDirectClick
||
((
ev
->
modifiers
()
&
Qt
::
ControlModifier
)
!=
0u
))
||
(
cursor
().
shape
()
==
Qt
::
PointingHandCursor
))
{
setCursor
(
_usesMouseTracking
?
Qt
::
ArrowCursor
:
Qt
::
IBeamCursor
);
}
update
(
_mouseOverHotspotArea
);
// set hotspot area to an invalid rectangle
_mouseOverHotspotArea
=
QRegion
();
FileFilterHotSpot
::
stopThumbnailGeneration
();
_currentlyHoveredHotspot
.
clear
();
if
(
spot
)
{
spot
->
mouseMoveEvent
(
this
,
ev
);
}
// for auto-hiding the cursor, we need mouseTracking
...
...
@@ -2448,15 +2422,11 @@ void TerminalDisplay::mouseMoveEvent(QMouseEvent* ev)
extendSelection
(
ev
->
pos
());
}
void
TerminalDisplay
::
leaveEvent
(
QEvent
*
)
void
TerminalDisplay
::
leaveEvent
(
QEvent
*
ev
)
{
// remove underline from an active link when cursor leaves the widget area,
// also restore regular mouse cursor shape
if
(
!
_mouseOverHotspotArea
.
isEmpty
())
{
update
(
_mouseOverHotspotArea
);
_mouseOverHotspotArea
=
QRegion
();
setCursor
(
Qt
::
IBeamCursor
);
}
_filterChain
->
leaveEvent
(
this
,
ev
);
}
void
TerminalDisplay
::
extendSelection
(
const
QPoint
&
position
)
...
...
@@ -3665,8 +3635,9 @@ void TerminalDisplay::keyPressEvent(QKeyEvent* event)
}
}
if
(
_currentlyHoveredHotspot
!=
nullptr
)
{
auto
fileHotspot
=
_currentlyHoveredHotspot
.
dynamicCast
<
FileFilterHotSpot
>
();
// TODO: Move this to hotSpot::keyPressEvent.
if
(
HotSpot
::
currentlyHoveredHotSpot
!=
nullptr
)
{
auto
fileHotspot
=
HotSpot
::
currentlyHoveredHotSpot
.
dynamicCast
<
FileFilterHotSpot
>
();
if
(
!
fileHotspot
)
{
return
;
}
...
...
src/widgets/TerminalDisplay.h
View file @
69865507
...
...
@@ -322,6 +322,9 @@ public:
/** Reset the font size */
void
resetFontSize
();
QRect
contentRect
()
const
{
return
_contentRect
;
}
bool
openLinksByDirectClick
()
const
{
return
_openLinksByDirectClick
;
}
/**
* Sets the terminal screen section which is displayed in this widget.
* When updateImage() is called, the display fetches the latest character image from the
...
...
@@ -844,7 +847,6 @@ private:
// list of filters currently applied to the display. used for links and
// search highlight
TerminalImageFilterChain
*
_filterChain
;
QRegion
_mouseOverHotspotArea
;
bool
_filterUpdateRequired
;
Enum
::
CursorShapeEnum
_cursorShape
;
...
...
@@ -914,8 +916,6 @@ private:
bool
_hasCompositeFocus
;
bool
_displayVerticalLine
;
int
_displayVerticalLineAtChar
;
QSharedPointer
<
HotSpot
>
_currentlyHoveredHotspot
;
};
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment