Put example data in channel TreeView.

This commit is contained in:
tastytea 2020-02-26 03:22:52 +01:00
parent a722c0ccb4
commit e73a55e1ca
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
4 changed files with 203 additions and 3 deletions

52
gui/src/channel.hpp Normal file
View File

@ -0,0 +1,52 @@
#ifndef FEDIPOTATO_GUI_CHANNEL_HPP
#define FEDIPOTATO_GUI_CHANNEL_HPP
#include <QStandardItem>
#include <QString>
#include <qstandarditemmodel.h>
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

View File

@ -15,23 +15,63 @@
*/
#include "window_main.hpp"
#include "channel.hpp"
#include "dialog_about.hpp"
#include <QDesktopServices>
#include <QUrl>
#include <QStandardItem>
#include <QFont>
#include <QDebug>
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<ChannelItem*>(_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

View File

@ -2,9 +2,13 @@
#define FEDIPOTATO_GUI_WINDOW_MAIN_HPP
#include "../ui/ui_window_main.h"
#include "channel.hpp"
#include <QMainWindow>
#include <QLabel>
#include <QStandardItemModel>
#include <QModelIndex>
#include <QString>
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

View File

@ -13,7 +13,40 @@
<property name="windowTitle">
<string>FediPotato</string>
</property>
<widget class="QWidget" name="centralwidget"/>
<widget class="QWidget" name="centralWidget">
<layout class="QHBoxLayout" name="vbox_main">
<item>
<layout class="QHBoxLayout" name="hbox_trees">
<item>
<widget class="QTreeView" name="treeview_channel">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="textElideMode">
<enum>Qt::ElideNone</enum>
</property>
<property name="headerHidden">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QTreeView" name="treeview_posts">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
@ -27,6 +60,7 @@
<property name="title">
<string>&amp;FediPotato</string>
</property>
<addaction name="action_account_add"/>
<addaction name="action_quit"/>
</widget>
<widget class="QMenu" name="menuHelp">
@ -58,6 +92,11 @@
<string>About FediPotato</string>
</property>
</action>
<action name="action_account_add">
<property name="text">
<string>Add account</string>
</property>
</action>
</widget>
<resources/>
<connections>
@ -109,9 +148,26 @@
</hint>
</hints>
</connection>
<connection>
<sender>treeview_channel</sender>
<signal>clicked(QModelIndex)</signal>
<receiver>WindowMain</receiver>
<slot>clicked_channel(QModelIndex)</slot>
<hints>
<hint type="sourcelabel">
<x>137</x>
<y>300</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>299</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>show_about()</slot>
<slot>open_website()</slot>
<slot>clicked_channel(QModelIndex)</slot>
</slots>
</ui>