vlc | branch: master | Adrien Maglo <[email protected]> | Fri May 24 15:07:17 2019 +0200| [4e7956aa601c1c6617c1401cd4d8d01be96d1694] | committer: Thomas Guillem
qml: implement the next navigation in the history Signed-off-by: Thomas Guillem <[email protected]> > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4e7956aa601c1c6617c1401cd4d8d01be96d1694 --- modules/gui/qt/components/navigation_history.cpp | 59 ++++++++++++++++++------ modules/gui/qt/components/navigation_history.hpp | 18 ++++++-- modules/gui/qt/qml/BannerSources.qml | 5 +- modules/gui/qt/qml/MainInterface.qml | 2 +- modules/gui/qt/qml/about/About.qml | 2 +- modules/gui/qt/qml/utils/IconToolButton.qml | 7 +-- 6 files changed, 69 insertions(+), 24 deletions(-) diff --git a/modules/gui/qt/components/navigation_history.cpp b/modules/gui/qt/components/navigation_history.cpp index 39a428a7d9..5f494d1c58 100644 --- a/modules/gui/qt/components/navigation_history.cpp +++ b/modules/gui/qt/components/navigation_history.cpp @@ -1,28 +1,43 @@ #include "navigation_history.hpp" #include <QDebug> -NavigationHistory::NavigationHistory(QObject *parent) : QObject(parent) +NavigationHistory::NavigationHistory(QObject *parent) + : QObject(parent), m_position(-1) { } QVariant NavigationHistory::getCurrent() { + return m_history[m_position]; +} - return m_history.back(); +bool NavigationHistory::isPreviousEmpty() +{ + return m_position < 1; } -bool NavigationHistory::isEmpty() +bool NavigationHistory::isNextEmpty() { - return m_history.count() < 1; + return m_position == m_history.length() - 1; } void NavigationHistory::push(QVariantMap item, PostAction postAction) { + if (m_position < m_history.length() - 1) { + /* We want to push a new view while we have other views + * after the current one. + * In the case we delete all the following views. */ + m_history.erase(m_history.begin() + m_position + 1, m_history.end()); + emit nextEmptyChanged(true); + } + //m_history.push_back(VariantToPropertyMap(item)); m_history.push_back(item); - if (m_history.count() == 2) - emit emptyChanged(true); + // Set to last position + m_position++; + if (m_position == 1) + emit previousEmptyChanged(true); if (postAction == PostAction::Go) emit currentChanged(m_history.back()); } @@ -52,17 +67,35 @@ void NavigationHistory::push(QVariantList itemList, NavigationHistory::PostActio push(itemMap, postAction); } -void NavigationHistory::pop(PostAction postAction) +void NavigationHistory::previous(PostAction postAction) { - if (m_history.count() == 1) + if (m_position == 0) return; //delete m_history.back(); - m_history.pop_back(); + m_position--; + + if (m_position == 0) + emit previousEmptyChanged(true); + if (m_position == m_history.length() - 2) + emit nextEmptyChanged(false); - if (m_history.count() == 1) { - emit emptyChanged(true); - } if (postAction == PostAction::Go) - emit currentChanged(m_history.back()); + emit currentChanged(m_history[m_position]); +} + +void NavigationHistory::next(PostAction postAction) +{ + if (m_position == m_history.length() - 1) + return; + + m_position++; + + if (m_position == 1) + emit previousEmptyChanged(false); + if (m_position == m_history.length() - 1) + emit nextEmptyChanged(true); + + if (postAction == PostAction::Go) + emit currentChanged(m_history[m_position]); } diff --git a/modules/gui/qt/components/navigation_history.hpp b/modules/gui/qt/components/navigation_history.hpp index 36d8c4a8ce..a07c0ab93a 100644 --- a/modules/gui/qt/components/navigation_history.hpp +++ b/modules/gui/qt/components/navigation_history.hpp @@ -10,7 +10,8 @@ class NavigationHistory : public QObject Q_OBJECT public: Q_PROPERTY(QVariant current READ getCurrent NOTIFY currentChanged) - Q_PROPERTY(bool empty READ isEmpty NOTIFY emptyChanged) + Q_PROPERTY(bool previousEmpty READ isPreviousEmpty NOTIFY previousEmptyChanged) + Q_PROPERTY(bool nextEmpty READ isNextEmpty NOTIFY nextEmptyChanged) enum class PostAction{ Stay, @@ -22,11 +23,13 @@ public: explicit NavigationHistory(QObject *parent = nullptr); QVariant getCurrent(); - bool isEmpty(); + bool isPreviousEmpty(); + bool isNextEmpty(); signals: void currentChanged(QVariant current); - void emptyChanged(bool empty); + void previousEmptyChanged(bool empty); + void nextEmptyChanged(bool empty); public slots: /** @@ -62,11 +65,16 @@ public slots: * \endcode */ Q_INVOKABLE void push(QVariantList itemList, PostAction = PostAction::Stay ); - //pop the last page - void pop( PostAction = PostAction::Stay ); + + // Go to previous page + void previous( PostAction = PostAction::Stay ); + + // Go to next page + void next( PostAction = PostAction::Stay ); private: QVariantList m_history; + int m_position; }; #endif // NAVIGATION_HISTORY_HPP diff --git a/modules/gui/qt/qml/BannerSources.qml b/modules/gui/qt/qml/BannerSources.qml index a438039653..6caf918dc4 100644 --- a/modules/gui/qt/qml/BannerSources.qml +++ b/modules/gui/qt/qml/BannerSources.qml @@ -220,7 +220,8 @@ Utils.NavigableFocusScope { Layout.minimumWidth: width text: VLCIcons.topbar_previous KeyNavigation.right: history_next - onClicked: history.pop(History.Go) + onClicked: history.previous(History.Go) + enabled: !history.previousEmpty } Utils.IconToolButton { @@ -230,6 +231,8 @@ Utils.NavigableFocusScope { text: VLCIcons.topbar_next KeyNavigation.right: bar KeyNavigation.up: buttonView + onClicked: history.next(History.Go) + enabled: !history.nextEmpty } TabBar { diff --git a/modules/gui/qt/qml/MainInterface.qml b/modules/gui/qt/qml/MainInterface.qml index c6ad268015..0d23bc068b 100644 --- a/modules/gui/qt/qml/MainInterface.qml +++ b/modules/gui/qt/qml/MainInterface.qml @@ -50,7 +50,7 @@ Rectangle { focus: true onActionCancel: { console.log("onActionCancel") - history.pop(History.Go) + history.previous(History.Go) } } } diff --git a/modules/gui/qt/qml/about/About.qml b/modules/gui/qt/qml/about/About.qml index a24af79f3c..662b2653af 100644 --- a/modules/gui/qt/qml/about/About.qml +++ b/modules/gui/qt/qml/about/About.qml @@ -97,7 +97,7 @@ Utils.NavigableFocusScope { KeyNavigation.right: textScroll onClicked: { - history.pop(History.Go) + history.previous(History.Go) } } } diff --git a/modules/gui/qt/qml/utils/IconToolButton.qml b/modules/gui/qt/qml/utils/IconToolButton.qml index fabb7c6344..d142d0632f 100644 --- a/modules/gui/qt/qml/utils/IconToolButton.qml +++ b/modules/gui/qt/qml/utils/IconToolButton.qml @@ -22,9 +22,9 @@ import "qrc:///style/" ToolButton { id: control - property color color: control.checked - ? (control.activeFocus ? VLCStyle.colors.accent : VLCStyle.colors.bgHover ) - : VLCStyle.colors.buttonText + property color color: control.enabled ? + VLCStyle.colors.buttonText : VLCStyle.colors.lightText + property int size: VLCStyle.icon_normal property color highlightColor: VLCStyle.colors.accent @@ -40,6 +40,7 @@ ToolButton { } Label { + id: text text: control.text color: control.color _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
