Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
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
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 )
...
@@ -262,12 +262,10 @@ void SeekSlider::mouseMoveEvent( QMouseEvent *event )
chapterLabel
=
points
.
at
(
i_selected
).
name
;
chapterLabel
=
points
.
at
(
i_selected
).
name
;
}
}
QPoint
target
(
event
->
globalX
()
-
(
event
->
x
()
-
posX
),
QWidget
::
mapToGlobal
(
pos
()
).
y
()
);
secstotimestr
(
psz_length
,
(
posX
*
inputLength
)
/
size
().
width
()
);
secstotimestr
(
psz_length
,
(
posX
*
inputLength
)
/
size
().
width
()
);
mTimeTooltip
->
setText
(
psz_length
,
chapterLabel
);
mTimeTooltip
->
setTip
(
target
,
psz_length
,
chapterLabel
);
QPoint
p
(
event
->
globalX
()
-
(
event
->
x
()
-
posX
)
-
(
mTimeTooltip
->
width
()
/
2
),
QWidget
::
mapToGlobal
(
pos
()
).
y
()
-
(
mTimeTooltip
->
height
()
+
2
)
);
mTimeTooltip
->
move
(
p
);
}
}
event
->
accept
();
event
->
accept
();
}
}
...
...
modules/gui/qt4/util/timetooltip.cpp
View file @
b29a9f0d
...
@@ -26,6 +26,7 @@
...
@@ -26,6 +26,7 @@
#include <QPainterPath>
#include <QPainterPath>
#include <QBitmap>
#include <QBitmap>
#include <QFontMetrics>
#include <QFontMetrics>
#include <QDesktopWidget>
#define TIP_HEIGHT 5
#define TIP_HEIGHT 5
...
@@ -51,29 +52,47 @@ TimeTooltip::TimeTooltip( QWidget *parent ) :
...
@@ -51,29 +52,47 @@ TimeTooltip::TimeTooltip( QWidget *parent ) :
// Inherit from the system default font size -5
// Inherit from the system default font size -5
mFont
=
QFont
(
"Verdana"
,
qMax
(
qApp
->
font
().
pointSize
()
-
5
,
7
)
);
mFont
=
QFont
(
"Verdana"
,
qMax
(
qApp
->
font
().
pointSize
()
-
5
,
7
)
);
mPreviousMetricsWidth
=
0
;
mTipX
=
-
1
;
// Set default text
setText
(
"00:00:00"
,
""
);
}
}
void
TimeTooltip
::
buildPath
()
void
TimeTooltip
::
adjustPosition
()
{
{
// Get the bounding box required to print the text and add some padding
QFontMetrics
metrics
(
mFont
);
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
//
Resize the widget to fit our needs
Q
Rect
textbox
=
metrics
.
boundingRect
(
mDisplayedText
).
adjusted
(
-
2
,
-
2
,
2
,
2
);
Q
Size
size
(
textbox
.
width
()
+
1
,
textbox
.
height
()
+
TIP_HEIGHT
+
1
);
if
(
mPreviousMetricsWidth
==
textbox
.
width
()
)
// The desired label position is just above the target
return
;
//same width == same path
QPoint
position
(
mTarget
.
x
()
-
size
.
width
()
/
2
,
else
mTarget
.
y
()
-
size
.
height
()
+
TIP_HEIGHT
/
2
);
mPreviousMetricsWidth
=
textbox
.
width
();
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
move
(
position
);
resize
(
mBox
.
width
()
+
1
,
mBox
.
height
()
+
TIP_HEIGHT
+
1
);
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
// Prepare the painter path for future use so
// we only have to generate the text at runtime.
// we only have to generate the text at runtime.
...
@@ -82,12 +101,10 @@ void TimeTooltip::buildPath()
...
@@ -82,12 +101,10 @@ void TimeTooltip::buildPath()
mPainterPath
.
addRect
(
mBox
);
mPainterPath
.
addRect
(
mBox
);
// Draw the tip
// Draw the tip
int
center
=
mBox
.
width
()
/
2
;
QPolygon
polygon
;
QPolygon
polygon
;
polygon
<<
QPoint
(
center
-
3
,
mBox
.
height
()
)
polygon
<<
QPoint
(
qMax
(
0
,
mTipX
-
3
),
mBox
.
height
()
)
<<
QPoint
(
center
,
mBox
.
height
()
+
TIP_HEIGHT
)
<<
QPoint
(
mTipX
,
mBox
.
height
()
+
TIP_HEIGHT
)
<<
QPoint
(
center
+
3
,
mBox
.
height
()
);
<<
QPoint
(
qMin
(
mTipX
+
3
,
mBox
.
width
()
),
mBox
.
height
()
);
mPainterPath
.
addPolygon
(
polygon
);
mPainterPath
.
addPolygon
(
polygon
);
// Store the simplified version of the path
// Store the simplified version of the path
...
@@ -98,25 +115,26 @@ void TimeTooltip::buildPath()
...
@@ -98,25 +115,26 @@ void TimeTooltip::buildPath()
mMask
=
QBitmap
(
size
()
);
mMask
=
QBitmap
(
size
()
);
QPainter
painter
(
&
mMask
);
QPainter
painter
(
&
mMask
);
painter
.
fillRect
(
mMask
.
rect
(),
Qt
::
white
);
painter
.
fillRect
(
mMask
.
rect
(),
Qt
::
white
);
painter
.
setPen
(
Q
Color
(
0
,
0
,
0
)
);
painter
.
setPen
(
Q
t
::
black
);
painter
.
setBrush
(
Q
Color
(
0
,
0
,
0
)
);
painter
.
setBrush
(
Q
t
::
black
);
painter
.
drawPath
(
mPainterPath
);
painter
.
drawPath
(
mPainterPath
);
painter
.
end
();
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
;
mDisplayedText
=
time
;
if
(
!
text
.
isEmpty
()
)
if
(
!
text
.
isEmpty
()
)
mDisplayedText
.
append
(
" - "
).
append
(
text
);
mDisplayedText
.
append
(
" - "
).
append
(
text
);
if
(
time
.
length
()
!=
mTime
.
length
()
||
mText
!=
text
)
if
(
mTarget
!=
target
||
time
.
length
()
!=
mTime
.
length
()
||
mText
!=
text
)
buildPath
();
{
mTarget
=
target
;
mTime
=
time
;
mText
=
text
;
adjustPosition
();
}
mTime
=
time
;
mText
=
text
;
update
();
update
();
}
}
...
@@ -133,5 +151,3 @@ void TimeTooltip::paintEvent( QPaintEvent * )
...
@@ -133,5 +151,3 @@ void TimeTooltip::paintEvent( QPaintEvent * )
p
.
setPen
(
QPen
(
qApp
->
palette
().
text
(),
1
)
);
p
.
setPen
(
QPen
(
qApp
->
palette
().
text
(),
1
)
);
p
.
drawText
(
mBox
,
Qt
::
AlignCenter
,
mDisplayedText
);
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
...
@@ -36,13 +36,15 @@ class TimeTooltip : public QWidget
Q_OBJECT
Q_OBJECT
public:
public:
explicit
TimeTooltip
(
QWidget
*
parent
=
0
);
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:
protected:
virtual
void
paintEvent
(
QPaintEvent
*
);
virtual
void
paintEvent
(
QPaintEvent
*
);
private:
private:
void
adjustPosition
();
void
buildPath
();
void
buildPath
();
QPoint
mTarget
;
QString
mTime
;
QString
mTime
;
QString
mText
;
QString
mText
;
QString
mDisplayedText
;
QString
mDisplayedText
;
...
@@ -50,7 +52,7 @@ private:
...
@@ -50,7 +52,7 @@ private:
QRect
mBox
;
QRect
mBox
;
QPainterPath
mPainterPath
;
QPainterPath
mPainterPath
;
QBitmap
mMask
;
QBitmap
mMask
;
int
m
PreviousMetricsWidth
;
int
m
TipX
;
};
};
#endif // TIMETOOLTIP_H
#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