uisupport: Forcefully disable horizontal scrollbar in BufferView
[quassel.git] / src / uisupport / bufferview.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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.                                           *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
20
21 #include "bufferview.h"
22
23 #include <QApplication>
24 #include <QAction>
25 #include <QFlags>
26 #include <QHeaderView>
27 #include <QLineEdit>
28 #include <QMenu>
29 #include <QMessageBox>
30 #include <QSet>
31
32 #include "action.h"
33 #include "buffermodel.h"
34 #include "bufferviewfilter.h"
35 #include "buffersettings.h"
36 #include "buffersyncer.h"
37 #include "client.h"
38 #include "contextmenuactionprovider.h"
39 #include "graphicalui.h"
40 #include "network.h"
41 #include "networkmodel.h"
42 #include "contextmenuactionprovider.h"
43
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)
51 {
52     connect(this, SIGNAL(collapsed(const QModelIndex &)), SLOT(storeExpandedState(const QModelIndex &)));
53     connect(this, SIGNAL(expanded(const QModelIndex &)), SLOT(storeExpandedState(const QModelIndex &)));
54
55     setSelectionMode(QAbstractItemView::ExtendedSelection);
56
57     QAbstractItemDelegate *oldDelegate = itemDelegate();
58     BufferViewDelegate *tristateDelegate = new BufferViewDelegate(this);
59     setItemDelegate(tristateDelegate);
60     delete oldDelegate;
61 }
62
63
64 void BufferView::init()
65 {
66     header()->setContextMenuPolicy(Qt::ActionsContextMenu);
67     hideColumn(1);
68     hideColumn(2);
69     setIndentation(10);
70
71     // New entries will be expanded automatically when added; no need to call expandAll()
72
73     header()->hide(); // nobody seems to use this anyway
74
75     setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
76
77     // breaks with Qt 4.8
78     if (QString("4.8.0") > qVersion()) // FIXME breaks with Qt versions >= 4.10!
79         setAnimated(true);
80
81     // FIXME This is to workaround bug #663
82     setUniformRowHeights(true);
83
84 #ifndef QT_NO_DRAGANDDROP
85     setDragEnabled(true);
86     setAcceptDrops(true);
87     setDropIndicatorShown(true);
88 #endif
89
90     setSortingEnabled(true);
91     sortByColumn(0, Qt::AscendingOrder);
92
93 #if defined Q_OS_MACOS || defined Q_OS_WIN
94     // afaik this is better on Mac and Windows
95     disconnect(this, SIGNAL(activated(QModelIndex)), this, SLOT(joinChannel(QModelIndex)));
96     connect(this, SIGNAL(activated(QModelIndex)), SLOT(joinChannel(QModelIndex)));
97 #else
98     disconnect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(joinChannel(QModelIndex)));
99     connect(this, SIGNAL(doubleClicked(QModelIndex)), SLOT(joinChannel(QModelIndex)));
100 #endif
101 }
102
103
104 void BufferView::setModel(QAbstractItemModel *model)
105 {
106     delete selectionModel();
107
108     TreeViewTouch::setModel(model);
109     init();
110     // remove old Actions
111     QList<QAction *> oldactions = header()->actions();
112     foreach(QAction *action, oldactions) {
113         header()->removeAction(action);
114         action->deleteLater();
115     }
116
117     if (!model)
118         return;
119
120     QString sectionName;
121     QAction *showSection;
122     for (int i = 1; i < model->columnCount(); i++) {
123         sectionName = (model->headerData(i, Qt::Horizontal, Qt::DisplayRole)).toString();
124         showSection = new QAction(sectionName, header());
125         showSection->setCheckable(true);
126         showSection->setChecked(!isColumnHidden(i));
127         showSection->setProperty("column", i);
128         connect(showSection, SIGNAL(toggled(bool)), this, SLOT(toggleHeader(bool)));
129         header()->addAction(showSection);
130     }
131
132     connect(model, SIGNAL(layoutChanged()), this, SLOT(on_layoutChanged()));
133
134     // Make sure collapsation is correct after setting a model
135     // This might not be needed here, only in BufferView::setFilteredModel().  If issues arise, just
136     // move down to setFilteredModel (which calls this function).
137     setExpandedState();
138 }
139
140
141 void BufferView::setFilteredModel(QAbstractItemModel *model_, BufferViewConfig *config)
142 {
143     BufferViewFilter *filter = qobject_cast<BufferViewFilter *>(model());
144     if (filter) {
145         filter->setConfig(config);
146         setConfig(config);
147         return;
148     }
149
150     if (model()) {
151         disconnect(this, 0, model(), 0);
152         disconnect(model(), 0, this, 0);
153     }
154
155     if (!model_) {
156         setModel(model_);
157     }
158     else {
159         BufferViewFilter *filter = new BufferViewFilter(model_, config);
160         setModel(filter);
161         connect(filter, SIGNAL(configChanged()), this, SLOT(on_configChanged()));
162     }
163     setConfig(config);
164 }
165
166
167 void BufferView::setConfig(BufferViewConfig *config)
168 {
169     if (_config == config)
170         return;
171
172     if (_config) {
173         disconnect(_config, 0, this, 0);
174     }
175
176     _config = config;
177     if (config) {
178         connect(config, SIGNAL(networkIdSet(const NetworkId &)), this, SLOT(setRootIndexForNetworkId(const NetworkId &)));
179         setRootIndexForNetworkId(config->networkId());
180     }
181     else {
182         setIndentation(10);
183         setRootIndex(QModelIndex());
184     }
185 }
186
187
188 void BufferView::setRootIndexForNetworkId(const NetworkId &networkId)
189 {
190     if (!networkId.isValid() || !model()) {
191         setIndentation(10);
192         setRootIndex(QModelIndex());
193     }
194     else {
195         setIndentation(5);
196         int networkCount = model()->rowCount();
197         QModelIndex child;
198         for (int i = 0; i < networkCount; i++) {
199             child = model()->index(i, 0);
200             if (networkId == model()->data(child, NetworkModel::NetworkIdRole).value<NetworkId>())
201                 setRootIndex(child);
202         }
203     }
204 }
205
206
207 void BufferView::joinChannel(const QModelIndex &index)
208 {
209     BufferInfo::Type bufferType = (BufferInfo::Type)index.data(NetworkModel::BufferTypeRole).value<int>();
210
211     if (bufferType != BufferInfo::ChannelBuffer)
212         return;
213
214     BufferInfo bufferInfo = index.data(NetworkModel::BufferInfoRole).value<BufferInfo>();
215
216     Client::userInput(bufferInfo, QString("/JOIN %1").arg(bufferInfo.bufferName()));
217 }
218
219
220 void BufferView::keyPressEvent(QKeyEvent *event)
221 {
222     if (event->key() == Qt::Key_Backspace || event->key() == Qt::Key_Delete) {
223         event->accept();
224         removeSelectedBuffers();
225     }
226     TreeViewTouch::keyPressEvent(event);
227 }
228
229
230 void BufferView::dropEvent(QDropEvent *event)
231 {
232     QModelIndex index = indexAt(event->pos());
233
234     QRect indexRect = visualRect(index);
235     QPoint cursorPos = event->pos();
236
237     // check if we're really _on_ the item and not indicating a move to just above or below the item
238     // Magic margin number for this is from QAbstractItemViewPrivate::position()
239     const int margin = 2;
240     if (cursorPos.y() - indexRect.top() < margin
241         || indexRect.bottom() - cursorPos.y() < margin)
242         return TreeViewTouch::dropEvent(event);
243
244     // If more than one buffer was being dragged, treat this as a rearrangement instead of a merge request
245     QList<QPair<NetworkId, BufferId> > bufferList = Client::networkModel()->mimeDataToBufferList(event->mimeData());
246     if (bufferList.count() != 1)
247         return TreeViewTouch::dropEvent(event);
248
249     // Get the Buffer ID of the buffer that was being dragged
250     BufferId bufferId2 = bufferList[0].second;
251
252     // Get the Buffer ID of the target buffer
253     BufferId bufferId1 = index.data(NetworkModel::BufferIdRole).value<BufferId>();
254
255     // If the source and target are the same buffer, this was an aborted rearrangement
256     if (bufferId1 == bufferId2)
257         return TreeViewTouch::dropEvent(event);
258
259     // Get index of buffer that was being dragged
260     QModelIndex index2 = Client::networkModel()->bufferIndex(bufferId2);
261
262     // If the buffer being dragged is a channel and we're still joined to it, treat this as a rearrangement
263     // This prevents us from being joined to a channel with no associated UI elements
264     if (index2.data(NetworkModel::BufferTypeRole) == BufferInfo::ChannelBuffer && index2.data(NetworkModel::ItemActiveRole) == true)
265         return TreeViewTouch::dropEvent(event);
266
267     //If the source buffer is not mergeable(AKA not a Channel and not a Query), try rearranging instead
268     if (index2.data(NetworkModel::BufferTypeRole) != BufferInfo::ChannelBuffer && index2.data(NetworkModel::BufferTypeRole) != BufferInfo::QueryBuffer)
269         return TreeViewTouch::dropEvent(event);
270
271     // If the target buffer is not mergeable(AKA not a Channel and not a Query), try rearranging instead
272     if (index.data(NetworkModel::BufferTypeRole) != BufferInfo::ChannelBuffer && index.data(NetworkModel::BufferTypeRole) != BufferInfo::QueryBuffer)
273         return TreeViewTouch::dropEvent(event);
274
275     // Confirm that the user really wants to merge the buffers before doing so
276     int res = QMessageBox::question(0, tr("Merge buffers permanently?"),
277         tr("Do you want to merge the buffer \"%1\" permanently into buffer \"%2\"?\n This cannot be reversed!").arg(Client::networkModel()->bufferName(bufferId2)).arg(Client::networkModel()->bufferName(bufferId1)),
278         QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
279     if (res == QMessageBox::Yes) {
280         Client::mergeBuffersPermanently(bufferId1, bufferId2);
281     }
282 }
283
284
285 void BufferView::removeSelectedBuffers(bool permanently)
286 {
287     if (!config())
288         return;
289
290     BufferId bufferId;
291     QSet<BufferId> removedRows;
292     foreach(QModelIndex index, selectionModel()->selectedIndexes()) {
293         if (index.data(NetworkModel::ItemTypeRole) != NetworkModel::BufferItemType)
294             continue;
295
296         bufferId = index.data(NetworkModel::BufferIdRole).value<BufferId>();
297         if (removedRows.contains(bufferId))
298             continue;
299
300         removedRows << bufferId;
301     }
302
303     foreach(BufferId bufferId, removedRows) {
304         if (permanently)
305             config()->requestRemoveBufferPermanently(bufferId);
306         else
307             config()->requestRemoveBuffer(bufferId);
308     }
309 }
310
311
312 void BufferView::rowsInserted(const QModelIndex &parent, int start, int end)
313 {
314     TreeViewTouch::rowsInserted(parent, start, end);
315
316     // ensure that newly inserted network nodes are expanded per default
317     if (parent.data(NetworkModel::ItemTypeRole) != NetworkModel::NetworkItemType)
318         return;
319
320     setExpandedState(parent);
321 }
322
323
324 void BufferView::on_layoutChanged()
325 {
326     int numNets = model()->rowCount(QModelIndex());
327     for (int row = 0; row < numNets; row++) {
328         QModelIndex networkIdx = model()->index(row, 0, QModelIndex());
329         setExpandedState(networkIdx);
330     }
331 }
332
333
334 void BufferView::on_configChanged()
335 {
336     Q_ASSERT(model());
337
338     // Expand/collapse as needed
339     setExpandedState();
340
341     if (config()) {
342         // update selection to current one
343         Client::bufferModel()->synchronizeView(this);
344     }
345 }
346
347
348 void BufferView::setExpandedState()
349 {
350     // Expand all active networks, collapse inactive ones... unless manually changed
351     QModelIndex networkIdx;
352     NetworkId networkId;
353     for (int row = 0; row < model()->rowCount(); row++) {
354         networkIdx = model()->index(row, 0);
355         if (model()->rowCount(networkIdx) ==  0)
356             continue;
357
358         networkId = model()->data(networkIdx, NetworkModel::NetworkIdRole).value<NetworkId>();
359         if (!networkId.isValid())
360             continue;
361
362         setExpandedState(networkIdx);
363     }
364 }
365
366
367 void BufferView::storeExpandedState(const QModelIndex &networkIdx)
368 {
369     NetworkId networkId = model()->data(networkIdx, NetworkModel::NetworkIdRole).value<NetworkId>();
370
371     int oldState = 0;
372     if (isExpanded(networkIdx))
373         oldState |= WasExpanded;
374     if (model()->data(networkIdx, NetworkModel::ItemActiveRole).toBool())
375         oldState |= WasActive;
376
377     _expandedState[networkId] = oldState;
378 }
379
380
381 void BufferView::setExpandedState(const QModelIndex &networkIdx)
382 {
383     if (model()->data(networkIdx, NetworkModel::ItemTypeRole) != NetworkModel::NetworkItemType)
384         return;
385
386     if (model()->rowCount(networkIdx) == 0)
387         return;
388
389     NetworkId networkId = model()->data(networkIdx, NetworkModel::NetworkIdRole).value<NetworkId>();
390
391     bool networkActive = model()->data(networkIdx, NetworkModel::ItemActiveRole).toBool();
392     bool expandNetwork = networkActive;
393     if (_expandedState.contains(networkId)) {
394         int oldState = _expandedState[networkId];
395         if ((bool)(oldState & WasActive) == networkActive)
396             expandNetwork = (bool)(oldState & WasExpanded);
397     }
398
399     if (expandNetwork != isExpanded(networkIdx)) {
400         update(networkIdx);
401         setExpanded(networkIdx, expandNetwork);
402     }
403     storeExpandedState(networkIdx); // this call is needed to keep track of the isActive state
404 }
405
406 #if QT_VERSION < 0x050000
407 void BufferView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
408 {
409     TreeViewTouch::dataChanged(topLeft, bottomRight);
410 #else
411 void BufferView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
412 {
413     TreeViewTouch::dataChanged(topLeft, bottomRight, roles);
414 #endif
415
416     // determine how many items have been changed and if any of them is a networkitem
417     // which just swichted from active to inactive or vice versa
418     if (topLeft.data(NetworkModel::ItemTypeRole) != NetworkModel::NetworkItemType)
419         return;
420
421     for (int i = topLeft.row(); i <= bottomRight.row(); i++) {
422         QModelIndex networkIdx = topLeft.sibling(i, 0);
423         setExpandedState(networkIdx);
424     }
425 }
426
427
428 void BufferView::toggleHeader(bool checked)
429 {
430     QAction *action = qobject_cast<QAction *>(sender());
431     header()->setSectionHidden((action->property("column")).toInt(), !checked);
432 }
433
434
435 void BufferView::contextMenuEvent(QContextMenuEvent *event)
436 {
437     QModelIndex index = indexAt(event->pos());
438     if (!index.isValid())
439         index = rootIndex();
440
441     QMenu contextMenu(this);
442
443     if (index.isValid()) {
444         addActionsToMenu(&contextMenu, index);
445     }
446
447     addFilterActions(&contextMenu, index);
448
449     if (!contextMenu.actions().isEmpty())
450         contextMenu.exec(QCursor::pos());
451 }
452
453
454 void BufferView::addActionsToMenu(QMenu *contextMenu, const QModelIndex &index)
455 {
456     QModelIndexList indexList = selectedIndexes();
457     // make sure the item we clicked on is first
458     indexList.removeAll(index);
459     indexList.prepend(index);
460
461     GraphicalUi::contextMenuActionProvider()->addActions(contextMenu, indexList, this, "menuActionTriggered", (bool)config());
462 }
463
464
465 void BufferView::addFilterActions(QMenu *contextMenu, const QModelIndex &index)
466 {
467     BufferViewFilter *filter = qobject_cast<BufferViewFilter *>(model());
468     if (filter) {
469         QList<QAction *> filterActions = filter->actions(index);
470         if (!filterActions.isEmpty()) {
471             contextMenu->addSeparator();
472             foreach(QAction *action, filterActions) {
473                 contextMenu->addAction(action);
474             }
475         }
476     }
477 }
478
479
480 void BufferView::menuActionTriggered(QAction *result)
481 {
482     ContextMenuActionProvider::ActionType type = (ContextMenuActionProvider::ActionType)result->data().toInt();
483     switch (type) {
484     case ContextMenuActionProvider::HideBufferTemporarily:
485         removeSelectedBuffers();
486         break;
487     case ContextMenuActionProvider::HideBufferPermanently:
488         removeSelectedBuffers(true);
489         break;
490     default:
491         return;
492     }
493 }
494
495
496 void BufferView::nextBuffer()
497 {
498     changeBuffer(Forward);
499 }
500
501
502 void BufferView::previousBuffer()
503 {
504     changeBuffer(Backward);
505 }
506
507
508 void BufferView::changeBuffer(Direction direction)
509 {
510     QModelIndex currentIndex = selectionModel()->currentIndex();
511     QModelIndex resultingIndex;
512
513     if (currentIndex.parent().isValid()) {
514         //If we are a child node just switch among siblings unless it's the first/last child
515         resultingIndex = currentIndex.sibling(currentIndex.row() + direction, 0);
516
517         if (!resultingIndex.isValid()) {
518             QModelIndex parent = currentIndex.parent();
519             if (direction == Backward)
520                 resultingIndex = parent;
521             else
522                 resultingIndex = parent.sibling(parent.row() + direction, 0);
523         }
524     }
525     else {
526         //If we have a toplevel node, try and get an adjacent child
527         if (direction == Backward) {
528             QModelIndex newParent = currentIndex.sibling(currentIndex.row() - 1, 0);
529             if (model()->hasChildren(newParent))
530                 resultingIndex = newParent.child(model()->rowCount(newParent) - 1, 0);
531             else
532                 resultingIndex = newParent;
533         }
534         else {
535             if (model()->hasChildren(currentIndex))
536                 resultingIndex = currentIndex.child(0, 0);
537             else
538                 resultingIndex = currentIndex.sibling(currentIndex.row() + 1, 0);
539         }
540     }
541
542     if (!resultingIndex.isValid())
543         return;
544
545     selectionModel()->setCurrentIndex(resultingIndex, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
546     selectionModel()->select(resultingIndex, QItemSelectionModel::ClearAndSelect);
547 }
548
549
550 void BufferView::wheelEvent(QWheelEvent *event)
551 {
552     if (ItemViewSettings().mouseWheelChangesBuffer() == (bool)(event->modifiers() & Qt::AltModifier))
553         return TreeViewTouch::wheelEvent(event);
554
555     int rowDelta = (event->delta() > 0) ? -1 : 1;
556     changeBuffer((Direction)rowDelta);
557 }
558
559
560 void BufferView::hideCurrentBuffer()
561 {
562     QModelIndex index = selectionModel()->currentIndex();
563     if (index.data(NetworkModel::ItemTypeRole) != NetworkModel::BufferItemType)
564         return;
565
566     BufferId bufferId = index.data(NetworkModel::BufferIdRole).value<BufferId>();
567
568     //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.
569     changeBuffer(Backward);
570
571     /*if(removedRows.contains(bufferId))
572       continue;
573
574     removedRows << bufferId;*/
575     /*if(permanently)
576       config()->requestRemoveBufferPermanently(bufferId);
577     else*/
578     config()->requestRemoveBuffer(bufferId);
579 }
580
581
582 QSize BufferView::sizeHint() const
583 {
584     return TreeViewTouch::sizeHint();
585
586     if (!model())
587         return TreeViewTouch::sizeHint();
588
589     if (model()->rowCount() == 0)
590         return QSize(120, 50);
591
592     int columnSize = 0;
593     for (int i = 0; i < model()->columnCount(); i++) {
594         if (!isColumnHidden(i))
595             columnSize += sizeHintForColumn(i);
596     }
597     return QSize(columnSize, 50);
598 }
599
600
601 // ****************************************
602 //  BufferViewDelgate
603 // ****************************************
604 class ColorsChangedEvent : public QEvent
605 {
606 public:
607     ColorsChangedEvent() : QEvent(QEvent::User) {};
608 };
609
610
611 BufferViewDelegate::BufferViewDelegate(QObject *parent)
612     : QStyledItemDelegate(parent)
613 {
614 }
615
616
617 void BufferViewDelegate::customEvent(QEvent *event)
618 {
619     if (event->type() != QEvent::User)
620         return;
621
622     event->accept();
623 }
624
625
626 bool BufferViewDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
627 {
628     if (event->type() != QEvent::MouseButtonRelease)
629         return QStyledItemDelegate::editorEvent(event, model, option, index);
630
631     if (!(model->flags(index) & Qt::ItemIsUserCheckable))
632         return QStyledItemDelegate::editorEvent(event, model, option, index);
633
634     QVariant value = index.data(Qt::CheckStateRole);
635     if (!value.isValid())
636         return QStyledItemDelegate::editorEvent(event, model, option, index);
637
638 #if QT_VERSION < 0x050000
639     QStyleOptionViewItemV4 viewOpt(option);
640 #else
641     QStyleOptionViewItem viewOpt(option);
642 #endif
643     initStyleOption(&viewOpt, index);
644
645     QRect checkRect = viewOpt.widget->style()->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, &viewOpt, viewOpt.widget);
646     QMouseEvent *me = static_cast<QMouseEvent *>(event);
647
648     if (me->button() != Qt::LeftButton || !checkRect.contains(me->pos()))
649         return QStyledItemDelegate::editorEvent(event, model, option, index);
650
651     Qt::CheckState state = static_cast<Qt::CheckState>(value.toInt());
652     if (state == Qt::Unchecked)
653         state = Qt::PartiallyChecked;
654     else if (state == Qt::PartiallyChecked)
655         state = Qt::Checked;
656     else
657         state = Qt::Unchecked;
658     model->setData(index, state, Qt::CheckStateRole);
659     return true;
660 }
661
662
663 // ==============================
664 //  BufferView Dock
665 // ==============================
666 BufferViewDock::BufferViewDock(BufferViewConfig *config, QWidget *parent)
667     : QDockWidget(parent),
668     _active(false),
669     _title(config->bufferViewName())
670 {
671     setObjectName("BufferViewDock-" + QString::number(config->bufferViewId()));
672     toggleViewAction()->setData(config->bufferViewId());
673     setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea);
674     connect(config, SIGNAL(bufferViewNameSet(const QString &)), this, SLOT(bufferViewRenamed(const QString &)));
675     updateTitle();
676 }
677
678
679 void BufferViewDock::updateTitle()
680 {
681     QString title = _title;
682     if (isActive())
683         title.prepend(QString::fromUtf8("• "));
684     setWindowTitle(title);
685 }
686
687
688 void BufferViewDock::setActive(bool active)
689 {
690     if (active != isActive()) {
691         _active = active;
692         updateTitle();
693         if (active)
694             raise();  // for tabbed docks
695     }
696 }
697
698
699 void BufferViewDock::bufferViewRenamed(const QString &newName)
700 {
701     _title = newName;
702     updateTitle();
703     toggleViewAction()->setText(newName);
704 }
705
706
707 int BufferViewDock::bufferViewId() const
708 {
709     BufferView *view = bufferView();
710     if (!view)
711         return 0;
712
713     if (view->config())
714         return view->config()->bufferViewId();
715     else
716         return 0;
717 }
718
719
720 BufferViewConfig *BufferViewDock::config() const
721 {
722     BufferView *view = bufferView();
723     if (!view)
724         return 0;
725     else
726         return view->config();
727 }