File indexing completed on 2024-09-22 05:16:05
0001 /* 0002 This file is part of the Kasten Framework, made within the KDE community. 0003 0004 SPDX-FileCopyrightText: 2009 Friedrich W. H. Kossebau <kossebau@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #include "documentsview.hpp" 0010 0011 // tool 0012 #include "documentlistmodel.hpp" 0013 #include "documentstool.hpp" 0014 // Qt 0015 #include <QTreeView> 0016 #include <QVBoxLayout> 0017 0018 namespace Kasten { 0019 0020 DocumentsView::DocumentsView(DocumentsTool* tool, QWidget* parent) 0021 : QWidget(parent) 0022 , mTool(tool) 0023 { 0024 mDocumentListModel = new DocumentListModel(mTool, this); 0025 0026 auto* baseLayout = new QVBoxLayout(this); 0027 baseLayout->setContentsMargins(0, 0, 0, 0); 0028 baseLayout->setSpacing(0); 0029 0030 mDocumentListView = new QTreeView(this); 0031 mDocumentListView->setObjectName(QStringLiteral("DocumentListView")); 0032 mDocumentListView->setRootIsDecorated(false); 0033 mDocumentListView->setItemsExpandable(false); 0034 mDocumentListView->setUniformRowHeights(true); 0035 mDocumentListView->setAllColumnsShowFocus(true); 0036 mDocumentListView->setModel(mDocumentListModel); 0037 connect(mDocumentListView, &QAbstractItemView::activated, 0038 this, &DocumentsView::onDocumentActivated); 0039 for (int c = 0; c < DocumentListModel::NoOfColumnIds; ++c) { 0040 mDocumentListView->resizeColumnToContents(c); 0041 } 0042 0043 baseLayout->addWidget(mDocumentListView, 10); 0044 } 0045 0046 DocumentsView::~DocumentsView() = default; 0047 0048 void DocumentsView::onDocumentActivated(const QModelIndex& index) 0049 { 0050 const int documentIndex = index.row(); 0051 AbstractDocument* document = mTool->documents().at(documentIndex); 0052 0053 if (document) { 0054 mTool->setFocussedDocument(document); 0055 } 0056 } 0057 0058 } 0059 0060 #include "moc_documentsview.cpp"