Added newspaper view widget.

This commit is contained in:
Martin Rotter 2016-04-03 06:49:00 +02:00
parent 2eb40949c9
commit 724165b0dd
8 changed files with 228 additions and 8 deletions

View File

@ -261,8 +261,8 @@ void FeedMessageViewer::createConnections() {
connect(m_feedsView->sourceModel(), SIGNAL(feedsUpdateStarted()), this, SLOT(onFeedsUpdateStarted()));
// Message openers.
connect(m_messagesView, SIGNAL(openMessagesInNewspaperView(QList<Message>)),
form_main->m_ui->m_tabWidget, SLOT(addBrowserWithMessages(QList<Message>)));
connect(m_messagesView, SIGNAL(openMessagesInNewspaperView(RootItem*,QList<Message>)),
form_main->m_ui->m_tabWidget, SLOT(addBrowserWithMessages(RootItem*,QList<Message>)));
connect(m_feedsView, SIGNAL(openMessagesInNewspaperView(QList<Message>)),
form_main->m_ui->m_tabWidget, SLOT(addBrowserWithMessages(QList<Message>)));

View File

@ -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()));

View File

@ -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<Message> &messages);
void openMessagesInNewspaperView(RootItem *root, const QList<Message> &messages);
// Notify others about message selections.
void currentMessageChanged(const Message &message, RootItem *root);

View File

@ -0,0 +1,58 @@
// This file is part of RSS Guard.
//
// Copyright (C) 2011-2016 by Martin Rotter <rotter.martinos@gmail.com>
//
// 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 <http://www.gnu.org/licenses/>.
#include "gui/newspaperpreviewer.h"
#include "gui/messagepreviewer.h"
NewspaperPreviewer::NewspaperPreviewer(RootItem *root, QList<Message> 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
}
}

View File

@ -0,0 +1,58 @@
// This file is part of RSS Guard.
//
// Copyright (C) 2011-2016 by Martin Rotter <rotter.martinos@gmail.com>
//
// 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 <http://www.gnu.org/licenses/>.
#ifndef NEWSPAPERPREVIEWER_H
#define NEWSPAPERPREVIEWER_H
#include <QWidget>
#include "gui/tabcontent.h"
#include "ui_newspaperpreviewer.h"
#include "core/message.h"
#include "services/abstract/rootitem.h"
#include <QPointer>
namespace Ui {
class NewspaperPreviewer;
}
class RootItem;
class NewspaperPreviewer : public TabContent {
Q_OBJECT
public:
explicit NewspaperPreviewer(RootItem *root, QList<Message> messages, QWidget *parent = 0);
virtual ~NewspaperPreviewer();
private slots:
void showMoreMessages();
signals:
void requestMessageListReload(bool mark_current_as_read);
private:
QScopedPointer<Ui::NewspaperPreviewer> m_ui;
QPointer<RootItem> m_root;
QList<Message> m_messages;
};
#endif // NEWSPAPERPREVIEWER_H

View File

@ -0,0 +1,102 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>NewspaperPreviewer</class>
<widget class="QWidget" name="NewspaperPreviewer">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>398</width>
<height>298</height>
</rect>
</property>
<layout class="QVBoxLayout" name="m_layout">
<item>
<layout class="QHBoxLayout" name="m_btnLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="m_btnShowMoreMessages">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>246</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -26,6 +26,7 @@
#include "gui/feedmessageviewer.h"
#include "gui/plaintoolbutton.h"
#include "gui/dialogs/formmain.h"
#include "gui/newspaperpreviewer.h"
#include <QMenu>
#include <QToolButton>
@ -239,9 +240,9 @@ int TabWidget::insertTab(int index, QWidget *widget, const QString &label, const
return tab_index;
}
int TabWidget::addBrowserWithMessages(const QList<Message> &messages) {
// TODO: TODO - volano kdyz se maji zobrazit zpravy v novinovem nahledu
return 0; /* new index */
int TabWidget::addBrowserWithMessages(RootItem *root, const QList<Message> &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) {

View File

@ -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<Message> &messages);
int addBrowserWithMessages(RootItem *root, const QList<Message> &messages);
private:
PlainToolButton *m_btnMainMenu;