Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-2-2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc-2-2
Commits
b29a9f0d
Commit
b29a9f0d
authored
Jan 27, 2012
by
Tobias Güntner
Committed by
Jean-Baptiste Kempf
Feb 01, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Keep tooltip within screen boundaries. Adjust tip position accordingly.
Signed-off-by:
Jean-Baptiste Kempf
<
jb@videolan.org
>
parent
cb1fe28b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
37 deletions
+53
-37
modules/gui/qt4/util/input_slider.cpp
modules/gui/qt4/util/input_slider.cpp
+3
-5
modules/gui/qt4/util/timetooltip.cpp
modules/gui/qt4/util/timetooltip.cpp
+46
-30
modules/gui/qt4/util/timetooltip.hpp
modules/gui/qt4/util/timetooltip.hpp
+4
-2
No files found.
modules/gui/qt4/util/input_slider.cpp
View file @
b29a9f0d
...
...
@@ -262,12 +262,10 @@ void SeekSlider::mouseMoveEvent( QMouseEvent *event )
chapterLabel
=
points
.
at
(
i_selected
).
name
;
}
QPoint
target
(
event
->
globalX
()
-
(
event
->
x
()
-
posX
),
QWidget
::
mapToGlobal
(
pos
()
).
y
()
);
secstotimestr
(
psz_length
,
(
posX
*
inputLength
)
/
size
().
width
()
);
mTimeTooltip
->
setText
(
psz_length
,
chapterLabel
);
QPoint
p
(
event
->
globalX
()
-
(
event
->
x
()
-
posX
)
-
(
mTimeTooltip
->
width
()
/
2
),
QWidget
::
mapToGlobal
(
pos
()
).
y
()
-
(
mTimeTooltip
->
height
()
+
2
)
);
mTimeTooltip
->
move
(
p
);
mTimeTooltip
->
setTip
(
target
,
psz_length
,
chapterLabel
);
}
event
->
accept
();
}
...
...
modules/gui/qt4/util/timetooltip.cpp
View file @
b29a9f0d
...
...
@@ -26,6 +26,7 @@
#include <QPainterPath>
#include <QBitmap>
#include <QFontMetrics>
#include <QDesktopWidget>
#define TIP_HEIGHT 5
...
...
@@ -51,29 +52,47 @@ TimeTooltip::TimeTooltip( QWidget *parent ) :
// Inherit from the system default font size -5
mFont
=
QFont
(
"Verdana"
,
qMax
(
qApp
->
font
().
pointSize
()
-
5
,
7
)
);
mPreviousMetricsWidth
=
0
;
// Set default text
setText
(
"00:00:00"
,
""
);
mTipX
=
-
1
;
}
void
TimeTooltip
::
buildPath
()
void
TimeTooltip
::
adjustPosition
()
{
// Get the bounding box required to print the text and add some padding
QFontMetrics
metrics
(
mFont
);
QRect
textbox
=
metrics
.
boundingRect
(
mDisplayedText
);
textbox
.
adjust
(
-
2
,
-
2
,
2
,
2
);
textbox
.
moveTo
(
0
,
0
);
//
Get the bounding box required to print the text and add some padding
Q
Rect
textbox
=
metrics
.
boundingRect
(
mDisplayedText
).
adjusted
(
-
2
,
-
2
,
2
,
2
);
//
Resize the widget to fit our needs
Q
Size
size
(
textbox
.
width
()
+
1
,
textbox
.
height
()
+
TIP_HEIGHT
+
1
);
if
(
mPreviousMetricsWidth
==
textbox
.
width
()
)
return
;
//same width == same path
else
mPreviousMetricsWidth
=
textbox
.
width
();
// The desired label position is just above the target
QPoint
position
(
mTarget
.
x
()
-
size
.
width
()
/
2
,
mTarget
.
y
()
-
size
.
height
()
+
TIP_HEIGHT
/
2
);
mBox
=
QRect
(
0
,
0
,
textbox
.
width
(),
textbox
.
height
()
);
// Keep the tooltip on the same screen if possible
QRect
screen
=
QApplication
::
desktop
()
->
screenGeometry
(
mTarget
);
position
.
setX
(
qMax
(
screen
.
left
(),
qMin
(
position
.
x
(),
screen
.
left
()
+
screen
.
width
()
-
size
.
width
()
)
)
);
position
.
setY
(
qMax
(
screen
.
top
(),
qMin
(
position
.
y
(),
screen
.
top
()
+
screen
.
height
()
-
size
.
height
()
)
)
);
// Resize the widget to fit our needs
resize
(
mBox
.
width
()
+
1
,
mBox
.
height
()
+
TIP_HEIGHT
+
1
);
move
(
position
);
int
tipX
=
mTarget
.
x
()
-
position
.
x
();
if
(
mBox
!=
textbox
||
mTipX
!=
tipX
)
{
mBox
=
textbox
;
mTipX
=
tipX
;
resize
(
size
);
buildPath
();
setMask
(
mMask
);
}
}
void
TimeTooltip
::
buildPath
()
{
// Prepare the painter path for future use so
// we only have to generate the text at runtime.
...
...
@@ -82,12 +101,10 @@ void TimeTooltip::buildPath()
mPainterPath
.
addRect
(
mBox
);
// Draw the tip
int
center
=
mBox
.
width
()
/
2
;
QPolygon
polygon
;
polygon
<<
QPoint
(
center
-
3
,
mBox
.
height
()
)
<<
QPoint
(
center
,
mBox
.
height
()
+
TIP_HEIGHT
)
<<
QPoint
(
center
+
3
,
mBox
.
height
()
);
polygon
<<
QPoint
(
qMax
(
0
,
mTipX
-
3
),
mBox
.
height
()
)
<<
QPoint
(
mTipX
,
mBox
.
height
()
+
TIP_HEIGHT
)
<<
QPoint
(
qMin
(
mTipX
+
3
,
mBox
.
width
()
),
mBox
.
height
()
);
mPainterPath
.
addPolygon
(
polygon
);
// Store the simplified version of the path
...
...
@@ -98,25 +115,26 @@ void TimeTooltip::buildPath()
mMask
=
QBitmap
(
size
()
);
QPainter
painter
(
&
mMask
);
painter
.
fillRect
(
mMask
.
rect
(),
Qt
::
white
);
painter
.
setPen
(
Q
Color
(
0
,
0
,
0
)
);
painter
.
setBrush
(
Q
Color
(
0
,
0
,
0
)
);
painter
.
setPen
(
Q
t
::
black
);
painter
.
setBrush
(
Q
t
::
black
);
painter
.
drawPath
(
mPainterPath
);
painter
.
end
();
setMask
(
mMask
);
}
void
TimeTooltip
::
setT
ext
(
const
QString
&
time
,
const
QString
&
text
)
void
TimeTooltip
::
setT
ip
(
const
QPoint
&
target
,
const
QString
&
time
,
const
QString
&
text
)
{
mDisplayedText
=
time
;
if
(
!
text
.
isEmpty
()
)
mDisplayedText
.
append
(
" - "
).
append
(
text
);
if
(
time
.
length
()
!=
mTime
.
length
()
||
mText
!=
text
)
buildPath
();
if
(
mTarget
!=
target
||
time
.
length
()
!=
mTime
.
length
()
||
mText
!=
text
)
{
mTarget
=
target
;
mTime
=
time
;
mText
=
text
;
adjustPosition
();
}
mTime
=
time
;
mText
=
text
;
update
();
}
...
...
@@ -133,5 +151,3 @@ void TimeTooltip::paintEvent( QPaintEvent * )
p
.
setPen
(
QPen
(
qApp
->
palette
().
text
(),
1
)
);
p
.
drawText
(
mBox
,
Qt
::
AlignCenter
,
mDisplayedText
);
}
#undef TIP_HEIGHT
modules/gui/qt4/util/timetooltip.hpp
View file @
b29a9f0d
...
...
@@ -36,13 +36,15 @@ class TimeTooltip : public QWidget
Q_OBJECT
public:
explicit
TimeTooltip
(
QWidget
*
parent
=
0
);
void
setT
ext
(
const
QString
&
time
,
const
QString
&
text
);
void
setT
ip
(
const
QPoint
&
pos
,
const
QString
&
time
,
const
QString
&
text
);
protected:
virtual
void
paintEvent
(
QPaintEvent
*
);
private:
void
adjustPosition
();
void
buildPath
();
QPoint
mTarget
;
QString
mTime
;
QString
mText
;
QString
mDisplayedText
;
...
...
@@ -50,7 +52,7 @@ private:
QRect
mBox
;
QPainterPath
mPainterPath
;
QBitmap
mMask
;
int
m
PreviousMetricsWidth
;
int
m
TipX
;
};
#endif // TIMETOOLTIP_H
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