+
+void BufferView::changeBuffer(Direction direction)
+{
+ QModelIndex currentIndex = selectionModel()->currentIndex();
+ QModelIndex resultingIndex;
+
+ if (currentIndex.parent().isValid()) {
+ //If we are a child node just switch among siblings unless it's the first/last child
+ resultingIndex = currentIndex.sibling(currentIndex.row() + direction, 0);
+
+ if (!resultingIndex.isValid()) {
+ QModelIndex parent = currentIndex.parent();
+ if (direction == Backward)
+ resultingIndex = parent;
+ else
+ resultingIndex = parent.sibling(parent.row() + direction, 0);
+ }
+ }
+ else {
+ //If we have a toplevel node, try and get an adjacent child
+ if (direction == Backward) {
+ QModelIndex newParent = currentIndex.sibling(currentIndex.row() - 1, 0);
+ if (model()->hasChildren(newParent))
+ resultingIndex = newParent.child(model()->rowCount(newParent) - 1, 0);
+ else
+ resultingIndex = newParent;
+ }
+ else {
+ if (model()->hasChildren(currentIndex))
+ resultingIndex = currentIndex.child(0, 0);
+ else
+ resultingIndex = currentIndex.sibling(currentIndex.row() + 1, 0);
+ }
+ }
+
+ if (!resultingIndex.isValid())
+ return;
+
+ selectionModel()->setCurrentIndex(resultingIndex, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
+ selectionModel()->select(resultingIndex, QItemSelectionModel::ClearAndSelect);
+}
+
+
+void BufferView::wheelEvent(QWheelEvent *event)
+{
+ if (ItemViewSettings().mouseWheelChangesBuffer() == (bool)(event->modifiers() & Qt::AltModifier))
+ return TreeViewTouch::wheelEvent(event);
+
+ int rowDelta = (event->delta() > 0) ? -1 : 1;
+ changeBuffer((Direction)rowDelta);
+}
+
+
+void BufferView::hideCurrentBuffer()
+{
+ QModelIndex index = selectionModel()->currentIndex();
+ if (index.data(NetworkModel::ItemTypeRole) != NetworkModel::BufferItemType)
+ return;
+
+ BufferId bufferId = index.data(NetworkModel::BufferIdRole).value<BufferId>();
+
+ //The check above means we won't be looking at a network, which should always be the first row, so we can just go backwards.
+ changeBuffer(Backward);
+
+ /*if(removedRows.contains(bufferId))
+ continue;
+
+ removedRows << bufferId;*/
+ /*if(permanently)
+ config()->requestRemoveBufferPermanently(bufferId);
+ else*/
+ config()->requestRemoveBuffer(bufferId);
+}
+
+
+QSize BufferView::sizeHint() const
+{
+ return TreeViewTouch::sizeHint();
+
+ if (!model())
+ return TreeViewTouch::sizeHint();
+
+ if (model()->rowCount() == 0)
+ return QSize(120, 50);
+
+ int columnSize = 0;
+ for (int i = 0; i < model()->columnCount(); i++) {
+ if (!isColumnHidden(i))
+ columnSize += sizeHintForColumn(i);
+ }
+ return QSize(columnSize, 50);
+}
+
+
+// ****************************************
+// BufferViewDelgate
+// ****************************************
+class ColorsChangedEvent : public QEvent
+{
+public:
+ ColorsChangedEvent() : QEvent(QEvent::User) {};
+};
+
+
+BufferViewDelegate::BufferViewDelegate(QObject *parent)
+ : QStyledItemDelegate(parent)
+{
+}
+
+
+void BufferViewDelegate::customEvent(QEvent *event)
+{
+ if (event->type() != QEvent::User)
+ return;
+
+ event->accept();
+}
+
+
+bool BufferViewDelegate::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);
+
+#if QT_VERSION < 0x050000
+ QStyleOptionViewItemV4 viewOpt(option);
+#else
+ QStyleOptionViewItem viewOpt(option);
+#endif
+ initStyleOption(&viewOpt, index);
+
+ QRect checkRect = viewOpt.widget->style()->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, &viewOpt, viewOpt.widget);
+ QMouseEvent *me = static_cast<QMouseEvent *>(event);
+
+ if (me->button() != Qt::LeftButton || !checkRect.contains(me->pos()))
+ return QStyledItemDelegate::editorEvent(event, model, option, index);
+
+ Qt::CheckState state = static_cast<Qt::CheckState>(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;
+}
+
+