save woprk

This commit is contained in:
Martin Rotter 2023-09-22 14:32:47 +02:00
parent 8b50c209b7
commit 6f7d192a98
5 changed files with 43 additions and 1 deletions

View File

@ -18,6 +18,10 @@ void ArticleListNotificationModel::setArticles(const QList<Message>& msgs) {
emit previousPagePossibleChanged(previousPageAvailable());
}
Message ArticleListNotificationModel::message(const QModelIndex& idx) const {
return m_articles.at((m_currentPage * NOTIFICATIONS_PAGE_SIZE) + idx.row());
}
void ArticleListNotificationModel::nextPage() {
m_currentPage++;
reloadWholeLayout();

View File

@ -16,6 +16,8 @@ class ArticleListNotificationModel : public QAbstractListModel {
void setArticles(const QList<Message>& msgs);
Message message(const QModelIndex& idx) const;
void nextPage();
void previousPage();

View File

@ -5,6 +5,8 @@
#include "core/articlelistnotificationmodel.h"
#include "miscellaneous/iconfactory.h"
#include <QTreeView>
ArticleListNotification::ArticleListNotification(QWidget* parent)
: BaseToastNotification(parent), m_model(new ArticleListNotificationModel(this)) {
m_ui.setupUi(this);
@ -25,6 +27,12 @@ ArticleListNotification::ArticleListNotification(QWidget* parent)
&ArticleListNotificationModel::previousPagePossibleChanged,
m_ui.m_btnPreviousPage,
&PlainToolButton::setEnabled);
connect(m_ui.m_btnNextPage, &PlainToolButton::clicked, m_model, &ArticleListNotificationModel::nextPage);
connect(m_ui.m_btnPreviousPage, &PlainToolButton::clicked, m_model, &ArticleListNotificationModel::previousPage);
connect(m_ui.m_treeArticles->selectionModel(),
&QItemSelectionModel::currentChanged,
this,
&ArticleListNotificationModel::onMessageSelected);
m_ui.m_treeArticles->setAttribute(Qt::WA_NoSystemBackground, true);
@ -56,6 +64,20 @@ void ArticleListNotification::loadResults(const QHash<Feed*, QList<Message>>& ne
}
}
void ArticleListNotification::onMessageSelected(const QModelIndex& current, const QModelIndex& previous) {
m_ui.m_btnOpenArticleList->setEnabled(current.isValid());
m_ui.m_btnOpenWebBrowser->setEnabled(current.isValid());
}
void ArticleListNotification::showFeed(int index) {
m_model->setArticles(m_newMessages.value(m_ui.m_cmbFeeds->itemData(index).value<Feed*>()));
}
Message ArticleListNotification::selectedMessage() const {
if (m_ui.m_treeArticles->currentIndex().isValid()) {
return m_model->message(m_ui.m_treeArticles->currentIndex());
}
else {
throw ApplicationException("message cannot be loaded, wrong index");
}
}

View File

@ -21,8 +21,12 @@ class ArticleListNotification : public BaseToastNotification {
void loadResults(const QHash<Feed*, QList<Message>>& new_messages);
private slots:
void onMessageSelected(const QModelIndex& current, const QModelIndex& previous);
void showFeed(int index);
private:
Message selectedMessage() const;
private:
Ui::ArticleListNotification m_ui;
ArticleListNotificationModel* m_model;

View File

@ -75,13 +75,23 @@
<item row="2" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QComboBox" name="m_cmbFeeds"/>
<widget class="QComboBox" name="m_cmbFeeds">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Minimum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>