Changeset View
Changeset View
Standalone View
Standalone View
src/filewidgets/kdiroperator.cpp
Show All 17 Lines | 1 | /* This file is part of the KDE libraries | |||
---|---|---|---|---|---|
18 | Boston, MA 02110-1301, USA. | 18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "kdiroperator.h" | 21 | #include "kdiroperator.h" | ||
22 | #include <kprotocolmanager.h> | 22 | #include <kprotocolmanager.h> | ||
23 | #include <kiconloader.h> | 23 | #include <kiconloader.h> | ||
24 | #include "kdirmodel.h" | 24 | #include "kdirmodel.h" | ||
25 | #include "kdiroperatordetailview_p.h" | 25 | #include "kdiroperatordetailview_p.h" | ||
26 | #include "kdiroperatoriconview_p.h" | ||||
26 | #include "kdirsortfilterproxymodel.h" | 27 | #include "kdirsortfilterproxymodel.h" | ||
27 | #include "kfileitem.h" | 28 | #include "kfileitem.h" | ||
28 | #include "kfilemetapreview_p.h" | 29 | #include "kfilemetapreview_p.h" | ||
29 | #include "kpreviewwidgetbase.h" | 30 | #include "kpreviewwidgetbase.h" | ||
30 | #include "knewfilemenu.h" | 31 | #include "knewfilemenu.h" | ||
31 | #include <kurlmimedata.h> | 32 | #include <kurlmimedata.h> | ||
32 | #include "../pathhelpers_p.h" | 33 | #include "../pathhelpers_p.h" | ||
33 | 34 | | |||
34 | #include <config-kiofilewidgets.h> | 35 | #include <config-kiofilewidgets.h> | ||
35 | #include <defaults-kfile.h> // ConfigGroup, DefaultShowHidden, DefaultDirsFirst, DefaultSortReversed | 36 | #include <defaults-kfile.h> // ConfigGroup, DefaultShowHidden, DefaultDirsFirst, DefaultSortReversed | ||
36 | 37 | | |||
37 | #include <QApplication> | 38 | #include <QApplication> | ||
38 | #include <QHeaderView> | 39 | #include <QHeaderView> | ||
39 | #include <QListView> | 40 | #include <QListView> | ||
40 | #include <QMenu> | 41 | #include <QMenu> | ||
41 | #include <QMimeData> | | |||
42 | #include <QProgressBar> | 42 | #include <QProgressBar> | ||
43 | #include <QScrollBar> | | |||
44 | #include <QSplitter> | 43 | #include <QSplitter> | ||
45 | #include <QWheelEvent> | 44 | #include <QWheelEvent> | ||
46 | #include <QTimer> | 45 | #include <QTimer> | ||
47 | #include <QDebug> | 46 | #include <QDebug> | ||
48 | #include <QMimeDatabase> | 47 | #include <QMimeDatabase> | ||
49 | 48 | | |||
50 | #include <kdirlister.h> | 49 | #include <kdirlister.h> | ||
51 | #include <kfileitemdelegate.h> | 50 | #include <kfileitemdelegate.h> | ||
Show All 13 Lines | |||||
65 | #include <ksharedconfig.h> | 64 | #include <ksharedconfig.h> | ||
66 | 65 | | |||
67 | template class QHash<QString, KFileItem>; | 66 | template class QHash<QString, KFileItem>; | ||
68 | 67 | | |||
69 | // QDir::SortByMask is not only undocumented, it also omits QDir::Type which is another | 68 | // QDir::SortByMask is not only undocumented, it also omits QDir::Type which is another | ||
70 | // sorting mode. | 69 | // sorting mode. | ||
71 | static const int QDirSortMask = QDir::SortByMask | QDir::Type; | 70 | static const int QDirSortMask = QDir::SortByMask | QDir::Type; | ||
72 | 71 | | |||
73 | /** | | |||
74 | * Default icon view for KDirOperator using | | |||
75 | * custom view options. | | |||
76 | */ | | |||
77 | class KDirOperatorIconView : public QListView | | |||
78 | { | | |||
79 | Q_OBJECT | | |||
80 | public: | | |||
81 | KDirOperatorIconView(KDirOperator *dirOperator, QWidget *parent = nullptr); | | |||
82 | virtual ~KDirOperatorIconView(); | | |||
83 | | ||||
84 | protected: | | |||
85 | QStyleOptionViewItem viewOptions() const override; | | |||
86 | void dragEnterEvent(QDragEnterEvent *event) override; | | |||
87 | void mousePressEvent(QMouseEvent *event) override; | | |||
88 | void wheelEvent(QWheelEvent *event) override; | | |||
89 | | ||||
90 | private: | | |||
91 | KDirOperator *ops; | | |||
92 | }; | | |||
93 | | ||||
94 | KDirOperatorIconView::KDirOperatorIconView(KDirOperator *dirOperator, QWidget *parent) : | | |||
95 | QListView(parent), | | |||
96 | ops(dirOperator) | | |||
97 | { | | |||
98 | setViewMode(QListView::IconMode); | | |||
99 | setFlow(QListView::TopToBottom); | | |||
100 | setResizeMode(QListView::Adjust); | | |||
101 | setSpacing(0); | | |||
102 | setMovement(QListView::Static); | | |||
103 | setDragDropMode(QListView::DragOnly); | | |||
104 | setVerticalScrollMode(QListView::ScrollPerPixel); | | |||
105 | setHorizontalScrollMode(QListView::ScrollPerPixel); | | |||
106 | setEditTriggers(QAbstractItemView::NoEditTriggers); | | |||
107 | setWordWrap(true); | | |||
108 | setIconSize(QSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall)); | | |||
109 | } | | |||
110 | | ||||
111 | KDirOperatorIconView::~KDirOperatorIconView() | | |||
112 | { | | |||
113 | } | | |||
114 | | ||||
115 | QStyleOptionViewItem KDirOperatorIconView::viewOptions() const | | |||
116 | { | | |||
117 | QStyleOptionViewItem viewOptions = QListView::viewOptions(); | | |||
118 | viewOptions.showDecorationSelected = true; | | |||
119 | viewOptions.decorationPosition = ops->decorationPosition(); | | |||
120 | if (viewOptions.decorationPosition == QStyleOptionViewItem::Left) { | | |||
121 | viewOptions.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter; | | |||
122 | } else { | | |||
123 | viewOptions.displayAlignment = Qt::AlignCenter; | | |||
124 | } | | |||
125 | | ||||
126 | return viewOptions; | | |||
127 | } | | |||
128 | | ||||
129 | void KDirOperatorIconView::dragEnterEvent(QDragEnterEvent *event) | | |||
130 | { | | |||
131 | if (event->mimeData()->hasUrls()) { | | |||
132 | event->acceptProposedAction(); | | |||
133 | } | | |||
134 | } | | |||
135 | | ||||
136 | void KDirOperatorIconView::mousePressEvent(QMouseEvent *event) | | |||
137 | { | | |||
138 | if (!indexAt(event->pos()).isValid()) { | | |||
139 | const Qt::KeyboardModifiers modifiers = QApplication::keyboardModifiers(); | | |||
140 | if (!(modifiers & Qt::ShiftModifier) && !(modifiers & Qt::ControlModifier)) { | | |||
141 | clearSelection(); | | |||
142 | } | | |||
143 | } | | |||
144 | | ||||
145 | QListView::mousePressEvent(event); | | |||
146 | } | | |||
147 | | ||||
148 | void KDirOperatorIconView::wheelEvent(QWheelEvent *event) | | |||
149 | { | | |||
150 | QListView::wheelEvent(event); | | |||
151 | | ||||
152 | // apply the vertical wheel event to the horizontal scrollbar, as | | |||
153 | // the items are aligned from left to right | | |||
154 | if (event->orientation() == Qt::Vertical) { | | |||
155 | QWheelEvent horizEvent(event->pos(), | | |||
156 | event->delta(), | | |||
157 | event->buttons(), | | |||
158 | event->modifiers(), | | |||
159 | Qt::Horizontal); | | |||
160 | QApplication::sendEvent(horizontalScrollBar(), &horizEvent); | | |||
161 | } | | |||
162 | } | | |||
163 | 72 | | |||
164 | void KDirOperator::keyPressEvent(QKeyEvent *e) | 73 | void KDirOperator::keyPressEvent(QKeyEvent *e) | ||
165 | { | 74 | { | ||
166 | if (!(e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter)) { | 75 | if (!(e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter)) { | ||
167 | QWidget::keyPressEvent(e); | 76 | QWidget::keyPressEvent(e); | ||
168 | } else { | 77 | } else { | ||
169 | emit keyEnterReturnPressed(); | 78 | emit keyEnterReturnPressed(); | ||
170 | } | 79 | } | ||
Show All 27 Lines | 84 | public: | |||
198 | QMetaObject::Connection m_connection; | 107 | QMetaObject::Connection m_connection; | ||
199 | 108 | | |||
200 | // private slots | 109 | // private slots | ||
201 | void _k_slotDetailedView(); | 110 | void _k_slotDetailedView(); | ||
202 | void _k_slotSimpleView(); | 111 | void _k_slotSimpleView(); | ||
203 | void _k_slotTreeView(); | 112 | void _k_slotTreeView(); | ||
204 | void _k_slotDetailedTreeView(); | 113 | void _k_slotDetailedTreeView(); | ||
205 | void _k_slotToggleHidden(bool); | 114 | void _k_slotToggleHidden(bool); | ||
115 | void _k_slotToggleAllowExpansion(bool); | ||||
206 | void _k_togglePreview(bool); | 116 | void _k_togglePreview(bool); | ||
207 | void _k_toggleInlinePreviews(bool); | 117 | void _k_toggleInlinePreviews(bool); | ||
208 | void _k_slotOpenFileManager(); | 118 | void _k_slotOpenFileManager(); | ||
209 | void _k_slotSortByName(); | 119 | void _k_slotSortByName(); | ||
210 | void _k_slotSortBySize(); | 120 | void _k_slotSortBySize(); | ||
211 | void _k_slotSortByDate(); | 121 | void _k_slotSortByDate(); | ||
212 | void _k_slotSortByType(); | 122 | void _k_slotSortByType(); | ||
213 | void _k_slotSortReversed(bool doReverse); | 123 | void _k_slotSortReversed(bool doReverse); | ||
214 | void _k_slotToggleDirsFirst(); | 124 | void _k_slotToggleDirsFirst(); | ||
125 | void _k_slotToggleIconsView(); | ||||
126 | void _k_slotToggleCompactView(); | ||||
127 | void _k_slotToggleDetailsView(); | ||||
215 | void _k_slotToggleIgnoreCase(); | 128 | void _k_slotToggleIgnoreCase(); | ||
216 | void _k_slotStarted(); | 129 | void _k_slotStarted(); | ||
217 | void _k_slotProgress(int); | 130 | void _k_slotProgress(int); | ||
218 | void _k_slotShowProgress(); | 131 | void _k_slotShowProgress(); | ||
219 | void _k_slotIOFinished(); | 132 | void _k_slotIOFinished(); | ||
220 | void _k_slotCanceled(); | 133 | void _k_slotCanceled(); | ||
221 | void _k_slotRedirected(const QUrl &); | 134 | void _k_slotRedirected(const QUrl &); | ||
222 | void _k_slotProperties(); | 135 | void _k_slotProperties(); | ||
223 | void _k_slotActivated(const QModelIndex &); | 136 | void _k_slotActivated(const QModelIndex &); | ||
224 | void _k_slotSelectionChanged(); | 137 | void _k_slotSelectionChanged(); | ||
225 | void _k_openContextMenu(const QPoint &); | 138 | void _k_openContextMenu(const QPoint &); | ||
226 | void _k_triggerPreview(const QModelIndex &); | 139 | void _k_triggerPreview(const QModelIndex &); | ||
227 | void _k_showPreview(); | 140 | void _k_showPreview(); | ||
228 | void _k_slotSplitterMoved(int, int); | 141 | void _k_slotSplitterMoved(int, int); | ||
229 | void _k_assureVisibleSelection(); | 142 | void _k_assureVisibleSelection(); | ||
230 | void _k_synchronizeSortingState(int, Qt::SortOrder); | 143 | void _k_synchronizeSortingState(int, Qt::SortOrder); | ||
231 | void _k_slotChangeDecorationPosition(); | 144 | void _k_slotChangeDecorationPosition(); | ||
232 | void _k_slotExpandToUrl(const QModelIndex &); | 145 | void _k_slotExpandToUrl(const QModelIndex &); | ||
233 | void _k_slotItemsChanged(); | 146 | void _k_slotItemsChanged(); | ||
234 | void _k_slotDirectoryCreated(const QUrl &); | 147 | void _k_slotDirectoryCreated(const QUrl &); | ||
235 | 148 | | |||
236 | void updateListViewGrid(); | | |||
237 | int iconSizeForViewType(QAbstractItemView *itemView) const; | 149 | int iconSizeForViewType(QAbstractItemView *itemView) const; | ||
238 | 150 | | |||
239 | // private members | 151 | // private members | ||
240 | KDirOperator * const parent; | 152 | KDirOperator * const parent; | ||
241 | QStack<QUrl *> backStack; ///< Contains all URLs you can reach with the back button. | 153 | QStack<QUrl *> backStack; ///< Contains all URLs you can reach with the back button. | ||
242 | QStack<QUrl *> forwardStack; ///< Contains all URLs you can reach with the forward button. | 154 | QStack<QUrl *> forwardStack; ///< Contains all URLs you can reach with the forward button. | ||
243 | 155 | | |||
244 | QModelIndex lastHoveredIndex; | 156 | QModelIndex lastHoveredIndex; | ||
▲ Show 20 Lines • Show All 370 Lines • ▼ Show 20 Line(s) | |||||
615 | } | 527 | } | ||
616 | 528 | | |||
617 | void KDirOperator::Private::_k_slotDetailedTreeView() | 529 | void KDirOperator::Private::_k_slotDetailedTreeView() | ||
618 | { | 530 | { | ||
619 | KFile::FileView view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::DetailTree); | 531 | KFile::FileView view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::DetailTree); | ||
620 | parent->setView(view); | 532 | parent->setView(view); | ||
621 | } | 533 | } | ||
622 | 534 | | |||
535 | void KDirOperator::Private::_k_slotToggleAllowExpansion(bool allow) { | ||||
536 | KFile::FileView view = KFile::Detail; | ||||
537 | if (allow) { | ||||
538 | view = KFile::DetailTree; | ||||
539 | } | ||||
540 | parent->setView(view); | ||||
541 | } | ||||
542 | | ||||
623 | void KDirOperator::Private::_k_slotToggleHidden(bool show) | 543 | void KDirOperator::Private::_k_slotToggleHidden(bool show) | ||
624 | { | 544 | { | ||
625 | dirLister->setShowingDotFiles(show); | 545 | dirLister->setShowingDotFiles(show); | ||
626 | parent->updateDir(); | 546 | parent->updateDir(); | ||
627 | _k_assureVisibleSelection(); | 547 | _k_assureVisibleSelection(); | ||
628 | } | 548 | } | ||
629 | 549 | | |||
630 | void KDirOperator::Private::_k_togglePreview(bool on) | 550 | void KDirOperator::Private::_k_togglePreview(bool on) | ||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Line(s) | |||||
707 | } | 627 | } | ||
708 | 628 | | |||
709 | void KDirOperator::Private::_k_slotToggleDirsFirst() | 629 | void KDirOperator::Private::_k_slotToggleDirsFirst() | ||
710 | { | 630 | { | ||
711 | QDir::SortFlags s = (sorting ^ QDir::DirsFirst); | 631 | QDir::SortFlags s = (sorting ^ QDir::DirsFirst); | ||
712 | updateSorting(s); | 632 | updateSorting(s); | ||
713 | } | 633 | } | ||
714 | 634 | | |||
635 | void KDirOperator::Private::_k_slotToggleIconsView() | ||||
636 | { | ||||
637 | // Put the icons on top | ||||
638 | actionCollection->action(QStringLiteral("decorationAtTop"))->setChecked(true); | ||||
639 | decorationPosition = QStyleOptionViewItem::Top; | ||||
640 | | ||||
641 | // Switch to simple view | ||||
642 | KFile::FileView fileView = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::Simple); | ||||
643 | parent->setView(fileView); | ||||
644 | } | ||||
645 | | ||||
646 | void KDirOperator::Private::_k_slotToggleCompactView() | ||||
647 | { | ||||
648 | // Put the icons on the side | ||||
649 | actionCollection->action(QStringLiteral("decorationAtLeft"))->setChecked(true); | ||||
650 | decorationPosition = QStyleOptionViewItem::Left; | ||||
651 | | ||||
652 | // Switch to simple view | ||||
653 | KFile::FileView fileView = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::Simple); | ||||
654 | parent->setView(fileView); | ||||
655 | } | ||||
656 | | ||||
657 | void KDirOperator::Private::_k_slotToggleDetailsView() | ||||
658 | { | ||||
659 | KFile::FileView view; | ||||
660 | if (actionCollection->action(QStringLiteral("allow expansion"))->isChecked()) { | ||||
661 | view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::DetailTree); | ||||
662 | } else { | ||||
663 | view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::Detail); | ||||
664 | } | ||||
665 | parent->setView(view); | ||||
666 | } | ||||
667 | | ||||
715 | void KDirOperator::Private::_k_slotToggleIgnoreCase() | 668 | void KDirOperator::Private::_k_slotToggleIgnoreCase() | ||
716 | { | 669 | { | ||
717 | // TODO: port to Qt4's QAbstractItemView | 670 | // TODO: port to Qt4's QAbstractItemView | ||
718 | /*if ( !d->fileView ) | 671 | /*if ( !d->fileView ) | ||
719 | return; | 672 | return; | ||
720 | 673 | | |||
721 | QDir::SortFlags sorting = d->fileView->sorting(); | 674 | QDir::SortFlags sorting = d->fileView->sorting(); | ||
722 | if ( !KFile::isSortCaseInsensitive( sorting ) ) | 675 | if ( !KFile::isSortCaseInsensitive( sorting ) ) | ||
▲ Show 20 Lines • Show All 192 Lines • ▼ Show 20 Line(s) | 858 | { | |||
915 | 868 | | |||
916 | if (!d->previewGenerator) { | 869 | if (!d->previewGenerator) { | ||
917 | return; | 870 | return; | ||
918 | } | 871 | } | ||
919 | 872 | | |||
920 | const int maxSize = KIconLoader::SizeEnormous - KIconLoader::SizeSmall; | 873 | const int maxSize = KIconLoader::SizeEnormous - KIconLoader::SizeSmall; | ||
921 | const int val = (maxSize * value / 100) + KIconLoader::SizeSmall; | 874 | const int val = (maxSize * value / 100) + KIconLoader::SizeSmall; | ||
922 | d->itemView->setIconSize(QSize(val, val)); | 875 | d->itemView->setIconSize(QSize(val, val)); | ||
923 | d->updateListViewGrid(); | | |||
924 | d->previewGenerator->updatePreviews(); | 876 | d->previewGenerator->updatePreviews(); | ||
925 | 877 | | |||
926 | emit currentIconSizeChanged(value); | 878 | emit currentIconSizeChanged(value); | ||
927 | } | 879 | } | ||
928 | 880 | | |||
929 | void KDirOperator::close() | 881 | void KDirOperator::close() | ||
930 | { | 882 | { | ||
931 | resetCursor(); | 883 | resetCursor(); | ||
▲ Show 20 Lines • Show All 593 Lines • ▼ Show 20 Line(s) | |||||
1525 | QAbstractItemView *KDirOperator::createView(QWidget *parent, KFile::FileView viewKind) | 1477 | QAbstractItemView *KDirOperator::createView(QWidget *parent, KFile::FileView viewKind) | ||
1526 | { | 1478 | { | ||
1527 | QAbstractItemView *itemView = nullptr; | 1479 | QAbstractItemView *itemView = nullptr; | ||
1528 | if (KFile::isDetailView(viewKind) || KFile::isTreeView(viewKind) || KFile::isDetailTreeView(viewKind)) { | 1480 | if (KFile::isDetailView(viewKind) || KFile::isTreeView(viewKind) || KFile::isDetailTreeView(viewKind)) { | ||
1529 | KDirOperatorDetailView *detailView = new KDirOperatorDetailView(parent); | 1481 | KDirOperatorDetailView *detailView = new KDirOperatorDetailView(parent); | ||
1530 | detailView->setViewMode(viewKind); | 1482 | detailView->setViewMode(viewKind); | ||
1531 | itemView = detailView; | 1483 | itemView = detailView; | ||
1532 | } else { | 1484 | } else { | ||
1533 | itemView = new KDirOperatorIconView(this, parent); | 1485 | itemView = new KDirOperatorIconView(parent, decorationPosition()); | ||
1534 | } | 1486 | } | ||
1535 | 1487 | | |||
1536 | return itemView; | 1488 | return itemView; | ||
1537 | } | 1489 | } | ||
1538 | 1490 | | |||
1539 | void KDirOperator::setAcceptDrops(bool acceptsDrops) | 1491 | void KDirOperator::setAcceptDrops(bool acceptsDrops) | ||
1540 | { | 1492 | { | ||
1541 | QWidget::setAcceptDrops(acceptsDrops); | 1493 | QWidget::setAcceptDrops(acceptsDrops); | ||
▲ Show 20 Lines • Show All 131 Lines • ▼ Show 20 Line(s) | 1578 | { | |||
1673 | 1625 | | |||
1674 | connect(d->itemView, SIGNAL(activated(QModelIndex)), | 1626 | connect(d->itemView, SIGNAL(activated(QModelIndex)), | ||
1675 | this, SLOT(_k_slotActivated(QModelIndex))); | 1627 | this, SLOT(_k_slotActivated(QModelIndex))); | ||
1676 | connect(d->itemView, SIGNAL(customContextMenuRequested(QPoint)), | 1628 | connect(d->itemView, SIGNAL(customContextMenuRequested(QPoint)), | ||
1677 | this, SLOT(_k_openContextMenu(QPoint))); | 1629 | this, SLOT(_k_openContextMenu(QPoint))); | ||
1678 | connect(d->itemView, SIGNAL(entered(QModelIndex)), | 1630 | connect(d->itemView, SIGNAL(entered(QModelIndex)), | ||
1679 | this, SLOT(_k_triggerPreview(QModelIndex))); | 1631 | this, SLOT(_k_triggerPreview(QModelIndex))); | ||
1680 | 1632 | | |||
1681 | updateViewActions(); | | |||
1682 | d->splitter->insertWidget(0, d->itemView); | 1633 | d->splitter->insertWidget(0, d->itemView); | ||
1683 | 1634 | | |||
1684 | d->splitter->resize(size()); | 1635 | d->splitter->resize(size()); | ||
1685 | d->itemView->show(); | 1636 | d->itemView->show(); | ||
1686 | 1637 | | |||
1687 | if (listDir) { | 1638 | if (listDir) { | ||
1688 | QApplication::setOverrideCursor(Qt::WaitCursor); | 1639 | QApplication::setOverrideCursor(Qt::WaitCursor); | ||
1689 | d->openUrl(d->currUrl); | 1640 | d->openUrl(d->currUrl); | ||
Show All 28 Lines | |||||
1718 | const int maxSize = KIconLoader::SizeEnormous - KIconLoader::SizeSmall; | 1669 | const int maxSize = KIconLoader::SizeEnormous - KIconLoader::SizeSmall; | ||
1719 | const int val = (maxSize * d->iconsZoom / 100) + KIconLoader::SizeSmall; | 1670 | const int val = (maxSize * d->iconsZoom / 100) + KIconLoader::SizeSmall; | ||
1720 | d->itemView->setIconSize(previewForcedToTrue ? QSize(KIconLoader::SizeHuge, KIconLoader::SizeHuge) : QSize(val, val)); | 1671 | d->itemView->setIconSize(previewForcedToTrue ? QSize(KIconLoader::SizeHuge, KIconLoader::SizeHuge) : QSize(val, val)); | ||
1721 | d->previewGenerator->setPreviewShown(previewShown); | 1672 | d->previewGenerator->setPreviewShown(previewShown); | ||
1722 | d->actionCollection->action(QStringLiteral("inline preview"))->setChecked(previewShown); | 1673 | d->actionCollection->action(QStringLiteral("inline preview"))->setChecked(previewShown); | ||
1723 | 1674 | | |||
1724 | // ensure we change everything needed | 1675 | // ensure we change everything needed | ||
1725 | d->_k_slotChangeDecorationPosition(); | 1676 | d->_k_slotChangeDecorationPosition(); | ||
1677 | updateViewActions(); | ||||
1726 | 1678 | | |||
1727 | emit viewChanged(view); | 1679 | emit viewChanged(view); | ||
1728 | 1680 | | |||
1729 | const int zoom = previewForcedToTrue ? (KIconLoader::SizeHuge - KIconLoader::SizeSmall + 1) * 100 / maxSize : d->iconSizeForViewType(view); | 1681 | const int zoom = previewForcedToTrue ? (KIconLoader::SizeHuge - KIconLoader::SizeSmall + 1) * 100 / maxSize : d->iconSizeForViewType(view); | ||
1730 | 1682 | | |||
1731 | // this will make d->iconsZoom be updated, since setIconsZoom slot will be called | 1683 | // this will make d->iconsZoom be updated, since setIconsZoom slot will be called | ||
1732 | emit currentIconSizeChanged(zoom); | 1684 | emit currentIconSizeChanged(zoom); | ||
1733 | } | 1685 | } | ||
▲ Show 20 Lines • Show All 261 Lines • ▼ Show 20 Line(s) | 1887 | { | |||
1995 | KToggleAction *descendingAction = new KToggleAction(i18n("Descending"), this); | 1947 | KToggleAction *descendingAction = new KToggleAction(i18n("Descending"), this); | ||
1996 | d->actionCollection->addAction(QStringLiteral("descending"), descendingAction); | 1948 | d->actionCollection->addAction(QStringLiteral("descending"), descendingAction); | ||
1997 | connect(descendingAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotSortReversed(bool))); | 1949 | connect(descendingAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotSortReversed(bool))); | ||
1998 | 1950 | | |||
1999 | KToggleAction *dirsFirstAction = new KToggleAction(i18n("Folders First"), this); | 1951 | KToggleAction *dirsFirstAction = new KToggleAction(i18n("Folders First"), this); | ||
2000 | d->actionCollection->addAction(QStringLiteral("dirs first"), dirsFirstAction); | 1952 | d->actionCollection->addAction(QStringLiteral("dirs first"), dirsFirstAction); | ||
2001 | connect(dirsFirstAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotToggleDirsFirst())); | 1953 | connect(dirsFirstAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotToggleDirsFirst())); | ||
2002 | 1954 | | |||
1955 | // View modes that match those of Dolphin | ||||
anthonyfieroni: Can we make them reusable, it should be in framework and then accessed in Dolphin. | |||||
Well there are pretty much reusable already, their actions are available in the actionCollection, although not documented. But reusing kdiroperator in dolphin is another matter. meven: Well there are pretty much reusable already, their actions are available in the… | |||||
Yeah, I'm afraid it isn't possible without putting KDirOperator back into Dolphin, which was removed on purpose many years ago. I like to see Dolphin once again use a re-usable component too, but that's outside the scope of this patch. ngraham: Yeah, I'm afraid it isn't possible without putting KDirOperator back into Dolphin, which was… | |||||
1956 | KToggleAction *iconsViewAction = new KToggleAction(i18n("Icons View"), this); | ||||
1957 | iconsViewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-icons"))); | ||||
1958 | d->actionCollection->addAction(QStringLiteral("icons view"), iconsViewAction); | ||||
1959 | connect(iconsViewAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotToggleIconsView())); | ||||
1960 | | ||||
1961 | KToggleAction *compactViewAction = new KToggleAction(i18n("Compact View"), this); | ||||
1962 | compactViewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-details"))); | ||||
1963 | d->actionCollection->addAction(QStringLiteral("compact view"), compactViewAction); | ||||
1964 | connect(compactViewAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotToggleCompactView())); | ||||
1965 | | ||||
1966 | KToggleAction *detailsViewAction = new KToggleAction(i18n("Details View"), this); | ||||
1967 | detailsViewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-tree"))); | ||||
1968 | d->actionCollection->addAction(QStringLiteral("details view"), detailsViewAction); | ||||
1969 | connect(detailsViewAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotToggleDetailsView())); | ||||
1970 | | ||||
1971 | QActionGroup *viewModeGroup = new QActionGroup(this); | ||||
1972 | viewModeGroup->setExclusive(true); | ||||
1973 | iconsViewAction->setActionGroup(viewModeGroup); | ||||
1974 | compactViewAction->setActionGroup(viewModeGroup); | ||||
1975 | detailsViewAction->setActionGroup(viewModeGroup); | ||||
1976 | | ||||
2003 | d->decorationMenu = new KActionMenu(i18n("Icon Position"), this); | 1977 | d->decorationMenu = new KActionMenu(i18n("Icon Position"), this); | ||
2004 | d->actionCollection->addAction(QStringLiteral("decoration menu"), d->decorationMenu); | 1978 | d->actionCollection->addAction(QStringLiteral("decoration menu"), d->decorationMenu); | ||
2005 | 1979 | | |||
2006 | d->leftAction = new KToggleAction(i18n("Next to File Name"), this); | 1980 | d->leftAction = new KToggleAction(i18n("Next to File Name"), this); | ||
2007 | d->actionCollection->addAction(QStringLiteral("decorationAtLeft"), d->leftAction); | 1981 | d->actionCollection->addAction(QStringLiteral("decorationAtLeft"), d->leftAction); | ||
2008 | connect(d->leftAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotChangeDecorationPosition())); | 1982 | connect(d->leftAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotChangeDecorationPosition())); | ||
2009 | 1983 | | |||
2010 | KToggleAction *topAction = new KToggleAction(i18n("Above File Name"), this); | 1984 | KToggleAction *topAction = new KToggleAction(i18n("Above File Name"), this); | ||
2011 | d->actionCollection->addAction(QStringLiteral("decorationAtTop"), topAction); | 1985 | d->actionCollection->addAction(QStringLiteral("decorationAtTop"), topAction); | ||
2012 | connect(topAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotChangeDecorationPosition())); | 1986 | connect(topAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotChangeDecorationPosition())); | ||
2013 | 1987 | | |||
2014 | d->decorationMenu->addAction(d->leftAction); | 1988 | d->decorationMenu->addAction(d->leftAction); | ||
2015 | d->decorationMenu->addAction(topAction); | 1989 | d->decorationMenu->addAction(topAction); | ||
2016 | 1990 | | |||
2017 | QActionGroup *decorationGroup = new QActionGroup(this); | 1991 | QActionGroup *decorationGroup = new QActionGroup(this); | ||
1992 | decorationGroup->setExclusive(true); | ||||
2018 | d->leftAction->setActionGroup(decorationGroup); | 1993 | d->leftAction->setActionGroup(decorationGroup); | ||
2019 | topAction->setActionGroup(decorationGroup); | 1994 | topAction->setActionGroup(decorationGroup); | ||
2020 | 1995 | | |||
2021 | KToggleAction *shortAction = new KToggleAction(i18n("Short View"), this); | 1996 | KToggleAction *shortAction = new KToggleAction(i18n("Short View"), this); | ||
2022 | d->actionCollection->addAction(QStringLiteral("short view"), shortAction); | 1997 | d->actionCollection->addAction(QStringLiteral("short view"), shortAction); | ||
2023 | shortAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-icons"))); | 1998 | shortAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-icons"))); | ||
2024 | connect(shortAction, SIGNAL(triggered()), SLOT(_k_slotSimpleView())); | 1999 | connect(shortAction, SIGNAL(triggered()), SLOT(_k_slotSimpleView())); | ||
2025 | 2000 | | |||
Show All 13 Lines | |||||
2039 | connect(detailedTreeAction, SIGNAL(triggered()), SLOT(_k_slotDetailedTreeView())); | 2014 | connect(detailedTreeAction, SIGNAL(triggered()), SLOT(_k_slotDetailedTreeView())); | ||
2040 | 2015 | | |||
2041 | QActionGroup *viewGroup = new QActionGroup(this); | 2016 | QActionGroup *viewGroup = new QActionGroup(this); | ||
2042 | shortAction->setActionGroup(viewGroup); | 2017 | shortAction->setActionGroup(viewGroup); | ||
2043 | detailedAction->setActionGroup(viewGroup); | 2018 | detailedAction->setActionGroup(viewGroup); | ||
2044 | treeAction->setActionGroup(viewGroup); | 2019 | treeAction->setActionGroup(viewGroup); | ||
2045 | detailedTreeAction->setActionGroup(viewGroup); | 2020 | detailedTreeAction->setActionGroup(viewGroup); | ||
2046 | 2021 | | |||
2022 | KToggleAction *allowExpansionAction = new KToggleAction(i18n("Allow Expansion in Details View"), this); | ||||
Now I wonder if this should say "Allow expansion in Details view" and not disable itself when using a different view. Otherwise it might be hard for people to figure out what it does or how to activate it. ngraham: Now I wonder if this should say "Allow expansion in Details view" and not disable itself when… | |||||
2023 | d->actionCollection->addAction(QStringLiteral("allow expansion"), allowExpansionAction); | ||||
2024 | connect(allowExpansionAction, SIGNAL(toggled(bool)), SLOT(_k_slotToggleAllowExpansion(bool))); | ||||
2025 | | ||||
2047 | KToggleAction *showHiddenAction = new KToggleAction(i18n("Show Hidden Files"), this); | 2026 | KToggleAction *showHiddenAction = new KToggleAction(i18n("Show Hidden Files"), this); | ||
2048 | d->actionCollection->addAction(QStringLiteral("show hidden"), showHiddenAction); | 2027 | d->actionCollection->addAction(QStringLiteral("show hidden"), showHiddenAction); | ||
2049 | showHiddenAction->setShortcuts({Qt::ALT + Qt::Key_Period, Qt::CTRL + Qt::Key_H, Qt::Key_F8}); | 2028 | showHiddenAction->setShortcuts({Qt::ALT + Qt::Key_Period, Qt::CTRL + Qt::Key_H, Qt::Key_F8}); | ||
2050 | connect(showHiddenAction, SIGNAL(toggled(bool)), SLOT(_k_slotToggleHidden(bool))); | 2029 | connect(showHiddenAction, SIGNAL(toggled(bool)), SLOT(_k_slotToggleHidden(bool))); | ||
2051 | 2030 | | |||
2052 | KToggleAction *previewAction = new KToggleAction(i18n("Show Preview Panel"), this); | 2031 | KToggleAction *previewAction = new KToggleAction(i18n("Show Preview Panel"), this); | ||
2053 | d->actionCollection->addAction(QStringLiteral("preview"), previewAction); | 2032 | d->actionCollection->addAction(QStringLiteral("preview"), previewAction); | ||
2054 | previewAction->setShortcut(Qt::Key_F11); | 2033 | previewAction->setShortcut(Qt::Key_F11); | ||
▲ Show 20 Lines • Show All 121 Lines • ▼ Show 20 Line(s) | 2152 | { | |||
2176 | //QAction *separateDirs = d->actionCollection->action("separate dirs"); | 2155 | //QAction *separateDirs = d->actionCollection->action("separate dirs"); | ||
2177 | //separateDirs->setChecked(KFile::isSeparateDirs(fv) && | 2156 | //separateDirs->setChecked(KFile::isSeparateDirs(fv) && | ||
2178 | // separateDirs->isEnabled()); | 2157 | // separateDirs->isEnabled()); | ||
2179 | 2158 | | |||
2180 | d->actionCollection->action(QStringLiteral("short view"))->setChecked(KFile::isSimpleView(fv)); | 2159 | d->actionCollection->action(QStringLiteral("short view"))->setChecked(KFile::isSimpleView(fv)); | ||
2181 | d->actionCollection->action(QStringLiteral("detailed view"))->setChecked(KFile::isDetailView(fv)); | 2160 | d->actionCollection->action(QStringLiteral("detailed view"))->setChecked(KFile::isDetailView(fv)); | ||
2182 | d->actionCollection->action(QStringLiteral("tree view"))->setChecked(KFile::isTreeView(fv)); | 2161 | d->actionCollection->action(QStringLiteral("tree view"))->setChecked(KFile::isTreeView(fv)); | ||
2183 | d->actionCollection->action(QStringLiteral("detailed tree view"))->setChecked(KFile::isDetailTreeView(fv)); | 2162 | d->actionCollection->action(QStringLiteral("detailed tree view"))->setChecked(KFile::isDetailTreeView(fv)); | ||
2163 | | ||||
2164 | // dolphin style views | ||||
2165 | d->actionCollection->action(QStringLiteral("icons view"))->setChecked(KFile::isSimpleView(fv) && d->decorationPosition == QStyleOptionViewItem::Top); | ||||
2166 | d->actionCollection->action(QStringLiteral("compact view"))->setChecked(KFile::isSimpleView(fv) && d->decorationPosition == QStyleOptionViewItem::Left); | ||||
2167 | d->actionCollection->action(QStringLiteral("details view"))->setChecked(KFile::isDetailTreeView(fv) || KFile::isDetailView(fv)); | ||||
2184 | } | 2168 | } | ||
2185 | 2169 | | |||
2186 | void KDirOperator::readConfig(const KConfigGroup &configGroup) | 2170 | void KDirOperator::readConfig(const KConfigGroup &configGroup) | ||
2187 | { | 2171 | { | ||
2188 | d->defaultView = 0; | 2172 | d->defaultView = 0; | ||
2189 | QString viewStyle = configGroup.readEntry("View Style", "DetailTree"); | 2173 | QString viewStyle = configGroup.readEntry("View Style", "DetailTree"); | ||
2190 | if (viewStyle == QLatin1String("Detail")) { | 2174 | if (viewStyle == QLatin1String("Detail")) { | ||
2191 | d->defaultView |= KFile::Detail; | 2175 | d->defaultView |= KFile::Detail; | ||
Show All 15 Lines | |||||
2207 | d->previewWidth = configGroup.readEntry(QStringLiteral("Preview Width"), 100); | 2191 | d->previewWidth = configGroup.readEntry(QStringLiteral("Preview Width"), 100); | ||
2208 | 2192 | | |||
2209 | if (configGroup.readEntry(QStringLiteral("Show hidden files"), | 2193 | if (configGroup.readEntry(QStringLiteral("Show hidden files"), | ||
2210 | DefaultShowHidden)) { | 2194 | DefaultShowHidden)) { | ||
2211 | d->actionCollection->action(QStringLiteral("show hidden"))->setChecked(true); | 2195 | d->actionCollection->action(QStringLiteral("show hidden"))->setChecked(true); | ||
2212 | d->dirLister->setShowingDotFiles(true); | 2196 | d->dirLister->setShowingDotFiles(true); | ||
2213 | } | 2197 | } | ||
2214 | 2198 | | |||
2199 | if (configGroup.readEntry(QStringLiteral("Allow Expansion"), | ||||
2200 | DefaultShowHidden)) { | ||||
2201 | d->actionCollection->action(QStringLiteral("allow expansion"))->setChecked(true); | ||||
2202 | } | ||||
2203 | | ||||
2215 | QDir::SortFlags sorting = QDir::Name; | 2204 | QDir::SortFlags sorting = QDir::Name; | ||
2216 | if (configGroup.readEntry(QStringLiteral("Sort directories first"), | 2205 | if (configGroup.readEntry(QStringLiteral("Sort directories first"), | ||
2217 | DefaultDirsFirst)) { | 2206 | DefaultDirsFirst)) { | ||
2218 | sorting |= QDir::DirsFirst; | 2207 | sorting |= QDir::DirsFirst; | ||
2219 | } | 2208 | } | ||
2220 | QString name = QStringLiteral("Name"); | 2209 | QString name = QStringLiteral("Name"); | ||
2221 | QString sortBy = configGroup.readEntry(QStringLiteral("Sort by"), name); | 2210 | QString sortBy = configGroup.readEntry(QStringLiteral("Sort by"), name); | ||
2222 | if (sortBy == name) { | 2211 | if (sortBy == name) { | ||
2223 | sorting |= QDir::Name; | 2212 | sorting |= QDir::Name; | ||
2224 | } else if (sortBy == QLatin1String("Size")) { | 2213 | } else if (sortBy == QLatin1String("Size")) { | ||
2225 | sorting |= QDir::Size; | 2214 | sorting |= QDir::Size; | ||
2226 | } else if (sortBy == QLatin1String("Date")) { | 2215 | } else if (sortBy == QLatin1String("Date")) { | ||
2227 | sorting |= QDir::Time; | 2216 | sorting |= QDir::Time; | ||
2228 | } else if (sortBy == QLatin1String("Type")) { | 2217 | } else if (sortBy == QLatin1String("Type")) { | ||
2229 | sorting |= QDir::Type; | 2218 | sorting |= QDir::Type; | ||
2230 | } | 2219 | } | ||
2231 | if (configGroup.readEntry(QStringLiteral("Sort reversed"), DefaultSortReversed)) { | 2220 | if (configGroup.readEntry(QStringLiteral("Sort reversed"), DefaultSortReversed)) { | ||
2232 | sorting |= QDir::Reversed; | 2221 | sorting |= QDir::Reversed; | ||
2233 | } | 2222 | } | ||
2234 | d->updateSorting(sorting); | 2223 | d->updateSorting(sorting); | ||
2235 | 2224 | | |||
2236 | if (d->inlinePreviewState == Private::NotForced) { | 2225 | if (d->inlinePreviewState == Private::NotForced) { | ||
2237 | d->showPreviews = configGroup.readEntry(QStringLiteral("Show Inline Previews"), true); | 2226 | d->showPreviews = configGroup.readEntry(QStringLiteral("Show Inline Previews"), true); | ||
2238 | } | 2227 | } | ||
2239 | QStyleOptionViewItem::Position pos = (QStyleOptionViewItem::Position) configGroup.readEntry(QStringLiteral("Decoration position"), (int) QStyleOptionViewItem::Left); | 2228 | QStyleOptionViewItem::Position pos = (QStyleOptionViewItem::Position) configGroup.readEntry(QStringLiteral("Decoration position"), (int) QStyleOptionViewItem::Top); | ||
2240 | setDecorationPosition(pos); | 2229 | setDecorationPosition(pos); | ||
2241 | } | 2230 | } | ||
2242 | 2231 | | |||
2243 | void KDirOperator::writeConfig(KConfigGroup &configGroup) | 2232 | void KDirOperator::writeConfig(KConfigGroup &configGroup) | ||
2244 | { | 2233 | { | ||
2245 | QString sortBy = QStringLiteral("Name"); | 2234 | QString sortBy = QStringLiteral("Name"); | ||
2246 | if (KFile::isSortBySize(d->sorting)) { | 2235 | if (KFile::isSortBySize(d->sorting)) { | ||
2247 | sortBy = QStringLiteral("Size"); | 2236 | sortBy = QStringLiteral("Size"); | ||
Show All 31 Lines | 2264 | if (hasPreview) { | |||
2279 | configGroup.writeEntry(QStringLiteral("Preview Width"), sizes[1]); | 2268 | configGroup.writeEntry(QStringLiteral("Preview Width"), sizes[1]); | ||
2280 | } | 2269 | } | ||
2281 | } | 2270 | } | ||
2282 | } | 2271 | } | ||
2283 | 2272 | | |||
2284 | configGroup.writeEntry(QStringLiteral("Show hidden files"), | 2273 | configGroup.writeEntry(QStringLiteral("Show hidden files"), | ||
2285 | d->actionCollection->action(QStringLiteral("show hidden"))->isChecked()); | 2274 | d->actionCollection->action(QStringLiteral("show hidden"))->isChecked()); | ||
2286 | 2275 | | |||
2276 | configGroup.writeEntry(QStringLiteral("Allow Expansion"), | ||||
2277 | d->actionCollection->action(QStringLiteral("allow expansion"))->isChecked()); | ||||
2278 | | ||||
2287 | KFile::FileView fv = static_cast<KFile::FileView>(d->viewKind); | 2279 | KFile::FileView fv = static_cast<KFile::FileView>(d->viewKind); | ||
2288 | QString style; | 2280 | QString style; | ||
2289 | if (KFile::isDetailView(fv)) { | 2281 | if (KFile::isDetailView(fv)) { | ||
2290 | style = QStringLiteral("Detail"); | 2282 | style = QStringLiteral("Detail"); | ||
2291 | } else if (KFile::isSimpleView(fv)) { | 2283 | } else if (KFile::isSimpleView(fv)) { | ||
2292 | style = QStringLiteral("Simple"); | 2284 | style = QStringLiteral("Simple"); | ||
2293 | } else if (KFile::isTreeView(fv)) { | 2285 | } else if (KFile::isTreeView(fv)) { | ||
2294 | style = QStringLiteral("Tree"); | 2286 | style = QStringLiteral("Tree"); | ||
Show All 9 Lines | 2292 | if (d->inlinePreviewState == Private::NotForced) { | |||
2304 | } else { | 2296 | } else { | ||
2305 | configGroup.writeEntry(QStringLiteral("detailedViewIconSize"), d->iconsZoom); | 2297 | configGroup.writeEntry(QStringLiteral("detailedViewIconSize"), d->iconsZoom); | ||
2306 | } | 2298 | } | ||
2307 | } | 2299 | } | ||
2308 | 2300 | | |||
2309 | configGroup.writeEntry(QStringLiteral("Decoration position"), (int) d->decorationPosition); | 2301 | configGroup.writeEntry(QStringLiteral("Decoration position"), (int) d->decorationPosition); | ||
2310 | } | 2302 | } | ||
2311 | 2303 | | |||
2304 | | ||||
2312 | void KDirOperator::resizeEvent(QResizeEvent *) | 2305 | void KDirOperator::resizeEvent(QResizeEvent *) | ||
2313 | { | 2306 | { | ||
2314 | // resize the splitter and assure that the width of | 2307 | // resize the splitter and assure that the width of | ||
2315 | // the preview widget is restored | 2308 | // the preview widget is restored | ||
2316 | QList<int> sizes = d->splitter->sizes(); | 2309 | QList<int> sizes = d->splitter->sizes(); | ||
2317 | const bool hasPreview = (sizes.count() == 2); | 2310 | const bool hasPreview = (sizes.count() == 2); | ||
2318 | 2311 | | |||
2319 | d->splitter->resize(size()); | 2312 | d->splitter->resize(size()); | ||
Show All 9 Lines | |||||
2329 | if (hasPreview) { | 2322 | if (hasPreview) { | ||
2330 | d->previewWidth = sizes[1]; | 2323 | d->previewWidth = sizes[1]; | ||
2331 | } | 2324 | } | ||
2332 | 2325 | | |||
2333 | if (d->progressBar->parent() == this) { | 2326 | if (d->progressBar->parent() == this) { | ||
2334 | // might be reparented into a statusbar | 2327 | // might be reparented into a statusbar | ||
2335 | d->progressBar->move(2, height() - d->progressBar->height() - 2); | 2328 | d->progressBar->move(2, height() - d->progressBar->height() - 2); | ||
2336 | } | 2329 | } | ||
2337 | | ||||
2338 | d->updateListViewGrid(); | | |||
2339 | } | 2330 | } | ||
2340 | 2331 | | |||
2341 | void KDirOperator::setOnlyDoubleClickSelectsFiles(bool enable) | 2332 | void KDirOperator::setOnlyDoubleClickSelectsFiles(bool enable) | ||
2342 | { | 2333 | { | ||
2343 | d->onlyDoubleClickSelectsFiles = enable; | 2334 | d->onlyDoubleClickSelectsFiles = enable; | ||
2344 | // TODO: port to QAbstractItemModel | 2335 | // TODO: port to QAbstractItemModel | ||
2345 | //if (d->itemView != 0) { | 2336 | //if (d->itemView != 0) { | ||
2346 | // d->itemView->setOnlyDoubleClickSelectsFiles(enable); | 2337 | // d->itemView->setOnlyDoubleClickSelectsFiles(enable); | ||
▲ Show 20 Lines • Show All 228 Lines • ▼ Show 20 Line(s) | |||||
2575 | } | 2566 | } | ||
2576 | 2567 | | |||
2577 | void KDirOperator::Private::_k_slotChangeDecorationPosition() | 2568 | void KDirOperator::Private::_k_slotChangeDecorationPosition() | ||
2578 | { | 2569 | { | ||
2579 | if (!itemView) { | 2570 | if (!itemView) { | ||
2580 | return; | 2571 | return; | ||
2581 | } | 2572 | } | ||
2582 | 2573 | | |||
2583 | QListView *view = qobject_cast<QListView *>(itemView); | 2574 | KDirOperatorIconView *view = qobject_cast<KDirOperatorIconView *>(itemView); | ||
2584 | 2575 | | |||
2585 | if (!view) { | 2576 | if (!view) { | ||
2586 | return; | 2577 | return; | ||
2587 | } | 2578 | } | ||
2588 | 2579 | | |||
2589 | const bool leftChecked = actionCollection->action(QStringLiteral("decorationAtLeft"))->isChecked(); | 2580 | const bool leftChecked = actionCollection->action(QStringLiteral("decorationAtLeft"))->isChecked(); | ||
2590 | 2581 | | |||
2591 | if (leftChecked) { | 2582 | if (leftChecked) { | ||
2592 | decorationPosition = QStyleOptionViewItem::Left; | 2583 | view->setDecorationPosition(QStyleOptionViewItem::Left); | ||
2593 | view->setFlow(QListView::TopToBottom); | | |||
2594 | } else { | 2584 | } else { | ||
2595 | decorationPosition = QStyleOptionViewItem::Top; | 2585 | view->setDecorationPosition(QStyleOptionViewItem::Top); | ||
2596 | view->setFlow(QListView::LeftToRight); | | |||
2597 | } | 2586 | } | ||
2598 | 2587 | | |||
2599 | updateListViewGrid(); | | |||
2600 | | ||||
2601 | itemView->update(); | 2588 | itemView->update(); | ||
2602 | } | 2589 | } | ||
2603 | 2590 | | |||
2604 | void KDirOperator::Private::_k_slotExpandToUrl(const QModelIndex &index) | 2591 | void KDirOperator::Private::_k_slotExpandToUrl(const QModelIndex &index) | ||
2605 | { | 2592 | { | ||
2606 | QTreeView *treeView = qobject_cast<QTreeView *>(itemView); | 2593 | QTreeView *treeView = qobject_cast<QTreeView *>(itemView); | ||
2607 | 2594 | | |||
2608 | if (!treeView) { | 2595 | if (!treeView) { | ||
Show All 34 Lines | |||||
2643 | } | 2630 | } | ||
2644 | } | 2631 | } | ||
2645 | 2632 | | |||
2646 | void KDirOperator::Private::_k_slotItemsChanged() | 2633 | void KDirOperator::Private::_k_slotItemsChanged() | ||
2647 | { | 2634 | { | ||
2648 | completeListDirty = true; | 2635 | completeListDirty = true; | ||
2649 | } | 2636 | } | ||
2650 | 2637 | | |||
2651 | void KDirOperator::Private::updateListViewGrid() | | |||
2652 | { | | |||
2653 | if (!itemView) { | | |||
2654 | return; | | |||
2655 | } | | |||
2656 | | ||||
2657 | QListView *view = qobject_cast<QListView *>(itemView); | | |||
2658 | | ||||
2659 | if (!view) { | | |||
2660 | return; | | |||
2661 | } | | |||
2662 | | ||||
2663 | const bool leftChecked = actionCollection->action(QStringLiteral("decorationAtLeft"))->isChecked(); | | |||
2664 | | ||||
2665 | if (leftChecked) { | | |||
2666 | view->setGridSize(QSize()); | | |||
2667 | KFileItemDelegate *delegate = qobject_cast<KFileItemDelegate *>(view->itemDelegate()); | | |||
2668 | if (delegate) { | | |||
2669 | delegate->setMaximumSize(QSize()); | | |||
2670 | } | | |||
2671 | } else { | | |||
2672 | const QFontMetrics metrics(itemView->viewport()->font()); | | |||
2673 | | ||||
2674 | const int height = itemView->iconSize().height() + metrics.height() * 2.5; | | |||
2675 | const int minWidth = qMax(height, metrics.height() * 5); | | |||
2676 | | ||||
2677 | const int scrollBarWidth = itemView->verticalScrollBar()->sizeHint().width(); | | |||
2678 | | ||||
2679 | // Subtract 1 px to prevent flickering when resizing the window | | |||
2680 | // For Oxygen a column is missing after showing the dialog without resizing it, | | |||
2681 | // therefore subtract 4 more (scaled) pixels | | |||
2682 | const int viewPortWidth = itemView->contentsRect().width() - scrollBarWidth - 1 - 4 * itemView->devicePixelRatioF(); | | |||
2683 | const int itemsInRow = qMax(1, viewPortWidth / minWidth); | | |||
2684 | const int remainingWidth = viewPortWidth - (minWidth * itemsInRow); | | |||
2685 | const int width = minWidth + (remainingWidth / itemsInRow); | | |||
2686 | | ||||
2687 | const QSize itemSize(width, height); | | |||
2688 | | ||||
2689 | view->setGridSize(itemSize); | | |||
2690 | KFileItemDelegate *delegate = qobject_cast<KFileItemDelegate *>(view->itemDelegate()); | | |||
2691 | if (delegate) { | | |||
2692 | delegate->setMaximumSize(itemSize); | | |||
2693 | } | | |||
2694 | } | | |||
2695 | } | | |||
2696 | | ||||
2697 | int KDirOperator::Private::iconSizeForViewType(QAbstractItemView *itemView) const | 2638 | int KDirOperator::Private::iconSizeForViewType(QAbstractItemView *itemView) const | ||
2698 | { | 2639 | { | ||
2699 | if (!itemView || !configGroup) { | 2640 | if (!itemView || !configGroup) { | ||
2700 | return 0; | 2641 | return 0; | ||
2701 | } | 2642 | } | ||
2702 | 2643 | | |||
2703 | if (qobject_cast<QListView *>(itemView)) { | 2644 | if (qobject_cast<QListView *>(itemView)) { | ||
2704 | return configGroup->readEntry("listViewIconSize", 0); | 2645 | return configGroup->readEntry("listViewIconSize", 0); | ||
▲ Show 20 Lines • Show All 65 Lines • Show Last 20 Lines |
Can we make them reusable, it should be in framework and then accessed in Dolphin.