diff --git a/src/presentation/tasklistmodel.h b/src/presentation/tasklistmodel.h --- a/src/presentation/tasklistmodel.h +++ b/src/presentation/tasklistmodel.h @@ -54,8 +54,8 @@ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); -private: Domain::Task::Ptr taskForIndex(const QModelIndex &index) const; +private: bool isModelIndexValid(const QModelIndex &index) const; TaskList::Ptr m_taskList; diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt --- a/src/widgets/CMakeLists.txt +++ b/src/widgets/CMakeLists.txt @@ -14,6 +14,7 @@ newpagedialog.cpp newpagedialoginterface.cpp pageview.cpp + printwidget.cpp ) qt4_wrap_ui(widgets_SRCS diff --git a/src/widgets/pageview.h b/src/widgets/pageview.h --- a/src/widgets/pageview.h +++ b/src/widgets/pageview.h @@ -43,6 +43,7 @@ namespace Widgets { class FilterWidget; +class PrintWidget; class PageView : public QWidget { @@ -76,6 +77,7 @@ FilterWidget *m_filterWidget; QTreeView *m_centralView; QLineEdit *m_quickAddEdit; + PrintWidget *m_printWidget; MessageBoxInterface::Ptr m_messageBoxInterface; ApplicationMode m_mode; }; diff --git a/src/widgets/pageview.cpp b/src/widgets/pageview.cpp --- a/src/widgets/pageview.cpp +++ b/src/widgets/pageview.cpp @@ -23,6 +23,7 @@ #include "pageview.h" +#include "printwidget.h" #include #include @@ -87,7 +88,8 @@ m_filterWidget(new FilterWidget(this)), m_centralView(new PageTreeView(this)), m_quickAddEdit(new QLineEdit(this)), - m_mode(mode) + m_mode(mode), + m_printWidget(new PrintWidget(parent)) { m_filterWidget->setObjectName("filterWidget"); @@ -121,6 +123,7 @@ auto layout = new QVBoxLayout; layout->addWidget(m_filterWidget); layout->addWidget(m_centralView); + layout->addWidget(m_printWidget); layout->addLayout(hLayout); setLayout(layout); @@ -134,6 +137,7 @@ addAction(removeItemAction); m_messageBoxInterface = MessageBox::Ptr::create(); + } QObject *PageView::model() const diff --git a/src/widgets/pageview.h b/src/widgets/printwidget.h copy from src/widgets/pageview.h copy to src/widgets/printwidget.h --- a/src/widgets/pageview.h +++ b/src/widgets/printwidget.h @@ -1,6 +1,6 @@ /* This file is part of Zanshin - Copyright 2014 Kevin Ottens + Copyright 2015 Sandro Knauß This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -21,9 +21,8 @@ USA. */ - -#ifndef WIDGETS_PAGEVIEW_H -#define WIDGETS_PAGEVIEW_H +#ifndef WIDGETS_PRINTWIDGET_H +#define WIDGETS_PRINTWIDGET_H #include @@ -32,19 +31,25 @@ #include #include "domain/artifact.h" -#include "messageboxinterface.h" +#include "domain/task.h" class QLineEdit; class QModelIndex; class QTreeView; class QMessageBox; class QMenu; +class QTextDocument; +class QTextEdit; +class QTimer; -namespace Widgets { +namespace Akonadi { + class TaskRepository; + class TaskQueries; +} -class FilterWidget; +namespace Widgets { -class PageView : public QWidget +class PrintWidget : public QWidget { Q_OBJECT public: @@ -53,33 +58,29 @@ NotesOnly, TasksAndNotes }; - explicit PageView(QWidget *parent = 0, ApplicationMode mode = TasksAndNotes); + explicit PrintWidget(QWidget *parent = 0, ApplicationMode mode = TasksAndNotes); QObject *model() const; - MessageBoxInterface::Ptr messageBoxInterface() const; public slots: void setModel(QObject *model); - void setMessageBoxInterface(const MessageBoxInterface::Ptr &interface); - void configurePopupMenu(QMenu *menu, const Domain::Artifact::Ptr &artifact); -signals: - void currentArtifactChanged(const Domain::Artifact::Ptr &artifact); +private: + QObject *m_model; + QTextDocument *m_document; + QTextEdit *m_edit; + QTimer *m_timer; + ApplicationMode m_mode; + Akonadi::TaskRepository *m_repository; + Akonadi::TaskQueries *m_queries; private slots: - void onEditingFinished(); - void onRemoveItemRequested(); - void onCurrentChanged(const QModelIndex ¤t); + void render(); private: - QObject *m_model; - FilterWidget *m_filterWidget; - QTreeView *m_centralView; - QLineEdit *m_quickAddEdit; - MessageBoxInterface::Ptr m_messageBoxInterface; - ApplicationMode m_mode; + QString renderItem(const Domain::Task::Ptr &task); }; } -#endif // WIDGETS_PAGEVIEW_H +#endif // WIDGETS_PRINTWIDGET_H diff --git a/src/widgets/printwidget.cpp b/src/widgets/printwidget.cpp new file mode 100644 --- /dev/null +++ b/src/widgets/printwidget.cpp @@ -0,0 +1,125 @@ +/* This file is part of Zanshin + + Copyright 2015 Sandro Knauß + + This program 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 2 of + the License or (at your option) version 3 or any later version + accepted by the membership of KDE e.V. (or its successor approved + by the membership of KDE e.V.), which shall act as a proxy + defined in Section 14 of version 3 of the license. + + This program 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 this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "printwidget.h" + +#include +#include +#include +#include + +#include + +#include "presentation/artifactfilterproxymodel.h" +#include "presentation/metatypes.h" + +#include "akonadi/akonaditaskqueries.h" +#include "akonadi/akonaditaskrepository.h" +#include "presentation/tasklistmodel.h" + +using namespace Widgets; + +PrintWidget::PrintWidget(QWidget *parent, ApplicationMode mode) + : QWidget(parent), + m_model(0), + m_mode(mode), + m_document(new QTextDocument(this)), + m_edit(new QTextEdit()), + m_timer(new QTimer()), + m_repository(new Akonadi::TaskRepository), + m_queries(new Akonadi::TaskQueries) +{ + m_edit->setDocument(m_document); + + connect(m_timer, SIGNAL(timeout()), SLOT(render())); + m_timer->setInterval(500); + + auto layout = new QVBoxLayout; + layout->addWidget(m_edit); + setLayout(layout); + + auto taskList = m_queries->findAll(); + m_model = new Presentation::TaskListModel(taskList, m_repository, this); + m_timer->start(); +} + +QObject *PrintWidget::model() const +{ + return m_model; +} + +void PrintWidget::setModel(QObject *model) +{ + if (model == m_model) + return; + + m_model = model; + + if (!m_model) { + m_timer->stop(); + return; + } + m_timer->start(); +} + +QString PrintWidget::renderItem(const Domain::Task::Ptr &task) +{ + QString html; + + const auto title = task->title(); + const auto text = task->text(); + const auto done = task->isDone(); + + html = "
"; + html += "

"+title; + if (done) { + html += " "+ i18n("Done"); + } + html +="

"; + + if (!text.isEmpty()) { + html += "

"+text+"

"; + } + + html += "
\n"; + + return html; +} + +void PrintWidget::render() +{ + if (!m_model) { + return; + } + + auto model = static_cast(m_model); + + QString html; + + for(int i=0; irowCount(); i++) { + auto index = model->index(i,0); + html += renderItem(model->taskForIndex(index)); + } + + m_document->setHtml(html); +}