Skip to content

Commit

Permalink
Merge pull request #31 from Blackmane/horizontal-channel-icons
Browse files Browse the repository at this point in the history
Add guild view direction
  • Loading branch information
guerinoni authored Apr 17, 2021
2 parents 4cbbe24 + 83b217c commit 156612e
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/app/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Application::Application(QQmlContext *ctx, QObject *parent) : QObject(parent)
ctx->setContextProperty("settingsModel", &m_settingsModel);

qmlRegisterUncreatableType<GuildsModel>("ui", 1, 0, "ViewMode", {});
qmlRegisterUncreatableType<GuildsModel>("ui", 1, 0, "ViewIconDirection", {});

connect(&m_auth, &Authenticator::authenticationSuccess, this,
&Application::handleLoginSuccess);
Expand Down Expand Up @@ -118,4 +119,7 @@ void Application::updateUI()
m_guildsModel->setViewMode(m_settings.guildsViewAsIcon()
? GuildsModel::ViewMode::Icon
: GuildsModel::ViewMode::Text);
m_guildsModel->setViewIconDirection(m_settings.guildsIconsAsHorizontalDirection()
? GuildsModel::ViewIconDirection::Horizontal
: GuildsModel::ViewIconDirection::Vertical);
}
20 changes: 17 additions & 3 deletions src/core/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ namespace SettingsCategory
const QString token = "auth/token";
const QString meInfo = "auth/meInfo";

const QString guidsView = "UI/guildsView";
const QString guildsView = "UI/guildsView";
const QString guildsViewIconDirection = "UI/guildsViewIconDirection";

} // namespace SettingsCategory

Expand All @@ -18,8 +19,15 @@ Settings::Settings(QObject *parent) : QObject(parent)
{ "text", "icon" },
0,
UserSettingPOD::ComboBox,
SettingsCategory::guidsView,
SettingsCategory::guildsView,
});
m_parameters.push_back({
"Set guilds icons direction:",
{ "vertical", "horizontal" },
0,
UserSettingPOD::ComboBox,
SettingsCategory::guildsViewIconDirection,
});
}

void Settings::loadSettings()
Expand All @@ -32,7 +40,8 @@ void Settings::loadSettings()
m_meInfo = settings.value(SettingsCategory::meInfo).toByteArray();
}

m_parameters[0].value = settings.value(SettingsCategory::guidsView).toInt();
m_parameters[0].value = settings.value(SettingsCategory::guildsView).toInt();
m_parameters[1].value = settings.value(SettingsCategory::guildsViewIconDirection).toInt();
}

void Settings::save() const
Expand Down Expand Up @@ -80,3 +89,8 @@ bool Settings::guildsViewAsIcon() const noexcept
{
return m_parameters[0].value == 1; // TODO: Fix magic numbers.
}

bool Settings::guildsIconsAsHorizontalDirection() const noexcept
{
return m_parameters[1].value == 1; // TODO: Fix magic numbers.
}
1 change: 1 addition & 0 deletions src/core/Settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Settings : public QObject
void setParameter(int indexOfParam, int valueOfChoices);

bool guildsViewAsIcon() const noexcept;
bool guildsIconsAsHorizontalDirection() const noexcept;

private:
const QString m_settingsFilename = "unofficial-discord-client";
Expand Down
11 changes: 11 additions & 0 deletions src/gui/GuildsModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ GuildsModel::ViewMode GuildsModel::viewMode() const noexcept
return m_viewMode;
}

void GuildsModel::setViewIconDirection(GuildsModel::ViewIconDirection vdir)
{
m_viewIconDirection = vdir;
emit viewIconDirectionChanged();
}

GuildsModel::ViewIconDirection GuildsModel::viewIconDirection () const noexcept
{
return m_viewIconDirection;
}

void GuildsModel::updateGuildIcon()
{
if (m_viewMode == ViewMode::Icon) {
Expand Down
9 changes: 9 additions & 0 deletions src/gui/GuildsModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class GuildsModel : public QAbstractListModel
Q_PROPERTY(int selected READ selected NOTIFY selectedChanged)
Q_PROPERTY(ChannelsModel *channelsModel READ channelsModel CONSTANT)
Q_PROPERTY(ViewMode viewMode READ viewMode NOTIFY viewModeChanged)
Q_PROPERTY(ViewIconDirection viewIconDirection READ viewIconDirection NOTIFY viewIconDirectionChanged)
Q_ENUMS(ViewMode)
Q_ENUMS(ViewIconDirection)
// clang-format on

public:
Expand All @@ -38,11 +40,17 @@ class GuildsModel : public QAbstractListModel
void setViewMode(ViewMode vm);
ViewMode viewMode() const noexcept;

enum class ViewIconDirection { Horizontal, Vertical};

void setViewIconDirection(ViewIconDirection vdir);
ViewIconDirection viewIconDirection () const noexcept;

void updateGuildIcon();

signals:
void selectedChanged();
void viewModeChanged();
void viewIconDirectionChanged();

public slots:
void updateMessages();
Expand All @@ -52,4 +60,5 @@ class GuildsModel : public QAbstractListModel
int m_selected{ -1 };
ChannelsModel m_channelsModel;
ViewMode m_viewMode;
ViewIconDirection m_viewIconDirection;
};
2 changes: 2 additions & 0 deletions src/qml/GuildsBar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Rectangle {
visible: hmi.guildModelVisible
clip: true
boundsBehavior: ListView.StopAtBounds
layoutDirection: Qt.LeftToRight
orientation: hmi.guildsModel.viewIconDirection === ViewIconDirection.Horizontal ? ListView.Horizontal : ListView.Vertical

delegate: Item {
height: txt.visible ? txt.height : img.height
Expand Down
12 changes: 7 additions & 5 deletions src/qml/Settings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,25 @@ Rectangle {
}

ListView {
id: lw

anchors {
top: title.bottom
bottom: okButton.top
}

model: settingsModel

DelegateChooser {
delegate: DelegateChooser {
id: chooser

role: "typeRole"

DelegateChoice {
roleValue: 0

Row {
readonly property int listIdx: index
spacing: 5

Text {
Expand All @@ -52,13 +56,11 @@ Rectangle {
anchors.verticalCenter: parent.verticalCenter
currentIndex: startValueRole
onActivated: settingsModel.setParameter(
settingsModel.currentIndex, index)
parent.listIdx, index)
}
}
}
}

delegate: chooser
}

Button {
Expand All @@ -79,4 +81,4 @@ Rectangle {
stackview.pop()
}
}
}
}

0 comments on commit 156612e

Please sign in to comment.