1 /***************************************************************************
2 * Copyright (C) 2005-2018 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #include "bufferview.h"
24 #include <QApplication>
26 #include <QHeaderView>
29 #include <QMessageBox>
31 #include <QVBoxLayout>
34 #include "buffermodel.h"
35 #include "buffersettings.h"
36 #include "buffersyncer.h"
37 #include "bufferviewfilter.h"
39 #include "contextmenuactionprovider.h"
40 #include "graphicalui.h"
42 #include "networkmodel.h"
44 /*****************************************
45 * The TreeView showing the Buffers
46 *****************************************/
47 // Please be carefull when reimplementing methods which are used to inform the view about changes to the data
48 // to be on the safe side: call QTreeView's method aswell (or TreeViewTouch's)
49 BufferView::BufferView(QWidget* parent)
50 : TreeViewTouch(parent)
52 connect(this, &QTreeView::collapsed, this, &BufferView::storeExpandedState);
53 connect(this, &QTreeView::expanded, this, &BufferView::storeExpandedState);
55 setSelectionMode(QAbstractItemView::ExtendedSelection);
57 QAbstractItemDelegate* oldDelegate = itemDelegate();
58 auto* tristateDelegate = new BufferViewDelegate(this);
59 setItemDelegate(tristateDelegate);
63 void BufferView::init()
65 header()->setContextMenuPolicy(Qt::ActionsContextMenu);
70 // New entries will be expanded automatically when added; no need to call expandAll()
72 header()->hide(); // nobody seems to use this anyway
74 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
78 // FIXME This is to workaround bug #663
79 setUniformRowHeights(true);
81 #ifndef QT_NO_DRAGANDDROP
84 setDropIndicatorShown(true);
87 setSortingEnabled(true);
88 sortByColumn(0, Qt::AscendingOrder);
90 #if defined Q_OS_MACOS || defined Q_OS_WIN
91 // afaik this is better on Mac and Windows
92 connect(this, &QAbstractItemView::activated, this, &BufferView::joinChannel, Qt::UniqueConnection);
94 connect(this, &QAbstractItemView::doubleClicked, this, &BufferView::joinChannel, Qt::UniqueConnection);
98 void BufferView::setModel(QAbstractItemModel* model)
100 delete selectionModel();
102 TreeViewTouch::setModel(model);
104 // remove old Actions
105 QList<QAction*> oldactions = header()->actions();
106 foreach (QAction* action, oldactions) {
107 header()->removeAction(action);
108 action->deleteLater();
115 QAction* showSection;
116 for (int i = 1; i < model->columnCount(); i++) {
117 sectionName = (model->headerData(i, Qt::Horizontal, Qt::DisplayRole)).toString();
118 showSection = new QAction(sectionName, header());
119 showSection->setCheckable(true);
120 showSection->setChecked(!isColumnHidden(i));
121 showSection->setProperty("column", i);
122 connect(showSection, &QAction::toggled, this, &BufferView::toggleHeader);
123 header()->addAction(showSection);
126 connect(model, &QAbstractItemModel::layoutChanged, this, &BufferView::on_layoutChanged);
128 // Make sure collapsation is correct after setting a model
129 // This might not be needed here, only in BufferView::setFilteredModel(). If issues arise, just
130 // move down to setFilteredModel (which calls this function).
134 void BufferView::setFilteredModel(QAbstractItemModel* model_, BufferViewConfig* config)
136 auto* filter = qobject_cast<BufferViewFilter*>(model());
138 filter->setConfig(config);
144 disconnect(this, nullptr, model(), nullptr);
145 disconnect(model(), nullptr, this, nullptr);
152 auto* filter = new BufferViewFilter(model_, config);
154 connect(filter, &BufferViewFilter::configChanged, this, &BufferView::on_configChanged);
159 void BufferView::setConfig(BufferViewConfig* config)
161 if (_config == config)
165 disconnect(_config, nullptr, this, nullptr);
170 connect(config, &BufferViewConfig::networkIdSet, this, &BufferView::setRootIndexForNetworkId);
171 setRootIndexForNetworkId(config->networkId());
175 setRootIndex(QModelIndex());
179 void BufferView::setRootIndexForNetworkId(const NetworkId& networkId)
181 if (!networkId.isValid() || !model()) {
183 setRootIndex(QModelIndex());
187 int networkCount = model()->rowCount();
189 for (int i = 0; i < networkCount; i++) {
190 child = model()->index(i, 0);
191 if (networkId == model()->data(child, NetworkModel::NetworkIdRole).value<NetworkId>())
197 void BufferView::joinChannel(const QModelIndex& index)
199 BufferInfo::Type bufferType = (BufferInfo::Type)index.data(NetworkModel::BufferTypeRole).value<int>();
201 if (bufferType != BufferInfo::ChannelBuffer)
204 BufferInfo bufferInfo = index.data(NetworkModel::BufferInfoRole).value<BufferInfo>();
206 Client::userInput(bufferInfo, QString("/JOIN %1").arg(bufferInfo.bufferName()));
209 void BufferView::dropEvent(QDropEvent* event)
211 QModelIndex index = indexAt(event->pos());
213 QRect indexRect = visualRect(index);
214 QPoint cursorPos = event->pos();
216 // check if we're really _on_ the item and not indicating a move to just above or below the item
217 // Magic margin number for this is from QAbstractItemViewPrivate::position()
218 const int margin = 2;
219 if (cursorPos.y() - indexRect.top() < margin || indexRect.bottom() - cursorPos.y() < margin)
220 return TreeViewTouch::dropEvent(event);
222 // If more than one buffer was being dragged, treat this as a rearrangement instead of a merge request
223 QList<QPair<NetworkId, BufferId>> bufferList = Client::networkModel()->mimeDataToBufferList(event->mimeData());
224 if (bufferList.count() != 1)
225 return TreeViewTouch::dropEvent(event);
227 // Get the Buffer ID of the buffer that was being dragged
228 BufferId bufferId2 = bufferList[0].second;
230 // Get the Buffer ID of the target buffer
231 BufferId bufferId1 = index.data(NetworkModel::BufferIdRole).value<BufferId>();
233 // If the source and target are the same buffer, this was an aborted rearrangement
234 if (bufferId1 == bufferId2)
235 return TreeViewTouch::dropEvent(event);
237 // Get index of buffer that was being dragged
238 QModelIndex index2 = Client::networkModel()->bufferIndex(bufferId2);
240 // If the buffer being dragged is a channel and we're still joined to it, treat this as a rearrangement
241 // This prevents us from being joined to a channel with no associated UI elements
242 if (index2.data(NetworkModel::BufferTypeRole) == BufferInfo::ChannelBuffer && index2.data(NetworkModel::ItemActiveRole) == true)
243 return TreeViewTouch::dropEvent(event);
245 // If the source buffer is not mergeable(AKA not a Channel and not a Query), try rearranging instead
246 if (index2.data(NetworkModel::BufferTypeRole) != BufferInfo::ChannelBuffer
247 && index2.data(NetworkModel::BufferTypeRole) != BufferInfo::QueryBuffer)
248 return TreeViewTouch::dropEvent(event);
250 // If the target buffer is not mergeable(AKA not a Channel and not a Query), try rearranging instead
251 if (index.data(NetworkModel::BufferTypeRole) != BufferInfo::ChannelBuffer
252 && index.data(NetworkModel::BufferTypeRole) != BufferInfo::QueryBuffer)
253 return TreeViewTouch::dropEvent(event);
255 // Confirm that the user really wants to merge the buffers before doing so
256 int res = QMessageBox::question(nullptr,
257 tr("Merge buffers permanently?"),
258 tr("Do you want to merge the buffer \"%1\" permanently into buffer \"%2\"?\n This cannot be reversed!")
259 .arg(Client::networkModel()->bufferName(bufferId2))
260 .arg(Client::networkModel()->bufferName(bufferId1)),
261 QMessageBox::Yes | QMessageBox::No,
263 if (res == QMessageBox::Yes) {
264 Client::mergeBuffersPermanently(bufferId1, bufferId2);
268 void BufferView::removeSelectedBuffers(bool permanently)
274 QSet<BufferId> removedRows;
275 foreach (QModelIndex index, selectionModel()->selectedIndexes()) {
276 if (index.data(NetworkModel::ItemTypeRole) != NetworkModel::BufferItemType)
279 bufferId = index.data(NetworkModel::BufferIdRole).value<BufferId>();
280 if (removedRows.contains(bufferId))
283 removedRows << bufferId;
286 foreach (BufferId bufferId, removedRows) {
288 config()->requestRemoveBufferPermanently(bufferId);
290 config()->requestRemoveBuffer(bufferId);
294 void BufferView::rowsInserted(const QModelIndex& parent, int start, int end)
296 TreeViewTouch::rowsInserted(parent, start, end);
298 // ensure that newly inserted network nodes are expanded per default
299 if (parent.data(NetworkModel::ItemTypeRole) != NetworkModel::NetworkItemType)
302 setExpandedState(parent);
305 void BufferView::on_layoutChanged()
307 int numNets = model()->rowCount(QModelIndex());
308 for (int row = 0; row < numNets; row++) {
309 QModelIndex networkIdx = model()->index(row, 0, QModelIndex());
310 setExpandedState(networkIdx);
314 void BufferView::on_configChanged()
318 // Expand/collapse as needed
322 // update selection to current one
323 Client::bufferModel()->synchronizeView(this);
327 void BufferView::setExpandedState()
329 // Expand all active networks, collapse inactive ones... unless manually changed
330 QModelIndex networkIdx;
332 for (int row = 0; row < model()->rowCount(); row++) {
333 networkIdx = model()->index(row, 0);
334 if (model()->rowCount(networkIdx) == 0)
337 networkId = model()->data(networkIdx, NetworkModel::NetworkIdRole).value<NetworkId>();
338 if (!networkId.isValid())
341 setExpandedState(networkIdx);
345 void BufferView::storeExpandedState(const QModelIndex& networkIdx)
347 NetworkId networkId = model()->data(networkIdx, NetworkModel::NetworkIdRole).value<NetworkId>();
350 if (isExpanded(networkIdx))
351 oldState |= WasExpanded;
352 if (model()->data(networkIdx, NetworkModel::ItemActiveRole).toBool())
353 oldState |= WasActive;
355 _expandedState[networkId] = oldState;
358 void BufferView::setExpandedState(const QModelIndex& networkIdx)
360 if (model()->data(networkIdx, NetworkModel::ItemTypeRole) != NetworkModel::NetworkItemType)
363 if (model()->rowCount(networkIdx) == 0)
366 NetworkId networkId = model()->data(networkIdx, NetworkModel::NetworkIdRole).value<NetworkId>();
368 bool networkActive = model()->data(networkIdx, NetworkModel::ItemActiveRole).toBool();
369 bool expandNetwork = networkActive;
370 if (_expandedState.contains(networkId)) {
371 int oldState = _expandedState[networkId];
372 if ((bool)(oldState & WasActive) == networkActive)
373 expandNetwork = (bool)(oldState & WasExpanded);
376 if (expandNetwork != isExpanded(networkIdx)) {
378 setExpanded(networkIdx, expandNetwork);
380 storeExpandedState(networkIdx); // this call is needed to keep track of the isActive state
383 void BufferView::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles)
385 TreeViewTouch::dataChanged(topLeft, bottomRight, roles);
387 // determine how many items have been changed and if any of them is a networkitem
388 // which just swichted from active to inactive or vice versa
389 if (topLeft.data(NetworkModel::ItemTypeRole) != NetworkModel::NetworkItemType)
392 for (int i = topLeft.row(); i <= bottomRight.row(); i++) {
393 QModelIndex networkIdx = topLeft.sibling(i, 0);
394 setExpandedState(networkIdx);
398 void BufferView::toggleHeader(bool checked)
400 auto* action = qobject_cast<QAction*>(sender());
401 header()->setSectionHidden((action->property("column")).toInt(), !checked);
404 void BufferView::contextMenuEvent(QContextMenuEvent* event)
406 QModelIndex index = indexAt(event->pos());
407 if (!index.isValid())
410 QMenu contextMenu(this);
412 if (index.isValid()) {
413 addActionsToMenu(&contextMenu, index);
416 addFilterActions(&contextMenu, index);
418 if (!contextMenu.actions().isEmpty())
419 contextMenu.exec(QCursor::pos());
422 void BufferView::addActionsToMenu(QMenu* contextMenu, const QModelIndex& index)
424 QModelIndexList indexList = selectedIndexes();
425 // make sure the item we clicked on is first
426 indexList.removeAll(index);
427 indexList.prepend(index);
429 GraphicalUi::contextMenuActionProvider()->addActions(contextMenu, indexList, this, &BufferView::menuActionTriggered, (bool)config());
432 void BufferView::addFilterActions(QMenu* contextMenu, const QModelIndex& index)
434 auto* filter = qobject_cast<BufferViewFilter*>(model());
436 QList<QAction*> filterActions = filter->actions(index);
437 if (!filterActions.isEmpty()) {
438 contextMenu->addSeparator();
439 foreach (QAction* action, filterActions) {
440 contextMenu->addAction(action);
446 void BufferView::menuActionTriggered(QAction* result)
448 ContextMenuActionProvider::ActionType type = (ContextMenuActionProvider::ActionType)result->data().toInt();
450 case ContextMenuActionProvider::HideBufferTemporarily:
451 removeSelectedBuffers();
453 case ContextMenuActionProvider::HideBufferPermanently:
454 removeSelectedBuffers(true);
461 void BufferView::nextBuffer()
463 changeBuffer(Forward);
466 void BufferView::previousBuffer()
468 changeBuffer(Backward);
471 void BufferView::changeBuffer(Direction direction)
473 QModelIndex currentIndex = selectionModel()->currentIndex();
474 QModelIndex resultingIndex;
476 QModelIndex lastNetIndex = model()->index(model()->rowCount() - 1, 0, QModelIndex());
478 if (currentIndex.parent().isValid()) {
479 // If we are a child node just switch among siblings unless it's the first/last child
480 resultingIndex = currentIndex.sibling(currentIndex.row() + direction, 0);
482 if (!resultingIndex.isValid()) {
483 QModelIndex parent = currentIndex.parent();
484 if (direction == Backward)
485 resultingIndex = parent;
487 resultingIndex = parent.sibling(parent.row() + direction, 0);
491 // If we have a toplevel node, try and get an adjacent child
492 if (direction == Backward) {
493 QModelIndex newParent = currentIndex.sibling(currentIndex.row() - 1, 0);
494 if (currentIndex.row() == 0)
495 newParent = lastNetIndex;
496 if (model()->hasChildren(newParent))
497 resultingIndex = newParent.child(model()->rowCount(newParent) - 1, 0);
499 resultingIndex = newParent;
502 if (model()->hasChildren(currentIndex))
503 resultingIndex = currentIndex.child(0, 0);
505 resultingIndex = currentIndex.sibling(currentIndex.row() + 1, 0);
509 if (!resultingIndex.isValid()) {
510 if (direction == Forward)
511 resultingIndex = model()->index(0, 0, QModelIndex());
513 resultingIndex = lastNetIndex.child(model()->rowCount(lastNetIndex) - 1, 0);
516 selectionModel()->setCurrentIndex(resultingIndex, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
517 selectionModel()->select(resultingIndex, QItemSelectionModel::ClearAndSelect);
520 void BufferView::selectFirstBuffer()
522 int networksCount = model()->rowCount(QModelIndex());
523 if (networksCount == 0) {
527 QModelIndex bufferIndex;
528 for (int row = 0; row < networksCount; row++) {
529 QModelIndex networkIndex = model()->index(row, 0, QModelIndex());
530 int childCount = model()->rowCount(networkIndex);
531 if (childCount > 0) {
532 bufferIndex = model()->index(0, 0, networkIndex);
537 if (!bufferIndex.isValid()) {
541 selectionModel()->setCurrentIndex(bufferIndex, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
542 selectionModel()->select(bufferIndex, QItemSelectionModel::ClearAndSelect);
545 void BufferView::wheelEvent(QWheelEvent* event)
547 if (ItemViewSettings().mouseWheelChangesBuffer() == (bool)(event->modifiers() & Qt::AltModifier))
548 return TreeViewTouch::wheelEvent(event);
550 int rowDelta = (event->delta() > 0) ? -1 : 1;
551 changeBuffer((Direction)rowDelta);
554 void BufferView::hideCurrentBuffer()
556 QModelIndex index = selectionModel()->currentIndex();
557 if (index.data(NetworkModel::ItemTypeRole) != NetworkModel::BufferItemType)
560 BufferId bufferId = index.data(NetworkModel::BufferIdRole).value<BufferId>();
562 // 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.
563 changeBuffer(Backward);
565 config()->requestRemoveBuffer(bufferId);
568 void BufferView::filterTextChanged(const QString& filterString)
570 auto* filter = qobject_cast<BufferViewFilter*>(model());
574 filter->setFilterString(filterString);
575 on_configChanged(); // make sure collapsation is correct
578 QSize BufferView::sizeHint() const
580 return TreeViewTouch::sizeHint();
583 return TreeViewTouch::sizeHint();
585 if (model()->rowCount() == 0)
589 for (int i = 0; i < model()->columnCount(); i++) {
590 if (!isColumnHidden(i))
591 columnSize += sizeHintForColumn(i);
593 return {columnSize, 50};
596 void BufferView::changeHighlight(BufferView::Direction direction)
598 // If for some weird reason we get a new delegate
599 auto delegate = qobject_cast<BufferViewDelegate*>(itemDelegate(_currentHighlight));
601 delegate->currentHighlight = QModelIndex();
604 QModelIndex newIndex = _currentHighlight;
605 if (!newIndex.isValid()) {
606 newIndex = model()->index(0, 0);
609 if (direction == Backward) {
610 newIndex = indexBelow(newIndex);
613 newIndex = indexAbove(newIndex);
616 if (!newIndex.isValid()) {
620 _currentHighlight = newIndex;
622 delegate = qobject_cast<BufferViewDelegate*>(itemDelegate(_currentHighlight));
624 delegate->currentHighlight = _currentHighlight;
626 viewport()->update();
629 void BufferView::selectHighlighted()
631 if (_currentHighlight.isValid()) {
632 selectionModel()->setCurrentIndex(_currentHighlight, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
633 selectionModel()->select(_currentHighlight, QItemSelectionModel::ClearAndSelect);
642 void BufferView::clearHighlight()
644 // If for some weird reason we get a new delegate
645 auto delegate = qobject_cast<BufferViewDelegate*>(itemDelegate(_currentHighlight));
647 delegate->currentHighlight = QModelIndex();
649 _currentHighlight = QModelIndex();
650 viewport()->update();
653 // ****************************************
654 // BufferViewDelegate
655 // ****************************************
656 class ColorsChangedEvent : public QEvent
660 : QEvent(QEvent::User){};
663 BufferViewDelegate::BufferViewDelegate(QObject* parent)
664 : QStyledItemDelegate(parent)
667 void BufferViewDelegate::customEvent(QEvent* event)
669 if (event->type() != QEvent::User)
675 bool BufferViewDelegate::editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index)
677 if (event->type() != QEvent::MouseButtonRelease)
678 return QStyledItemDelegate::editorEvent(event, model, option, index);
680 if (!(model->flags(index) & Qt::ItemIsUserCheckable))
681 return QStyledItemDelegate::editorEvent(event, model, option, index);
683 QVariant value = index.data(Qt::CheckStateRole);
684 if (!value.isValid())
685 return QStyledItemDelegate::editorEvent(event, model, option, index);
687 QStyleOptionViewItem viewOpt(option);
688 initStyleOption(&viewOpt, index);
690 QRect checkRect = viewOpt.widget->style()->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, &viewOpt, viewOpt.widget);
691 auto* me = static_cast<QMouseEvent*>(event);
693 if (me->button() != Qt::LeftButton || !checkRect.contains(me->pos()))
694 return QStyledItemDelegate::editorEvent(event, model, option, index);
696 auto state = static_cast<Qt::CheckState>(value.toInt());
697 if (state == Qt::Unchecked)
698 state = Qt::PartiallyChecked;
699 else if (state == Qt::PartiallyChecked)
702 state = Qt::Unchecked;
703 model->setData(index, state, Qt::CheckStateRole);
707 // ==============================
709 // ==============================
710 BufferViewDock::BufferViewDock(BufferViewConfig* config, QWidget* parent)
711 : QDockWidget(parent)
712 , _childWidget(nullptr)
713 , _widget(new QWidget(parent))
714 , _filterEdit(new QLineEdit(parent))
716 , _title(config->bufferViewName())
718 setObjectName("BufferViewDock-" + QString::number(config->bufferViewId()));
719 toggleViewAction()->setData(config->bufferViewId());
720 setAllowedAreas(Qt::RightDockWidgetArea | Qt::LeftDockWidgetArea);
721 connect(config, &BufferViewConfig::bufferViewNameSet, this, &BufferViewDock::bufferViewRenamed);
722 connect(config, &BufferViewConfig::configChanged, this, &BufferViewDock::configChanged);
725 _widget->setLayout(new QVBoxLayout);
726 _widget->layout()->setSpacing(0);
727 _widget->layout()->setContentsMargins(0, 0, 0, 0);
729 // We need to potentially hide it early, so it doesn't flicker
730 _filterEdit->setVisible(config->showSearch());
731 _filterEdit->setFocusPolicy(Qt::ClickFocus);
732 _filterEdit->installEventFilter(this);
733 _filterEdit->setPlaceholderText(tr("Search..."));
734 connect(_filterEdit, &QLineEdit::returnPressed, this, &BufferViewDock::onFilterReturnPressed);
736 _widget->layout()->addWidget(_filterEdit);
737 QDockWidget::setWidget(_widget);
740 void BufferViewDock::setLocked(bool locked)
743 setFeatures(nullptr);
746 setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
750 void BufferViewDock::updateTitle()
752 QString title = _title;
754 title.prepend(QString::fromUtf8("• "));
755 setWindowTitle(title);
758 void BufferViewDock::configChanged()
760 if (_filterEdit->isVisible() != config()->showSearch()) {
761 _filterEdit->setVisible(config()->showSearch());
762 _filterEdit->clear();
766 void BufferViewDock::onFilterReturnPressed()
769 _oldFocusItem->setFocus();
770 _oldFocusItem = nullptr;
773 if (!config()->showSearch()) {
774 _filterEdit->setVisible(false);
777 BufferView* view = bufferView();
782 if (!_filterEdit->text().isEmpty()) {
783 view->selectHighlighted();
784 _filterEdit->clear();
787 view->clearHighlight();
791 void BufferViewDock::setActive(bool active)
793 if (active != isActive()) {
797 raise(); // for tabbed docks
802 bool BufferViewDock::eventFilter(QObject* object, QEvent* event)
804 if (object != _filterEdit) {
808 if (event->type() == QEvent::FocusOut) {
809 if (!config()->showSearch() && _filterEdit->text().isEmpty()) {
810 _filterEdit->setVisible(false);
814 else if (event->type() == QEvent::KeyRelease) {
815 auto keyEvent = static_cast<QKeyEvent*>(event);
817 BufferView* view = bufferView();
822 switch (keyEvent->key()) {
823 case Qt::Key_Escape: {
824 _filterEdit->clear();
826 if (!_oldFocusItem) {
830 _oldFocusItem->setFocus();
831 _oldFocusItem = nullptr;
835 view->changeHighlight(BufferView::Backward);
838 view->changeHighlight(BufferView::Forward);
850 void BufferViewDock::bufferViewRenamed(const QString& newName)
854 toggleViewAction()->setText(newName);
857 int BufferViewDock::bufferViewId() const
859 BufferView* view = bufferView();
864 return view->config()->bufferViewId();
869 BufferViewConfig* BufferViewDock::config() const
871 BufferView* view = bufferView();
875 return view->config();
878 void BufferViewDock::setWidget(QWidget* newWidget)
880 _widget->layout()->addWidget(newWidget);
881 _childWidget = newWidget;
883 connect(_filterEdit, &QLineEdit::textChanged, bufferView(), &BufferView::filterTextChanged);
886 void BufferViewDock::activateFilter()
888 if (!_filterEdit->isVisible()) {
889 _filterEdit->setVisible(true);
892 _oldFocusItem = qApp->focusWidget();
894 _filterEdit->setFocus();
898 void BufferViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
900 QStyleOptionViewItem newOption = option;
901 if (index == currentHighlight) {
902 newOption.state |= QStyle::State_HasFocus;
904 QStyledItemDelegate::paint(painter, newOption, index);