File indexing completed on 2024-10-06 09:40:31

0001 /*
0002     SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
0003     SPDX-FileContributor: Stephen Kelly <stephen@kdab.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include "breadcrumbdirectionwidget.h"
0009 
0010 #include <dynamictreemodel.h>
0011 #include <kbreadcrumbselectionmodel.h>
0012 
0013 #include <QEvent>
0014 #include <QHBoxLayout>
0015 #include <QSplitter>
0016 #include <QTreeView>
0017 
0018 BreadcrumbDirectionWidget::BreadcrumbDirectionWidget(QWidget *parent, Qt::WindowFlags f)
0019     : QWidget(parent, f)
0020 {
0021     DynamicTreeModel *rootModel = new DynamicTreeModel(this);
0022 
0023     ModelInsertCommand ins(rootModel);
0024     ins.setStartRow(0);
0025     ins.interpret(
0026         QLatin1String("- 1"
0027                       "- 2"
0028                       "- - 3"
0029                       "- - 3"
0030                       "- - - 4"
0031                       "- - - 4"
0032                       "- - - - 4"
0033                       "- - 4"
0034                       "- - 5"
0035                       "- - - 4"
0036                       "- - - - 4"
0037                       "- - 5"
0038                       "- 6"
0039                       "- 7"
0040                       "- - 8"
0041                       "- - - 9"
0042                       "- - - 10"
0043                       "- - - - 9"
0044                       "- - - - - 10"
0045                       "- - - - - - 9"
0046                       "- - - - - - 10"
0047                       "- - - - - - - 9"
0048                       "- - - - - - - - 10"
0049                       "- - - - - - - - 9"
0050                       "- - - - - - - 10"
0051                       "- 20"
0052                       "- 21"));
0053     ins.doCommand();
0054 
0055     QHBoxLayout *layout = new QHBoxLayout(this);
0056     QSplitter *splitter1 = new QSplitter(Qt::Vertical, this);
0057     layout->addWidget(splitter1);
0058     QSplitter *splitter2 = new QSplitter(splitter1);
0059     QSplitter *splitter3 = new QSplitter(splitter1);
0060 
0061     QTreeView *view1 = new QTreeView(splitter2);
0062     view1->setModel(rootModel);
0063     view1->expandAll();
0064     view1->viewport()->setBackgroundRole(QPalette::Button);
0065     QTreeView *view2 = new QTreeView(splitter2);
0066     view2->setModel(rootModel);
0067     view2->expandAll();
0068     view2->viewport()->installEventFilter(this);
0069     QTreeView *view3 = new QTreeView(splitter3);
0070     view3->setModel(rootModel);
0071     view3->expandAll();
0072     QTreeView *view4 = new QTreeView(splitter3);
0073     view4->setModel(rootModel);
0074     view4->expandAll();
0075     view4->viewport()->installEventFilter(this);
0076     view4->viewport()->setBackgroundRole(QPalette::Button);
0077 
0078     KBreadcrumbSelectionModel *breadcrumbSelection1 = new KBreadcrumbSelectionModel(view2->selectionModel(), this);
0079     view1->setSelectionModel(breadcrumbSelection1);
0080 
0081     KBreadcrumbSelectionModel *breadcrumbSelection2 =
0082         new KBreadcrumbSelectionModel(view3->selectionModel(), KBreadcrumbSelectionModel::MakeBreadcrumbSelectionInOther, this);
0083     view4->setSelectionModel(breadcrumbSelection2);
0084 }
0085 
0086 bool BreadcrumbDirectionWidget::eventFilter(QObject *o, QEvent *e)
0087 {
0088     if (e->type() == QEvent::MouseButtonPress || e->type() == QEvent::MouseButtonDblClick || e->type() == QEvent::MouseButtonRelease) {
0089         return true;
0090     }
0091     return QObject::eventFilter(o, e);
0092 }
0093 
0094 #include "moc_breadcrumbdirectionwidget.cpp"