diff --git a/plugins/projectmanagerview/projectmodelitemdelegate.cpp b/plugins/projectmanagerview/projectmodelitemdelegate.cpp index 3d59930531..ee266ccb00 100644 --- a/plugins/projectmanagerview/projectmodelitemdelegate.cpp +++ b/plugins/projectmanagerview/projectmodelitemdelegate.cpp @@ -1,160 +1,227 @@ /* This file is part of KDevelop Copyright 2013 Aleix Pol This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "projectmodelitemdelegate.h" #include "vcsoverlayproxymodel.h" - +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include #include +using namespace KDevelop; + ProjectModelItemDelegate::ProjectModelItemDelegate(QObject* parent) : QItemDelegate(parent) {} static QIcon::Mode IconMode( QStyle::State state ) { if (!(state & QStyle::State_Enabled)) { return QIcon::Disabled; } else if (state & QStyle::State_Selected) { return QIcon::Selected; } else { return QIcon::Normal; } } static QIcon::State IconState(QStyle::State state) { return (state & QStyle::State_Open) ? QIcon::On : QIcon::Off; } void ProjectModelItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& opt, const QModelIndex& index) const { // Qt5.5 HiDPI Fix part (1/2) // This fix is based on how Qt5.5's QItemDelegate::paint implementation deals with the same issue // Unfortunately, there doesn't seem to be a clean way to use the base implementation // and have the added functionality this class provides QPixmap decoData; QRect decorationRect; QIcon icon; QIcon::Mode mode = QIcon::Mode::Disabled; QIcon::State state = QIcon::State::Off; { QVariant value; value = index.data(Qt::DecorationRole); if (value.isValid()) { decoData = decoration(opt, value); if (value.type() == QVariant::Icon) { icon = qvariant_cast(value); mode = IconMode(opt.state); state = IconState(opt.state); QSize size = icon.actualSize( opt.decorationSize, mode, state ); decorationRect = QRect(QPoint(0, 0), size); } else { decorationRect = QRect(QPoint(0, 0), decoData.size()); } } else { decorationRect = QRect(); } } QRect checkRect; //unused in practice QRect spaceLeft = opt.rect; spaceLeft.setLeft(decorationRect.right()); QString displayData = index.data(Qt::DisplayRole).toString(); QRect displayRect = textRectangle(painter, spaceLeft, opt.font, displayData); displayRect.setLeft(spaceLeft.left()); QRect branchNameRect(displayRect.topRight(), opt.rect.bottomRight()); doLayout(opt, &checkRect, &decorationRect, &displayRect, false); branchNameRect.setLeft(branchNameRect.left() + displayRect.left()); branchNameRect.setTop(displayRect.top()); drawStyledBackground(painter, opt); // drawCheck(painter, opt, checkRect, checkState); // Qt5.5 HiDPI Fix part (2/2) // use the QIcon from above if possible if (!icon.isNull()) { icon.paint(painter, decorationRect, opt.decorationAlignment, mode, state ); } else { drawDecoration(painter, opt, decorationRect, decoData); } drawDisplay(painter, opt, displayRect, displayData); /// FIXME: this can apparently trigger a nested eventloop, see /// https://bugs.kde.org/show_bug.cgi?id=355099 QString branchNameData = index.data(VcsOverlayProxyModel::VcsStatusRole).toString(); drawBranchName(painter, opt, branchNameRect, branchNameData); drawFocus(painter, opt, displayRect); } void ProjectModelItemDelegate::drawBranchName(QPainter* painter, const QStyleOptionViewItem& option, const QRect& rect, const QString& branchName) const { QString text = option.fontMetrics.elidedText(branchName, Qt::ElideRight, rect.width()); bool selected = option.state & QStyle::State_Selected; QPalette::ColorGroup colorGroup = selected ? QPalette::Active : QPalette::Disabled; painter->save(); painter->setPen(option.palette.color(colorGroup, QPalette::Text)); painter->drawText(rect, text); painter->restore(); } void ProjectModelItemDelegate::drawStyledBackground(QPainter* painter, const QStyleOptionViewItem& option) const { QStyleOptionViewItem opt(option); QStyle *style = opt.widget->style(); style->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter, opt.widget); } void ProjectModelItemDelegate::drawDisplay(QPainter* painter, const QStyleOptionViewItem& option, const QRect& rect, const QString& text) const { QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) ? QPalette::Normal : QPalette::Disabled; if (option.state & QStyle::State_Editing) { painter->save(); painter->setPen(option.palette.color(cg, QPalette::Text)); painter->drawRect(rect.adjusted(0, 0, -1, -1)); painter->restore(); } if(text.isEmpty()) { return; } if (cg == QPalette::Normal && !(option.state & QStyle::State_Active)) { cg = QPalette::Inactive; } if (option.state & QStyle::State_Selected) { painter->setPen(option.palette.color(cg, QPalette::HighlightedText)); } else { painter->setPen(option.palette.color(cg, QPalette::Text)); } QFontMetrics fm(painter->fontMetrics()); painter->drawText(rect, fm.elidedText(text, Qt::ElideRight, rect.width())); } + +bool ProjectModelItemDelegate::helpEvent(QHelpEvent* event, + QAbstractItemView* view, const QStyleOptionViewItem& option, + const QModelIndex& index) +{ + if (!event || !view) { + return false; + } + + if (event->type() == QEvent::ToolTip) { + QHelpEvent* helpEvent = static_cast(event); + + // explicitely close current tooltip, as its autoclose margins overlap items + if ((m_tooltippedIndex != index) && m_tooltip) { + m_tooltip->close(); + m_tooltip.clear(); + } + + const ProjectBaseItem* it = index.data(ProjectModel::ProjectItemRole).value(); + + // show navigation tooltip for files + if (it && it->file()) { + if (!m_tooltip) { + m_tooltippedIndex = index; + KDevelop::DUChainReadLocker lock(KDevelop::DUChain::lock()); + const TopDUContext* top = DUChainUtils::standardContextForUrl(it->file()->path().toUrl()); + + if (top) { + QWidget* navigationWidget = top->createNavigationWidget(); + if (navigationWidget) { + // force possible existing normal tooltip for other list item to hide + // Seems that is still only done with a small delay though, + // but the API seems not to allow more control. + QToolTip::hideText(); + + m_tooltip = new KDevelop::NavigationToolTip(view, helpEvent->globalPos() + QPoint(40, 0), navigationWidget); + m_tooltip->resize(navigationWidget->sizeHint() + QSize(10, 10)); + auto rect = view->visualRect(m_tooltippedIndex); + rect.moveTopLeft(view->mapToGlobal(rect.topLeft())); + m_tooltip->setHandleRect(rect); + ActiveToolTip::showToolTip(m_tooltip); + } + } + } + + // tooltip successfully handled by us? + if (m_tooltip) { + return true; + } + } + } + + return QItemDelegate::helpEvent(event, view, option, index); +} diff --git a/plugins/projectmanagerview/projectmodelitemdelegate.h b/plugins/projectmanagerview/projectmodelitemdelegate.h index 854a88d563..3a6123a713 100644 --- a/plugins/projectmanagerview/projectmodelitemdelegate.h +++ b/plugins/projectmanagerview/projectmodelitemdelegate.h @@ -1,41 +1,53 @@ /* This file is part of KDevelop Copyright 2013 Aleix Pol This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KDEVPLATFORM_PLUGIN_PROJECTMODELITEMDELEGATE_H #define KDEVPLATFORM_PLUGIN_PROJECTMODELITEMDELEGATE_H #include +#include + +namespace KDevelop +{ +class NavigationToolTip; +} class ProjectModelItemDelegate : public QItemDelegate { Q_OBJECT public: explicit ProjectModelItemDelegate(QObject* parent = nullptr); void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override; void drawDisplay(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect, const QString &text) const override; + bool helpEvent(QHelpEvent* event, QAbstractItemView* view, const QStyleOptionViewItem& option, + const QModelIndex& index) override; private: void drawBranchName(QPainter* painter, const QStyleOptionViewItem& option, const QRect& rect, const QString& branchName) const; void drawStyledBackground(QPainter* painter, const QStyleOptionViewItem& option) const; + +private: + QPointer m_tooltip; + QPersistentModelIndex m_tooltippedIndex; }; #endif // KDEVPLATFORM_PLUGIN_PROJECTMODELITEMDELEGATE_H diff --git a/plugins/projectmanagerview/projecttreeview.cpp b/plugins/projectmanagerview/projecttreeview.cpp index 69f7250014..237f80b52b 100644 --- a/plugins/projectmanagerview/projecttreeview.cpp +++ b/plugins/projectmanagerview/projecttreeview.cpp @@ -1,522 +1,478 @@ /* This file is part of KDevelop Copyright 2005 Roberto Raggi Copyright 2007 Andreas Pakulat Copyright 2009 Aleix Pol This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "projecttreeview.h" #include #include #include #include #include #include #include #include #include #include -#include #include #include #include #include #include #include #include #include #include #include #include "projectmanagerviewplugin.h" #include "projectmodelsaver.h" #include "projectmodelitemdelegate.h" #include "debug.h" -#include -#include -#include #include #include using namespace KDevelop; namespace { const char settingsConfigGroup[] = "ProjectTreeView"; QList fileItemsWithin(const QList& items) { QList fileItems; fileItems.reserve(items.size()); foreach(ProjectBaseItem* item, items) { if (ProjectFileItem *file = item->file()) fileItems.append(file); else if (item->folder()) fileItems.append(fileItemsWithin(item->children())); } return fileItems; } QList topLevelItemsWithin(QList items) { std::sort(items.begin(), items.end(), ProjectBaseItem::pathLessThan); Path lastFolder; for (int i = items.size() - 1; i >= 0; --i) { if (lastFolder.isParentOf(items[i]->path())) items.removeAt(i); else if (items[i]->folder()) lastFolder = items[i]->path(); } return items; } template void filterDroppedItems(QList &items, ProjectBaseItem* dest) { for (int i = items.size() - 1; i >= 0; --i) { //No drag and drop from and to same location if (items[i]->parent() == dest) items.removeAt(i); //No moving between projects (technically feasible if the projectmanager is the same though...) else if (items[i]->project() != dest->project()) items.removeAt(i); } } //TODO test whether this could be replaced by projectbuildsetwidget.cpp::showContextMenu_appendActions void popupContextMenu_appendActions(QMenu& menu, const QList& actions) { menu.addActions(actions); menu.addSeparator(); } } ProjectTreeView::ProjectTreeView( QWidget *parent ) : QTreeView( parent ), m_previousSelection ( nullptr ) { header()->hide(); setEditTriggers( QAbstractItemView::EditKeyPressed ); setContextMenuPolicy( Qt::CustomContextMenu ); setSelectionMode( QAbstractItemView::ExtendedSelection ); setIndentation(10); setDragEnabled(true); setDragDropMode(QAbstractItemView::InternalMove); setAutoScroll(true); setAutoExpandDelay(300); setItemDelegate(new ProjectModelItemDelegate(this)); connect( this, &ProjectTreeView::customContextMenuRequested, this, &ProjectTreeView::popupContextMenu ); connect( this, &ProjectTreeView::activated, this, &ProjectTreeView::slotActivated ); connect( ICore::self(), &ICore::aboutToShutdown, this, &ProjectTreeView::aboutToShutdown); connect( ICore::self()->projectController(), &IProjectController::projectOpened, this, &ProjectTreeView::restoreState ); connect( ICore::self()->projectController(), &IProjectController::projectClosed, this, &ProjectTreeView::projectClosed ); } ProjectTreeView::~ProjectTreeView() { } ProjectBaseItem* ProjectTreeView::itemAtPos(const QPoint& pos) const { return indexAt(pos).data(ProjectModel::ProjectItemRole).value(); } void ProjectTreeView::dropEvent(QDropEvent* event) { ProjectItemContext* selectionCtxt = static_cast(KDevelop::ICore::self()->selectionController()->currentSelection()); ProjectBaseItem* destItem = itemAtPos(event->pos()); if (destItem && (dropIndicatorPosition() == AboveItem || dropIndicatorPosition() == BelowItem)) destItem = destItem->parent(); if (selectionCtxt && destItem) { if (ProjectFolderItem *folder = destItem->folder()) { QMenu dropMenu(this); QString seq = QKeySequence( Qt::ShiftModifier ).toString(); seq.chop(1); // chop superfluous '+' QAction* move = new QAction(i18n( "&Move Here" ) + '\t' + seq, &dropMenu); move->setIcon(QIcon::fromTheme(QStringLiteral("go-jump"))); dropMenu.addAction(move); seq = QKeySequence( Qt::ControlModifier ).toString(); seq.chop(1); QAction* copy = new QAction(i18n( "&Copy Here" ) + '\t' + seq, &dropMenu); copy->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy"))); dropMenu.addAction(copy); dropMenu.addSeparator(); QAction* cancel = new QAction(i18n( "C&ancel" ) + '\t' + QKeySequence( Qt::Key_Escape ).toString(), &dropMenu); cancel->setIcon(QIcon::fromTheme(QStringLiteral("process-stop"))); dropMenu.addAction(cancel); QAction *executedAction = nullptr; Qt::KeyboardModifiers modifiers = QApplication::keyboardModifiers(); if (modifiers == Qt::ControlModifier) { executedAction = copy; } else if (modifiers == Qt::ShiftModifier) { executedAction = move; } else { executedAction = dropMenu.exec(this->mapToGlobal(event->pos())); } QList usefulItems = topLevelItemsWithin(selectionCtxt->items()); filterDroppedItems(usefulItems, destItem); Path::List paths; foreach (ProjectBaseItem* i, usefulItems) { paths << i->path(); } bool success = false; if (executedAction == copy) { success = destItem->project()->projectFileManager()->copyFilesAndFolders(paths, folder); } else if (executedAction == move) { success = destItem->project()->projectFileManager()->moveFilesAndFolders(usefulItems, folder); } if (success) { //expand target folder expand( mapFromItem(folder)); //and select new items QItemSelection selection; foreach (const Path &path, paths) { const Path targetPath(folder->path(), path.lastPathSegment()); foreach (ProjectBaseItem *item, folder->children()) { if (item->path() == targetPath) { QModelIndex indx = mapFromItem( item ); selection.append(QItemSelectionRange(indx, indx)); setCurrentIndex(indx); } } } selectionModel()->select(selection, QItemSelectionModel::ClearAndSelect); } } else if (destItem->target() && destItem->project()->buildSystemManager()) { QMenu dropMenu(this); QString seq = QKeySequence( Qt::ControlModifier ).toString(); seq.chop(1); QAction* addToTarget = new QAction(i18n( "&Add to Target" ) + '\t' + seq, &dropMenu); addToTarget->setIcon(QIcon::fromTheme(QStringLiteral("edit-link"))); dropMenu.addAction(addToTarget); dropMenu.addSeparator(); QAction* cancel = new QAction(i18n( "C&ancel" ) + '\t' + QKeySequence( Qt::Key_Escape ).toString(), &dropMenu); cancel->setIcon(QIcon::fromTheme(QStringLiteral("process-stop"))); dropMenu.addAction(cancel); QAction *executedAction = nullptr; Qt::KeyboardModifiers modifiers = QApplication::keyboardModifiers(); if (modifiers == Qt::ControlModifier) { executedAction = addToTarget; } else { executedAction = dropMenu.exec(this->mapToGlobal(event->pos())); } if (executedAction == addToTarget) { QList usefulItems = fileItemsWithin(selectionCtxt->items()); filterDroppedItems(usefulItems, destItem); destItem->project()->buildSystemManager()->addFilesToTarget(usefulItems, destItem->target()); } } } event->accept(); } QModelIndex ProjectTreeView::mapFromSource(const QAbstractProxyModel* proxy, const QModelIndex& sourceIdx) { const QAbstractItemModel* next = proxy->sourceModel(); Q_ASSERT(next == sourceIdx.model() || qobject_cast(next)); if(next == sourceIdx.model()) return proxy->mapFromSource(sourceIdx); else { const QAbstractProxyModel* nextProxy = qobject_cast(next); QModelIndex idx = mapFromSource(nextProxy, sourceIdx); Q_ASSERT(idx.model() == nextProxy); return proxy->mapFromSource(idx); } } QModelIndex ProjectTreeView::mapFromItem(const ProjectBaseItem* item) { QModelIndex ret = mapFromSource(qobject_cast(model()), item->index()); Q_ASSERT(ret.model() == model()); return ret; } void ProjectTreeView::slotActivated( const QModelIndex &index ) { if ( QApplication::keyboardModifiers() & Qt::CTRL || QApplication::keyboardModifiers() & Qt::SHIFT ) { // Do not open file when Ctrl or Shift is pressed; that's for selection return; } KDevelop::ProjectBaseItem *item = index.data(ProjectModel::ProjectItemRole).value(); if ( item && item->file() ) { emit activate( item->file()->path() ); } } void ProjectTreeView::projectClosed(KDevelop::IProject* project) { if ( project == m_previousSelection ) m_previousSelection = nullptr; } QList ProjectTreeView::selectedProjects() { QList itemlist; if ( selectionModel()->hasSelection() ) { QModelIndexList indexes = selectionModel()->selectedRows(); for ( const QModelIndex& index: indexes ) { ProjectBaseItem* item = index.data( ProjectModel::ProjectItemRole ).value(); if ( item ) { itemlist << item; m_previousSelection = item->project(); } } } // add previous selection if nothing is selected right now if ( itemlist.isEmpty() && m_previousSelection ) { itemlist << m_previousSelection->projectItem(); } return itemlist; } KDevelop::IProject* ProjectTreeView::getCurrentProject() { auto itemList = selectedProjects(); if ( !itemList.isEmpty() ) { return itemList.at( 0 )->project(); } return nullptr; } void ProjectTreeView::popupContextMenu( const QPoint &pos ) { QList itemlist; if ( indexAt( pos ).isValid() ) { itemlist = selectedProjects(); } QMenu menu( this ); KDevelop::ProjectItemContextImpl context(itemlist); QList extensions = ICore::self()->pluginController()->queryPluginsForContextMenuExtensions(&context, &menu); QList buildActions; QList vcsActions; QList analyzeActions; QList extActions; QList projectActions; QList fileActions; QList runActions; foreach( const ContextMenuExtension& ext, extensions ) { buildActions += ext.actions(ContextMenuExtension::BuildGroup); fileActions += ext.actions(ContextMenuExtension::FileGroup); projectActions += ext.actions(ContextMenuExtension::ProjectGroup); vcsActions += ext.actions(ContextMenuExtension::VcsGroup); analyzeActions += ext.actions(ContextMenuExtension::AnalyzeProjectGroup); extActions += ext.actions(ContextMenuExtension::ExtensionGroup); runActions += ext.actions(ContextMenuExtension::RunGroup); } if ( analyzeActions.count() ) { QMenu* analyzeMenu = new QMenu(i18n("Analyze With"), &menu); analyzeMenu->setIcon(QIcon::fromTheme(QStringLiteral("dialog-ok"))); foreach( QAction* act, analyzeActions ) { analyzeMenu->addAction( act ); } analyzeActions = {analyzeMenu->menuAction()}; } popupContextMenu_appendActions(menu, buildActions); popupContextMenu_appendActions(menu, runActions ); popupContextMenu_appendActions(menu, fileActions); popupContextMenu_appendActions(menu, vcsActions); popupContextMenu_appendActions(menu, analyzeActions); popupContextMenu_appendActions(menu, extActions); if (itemlist.size() == 1 && itemlist.first()->folder() && !itemlist.first()->folder()->parent()) { QAction* projectConfig = new QAction(i18n("Open Configuration..."), &menu); projectConfig->setIcon(QIcon::fromTheme(QStringLiteral("configure"))); connect( projectConfig, &QAction::triggered, this, &ProjectTreeView::openProjectConfig ); projectActions << projectConfig; } popupContextMenu_appendActions(menu, projectActions); if ( !menu.isEmpty() ) { menu.exec(viewport()->mapToGlobal(pos)); } } void ProjectTreeView::openProjectConfig() { if ( IProject* project = getCurrentProject() ) { IProjectController* ip = ICore::self()->projectController(); ip->configureProject( project ); } } void ProjectTreeView::saveState( IProject* project ) { // nullptr won't create a usable saved state, so spare the effort if ( !project ) { return; } KConfigGroup configGroup( ICore::self()->activeSession()->config(), QString( settingsConfigGroup ).append( project->name() ) ); ProjectModelSaver saver; saver.setProject( project ); saver.setView( this ); saver.saveState( configGroup ); } void ProjectTreeView::restoreState( IProject* project ) { if ( !project ) { return; } KConfigGroup configGroup( ICore::self()->activeSession()->config(), QString( settingsConfigGroup ).append( project->name() ) ); ProjectModelSaver saver; saver.setProject( project ); saver.setView( this ); saver.restoreState( configGroup ); } void ProjectTreeView::rowsInserted( const QModelIndex& parent, int start, int end ) { QTreeView::rowsInserted( parent, start, end ); if ( !parent.model() ) { for ( const auto& project: selectedProjects() ) { restoreState( project->project() ); } } } void ProjectTreeView::rowsAboutToBeRemoved( const QModelIndex& parent, int start, int end ) { if ( !parent.model() ) { for ( const auto& project: selectedProjects() ) { saveState( project->project() ); } } QTreeView::rowsAboutToBeRemoved( parent, start, end ); } void ProjectTreeView::aboutToShutdown() { // save all projects, not just the selected ones const auto projects = ICore::self()->projectController()->projects(); for ( const auto& project: projects ) { saveState( project ); } } -bool ProjectTreeView::event(QEvent* event) -{ - if(event->type()==QEvent::ToolTip) - { - QHelpEvent* helpEvent = static_cast(event); - QModelIndex idxView = indexAt(helpEvent->pos()); - - ProjectBaseItem* it = idxView.data(ProjectModel::ProjectItemRole).value(); - QModelIndex idx; - if(it) - idx = it->index(); - - if((m_idx!=idx || !m_tooltip) && it && it->file()) - { - m_idx=idx; - ProjectFileItem* file=it->file(); - KDevelop::DUChainReadLocker lock(KDevelop::DUChain::lock()); - TopDUContext* top= DUChainUtils::standardContextForUrl(file->path().toUrl()); - - if(m_tooltip) - m_tooltip->close(); - - if(top) - { - QWidget* navigationWidget = top->createNavigationWidget(); - if( navigationWidget ) - { - m_tooltip = new KDevelop::NavigationToolTip(this, helpEvent->globalPos() + QPoint(40, 0), navigationWidget); - m_tooltip->resize( navigationWidget->sizeHint() + QSize(10, 10) ); - qCDebug(PLUGIN_PROJECTMANAGERVIEW) << "tooltip size" << m_tooltip->size(); - ActiveToolTip::showToolTip(m_tooltip); - return true; - } - } - } - } - - return QAbstractItemView::event(event); -} - void ProjectTreeView::keyPressEvent(QKeyEvent* event) { if (event->key() == Qt::Key_Return && currentIndex().isValid() && state()!=QAbstractItemView::EditingState) { event->accept(); slotActivated(currentIndex()); } else QTreeView::keyPressEvent(event); } void ProjectTreeView::drawBranches(QPainter* painter, const QRect& rect, const QModelIndex& index) const { if (WidgetColorizer::colorizeByProject()) { const auto projectPath = index.data(ProjectModel::ProjectRole).value()->path(); const QColor color = WidgetColorizer::colorForId(qHash(projectPath), palette(), true); WidgetColorizer::drawBranches(this, painter, rect, index, color); } QTreeView::drawBranches(painter, rect, index); } diff --git a/plugins/projectmanagerview/projecttreeview.h b/plugins/projectmanagerview/projecttreeview.h index f143503b5b..918f19d2e4 100644 --- a/plugins/projectmanagerview/projecttreeview.h +++ b/plugins/projectmanagerview/projecttreeview.h @@ -1,79 +1,74 @@ /* This file is part of KDevelop Copyright 2005 Roberto Raggi Copyright 2007 Andreas Pakulat This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KDEVPLATFORM_PLUGIN_PROJECTTREEVIEW_H #define KDEVPLATFORM_PLUGIN_PROJECTTREEVIEW_H #include #include class QAbstractProxyModel; namespace KDevelop { class IProject; class ProjectBaseItem; -class NavigationToolTip; class Path; } class ProjectTreeView: public QTreeView { Q_OBJECT public: explicit ProjectTreeView( QWidget *parent = nullptr ); ~ProjectTreeView() override; static QModelIndex mapFromSource(const QAbstractProxyModel* proxy, const QModelIndex& sourceIdx); - bool event(QEvent* event) override; - Q_SIGNALS: void activate( const KDevelop::Path &url ); protected Q_SLOTS: void slotActivated( const QModelIndex &index ); void popupContextMenu( const QPoint &pos ); void openProjectConfig(); void saveState(KDevelop::IProject* project = nullptr); void restoreState(KDevelop::IProject* project = nullptr); void aboutToShutdown(); void projectClosed(KDevelop::IProject* project); void rowsInserted(const QModelIndex& parent, int start, int end) override; void rowsAboutToBeRemoved(const QModelIndex& parent, int start, int end) override; protected: void keyPressEvent(QKeyEvent *event) override; void dropEvent(QDropEvent* event) override; void drawBranches(QPainter* painter, const QRect& rect, const QModelIndex& index) const override; private: QModelIndex mapFromItem(const KDevelop::ProjectBaseItem* item); KDevelop::ProjectBaseItem* itemAtPos(const QPoint& pos) const; QList selectedProjects(); KDevelop::IProject* getCurrentProject(); QPointer m_previousSelection; - QPointer m_tooltip; - QPersistentModelIndex m_idx; }; #endif // KDEVPLATFORM_PLUGIN_PROJECTTREEVIEW_H