Changeset View
Changeset View
Standalone View
Standalone View
plugins/projectmanagerview/projecttreeview.cpp
Show All 23 Lines | |||||
24 | 24 | | |||
25 | #include <QAction> | 25 | #include <QAction> | ||
26 | #include <QAbstractProxyModel> | 26 | #include <QAbstractProxyModel> | ||
27 | #include <QApplication> | 27 | #include <QApplication> | ||
28 | #include <QHeaderView> | 28 | #include <QHeaderView> | ||
29 | #include <QMenu> | 29 | #include <QMenu> | ||
30 | #include <QMouseEvent> | 30 | #include <QMouseEvent> | ||
31 | #include <QPainter> | 31 | #include <QPainter> | ||
32 | #include <QScrollBar> | ||||
32 | 33 | | |||
33 | #include <KConfigGroup> | 34 | #include <KConfigGroup> | ||
34 | #include <KLocalizedString> | 35 | #include <KLocalizedString> | ||
35 | 36 | | |||
36 | #include <project/projectmodel.h> | 37 | #include <project/projectmodel.h> | ||
37 | #include <language/duchain/duchainutils.h> | 38 | #include <language/duchain/duchainutils.h> | ||
38 | #include <interfaces/contextmenuextension.h> | 39 | #include <interfaces/contextmenuextension.h> | ||
39 | #include <interfaces/iprojectcontroller.h> | 40 | #include <interfaces/iprojectcontroller.h> | ||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Line(s) | 109 | { | |||
109 | menu.addActions(actions); | 110 | menu.addActions(actions); | ||
110 | menu.addSeparator(); | 111 | menu.addSeparator(); | ||
111 | } | 112 | } | ||
112 | 113 | | |||
113 | } | 114 | } | ||
114 | 115 | | |||
115 | ProjectTreeView::ProjectTreeView( QWidget *parent ) | 116 | ProjectTreeView::ProjectTreeView( QWidget *parent ) | ||
116 | : QTreeView( parent ), m_previousSelection ( nullptr ) | 117 | : QTreeView( parent ), m_previousSelection ( nullptr ) | ||
118 | #ifdef Q_OS_MACOS | ||||
119 | , m_isCocoa(QGuiApplication::platformName() == QStringLiteral("cocoa")) | ||||
120 | #endif | ||||
117 | { | 121 | { | ||
118 | header()->hide(); | 122 | header()->hide(); | ||
119 | 123 | | |||
120 | setEditTriggers( QAbstractItemView::EditKeyPressed ); | 124 | setEditTriggers( QAbstractItemView::EditKeyPressed ); | ||
121 | 125 | | |||
122 | setContextMenuPolicy( Qt::CustomContextMenu ); | 126 | setContextMenuPolicy( Qt::CustomContextMenu ); | ||
123 | setSelectionMode( QAbstractItemView::ExtendedSelection ); | 127 | setSelectionMode( QAbstractItemView::ExtendedSelection ); | ||
124 | 128 | | |||
125 | setIndentation(10); | 129 | setIndentation(10); | ||
126 | 130 | | |||
127 | setDragEnabled(true); | 131 | setDragEnabled(true); | ||
128 | setDragDropMode(QAbstractItemView::InternalMove); | 132 | setDragDropMode(QAbstractItemView::InternalMove); | ||
129 | setAutoScroll(true); | 133 | setAutoScroll(true); | ||
130 | setAutoExpandDelay(300); | 134 | setAutoExpandDelay(300); | ||
131 | setItemDelegate(new ProjectModelItemDelegate(this)); | 135 | setItemDelegate(new ProjectModelItemDelegate(this)); | ||
132 | 136 | | |||
137 | setTextElideMode(Qt::ElideNone); | ||||
138 | | ||||
133 | connect( this, &ProjectTreeView::customContextMenuRequested, this, &ProjectTreeView::popupContextMenu ); | 139 | connect( this, &ProjectTreeView::customContextMenuRequested, this, &ProjectTreeView::popupContextMenu ); | ||
134 | connect( this, &ProjectTreeView::activated, this, &ProjectTreeView::slotActivated ); | 140 | connect( this, &ProjectTreeView::activated, this, &ProjectTreeView::slotActivated ); | ||
135 | 141 | | |||
136 | connect( ICore::self(), &ICore::aboutToShutdown, | 142 | connect( ICore::self(), &ICore::aboutToShutdown, | ||
137 | this, &ProjectTreeView::aboutToShutdown); | 143 | this, &ProjectTreeView::aboutToShutdown); | ||
138 | connect( ICore::self()->projectController(), &IProjectController::projectOpened, | 144 | connect( ICore::self()->projectController(), &IProjectController::projectOpened, | ||
139 | this, &ProjectTreeView::restoreState ); | 145 | this, &ProjectTreeView::restoreState ); | ||
140 | connect( ICore::self()->projectController(), &IProjectController::projectClosed, | 146 | connect( ICore::self()->projectController(), &IProjectController::projectClosed, | ||
141 | this, &ProjectTreeView::projectClosed ); | 147 | this, &ProjectTreeView::projectClosed ); | ||
148 | | ||||
149 | // install the event filter that will filter out the horizontal component | ||||
150 | // from scrolling in response to QWheelEvents (i.e. touch input) | ||||
151 | viewport()->installEventFilter(this); | ||||
142 | } | 152 | } | ||
143 | 153 | | |||
144 | ProjectTreeView::~ProjectTreeView() | 154 | ProjectTreeView::~ProjectTreeView() | ||
145 | { | 155 | { | ||
146 | } | 156 | } | ||
147 | 157 | | |||
148 | ProjectBaseItem* ProjectTreeView::itemAtPos(QPoint pos) | 158 | ProjectBaseItem* ProjectTreeView::itemAtPos(QPoint pos) | ||
149 | { | 159 | { | ||
▲ Show 20 Lines • Show All 356 Lines • ▼ Show 20 Line(s) | 514 | { | |||
506 | { | 516 | { | ||
507 | event->accept(); | 517 | event->accept(); | ||
508 | slotActivated(currentIndex()); | 518 | slotActivated(currentIndex()); | ||
509 | } | 519 | } | ||
510 | else | 520 | else | ||
511 | QTreeView::keyPressEvent(event); | 521 | QTreeView::keyPressEvent(event); | ||
512 | } | 522 | } | ||
513 | 523 | | |||
524 | void ProjectTreeView::resizeEvent(QResizeEvent* event) | ||||
525 | { | ||||
526 | header()->setMinimumSectionSize(viewport()->width()); | ||||
527 | QTreeView::resizeEvent(event); | ||||
528 | } | ||||
529 | | ||||
530 | bool ProjectTreeView::eventFilter(QObject* object, QEvent* event) | ||||
531 | { | ||||
532 | switch (event->type()) { | ||||
533 | case QEvent::Wheel: { | ||||
534 | QWheelEvent *e = static_cast<QWheelEvent*>(event); | ||||
535 | if ((e->pixelDelta().x() !=0 || e->angleDelta().x()!= 0 | ||||
536 | || e->orientation() == Qt::Orientation::Horizontal) | ||||
537 | #ifdef Q_OS_MACOS | ||||
538 | // Cocoa: allow horizontal scrolling controlled by a physical mouse wheel | ||||
539 | && (!m_isCocoa || e->source() != Qt::MouseEventNotSynthesized) | ||||
540 | #endif | ||||
541 | ){ | ||||
542 | QPoint pixelDelta(e->pixelDelta()), angleDelta(e->angleDelta()); | ||||
543 | pixelDelta.setX(0); | ||||
544 | angleDelta.setX(0); | ||||
545 | // discard the original event | ||||
546 | e->ignore(); | ||||
547 | if (!pixelDelta.isNull() || !angleDelta.isNull()) { | ||||
548 | QWheelEvent filtered(e->posF(), e->globalPosF(), pixelDelta, angleDelta, | ||||
549 | e->delta(), Qt::Orientation::Vertical, e->buttons(), | ||||
550 | e->modifiers(), e->phase(), Qt::MouseEventSynthesizedByApplication, e->inverted()); | ||||
551 | QCoreApplication::sendEvent(object, &filtered); | ||||
552 | } | ||||
553 | return true; | ||||
554 | } | ||||
555 | break; | ||||
556 | } | ||||
557 | } | ||||
558 | return QTreeView::eventFilter(object, event); | ||||
559 | } | ||||
560 | | ||||
514 | void ProjectTreeView::drawBranches(QPainter* painter, const QRect& rect, const QModelIndex& index) const | 561 | void ProjectTreeView::drawBranches(QPainter* painter, const QRect& rect, const QModelIndex& index) const | ||
515 | { | 562 | { | ||
516 | if (WidgetColorizer::colorizeByProject()) { | 563 | if (WidgetColorizer::colorizeByProject()) { | ||
517 | const auto projectPath = index.data(ProjectModel::ProjectRole).value<IProject *>()->path(); | 564 | const auto projectPath = index.data(ProjectModel::ProjectRole).value<IProject *>()->path(); | ||
518 | const QColor color = WidgetColorizer::colorForId(qHash(projectPath), palette(), true); | 565 | const QColor color = WidgetColorizer::colorForId(qHash(projectPath), palette(), true); | ||
519 | WidgetColorizer::drawBranches(this, painter, rect, index, color); | 566 | WidgetColorizer::drawBranches(this, painter, rect, index, color); | ||
520 | } | 567 | } | ||
521 | 568 | | |||
522 | QTreeView::drawBranches(painter, rect, index); | 569 | QTreeView::drawBranches(painter, rect, index); | ||
523 | } | 570 | } |