KIO

kdiroperatordetailview.cpp
1/*
2 SPDX-FileCopyrightText: 2007 Peter Penz <peter.penz@gmx.at>
3
4 SPDX-License-Identifier: LGPL-2.0-only
5*/
6
7#include "kdiroperatordetailview_p.h"
8
9#include <kdirlister.h>
10#include <kdirmodel.h>
11
12#include <QApplication>
13#include <QDragEnterEvent>
14#include <QEvent>
15#include <QHeaderView>
16#include <QListView>
17#include <QMimeData>
18#include <QScrollBar>
19
20KDirOperatorDetailView::KDirOperatorDetailView(QWidget *parent)
21 : QTreeView(parent)
22 , m_hideDetailColumns(false)
23{
24 setRootIsDecorated(false);
25 setSortingEnabled(true);
26 setUniformRowHeights(true);
27 setDragDropMode(QListView::DragOnly);
28 setSelectionBehavior(QAbstractItemView::SelectRows);
29 setEditTriggers(QAbstractItemView::NoEditTriggers);
30 setVerticalScrollMode(QListView::ScrollPerPixel);
31 setHorizontalScrollMode(QListView::ScrollPerPixel);
32
33 const QFontMetrics metrics(viewport()->font());
34 const int singleStep = metrics.height() * QApplication::wheelScrollLines();
35
36 verticalScrollBar()->setSingleStep(singleStep);
37 horizontalScrollBar()->setSingleStep(singleStep);
38}
39
40KDirOperatorDetailView::~KDirOperatorDetailView()
41{
42}
43
44bool KDirOperatorDetailView::setViewMode(KFile::FileView viewMode)
45{
46 bool tree = false;
47
48 if (KFile::isDetailView(viewMode)) {
49 m_hideDetailColumns = false;
50 setAlternatingRowColors(true);
51 } else if (KFile::isTreeView(viewMode)) {
52 m_hideDetailColumns = true;
53 setAlternatingRowColors(false);
54 tree = true;
55 } else if (KFile::isDetailTreeView(viewMode)) {
56 m_hideDetailColumns = false;
57 setAlternatingRowColors(true);
58 tree = true;
59 } else {
60 return false;
61 }
62
63 setRootIsDecorated(tree);
64 setItemsExpandable(tree);
65 // This allows to have a horizontal scrollbar in case this view is used as
66 // a plain treeview instead of cutting off filenames, especially useful when
67 // using KDirOperator in horizontally limited parts of an app.
68 if (tree && m_hideDetailColumns) {
69 header()->setSectionResizeMode(QHeaderView::ResizeToContents);
70 } else {
71 header()->setSectionResizeMode(QHeaderView::Interactive);
72 }
73
74 return true;
75}
76
77void KDirOperatorDetailView::initViewItemOption(QStyleOptionViewItem *option) const
78{
80 option->textElideMode = Qt::ElideMiddle;
81}
82
83bool KDirOperatorDetailView::event(QEvent *event)
84{
85 if (event->type() == QEvent::Polish) {
86 QHeaderView *headerView = header();
90 headerView->setStretchLastSection(false);
91 headerView->setSectionsMovable(false);
92
93 setColumnHidden(KDirModel::Size, m_hideDetailColumns);
94 setColumnHidden(KDirModel::ModifiedTime, m_hideDetailColumns);
95 hideColumn(KDirModel::Type);
96 hideColumn(KDirModel::Permissions);
97 hideColumn(KDirModel::Owner);
98 hideColumn(KDirModel::Group);
99 } else if (event->type() == QEvent::UpdateRequest) {
100 // A wheel movement will scroll 4 items
101 if (model()->rowCount()) {
102 verticalScrollBar()->setSingleStep((sizeHintForRow(0) / 3) * 4);
103 }
104 }
105
106 return QTreeView::event(event);
107}
108
109void KDirOperatorDetailView::dragEnterEvent(QDragEnterEvent *event)
110{
111 if (event->mimeData()->hasUrls()) {
112 event->acceptProposedAction();
113 }
114}
115
116void KDirOperatorDetailView::mousePressEvent(QMouseEvent *event)
117{
119
120 const QModelIndex index = indexAt(event->pos());
121 if (!index.isValid() || (index.column() != KDirModel::Name)) {
123 if (!(modifiers & Qt::ShiftModifier) && !(modifiers & Qt::ControlModifier)) {
124 clearSelection();
125 }
126 }
127}
128
129void KDirOperatorDetailView::currentChanged(const QModelIndex &current, const QModelIndex &previous)
130{
131 QTreeView::currentChanged(current, previous);
132}
133
134#include "moc_kdiroperatordetailview_p.cpp"
AKONADI_CALENDAR_EXPORT KCalendarCore::Event::Ptr event(const Akonadi::Item &item)
virtual bool event(QEvent *event) override
virtual void initViewItemOption(QStyleOptionViewItem *option) const const
Qt::KeyboardModifiers keyboardModifiers()
void setSectionResizeMode(ResizeMode mode)
void setSectionsMovable(bool movable)
void setStretchLastSection(bool stretch)
int column() const const
bool isValid() const const
typedef KeyboardModifiers
ElideMiddle
virtual void currentChanged(const QModelIndex &current, const QModelIndex &previous) override
virtual void mousePressEvent(QMouseEvent *event) override
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:16:28 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.