X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Fnickview.cpp;h=0b4a74107f08150bc8f6ae9e940bbbc8ebebd108;hp=bc8d97cc036844182145998e3a24f2e148dd8493;hb=4295cdd849be0ae914387d0f62afb6f653f5f27f;hpb=03896bdccdc8caf15bbce736680ba0f12bc2dc31 diff --git a/src/uisupport/nickview.cpp b/src/uisupport/nickview.cpp index bc8d97cc..0b4a7410 100644 --- a/src/uisupport/nickview.cpp +++ b/src/uisupport/nickview.cpp @@ -18,34 +18,48 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include "nickview.h" -#include "nickmodel.h" - #include #include +#include + +#include "nickview.h" +#include "nickmodel.h" +#include "networkmodel.h" +#include "types.h" +#include "client.h" -NickView::NickView(QWidget *parent) : QTreeView(parent) { - setGeometry(0, 0, 30, 30); - //setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); +NickView::NickView(QWidget *parent) + : QTreeView(parent) +{ setIndentation(10); - header()->hide(); - header()->hideSection(1); setAnimated(true); + header()->hide(); setSortingEnabled(true); sortByColumn(0, Qt::AscendingOrder); - expandAll(); + + setContextMenuPolicy(Qt::CustomContextMenu); + + connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), + this, SLOT(showContextMenu(const QPoint&))); } NickView::~NickView() { +} +void NickView::init() { + if(!model()) + return; -} + for(int i = 1; i < model()->columnCount(); i++) + setColumnHidden(i, true); + expandAll(); +} void NickView::setModel(QAbstractItemModel *model) { - QTreeView::setModel(model); - expandAll(); + QTreeView::setModel(model); + init(); } void NickView::rowsInserted(const QModelIndex &index, int start, int end) { @@ -53,3 +67,19 @@ void NickView::rowsInserted(const QModelIndex &index, int start, int end) { expandAll(); // FIXME We need to do this more intelligently. Maybe a pimped TreeView? } +void NickView::showContextMenu(const QPoint & pos ) { + QModelIndex index = indexAt(pos); + QString username = index.sibling(index.row(), 0).data().toString(); + BufferInfo bufferInfo = index.data(NetworkModel::BufferInfoRole).value(); + + QMenu nickContextMenu(this); + nickContextMenu.addAction(tr("context menu for %1").arg(username)); + nickContextMenu.addSeparator(); + + QAction *whoisAction = nickContextMenu.addAction(tr("WHOIS")); + QAction *result = nickContextMenu.exec(QCursor::pos()); + + if (result == whoisAction ) { + Client::instance()->userInput(bufferInfo, "/WHOIS "+username); + } +}