2013-11-17 16:41:44 +01:00
|
|
|
#include <QHeaderView>
|
2013-11-18 21:45:15 +01:00
|
|
|
#include <QKeyEvent>
|
2013-11-17 16:41:44 +01:00
|
|
|
|
2013-10-13 16:12:15 +02:00
|
|
|
#include "gui/messagesview.h"
|
2013-11-15 22:09:38 +01:00
|
|
|
#include "core/messagesproxymodel.h"
|
|
|
|
#include "core/messagesmodel.h"
|
2013-10-13 16:12:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
MessagesView::MessagesView(QWidget *parent) : QTreeView(parent) {
|
2013-11-15 22:09:38 +01:00
|
|
|
m_proxyModel = new MessagesProxyModel(this);
|
2013-11-17 16:41:44 +01:00
|
|
|
m_sourceModel = m_proxyModel->sourceModel();
|
2013-11-15 22:09:38 +01:00
|
|
|
|
|
|
|
setModel(m_proxyModel);
|
2013-11-18 21:45:15 +01:00
|
|
|
|
2013-11-19 21:25:55 +01:00
|
|
|
// Setup column resize strategies.
|
|
|
|
header()->setSectionResizeMode(MSG_DB_ID_INDEX, QHeaderView::Interactive);
|
|
|
|
header()->setSectionResizeMode(MSG_DB_READ_INDEX, QHeaderView::ResizeToContents);
|
|
|
|
header()->setSectionResizeMode(MSG_DB_DELETED_INDEX, QHeaderView::Interactive);
|
|
|
|
header()->setSectionResizeMode(MSG_DB_IMPORTANT_INDEX, QHeaderView::ResizeToContents);
|
|
|
|
header()->setSectionResizeMode(MSG_DB_FEED_INDEX, QHeaderView::Interactive);
|
|
|
|
header()->setSectionResizeMode(MSG_DB_TITLE_INDEX, QHeaderView::Stretch);
|
|
|
|
header()->setSectionResizeMode(MSG_DB_URL_INDEX, QHeaderView::Interactive);
|
|
|
|
header()->setSectionResizeMode(MSG_DB_AUTHOR_INDEX, QHeaderView::Interactive);
|
|
|
|
header()->setSectionResizeMode(MSG_DB_DCREATED_INDEX, QHeaderView::Interactive);
|
|
|
|
header()->setSectionResizeMode(MSG_DB_DUPDATED_INDEX, QHeaderView::Interactive);
|
|
|
|
header()->setSectionResizeMode(MSG_DB_CONTENTS_INDEX, QHeaderView::Interactive);
|
|
|
|
|
|
|
|
// Hide columns.
|
|
|
|
hideColumn(MSG_DB_ID_INDEX);
|
|
|
|
hideColumn(MSG_DB_DELETED_INDEX);
|
|
|
|
hideColumn(MSG_DB_FEED_INDEX);
|
|
|
|
hideColumn(MSG_DB_URL_INDEX);
|
|
|
|
hideColumn(MSG_DB_CONTENTS_INDEX);
|
|
|
|
|
|
|
|
|
|
|
|
//hideColumn(0);
|
2013-11-18 21:45:15 +01:00
|
|
|
|
|
|
|
// NOTE: It is recommended to call this after the model is set
|
|
|
|
// due to sorting performance.
|
2013-11-15 22:09:38 +01:00
|
|
|
setupAppearance();
|
2013-10-13 16:12:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MessagesView::~MessagesView() {
|
|
|
|
qDebug("Destroying MessagesView instance.");
|
|
|
|
}
|
2013-11-15 22:09:38 +01:00
|
|
|
|
2013-11-17 20:42:02 +01:00
|
|
|
MessagesModel *MessagesView::sourceModel() {
|
|
|
|
return m_sourceModel;
|
|
|
|
}
|
|
|
|
|
|
|
|
MessagesProxyModel *MessagesView::model() {
|
|
|
|
return m_proxyModel;
|
|
|
|
}
|
|
|
|
|
2013-11-19 21:25:55 +01:00
|
|
|
void MessagesView::setSortingEnabled(bool enable) {
|
|
|
|
QTreeView::setSortingEnabled(enable);
|
|
|
|
header()->setSortIndicatorShown(false);
|
|
|
|
}
|
2013-11-17 20:42:02 +01:00
|
|
|
|
2013-11-19 21:25:55 +01:00
|
|
|
void MessagesView::setupAppearance() {
|
|
|
|
header()->setStretchLastSection(false);
|
2013-11-18 21:45:15 +01:00
|
|
|
setUniformRowHeights(true);
|
2013-11-15 22:09:38 +01:00
|
|
|
setAcceptDrops(false);
|
|
|
|
setDragEnabled(false);
|
|
|
|
setDragDropMode(QAbstractItemView::NoDragDrop);
|
|
|
|
setExpandsOnDoubleClick(false);
|
|
|
|
setRootIsDecorated(false);
|
2013-11-15 22:24:38 +01:00
|
|
|
setItemsExpandable(false);
|
2013-11-18 21:45:15 +01:00
|
|
|
setSortingEnabled(true);
|
2013-11-17 16:41:44 +01:00
|
|
|
setAllColumnsShowFocus(true);
|
|
|
|
setSelectionMode(QAbstractItemView::ExtendedSelection);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MessagesView::selectionChanged(const QItemSelection &selected,
|
|
|
|
const QItemSelection &deselected) {
|
|
|
|
QTreeView::selectionChanged(selected, deselected);
|
|
|
|
}
|
|
|
|
|
2013-11-18 21:45:15 +01:00
|
|
|
void MessagesView::keyPressEvent(QKeyEvent *event) {
|
|
|
|
QTreeView::keyPressEvent(event);
|
|
|
|
}
|
|
|
|
|
2013-11-17 16:41:44 +01:00
|
|
|
void MessagesView::currentChanged(const QModelIndex ¤t,
|
|
|
|
const QModelIndex &previous) {
|
2013-11-24 14:44:17 +01:00
|
|
|
QModelIndex mapped_current = m_proxyModel->mapToSource(current);
|
2013-11-17 16:41:44 +01:00
|
|
|
|
|
|
|
|
2013-11-24 14:44:17 +01:00
|
|
|
qDebug("Current row changed, row [%d,%d] source %d %d",
|
2013-11-17 16:41:44 +01:00
|
|
|
current.row(), current.column(),
|
2013-11-24 14:44:17 +01:00
|
|
|
mapped_current.row(), mapped_current.column());
|
2013-11-17 16:41:44 +01:00
|
|
|
|
2013-11-24 14:44:17 +01:00
|
|
|
m_sourceModel->setMessageRead(mapped_current.row(), 1);
|
|
|
|
emit currentMessageChanged(m_sourceModel->messageAt(mapped_current.row()));
|
2013-11-19 21:25:55 +01:00
|
|
|
|
2013-11-17 16:41:44 +01:00
|
|
|
QTreeView::currentChanged(current, previous);
|
2013-11-15 22:09:38 +01:00
|
|
|
}
|
2013-11-24 14:44:17 +01:00
|
|
|
|
|
|
|
void MessagesView::setSelectedMessagesReadStatus(int read) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void MessagesView::setAllMessagesRead() {
|
|
|
|
selectAll();
|
|
|
|
QModelIndexList selected_indexes = selectedIndexes();
|
|
|
|
QModelIndexList mapp;
|
|
|
|
|
|
|
|
foreach (const QModelIndex &index, selected_indexes) {
|
|
|
|
mapp << m_proxyModel->mapToSource(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_sourceModel->switchBatchMessageImportance(mapp);
|
|
|
|
}
|