X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Fbufferview.cpp;h=7c4e6c5ef5a250c7b18b2dd78689460ec79daef0;hp=c8834341ce871500fc3fc026b228e18645ef24b3;hb=09fea00d02da49748b6a040752759eab16ccd392;hpb=9cd9c0a87ff92b2cdac7bd5a7efdbcc924b57b48 diff --git a/src/uisupport/bufferview.cpp b/src/uisupport/bufferview.cpp index c8834341..7c4e6c5e 100644 --- a/src/uisupport/bufferview.cpp +++ b/src/uisupport/bufferview.cpp @@ -18,6 +18,9 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include "bufferview.h" + +#include #include #include #include @@ -26,8 +29,6 @@ #include #include -#include "bufferview.h" - #include "action.h" #include "buffermodel.h" #include "bufferviewfilter.h" @@ -42,23 +43,64 @@ #include "quasselui.h" #include "uisettings.h" +bool TristateDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) { + if(event->type() != QEvent::MouseButtonRelease) + return QStyledItemDelegate::editorEvent(event, model, option, index); + + if(!(model->flags(index) & Qt::ItemIsUserCheckable)) + return QStyledItemDelegate::editorEvent(event, model, option, index); + + QVariant value = index.data(Qt::CheckStateRole); + if(!value.isValid()) + return QStyledItemDelegate::editorEvent(event, model, option, index); + + QStyleOptionViewItemV4 viewOpt(option); + initStyleOption(&viewOpt, index); + + QRect checkRect = viewOpt.widget->style()->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, &viewOpt, viewOpt.widget); + QMouseEvent *me = static_cast(event); + + if(me->button() != Qt::LeftButton || !checkRect.contains(me->pos())) + return QStyledItemDelegate::editorEvent(event, model, option, index); + + Qt::CheckState state = static_cast(value.toInt()); + if(state == Qt::Unchecked) + state = Qt::PartiallyChecked; + else if(state == Qt::PartiallyChecked) + state = Qt::Checked; + else + state = Qt::Unchecked; + model->setData(index, state, Qt::CheckStateRole); + return true; +} + + + + /***************************************** * The TreeView showing the Buffers *****************************************/ // Please be carefull when reimplementing methods which are used to inform the view about changes to the data // to be on the safe side: call QTreeView's method aswell -BufferView::BufferView(QWidget *parent) : QTreeView(parent) { +BufferView::BufferView(QWidget *parent) + : QTreeView(parent) +{ connect(this, SIGNAL(collapsed(const QModelIndex &)), SLOT(on_collapse(const QModelIndex &))); connect(this, SIGNAL(expanded(const QModelIndex &)), SLOT(on_expand(const QModelIndex &))); setSelectionMode(QAbstractItemView::ExtendedSelection); + + QAbstractItemDelegate *oldDelegate = itemDelegate(); + TristateDelegate *tristateDelegate = new TristateDelegate(this); + setItemDelegate(tristateDelegate); + delete oldDelegate; } void BufferView::init() { - setIndentation(10); header()->setContextMenuPolicy(Qt::ActionsContextMenu); hideColumn(1); hideColumn(2); + setIndentation(5); expandAll(); setAnimated(true); @@ -345,20 +387,36 @@ void BufferView::contextMenuEvent(QContextMenuEvent *event) { QModelIndex index = indexAt(event->pos()); if(!index.isValid()) index = rootIndex(); - if(!index.isValid()) - return; QMenu contextMenu(this); - addActionsToMenu(&contextMenu, index); + + if(index.isValid()) { + addActionsToMenu(&contextMenu, index); + } + + addFilterActions(&contextMenu, index); + if(!contextMenu.actions().isEmpty()) contextMenu.exec(QCursor::pos()); - } void BufferView::addActionsToMenu(QMenu *contextMenu, const QModelIndex &index) { Client::mainUi()->actionProvider()->addActions(contextMenu, index, this, "menuActionTriggered", (bool)config()); } +void BufferView::addFilterActions(QMenu *contextMenu, const QModelIndex &index) { + BufferViewFilter *filter = qobject_cast(model()); + if(filter) { + QList filterActions = filter->actions(index); + if(!filterActions.isEmpty()) { + contextMenu->addSeparator(); + foreach(QAction *action, filterActions) { + contextMenu->addAction(action); + } + } + } +} + void BufferView::menuActionTriggered(QAction *result) { NetworkModelActionProvider::ActionType type = (NetworkModelActionProvider::ActionType)result->data().toInt(); switch(type) {