2013-11-17 16:41:44 +01:00
|
|
|
#include <QHeaderView>
|
|
|
|
|
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);
|
|
|
|
setupAppearance();
|
2013-10-13 16:12:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MessagesView::~MessagesView() {
|
|
|
|
qDebug("Destroying MessagesView instance.");
|
|
|
|
}
|
2013-11-15 22:09:38 +01:00
|
|
|
|
|
|
|
void MessagesView::setupAppearance() {
|
|
|
|
setAcceptDrops(false);
|
|
|
|
setDragEnabled(false);
|
|
|
|
setDragDropMode(QAbstractItemView::NoDragDrop);
|
|
|
|
setExpandsOnDoubleClick(false);
|
|
|
|
setRootIsDecorated(false);
|
2013-11-15 22:24:38 +01:00
|
|
|
setItemsExpandable(false);
|
|
|
|
setSortingEnabled(true);
|
2013-11-17 16:41:44 +01:00
|
|
|
setAllColumnsShowFocus(true);
|
|
|
|
setSelectionMode(QAbstractItemView::ExtendedSelection);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MessagesView::selectionChanged(const QItemSelection &selected,
|
|
|
|
const QItemSelection &deselected) {
|
|
|
|
/*
|
|
|
|
if (selected.indexes().size() > 0) {
|
|
|
|
QModelIndex ind = m_proxyModel->mapToSource(selected.indexes().at(0));
|
|
|
|
QModelIndex a = selected.indexes().at(0);
|
|
|
|
|
|
|
|
qDebug("SelectionChanged %d %d source %d %d",
|
|
|
|
selected.indexes().at(0).row(), selected.indexes().at(0).column(),
|
|
|
|
ind.row(), ind.column());
|
|
|
|
|
|
|
|
m_sourceModel->setMessageRead(1, ind.row());
|
|
|
|
|
|
|
|
sortByColumn(header()->sortIndicatorSection(), header()->sortIndicatorOrder());
|
|
|
|
|
|
|
|
QModelIndex new_index = m_proxyModel->mapFromSource(ind);
|
|
|
|
|
|
|
|
// TODO: Buď tady obnovovat celý předchozí výběr nějak
|
|
|
|
// nebo použít starší kod a optimalizovat ho.
|
|
|
|
selectionModel()->clearSelection();
|
|
|
|
selectionModel()->blockSignals(true);
|
|
|
|
setCurrentIndex(new_index);
|
|
|
|
scrollTo(new_index);
|
|
|
|
selectionModel()->select(new_index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows | QItemSelectionModel::Current );
|
|
|
|
selectionModel()->blockSignals(false);
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
QTreeView::selectionChanged(selected, deselected);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MessagesView::currentChanged(const QModelIndex ¤t,
|
|
|
|
const QModelIndex &previous) {
|
|
|
|
QModelIndex ind = m_proxyModel->mapToSource(current);
|
|
|
|
|
|
|
|
|
|
|
|
qDebug("CurrentChanged %d %d source %d %d",
|
|
|
|
current.row(), current.column(),
|
|
|
|
ind.row(), ind.column());
|
|
|
|
|
|
|
|
m_sourceModel->setMessageRead(ind.row(), 1);
|
|
|
|
|
|
|
|
QTreeView::currentChanged(current, previous);
|
2013-11-15 22:09:38 +01:00
|
|
|
}
|