[vlc-commits] qt: add controlbar model default builder
Fatih Uzunoglu
git at videolan.org
Thu Aug 27 12:44:56 CEST 2020
vlc | branch: master | Fatih Uzunoglu <fuzun54 at outlook.com> | Tue Aug 4 22:26:08 2020 +0300| [ca8f76e4d8d09e156291004e0e842961b0b11b6a] | committer: Pierre Lamot
qt: add controlbar model default builder
and use it instead of #define.
Signed-off-by: Pierre Lamot <pierre at videolabs.io>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ca8f76e4d8d09e156291004e0e842961b0b11b6a
---
modules/gui/qt/player/playercontrolbarmodel.cpp | 59 ++++++++++++++++++++-----
modules/gui/qt/player/playercontrolbarmodel.hpp | 4 +-
2 files changed, 50 insertions(+), 13 deletions(-)
diff --git a/modules/gui/qt/player/playercontrolbarmodel.cpp b/modules/gui/qt/player/playercontrolbarmodel.cpp
index 42169168fb..c9ba166ca1 100644
--- a/modules/gui/qt/player/playercontrolbarmodel.cpp
+++ b/modules/gui/qt/player/playercontrolbarmodel.cpp
@@ -20,13 +20,39 @@
#include "qt.hpp"
#include "playercontrolbarmodel.hpp"
-#define MAIN_TB1_DEFAULT "20;21;65;17;3;0;1;4;18;65;33;7"
-#define MINI_TB_DEFAULT "65;17;3;0;1;4;18;65;33;7"
+
+static const PlayerControlBarModel::IconToolButton MAIN_TB_DEFAULT[] = {
+ {PlayerControlBarModel::LANG_BUTTON},
+ {PlayerControlBarModel::MENU_BUTTON},
+ {PlayerControlBarModel::WIDGET_SPACER_EXTEND},
+ {PlayerControlBarModel::RANDOM_BUTTON},
+ {PlayerControlBarModel::PREVIOUS_BUTTON},
+ {PlayerControlBarModel::PLAY_BUTTON},
+ {PlayerControlBarModel::STOP_BUTTON},
+ {PlayerControlBarModel::NEXT_BUTTON},
+ {PlayerControlBarModel::LOOP_BUTTON},
+ {PlayerControlBarModel::WIDGET_SPACER_EXTEND},
+ {PlayerControlBarModel::VOLUME},
+ {PlayerControlBarModel::FULLSCREEN_BUTTON}
+ };
+
+static const PlayerControlBarModel::IconToolButton MINI_TB_DEFAULT[] = {
+ {PlayerControlBarModel::WIDGET_SPACER_EXTEND},
+ {PlayerControlBarModel::RANDOM_BUTTON},
+ {PlayerControlBarModel::PREVIOUS_BUTTON},
+ {PlayerControlBarModel::PLAY_BUTTON},
+ {PlayerControlBarModel::STOP_BUTTON},
+ {PlayerControlBarModel::NEXT_BUTTON},
+ {PlayerControlBarModel::LOOP_BUTTON},
+ {PlayerControlBarModel::WIDGET_SPACER_EXTEND},
+ {PlayerControlBarModel::VOLUME},
+ {PlayerControlBarModel::FULLSCREEN_BUTTON}
+ };
+
PlayerControlBarModel::PlayerControlBarModel(QObject *_parent) : QAbstractListModel(_parent)
{
configName = "MainPlayerToolbar";
- defaultConfig = MAIN_TB1_DEFAULT;
}
void PlayerControlBarModel::saveConfig()
@@ -56,13 +82,28 @@ void PlayerControlBarModel::reloadModel()
{
beginResetModel();
mButtons.clear();
- QString config = getSettings() ->value( configName, defaultConfig )
- .toString();
- parseAndAdd(config);
+
+ QVariant config = getSettings() ->value(configName);
+
+ if (!config.isNull() && config.canConvert<QString>())
+ parseAndAdd(config.toString());
+ else if (configName == "MainPlayerToolbar")
+ parseDefault(MAIN_TB_DEFAULT, ARRAY_SIZE(MAIN_TB_DEFAULT));
+ else
+ parseDefault(MINI_TB_DEFAULT, ARRAY_SIZE(MINI_TB_DEFAULT));
+
endResetModel();
}
-void PlayerControlBarModel::parseAndAdd(QString &config)
+void PlayerControlBarModel::parseDefault(const PlayerControlBarModel::IconToolButton* config, const size_t config_size)
+{
+ beginInsertRows(QModelIndex(),rowCount(),rowCount() + config_size);
+ for (size_t i = 0; i < config_size; i++)
+ mButtons.append(config[i]);
+ endInsertRows();
+}
+
+void PlayerControlBarModel::parseAndAdd(const QString &config)
{
beginInsertRows(QModelIndex(),rowCount(),rowCount()+config.split(";", QString::SkipEmptyParts).length() - 1);
@@ -173,10 +214,6 @@ void PlayerControlBarModel::setConfigName(QString name)
if(configName == name)
return;
configName = name;
- if(configName == "MainPlayerToolbar")
- defaultConfig = MAIN_TB1_DEFAULT;
- else
- defaultConfig = MINI_TB_DEFAULT;
if (m_mainCtx)
reloadModel();
emit configNameChanged(name);
diff --git a/modules/gui/qt/player/playercontrolbarmodel.hpp b/modules/gui/qt/player/playercontrolbarmodel.hpp
index 6fe9c153cd..23172bc2f6 100644
--- a/modules/gui/qt/player/playercontrolbarmodel.hpp
+++ b/modules/gui/qt/player/playercontrolbarmodel.hpp
@@ -109,9 +109,9 @@ protected:
private:
QVector<IconToolButton> mButtons;
QString configName;
- QString defaultConfig;
- void parseAndAdd(QString& config);
+ void parseAndAdd(const QString& config);
+ void parseDefault(const IconToolButton* config, const size_t config_size);
bool setButtonAt(int index, const IconToolButton &button);
void addProfiles();
More information about the vlc-commits
mailing list