[vlc-commits] [Git][videolan/vlc][master] 7 commits: qt: add flag SubSecondFormattedAsMS to VLCTick
François Cartegnie (@fcartegnie)
gitlab at videolan.org
Mon Oct 21 04:09:31 UTC 2024
François Cartegnie pushed to branch master at VideoLAN / VLC
Commits:
08bbfd9b by Fatih Uzunoglu at 2024-10-21T03:48:05+00:00
qt: add flag SubSecondFormattedAsMS to VLCTick
- - - - -
0d282feb by Fatih Uzunoglu at 2024-10-21T03:48:05+00:00
qt: add `isSubSecond()` to `VLCTick`
- - - - -
8a3482aa by Fatih Uzunoglu at 2024-10-21T03:48:05+00:00
qt: use `isSubSecond()` in `VLCTick`
- - - - -
ae298e50 by Fatih Uzunoglu at 2024-10-21T03:48:05+00:00
qml: do not format position tick as duration in ArtworkInfoWidget
- - - - -
6ae4d3fa by Fatih Uzunoglu at 2024-10-21T03:48:05+00:00
qml: do not format position tick as duration in ControlBar
- - - - -
a43176f0 by Fatih Uzunoglu at 2024-10-21T03:48:05+00:00
qml: do not format position tick as duration in SliderBar
- - - - -
fdf37bda by Fatih Uzunoglu at 2024-10-21T03:48:05+00:00
qml: use fixed width with the time if control bar is compact
So that the slider bar, which is aligned to the texts, stays
in place when non-monospaced fonts are used. Such fonts may
cause text to have different width depending on the digits
used.
- - - - -
5 changed files:
- modules/gui/qt/player/qml/ControlBar.qml
- modules/gui/qt/player/qml/SliderBar.qml
- modules/gui/qt/player/qml/controlbarcontrols/ArtworkInfoWidget.qml
- modules/gui/qt/util/vlctick.cpp
- modules/gui/qt/util/vlctick.hpp
Changes:
=====================================
modules/gui/qt/player/qml/ControlBar.qml
=====================================
@@ -98,6 +98,13 @@ T.Pane {
colorSet: ColorContext.Window
}
+ TextMetrics {
+ id: timeTextMetrics
+ font.pixelSize: (textPosition === ControlBar.TimeTextPosition.LeftRightSlider) ? VLCStyle.fontSize_small
+ : VLCStyle.fontSize_normal
+ text: "00--00" // Some extra space to compensate non-monospaced fonts.
+ }
+
background: Rectangle {
color: theme.bg.primary
}
@@ -116,10 +123,16 @@ T.Pane {
readonly property list<Item> strayItems: [
T.Label {
id: mediaTime
- text: Player.time.formatHMS()
+
+ Layout.preferredWidth: (textPosition === ControlBar.TimeTextPosition.LeftRightSlider) ? timeTextMetrics.width : -1
+
+ text: {
+ const length = Player.length
+ return Player.time.formatHMS(length.isSubSecond() ? length.SubSecondFormattedAsMS : 0)
+ }
color: theme.fg.primary
- font.pixelSize: (textPosition === ControlBar.TimeTextPosition.LeftRightSlider) ? VLCStyle.fontSize_small
- : VLCStyle.fontSize_normal
+ font: timeTextMetrics.font
+ horizontalAlignment: Text.AlignHCenter
anchors.left: (parent === pseudoRow) ? parent.left : undefined
anchors.verticalCenter: (parent === pseudoRow) ? parent.verticalCenter : undefined
@@ -127,11 +140,14 @@ T.Pane {
T.Label {
id: mediaRemainingTime
+ Layout.preferredWidth: (textPosition === ControlBar.TimeTextPosition.LeftRightSlider) ? timeTextMetrics.width : -1
+
text: (MainCtx.showRemainingTime && Player.remainingTime.valid())
? "-" + Player.remainingTime.formatHMS()
: Player.length.formatHMS()
color: mediaTime.color
- font.pixelSize: mediaTime.font.pixelSize
+ font: timeTextMetrics.font
+ horizontalAlignment: Text.AlignHCenter
visible: root.showRemainingTime
=====================================
modules/gui/qt/player/qml/SliderBar.qml
=====================================
@@ -83,10 +83,13 @@ T.ProgressBar {
text: {
let _text
+ const length = Player.length
if (hoverHandler.hovered)
- _text = Player.length.scale(pos.x / control.width).formatHMS()
+ _text = length.scale(pos.x / control.width)
else
- _text = Player.time.formatHMS()
+ _text = Player.time
+
+ _text = _text.formatHMS(length.isSubSecond() ? length.SubSecondFormattedAsMS : 0)
if (Player.hasChapters)
_text += " - " + Player.chapters.getNameAtPosition(control._tooltipPosition)
=====================================
modules/gui/qt/player/qml/controlbarcontrols/ArtworkInfoWidget.qml
=====================================
@@ -250,8 +250,12 @@ AbstractButton {
text: {
if (paintOnly)
" -- / -- "
- else
- Player.time.formatHMS() + " / " + Player.length.formatHMS()
+ else {
+ const length = Player.length
+ return Player.time.formatHMS(length.isSubSecond() ? length.SubSecondFormattedAsMS : 0) +
+ " / " +
+ length.formatHMS()
+ }
}
color: theme.fg.secondary
}
=====================================
modules/gui/qt/util/vlctick.cpp
=====================================
@@ -50,13 +50,18 @@ bool VLCTick::valid() const
return m_ticks != VLC_TICK_INVALID;
}
-QString VLCTick::formatHMS() const
+bool VLCTick::isSubSecond() const
+{
+ return (MS_FROM_VLC_TICK(m_ticks) < 1000);
+}
+
+QString VLCTick::formatHMS(int formatFlags) const
{
if (m_ticks == VLC_TICK_INVALID)
return "--:--";
int64_t t_ms = MS_FROM_VLC_TICK(m_ticks);
- if (t_ms >= 1000)
+ if (!isSubSecond() || !(formatFlags & SubSecondFormattedAsMS))
{
//truncate milliseconds toward 0
int64_t t_sec = t_ms / 1000;
@@ -78,7 +83,7 @@ QString VLCTick::formatHMS() const
return qtr("%1 ms").arg(MS_FROM_VLC_TICK(m_ticks));
}
-QString VLCTick::formatLong() const
+QString VLCTick::formatLong(int formatFlags) const
{
if (m_ticks == VLC_TICK_INVALID)
return "--:--";
@@ -96,7 +101,7 @@ QString VLCTick::formatLong() const
.arg(hour)
.arg(min);
}
- else if (t_ms >= 1000)
+ else if (!isSubSecond() || !(formatFlags & SubSecondFormattedAsMS))
{
//round to the nearest second
t_ms = roundNearestMultiple(t_ms, 1000);
@@ -115,7 +120,7 @@ QString VLCTick::formatLong() const
return qtr("%1 ms").arg(t_ms);
}
-QString VLCTick::formatShort() const
+QString VLCTick::formatShort(int formatFlags) const
{
if (m_ticks == VLC_TICK_INVALID)
return "--:--";
@@ -133,7 +138,7 @@ QString VLCTick::formatShort() const
.arg(hour)
.arg(min, 2, 10, QChar('0'));
}
- else if (t_ms >= 1000)
+ else if (!isSubSecond() || !(formatFlags & SubSecondFormattedAsMS))
{
//round to the nearest second
t_ms = roundNearestMultiple(t_ms, 1000);
=====================================
modules/gui/qt/util/vlctick.hpp
=====================================
@@ -30,6 +30,11 @@ class VLCTick
{
Q_GADGET
public:
+ enum FormatFlag {
+ SubSecondFormattedAsMS = 1
+ };
+ Q_ENUM(FormatFlag)
+
VLCTick();
VLCTick(vlc_tick_t ticks);
@@ -37,8 +42,11 @@ public:
Q_INVOKABLE bool valid() const;
+ Q_INVOKABLE bool isSubSecond() const;
+
/**
* @brief formatHMS
+ * @param formatFlags flags to specialize formatting, default is SubSecondFormattedAsMS for legacy reasons
* @return time as HH:MM:SS
*
* this method should be used to present running time or
@@ -46,26 +54,28 @@ public:
*
* milliseconds will be truncated towards 0
*/
- Q_INVOKABLE QString formatHMS() const;
+ Q_INVOKABLE QString formatHMS(int formatFlags = SubSecondFormattedAsMS) const;
/**
* @brief formatLong
+ * @param formatFlags flags to specialize formatting, default is SubSecondFormattedAsMS for legacy reasons
* @return time in literal form
* 1h 2min
* 5 min
* 10 sec
* 43 ms
*/
- Q_INVOKABLE QString formatLong() const;
+ Q_INVOKABLE QString formatLong(int formatFlags = SubSecondFormattedAsMS) const;
/**
* @brief formatShort
+ * @param formatFlags flags to specialize formatting, default is SubSecondFormattedAsMS for legacy reasons
* @return time in literal form
* 1h02
* 02:42
* 43 ms
*/
- Q_INVOKABLE QString formatShort() const;
+ Q_INVOKABLE QString formatShort(int formatFlags = SubSecondFormattedAsMS) const;
Q_INVOKABLE VLCTick scale(float) const;
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/7366e61dcb8b41bec3c7e901dd4baf9744019a45...fdf37bda22388ecaa4b2eef4653a51667f984a2d
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/7366e61dcb8b41bec3c7e901dd4baf9744019a45...fdf37bda22388ecaa4b2eef4653a51667f984a2d
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list