-
-bool BufferView::checkRequirements(const QModelIndex &index, ItemActiveStates requiredActiveState) {
- if(!index.isValid())
- return false;
-
- ItemActiveStates isActive = index.data(NetworkModel::ItemActiveRole).toBool()
- ? ActiveState
- : InactiveState;
-
- if(!(isActive & requiredActiveState))
- return false;
-
- return true;
-}
-
-void BufferView::addItemToMenu(QAction *action, QMenu *menu, const QModelIndex &index, ItemActiveStates requiredActiveState) {
- addItemToMenu(action, menu, checkRequirements(index, requiredActiveState));
-}
-
-void BufferView::addItemToMenu(QAction *action, QMenu *menu, bool condition) {
- if(condition) {
- menu->addAction(action);
- action->setVisible(true);
- } else {
- action->setVisible(false);
- }
-}
-
-void BufferView::addItemToMenu(QMenu *subMenu, QMenu *menu, const QModelIndex &index, ItemActiveStates requiredActiveState) {
- if(checkRequirements(index, requiredActiveState)) {
- menu->addMenu(subMenu);
- subMenu->setVisible(true);
- } else {
- subMenu->setVisible(false);
- }
-}
-
-void BufferView::addSeparatorToMenu(QMenu *menu, const QModelIndex &index, ItemActiveStates requiredActiveState) {
- if(checkRequirements(index, requiredActiveState)) {
- menu->addSeparator();
- }
-}
-
-QMenu *BufferView::createHideEventsSubMenu(QMenu *menu, BufferId bufferId) {
- int filter = BufferSettings(bufferId).messageFilter();
- _menuActions.action("HideJoin")->setChecked(filter & Message::Join);
- _menuActions.action("HidePart")->setChecked(filter & Message::Part);
- _menuActions.action("HideQuit")->setChecked(filter & Message::Quit);
- _menuActions.action("HideNick")->setChecked(filter & Message::Nick);
- _menuActions.action("HideMode")->setChecked(filter & Message::Mode);
- _menuActions.action("HideDayChange")->setChecked(filter & Message::DayChange);
-
- QMenu *hideEventsMenu = menu->addMenu(tr("Hide Events"));
- hideEventsMenu->addAction(_menuActions.action("HideJoin"));
- hideEventsMenu->addAction(_menuActions.action("HidePart"));
- hideEventsMenu->addAction(_menuActions.action("HideQuit"));
- hideEventsMenu->addAction(_menuActions.action("HideNick"));
- hideEventsMenu->addAction(_menuActions.action("HideMode"));
- hideEventsMenu->addAction(_menuActions.action("HideDayChange"));
- return hideEventsMenu;
-}
-
-void BufferView::contextMenuEvent(QContextMenuEvent *event) {
- _menuIndex = indexAt(event->pos());
- if(!_menuIndex.isValid())
- _menuIndex = rootIndex();
- if(!_menuIndex.isValid())
- return;
-
- QMenu contextMenu(this);
- addActionsToMenu(&contextMenu, _menuIndex);
- if(!contextMenu.actions().isEmpty())
- contextMenu.exec(QCursor::pos());
-
- _menuIndex = QModelIndex();
-}
-
-void BufferView::addActionsToMenu(QMenu *contextMenu, const QModelIndex &index) {
- const Network *network = Client::network(index.data(NetworkModel::NetworkIdRole).value<NetworkId>());
- Q_CHECK_PTR(network);
-
- NetworkModel::itemType itemType = static_cast<NetworkModel::itemType>(index.data(NetworkModel::ItemTypeRole).toInt());
-
- switch(itemType) {
- case NetworkModel::NetworkItemType:
- showChannelList.setData(index.data(NetworkModel::NetworkIdRole));
- addItemToMenu(&showChannelList, contextMenu, index, ActiveState);
- addItemToMenu(_menuActions.action("DisconnectNet"), contextMenu, network->connectionState() != Network::Disconnected);
- addItemToMenu(_menuActions.action("ConnectNet"), contextMenu, network->connectionState() == Network::Disconnected);
- addSeparatorToMenu(contextMenu, index, ActiveState);
- addItemToMenu(_menuActions.action("JoinChannel"), contextMenu, index, ActiveState);
- break;
- case NetworkModel::BufferItemType:
- {
- BufferInfo bufferInfo = index.data(NetworkModel::BufferInfoRole).value<BufferInfo>();
- switch(bufferInfo.type()) {
- case BufferInfo::ChannelBuffer:
- addItemToMenu(_menuActions.action("JoinBuffer"), contextMenu, index, InactiveState);
- addItemToMenu(_menuActions.action("PartBuffer"), contextMenu, index, ActiveState);
- addItemToMenu(_menuActions.action("HideBuffersTemporarily"), contextMenu, (bool)config());
- addItemToMenu(_menuActions.action("HideBuffersPermanently"), contextMenu, (bool)config());
- addItemToMenu(_menuActions.action("RemoveBuffer"), contextMenu, index, InactiveState);
- createHideEventsSubMenu(contextMenu, bufferInfo.bufferId());
- addItemToMenu(_menuActions.action("IgnoreList"), contextMenu);
- break;
- case BufferInfo::QueryBuffer:
- addItemToMenu(_menuActions.action("HideBuffersTemporarily"), contextMenu, (bool)config());
- addItemToMenu(_menuActions.action("HideBuffersPermanently"), contextMenu, (bool)config());
- addItemToMenu(_menuActions.action("RemoveBuffer"), contextMenu);
- createHideEventsSubMenu(contextMenu, bufferInfo.bufferId());
+
+
+void BufferView::toggleHeader(bool checked)
+{
+ QAction *action = qobject_cast<QAction *>(sender());
+ header()->setSectionHidden((action->property("column")).toInt(), !checked);
+}
+
+
+void BufferView::contextMenuEvent(QContextMenuEvent *event)
+{
+ QModelIndex index = indexAt(event->pos());
+ if (!index.isValid())
+ index = rootIndex();
+
+ QMenu contextMenu(this);
+
+ 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)
+{
+ QModelIndexList indexList = selectedIndexes();
+ // make sure the item we clicked on is first
+ indexList.removeAll(index);
+ indexList.prepend(index);
+
+ GraphicalUi::contextMenuActionProvider()->addActions(contextMenu, indexList, this, "menuActionTriggered", (bool)config());
+}
+
+
+void BufferView::addFilterActions(QMenu *contextMenu, const QModelIndex &index)
+{
+ BufferViewFilter *filter = qobject_cast<BufferViewFilter *>(model());
+ if (filter) {
+ QList<QAction *> filterActions = filter->actions(index);
+ if (!filterActions.isEmpty()) {
+ contextMenu->addSeparator();
+ foreach(QAction *action, filterActions) {
+ contextMenu->addAction(action);
+ }
+ }
+ }
+}
+
+
+void BufferView::menuActionTriggered(QAction *result)
+{
+ ContextMenuActionProvider::ActionType type = (ContextMenuActionProvider::ActionType)result->data().toInt();
+ switch (type) {
+ case ContextMenuActionProvider::HideBufferTemporarily:
+ removeSelectedBuffers();