File indexing completed on 2024-04-28 04:38:37
0001 /* 0002 SPDX-FileCopyrightText: 2009 Andreas Pakulat <apaku@gmx.de> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "documentswitchertreeview.h" 0008 0009 #include <QKeyEvent> 0010 0011 #include <widgetcolorizer.h> 0012 #include <path.h> 0013 #include <projectmodel.h> 0014 #include <interfaces/iproject.h> 0015 0016 #include "documentswitcherplugin.h" 0017 0018 using namespace KDevelop; 0019 0020 DocumentSwitcherTreeView::DocumentSwitcherTreeView(DocumentSwitcherPlugin* plugin_ ) 0021 : QTreeView(nullptr) 0022 , plugin(plugin_) 0023 { 0024 setWindowFlags(Qt::Popup | Qt::FramelessWindowHint); 0025 } 0026 0027 void DocumentSwitcherTreeView::keyPressEvent(QKeyEvent* event) 0028 { 0029 if (event->key() == Qt::Key_Escape) { 0030 event->accept(); 0031 hide(); 0032 } else { 0033 QTreeView::keyPressEvent(event); 0034 } 0035 } 0036 0037 void DocumentSwitcherTreeView::keyReleaseEvent(QKeyEvent* event) 0038 { 0039 if (event->key() == Qt::Key_Control) { 0040 plugin->itemActivated(selectionModel()->currentIndex()); 0041 event->accept(); 0042 hide(); 0043 } else { 0044 QTreeView::keyReleaseEvent(event); 0045 } 0046 } 0047 0048 void DocumentSwitcherTreeView::drawBranches(QPainter* painter, const QRect& rect, const QModelIndex& index) const 0049 { 0050 if (WidgetColorizer::colorizeByProject()) { 0051 if (const auto project = index.data(ProjectRole).value<IProject *>()) { 0052 const auto projectPath = project->path(); 0053 const QColor color = WidgetColorizer::colorForId(qHash(projectPath), palette(), true); 0054 WidgetColorizer::drawBranches(this, painter, rect, index, color); 0055 } 0056 } 0057 // don't call the base implementation, as we only want to paint the colorization above 0058 // this means that for people who have the feature disabled, we get some padding on the left, 0059 // but that is OK imo 0060 } 0061 0062 #include "moc_documentswitchertreeview.cpp"