X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Fnickview.cpp;h=78cb709be6c17099d5922cfdd3f5e350c219e192;hp=1a97514fe33b5faa6fe5ffdd3e59946297a90fdc;hb=87828aeae2510b29619aa79a3bd76885e2c1ebd4;hpb=e0e822499bb989ab48cc996ad0677f7f73b4709e diff --git a/src/uisupport/nickview.cpp b/src/uisupport/nickview.cpp index 1a97514f..78cb709b 100644 --- a/src/uisupport/nickview.cpp +++ b/src/uisupport/nickview.cpp @@ -30,7 +30,8 @@ NickView::NickView(QWidget *parent) - : QTreeView(parent) + : QTreeView(parent), + _sizeHint(QTreeView::sizeHint()) { setIndentation(10); setAnimated(true); @@ -41,7 +42,7 @@ NickView::NickView(QWidget *parent) setContextMenuPolicy(Qt::CustomContextMenu); connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), - this, SLOT(showContextMenu(const QPoint&))); + this, SLOT(showContextMenu(const QPoint&))); connect(this, SIGNAL(activated( const QModelIndex& )), this, SLOT(startQuery( const QModelIndex& ))); } @@ -57,6 +58,7 @@ void NickView::init() { setColumnHidden(i, true); expandAll(); + updateSizeHint(); } void NickView::setModel(QAbstractItemModel *model) { @@ -64,9 +66,21 @@ void NickView::setModel(QAbstractItemModel *model) { init(); } -void NickView::rowsInserted(const QModelIndex &index, int start, int end) { - QTreeView::rowsInserted(index, start, end); - expandAll(); // FIXME We need to do this more intelligently. Maybe a pimped TreeView? +void NickView::rowsInserted(const QModelIndex &parent, int start, int end) { + QTreeView::rowsInserted(parent, start, end); + if(model()->data(parent, NetworkModel::ItemTypeRole) == NetworkModel::UserCategoryItemType && !isExpanded(parent)) + expand(parent); + updateSizeHint(); +} + +void NickView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) { + QTreeView::rowsAboutToBeRemoved(parent, start, end); + updateSizeHint(); +} + +void NickView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) { + QTreeView::dataChanged(topLeft, bottomRight); + updateSizeHint(); } QString NickView::nickFromModelIndex(const QModelIndex & index) { @@ -81,6 +95,8 @@ BufferInfo NickView::bufferInfoFromModelIndex(const QModelIndex & index) { void NickView::showContextMenu(const QPoint & pos ) { QModelIndex index = indexAt(pos); + if(index.data(NetworkModel::ItemTypeRole) != NetworkModel::IrcUserItemType) return; + QString nick = nickFromModelIndex(index); QMenu nickContextMenu(this); @@ -98,8 +114,10 @@ void NickView::showContextMenu(const QPoint & pos ) { QAction *deVoiceAction = modeMenu->addAction(tr("Devoice %1").arg(nick)); QMenu *kickBanMenu = nickContextMenu.addMenu(tr("Kick/Ban")); + //TODO: add kick message from network identity (kick reason) QAction *kickAction = kickBanMenu->addAction(tr("Kick %1").arg(nick)); QAction *kickBanAction = kickBanMenu->addAction(tr("Kickban %1").arg(nick)); + kickBanMenu->setEnabled(false); QAction *ignoreAction = nickContextMenu.addAction(tr("Ignore")); ignoreAction->setEnabled(false); @@ -138,3 +156,20 @@ void NickView::startQuery(const QModelIndex & index) { void NickView::executeCommand(const BufferInfo & bufferInfo, const QString & command) { Client::instance()->userInput(bufferInfo, command); } + +void NickView::updateSizeHint() { + if(!model()) + return; + + int columnSize = 0; + for(int i = 0; i < model()->columnCount(); i++) { + if(!isColumnHidden(i)) + columnSize += sizeHintForColumn(i); + } + + _sizeHint = QSize(columnSize, 50); +} + +QSize NickView::sizeHint() const { + return _sizeHint; +}