Put example data in channel TreeView.
This commit is contained in:
parent
a722c0ccb4
commit
e73a55e1ca
|
@ -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
|
|
@ -15,23 +15,63 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "window_main.hpp"
|
#include "window_main.hpp"
|
||||||
|
#include "channel.hpp"
|
||||||
#include "dialog_about.hpp"
|
#include "dialog_about.hpp"
|
||||||
|
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
#include <QStandardItem>
|
||||||
|
#include <QFont>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
namespace FediPotato
|
namespace FediPotato
|
||||||
{
|
{
|
||||||
|
|
||||||
WindowMain::WindowMain(QMainWindow *parent)
|
WindowMain::WindowMain(QMainWindow *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
|
, _model_channel(new QStandardItemModel(this))
|
||||||
{
|
{
|
||||||
setupUi(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()
|
void WindowMain::show_about()
|
||||||
{
|
{
|
||||||
auto *dlg = new DialogAbout(); // NOLINT(cppcoreguidelines-owning-memory)
|
auto *dlg{new DialogAbout()}; // NOLINT(cppcoreguidelines-owning-memory)
|
||||||
dlg->show();
|
dlg->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,5 +80,48 @@ void WindowMain::open_website()
|
||||||
QDesktopServices::openUrl(QUrl("http://fedipotato.org/"));
|
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
|
} // namespace FediPotato
|
||||||
|
|
|
@ -2,9 +2,13 @@
|
||||||
#define FEDIPOTATO_GUI_WINDOW_MAIN_HPP
|
#define FEDIPOTATO_GUI_WINDOW_MAIN_HPP
|
||||||
|
|
||||||
#include "../ui/ui_window_main.h"
|
#include "../ui/ui_window_main.h"
|
||||||
|
#include "channel.hpp"
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QStandardItemModel>
|
||||||
|
#include <QModelIndex>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
namespace FediPotato
|
namespace FediPotato
|
||||||
{
|
{
|
||||||
|
@ -32,11 +36,16 @@ public:
|
||||||
//! Move assignment operator
|
//! Move assignment operator
|
||||||
WindowMain& operator=(WindowMain &&other) noexcept = delete;
|
WindowMain& operator=(WindowMain &&other) noexcept = delete;
|
||||||
|
|
||||||
public:
|
private:
|
||||||
|
QStandardItemModel *_model_channel;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void add_account();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
static void show_about();
|
static void show_about();
|
||||||
static void open_website();
|
static void open_website();
|
||||||
|
void clicked_channel(const QModelIndex &index);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace FediPotato
|
} // namespace FediPotato
|
||||||
|
|
|
@ -13,7 +13,40 @@
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>FediPotato</string>
|
<string>FediPotato</string>
|
||||||
</property>
|
</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">
|
<widget class="QMenuBar" name="menubar">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
|
@ -27,6 +60,7 @@
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>&FediPotato</string>
|
<string>&FediPotato</string>
|
||||||
</property>
|
</property>
|
||||||
|
<addaction name="action_account_add"/>
|
||||||
<addaction name="action_quit"/>
|
<addaction name="action_quit"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenu" name="menuHelp">
|
<widget class="QMenu" name="menuHelp">
|
||||||
|
@ -58,6 +92,11 @@
|
||||||
<string>About FediPotato</string>
|
<string>About FediPotato</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="action_account_add">
|
||||||
|
<property name="text">
|
||||||
|
<string>Add account</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections>
|
<connections>
|
||||||
|
@ -109,9 +148,26 @@
|
||||||
</hint>
|
</hint>
|
||||||
</hints>
|
</hints>
|
||||||
</connection>
|
</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>
|
</connections>
|
||||||
<slots>
|
<slots>
|
||||||
<slot>show_about()</slot>
|
<slot>show_about()</slot>
|
||||||
<slot>open_website()</slot>
|
<slot>open_website()</slot>
|
||||||
|
<slot>clicked_channel(QModelIndex)</slot>
|
||||||
</slots>
|
</slots>
|
||||||
</ui>
|
</ui>
|
||||||
|
|
Reference in New Issue