diff --git a/gui/src/channel.hpp b/gui/src/channel.hpp new file mode 100644 index 0000000..acd953c --- /dev/null +++ b/gui/src/channel.hpp @@ -0,0 +1,52 @@ +#ifndef FEDIPOTATO_GUI_CHANNEL_HPP +#define FEDIPOTATO_GUI_CHANNEL_HPP + +#include +#include +#include + +namespace FediPotato +{ + + //! Identifier for ChannelItem. + enum class id_channel + { + none, + tl_home, + tl_instance, + tl_federated, + conversations, + hashtag, + filter + }; + +//! An Item for use with #treeview_channel. +class ChannelItem : public QStandardItem +{ +public: + ChannelItem(const QString &text, id_channel identifier) + : _identifier{identifier} + { + setText(text); + } + +public: + [[nodiscard]] + id_channel identifier() const + { + return _identifier; + } + + [[nodiscard]] + int type() const override + { + return QStandardItem::UserType; + } + +private: + const id_channel _identifier; +}; + +} // namespace FediPotato + +#endif // FEDIPOTATO_GUI_CHANNEL_HPP diff --git a/gui/src/window_main.cpp b/gui/src/window_main.cpp index 2cc766a..a2d76ae 100644 --- a/gui/src/window_main.cpp +++ b/gui/src/window_main.cpp @@ -15,23 +15,63 @@ */ #include "window_main.hpp" +#include "channel.hpp" #include "dialog_about.hpp" #include #include +#include +#include +#include namespace FediPotato { WindowMain::WindowMain(QMainWindow *parent) : QMainWindow(parent) + , _model_channel(new QStandardItemModel(this)) { setupUi(this); + + add_account(); +} + +void WindowMain::add_account() +{ + QStandardItem *item_root{_model_channel->invisibleRootItem()}; + auto *item_account{new ChannelItem("@user@example.com", id_channel::none)}; + item_root->appendRow(item_account); + + // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) + item_account->appendRow(new ChannelItem("Home Timeline", + id_channel::tl_home)); + // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) + item_account->appendRow(new ChannelItem("Instance Timeline", + id_channel::tl_instance)); + // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) + item_account->appendRow(new ChannelItem("Federated Timeline", + id_channel::tl_federated)); + // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) + item_account->appendRow(new ChannelItem("Conversations", + id_channel::conversations)); + // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) + item_account->appendRow(new ChannelItem("#tea", + id_channel::hashtag)); + // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) + item_account->appendRow(new ChannelItem("#FediPotato", + id_channel::hashtag)); + + treeview_channel->setModel(_model_channel); + treeview_channel->expandAll(); + + QFont font_channel{treeview_channel->font()}; + font_channel.setPointSize(font_channel.pointSize() + 2); + treeview_channel->setFont(font_channel); } void WindowMain::show_about() { - auto *dlg = new DialogAbout(); // NOLINT(cppcoreguidelines-owning-memory) + auto *dlg{new DialogAbout()}; // NOLINT(cppcoreguidelines-owning-memory) dlg->show(); } @@ -40,5 +80,48 @@ void WindowMain::open_website() QDesktopServices::openUrl(QUrl("http://fedipotato.org/")); } +void WindowMain::clicked_channel(const QModelIndex &index) +{ + auto item{dynamic_cast(_model_channel->itemFromIndex(index))}; + + switch (item->identifier()) + { + case id_channel::none: + { + qDebug() << "None."; + break; + } + case id_channel::tl_home: + { + qDebug() << "Home TL."; + break; + } + case id_channel::tl_instance: + { + qDebug() << "Instance TL."; + break; + } + case id_channel::tl_federated: + { + qDebug() << "Federated TL."; + break; + } + case id_channel::conversations: + { + qDebug() << "Conversations."; + break; + } + case id_channel::hashtag: + { + qDebug() << "Hashtag."; + break; + } + case id_channel::filter: + { + qDebug() << "Filter."; + break; + } + } +} } // namespace FediPotato diff --git a/gui/src/window_main.hpp b/gui/src/window_main.hpp index 20f0056..dcb2d25 100644 --- a/gui/src/window_main.hpp +++ b/gui/src/window_main.hpp @@ -2,9 +2,13 @@ #define FEDIPOTATO_GUI_WINDOW_MAIN_HPP #include "../ui/ui_window_main.h" +#include "channel.hpp" #include #include +#include +#include +#include namespace FediPotato { @@ -32,11 +36,16 @@ public: //! Move assignment operator WindowMain& operator=(WindowMain &&other) noexcept = delete; -public: +private: + QStandardItemModel *_model_channel; + +private: + void add_account(); private slots: static void show_about(); static void open_website(); + void clicked_channel(const QModelIndex &index); }; } // namespace FediPotato diff --git a/gui/ui/window_main.ui b/gui/ui/window_main.ui index 811179c..cea5535 100644 --- a/gui/ui/window_main.ui +++ b/gui/ui/window_main.ui @@ -13,7 +13,40 @@ FediPotato - + + + + + + + + + 0 + 0 + + + + QAbstractItemView::NoEditTriggers + + + Qt::ElideNone + + + true + + + + + + + QAbstractItemView::NoEditTriggers + + + + + + + @@ -27,6 +60,7 @@ &FediPotato + @@ -58,6 +92,11 @@ About FediPotato + + + Add account + + @@ -109,9 +148,26 @@ + + treeview_channel + clicked(QModelIndex) + WindowMain + clicked_channel(QModelIndex) + + + 137 + 300 + + + 399 + 299 + + + show_about() open_website() + clicked_channel(QModelIndex)