X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Fnickview.cpp;h=1a1c4bbaf9b966ee6732fb8dd11f487b109478cd;hp=ad13a2fb90cd7cee62fb2f0ae87e7a52883dd23f;hb=32a1f050b3292478f3b130c16ad66f22e6eb25c8;hpb=f1823aad7ce73a2dd17807ed4dfde552be7ae769 diff --git a/src/uisupport/nickview.cpp b/src/uisupport/nickview.cpp index ad13a2fb..1a1c4bba 100644 --- a/src/uisupport/nickview.cpp +++ b/src/uisupport/nickview.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-08 by the Quassel Project * + * Copyright (C) 2005-09 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -18,6 +18,8 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include "nickview.h" + #include #include #include @@ -25,11 +27,13 @@ #include "buffermodel.h" #include "client.h" +#include "contextmenuactionprovider.h" +#include "graphicalui.h" #include "nickview.h" #include "nickviewfilter.h" #include "networkmodel.h" -#include "quasselui.h" #include "types.h" +#include "uisettings.h" class ExpandAllEvent : public QEvent { public: @@ -39,6 +43,11 @@ public: NickView::NickView(QWidget *parent) : QTreeView(parent) { + QAbstractItemDelegate *oldDelegate = itemDelegate(); + NickViewDelegate *newDelegate = new NickViewDelegate(this); + setItemDelegate(newDelegate); + delete oldDelegate; + setIndentation(10); setAnimated(true); header()->hide(); @@ -47,10 +56,11 @@ NickView::NickView(QWidget *parent) sortByColumn(0, Qt::AscendingOrder); setContextMenuPolicy(Qt::CustomContextMenu); + setSelectionMode(QAbstractItemView::ExtendedSelection); connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), SLOT(showContextMenu(const QPoint&))); -#if defined Q_WS_QWS or defined Q_WS_X11 +#if defined Q_WS_QWS || defined Q_WS_X11 connect(this, SIGNAL(doubleClicked(QModelIndex)), SLOT(startQuery(QModelIndex))); #else // afaik this is better on Mac and Windows @@ -64,10 +74,16 @@ void NickView::init() { for(int i = 1; i < model()->columnCount(); i++) setColumnHidden(i, true); + + connect(selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), SIGNAL(selectionUpdated())); + connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), SIGNAL(selectionUpdated())); } -void NickView::setModel(QAbstractItemModel *model) { - QTreeView::setModel(model); +void NickView::setModel(QAbstractItemModel *model_) { + if(model()) + disconnect(model(), 0, this, 0); + + QTreeView::setModel(model_); init(); } @@ -84,13 +100,22 @@ void NickView::setRootIndex(const QModelIndex &index) { QCoreApplication::postEvent(this, new ExpandAllEvent); } -void NickView::showContextMenu(const QPoint & pos ) { - QModelIndex index = indexAt(pos); - if(index.data(NetworkModel::ItemTypeRole) != NetworkModel::IrcUserItemType) - return; +QModelIndexList NickView::selectedIndexes() const { + QModelIndexList indexList = QTreeView::selectedIndexes(); + + // make sure the item we clicked on is first + Q_ASSERT(indexList.contains(currentIndex())); + indexList.removeAll(currentIndex()); + indexList.prepend(currentIndex()); + + return indexList; +} + +void NickView::showContextMenu(const QPoint &pos ) { + Q_UNUSED(pos); QMenu contextMenu(this); - Client::mainUi()->actionProvider()->addActions(&contextMenu, index); + GraphicalUi::contextMenuActionProvider()->addActions(&contextMenu, selectedIndexes()); contextMenu.exec(QCursor::pos()); } @@ -137,3 +162,28 @@ void NickView::customEvent(QEvent *event) { } event->accept(); } + + +// **************************************** +// NickViewDelgate +// **************************************** +NickViewDelegate::NickViewDelegate(QObject *parent) + : QStyledItemDelegate(parent) +{ + UiSettings s("QtUiStyle/Colors"); + _FgOnlineStatus = s.value("onlineStatusFG", QVariant(QColor(Qt::black))).value(); + _FgAwayStatus = s.value("awayStatusFG", QVariant(QColor(Qt::gray))).value(); +} + +void NickViewDelegate::initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const { + QStyledItemDelegate::initStyleOption(option, index); + + if(!index.isValid()) + return; + + QColor fgColor = _FgOnlineStatus; + if(!index.data(NetworkModel::ItemActiveRole).toBool()) + fgColor = _FgAwayStatus; + + option->palette.setColor(QPalette::Text, fgColor); +}