From 724165b0ddd705e674f59bacf2e4177b0b464bf2 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Sun, 3 Apr 2016 06:49:00 +0200 Subject: [PATCH] Added newspaper view widget. --- src/gui/feedmessageviewer.cpp | 4 +- src/gui/messagesview.cpp | 2 +- src/gui/messagesview.h | 2 +- src/gui/newspaperpreviewer.cpp | 58 +++++++++++++++++++ src/gui/newspaperpreviewer.h | 58 +++++++++++++++++++ src/gui/newspaperpreviewer.ui | 102 +++++++++++++++++++++++++++++++++ src/gui/tabwidget.cpp | 7 ++- src/gui/tabwidget.h | 3 +- 8 files changed, 228 insertions(+), 8 deletions(-) create mode 100644 src/gui/newspaperpreviewer.cpp create mode 100644 src/gui/newspaperpreviewer.h create mode 100644 src/gui/newspaperpreviewer.ui diff --git a/src/gui/feedmessageviewer.cpp b/src/gui/feedmessageviewer.cpp index 66c7549d6..68f598dcf 100755 --- a/src/gui/feedmessageviewer.cpp +++ b/src/gui/feedmessageviewer.cpp @@ -261,8 +261,8 @@ void FeedMessageViewer::createConnections() { connect(m_feedsView->sourceModel(), SIGNAL(feedsUpdateStarted()), this, SLOT(onFeedsUpdateStarted())); // Message openers. - connect(m_messagesView, SIGNAL(openMessagesInNewspaperView(QList)), - form_main->m_ui->m_tabWidget, SLOT(addBrowserWithMessages(QList))); + connect(m_messagesView, SIGNAL(openMessagesInNewspaperView(RootItem*,QList)), + form_main->m_ui->m_tabWidget, SLOT(addBrowserWithMessages(RootItem*,QList))); connect(m_feedsView, SIGNAL(openMessagesInNewspaperView(QList)), form_main->m_ui->m_tabWidget, SLOT(addBrowserWithMessages(QList))); diff --git a/src/gui/messagesview.cpp b/src/gui/messagesview.cpp index 836bd32b7..79bc5d96b 100755 --- a/src/gui/messagesview.cpp +++ b/src/gui/messagesview.cpp @@ -258,7 +258,7 @@ void MessagesView::openSelectedMessagesInternally() { } if (!messages.isEmpty()) { - emit openMessagesInNewspaperView(messages); + emit openMessagesInNewspaperView(m_sourceModel->loadedItem(), messages); // Finally, mark opened messages as read. QTimer::singleShot(0, this, SLOT(markSelectedMessagesRead())); diff --git a/src/gui/messagesview.h b/src/gui/messagesview.h index 2f79d0c9f..5c5f66bec 100755 --- a/src/gui/messagesview.h +++ b/src/gui/messagesview.h @@ -92,7 +92,7 @@ class MessagesView : public QTreeView { // Link/message openers. void openLinkNewTab(const QString &link); void openLinkMiniBrowser(const QString &link); - void openMessagesInNewspaperView(const QList &messages); + void openMessagesInNewspaperView(RootItem *root, const QList &messages); // Notify others about message selections. void currentMessageChanged(const Message &message, RootItem *root); diff --git a/src/gui/newspaperpreviewer.cpp b/src/gui/newspaperpreviewer.cpp new file mode 100644 index 000000000..0d9ddd66c --- /dev/null +++ b/src/gui/newspaperpreviewer.cpp @@ -0,0 +1,58 @@ +// This file is part of RSS Guard. +// +// Copyright (C) 2011-2016 by Martin Rotter +// +// RSS Guard is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// RSS Guard is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with RSS Guard. If not, see . + +#include "gui/newspaperpreviewer.h" + +#include "gui/messagepreviewer.h" + + +NewspaperPreviewer::NewspaperPreviewer(RootItem *root, QList messages, QWidget *parent) + : TabContent(parent), m_ui(new Ui::NewspaperPreviewer), m_root(root), m_messages(messages) { + m_ui->setupUi(this); + connect(m_ui->m_btnShowMoreMessages, SIGNAL(clicked(bool)), this, SLOT(showMoreMessages())); + showMoreMessages(); +} + +NewspaperPreviewer::~NewspaperPreviewer() { +} + +void NewspaperPreviewer::showMoreMessages() { + if (!m_root.isNull()) { + for (int i = 0; i < 10 && !m_messages.isEmpty(); i++) { + Message msg = m_messages.takeFirst(); + MessagePreviewer *prev = new MessagePreviewer(this); + + connect(prev, SIGNAL(requestMessageListReload(bool)), this, SIGNAL(requestMessageListReload(bool))); + + prev->setFixedHeight(300); + prev->loadMessage(msg, m_root); + m_ui->m_layout->insertWidget(m_ui->m_layout->count() - 2, prev); + } + + m_ui->m_btnShowMoreMessages->setText(tr("Show more messages (%n remaining)", "", m_messages.size())); + m_ui->m_btnShowMoreMessages->setEnabled(!m_messages.isEmpty()); + + // TODO: pokračovat, pridat signal void requestMessageListReload(bool mark_current_as_read); + // ktery bude forwardovar tentyz signal z toho message previeweru kazdeho + // a ten signal navazat na obnoveni seznamu zprav + // + // taky opravit spojeni v pripade ze se zada o novinovy nahled z feedviewu + } + else { + // TODO: ukazat chybu + } +} diff --git a/src/gui/newspaperpreviewer.h b/src/gui/newspaperpreviewer.h new file mode 100644 index 000000000..253201659 --- /dev/null +++ b/src/gui/newspaperpreviewer.h @@ -0,0 +1,58 @@ +// This file is part of RSS Guard. +// +// Copyright (C) 2011-2016 by Martin Rotter +// +// RSS Guard is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// RSS Guard is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with RSS Guard. If not, see . + +#ifndef NEWSPAPERPREVIEWER_H +#define NEWSPAPERPREVIEWER_H + +#include + +#include "gui/tabcontent.h" + +#include "ui_newspaperpreviewer.h" + +#include "core/message.h" +#include "services/abstract/rootitem.h" + +#include + + +namespace Ui { + class NewspaperPreviewer; +} + +class RootItem; + +class NewspaperPreviewer : public TabContent { + Q_OBJECT + + public: + explicit NewspaperPreviewer(RootItem *root, QList messages, QWidget *parent = 0); + virtual ~NewspaperPreviewer(); + + private slots: + void showMoreMessages(); + + signals: + void requestMessageListReload(bool mark_current_as_read); + + private: + QScopedPointer m_ui; + QPointer m_root; + QList m_messages; +}; + +#endif // NEWSPAPERPREVIEWER_H diff --git a/src/gui/newspaperpreviewer.ui b/src/gui/newspaperpreviewer.ui new file mode 100644 index 000000000..6dfc2f57b --- /dev/null +++ b/src/gui/newspaperpreviewer.ui @@ -0,0 +1,102 @@ + + + NewspaperPreviewer + + + + 0 + 0 + 400 + 300 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + true + + + + + 0 + 0 + 398 + 298 + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + + 20 + 246 + + + + + + + + + + + + + diff --git a/src/gui/tabwidget.cpp b/src/gui/tabwidget.cpp index abdca760e..8a4a183bd 100755 --- a/src/gui/tabwidget.cpp +++ b/src/gui/tabwidget.cpp @@ -26,6 +26,7 @@ #include "gui/feedmessageviewer.h" #include "gui/plaintoolbutton.h" #include "gui/dialogs/formmain.h" +#include "gui/newspaperpreviewer.h" #include #include @@ -239,9 +240,9 @@ int TabWidget::insertTab(int index, QWidget *widget, const QString &label, const return tab_index; } -int TabWidget::addBrowserWithMessages(const QList &messages) { - // TODO: TODO - volano kdyz se maji zobrazit zpravy v novinovem nahledu - return 0; /* new index */ +int TabWidget::addBrowserWithMessages(RootItem *root, const QList &messages) { + NewspaperPreviewer *prev = new NewspaperPreviewer(root, messages, this); + return addTab(prev, qApp->icons()->fromTheme(QSL("item-newspaper")), tr("Newspaper view"), TabBar::Closable); } void TabWidget::changeIcon(int index, const QIcon &new_icon) { diff --git a/src/gui/tabwidget.h b/src/gui/tabwidget.h index cb09a1e1d..b5f5f828c 100755 --- a/src/gui/tabwidget.h +++ b/src/gui/tabwidget.h @@ -28,6 +28,7 @@ class QMenu; class PlainToolButton; class Message; +class RootItem; class FeedMessageViewer; class TabWidget : public QTabWidget { @@ -111,7 +112,7 @@ class TabWidget : public QTabWidget { void closeAllTabsExceptCurrent(); // Open single or multiple (newspaper mode) messages in new tab. - int addBrowserWithMessages(const QList &messages); + int addBrowserWithMessages(RootItem *root, const QList &messages); private: PlainToolButton *m_btnMainMenu;