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; | ||
150 | void writeIconZoomSettings(KConfigGroup &configGroup); | ||||
238 | 151 | | |||
239 | // private members | 152 | // private members | ||
240 | KDirOperator * const parent; | 153 | KDirOperator * const parent; | ||
241 | QStack<QUrl *> backStack; ///< Contains all URLs you can reach with the back button. | 154 | 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. | 155 | QStack<QUrl *> forwardStack; ///< Contains all URLs you can reach with the forward button. | ||
243 | 156 | | |||
244 | QModelIndex lastHoveredIndex; | 157 | QModelIndex lastHoveredIndex; | ||
245 | 158 | | |||
▲ Show 20 Lines • Show All 347 Lines • ▼ Show 20 Line(s) | |||||
593 | 506 | | |||
594 | KFile::FileView KDirOperator::Private::allViews() | 507 | KFile::FileView KDirOperator::Private::allViews() | ||
595 | { | 508 | { | ||
596 | return static_cast<KFile::FileView>(KFile::Simple | KFile::Detail | KFile::Tree | KFile::DetailTree); | 509 | return static_cast<KFile::FileView>(KFile::Simple | KFile::Detail | KFile::Tree | KFile::DetailTree); | ||
597 | } | 510 | } | ||
598 | 511 | | |||
599 | void KDirOperator::Private::_k_slotDetailedView() | 512 | void KDirOperator::Private::_k_slotDetailedView() | ||
600 | { | 513 | { | ||
514 | if (configGroup && itemView) { | ||||
515 | // save old zoom settings | ||||
516 | writeIconZoomSettings(*configGroup); | ||||
517 | } | ||||
518 | | ||||
601 | KFile::FileView view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::Detail); | 519 | KFile::FileView view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::Detail); | ||
602 | parent->setView(view); | 520 | parent->setView(view); | ||
603 | } | 521 | } | ||
604 | 522 | | |||
605 | void KDirOperator::Private::_k_slotSimpleView() | 523 | void KDirOperator::Private::_k_slotSimpleView() | ||
606 | { | 524 | { | ||
525 | if (configGroup && itemView) { | ||||
526 | // save old zoom settings | ||||
527 | writeIconZoomSettings(*configGroup); | ||||
528 | } | ||||
529 | | ||||
607 | KFile::FileView view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::Simple); | 530 | KFile::FileView view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::Simple); | ||
608 | parent->setView(view); | 531 | parent->setView(view); | ||
609 | } | 532 | } | ||
610 | 533 | | |||
611 | void KDirOperator::Private::_k_slotTreeView() | 534 | void KDirOperator::Private::_k_slotTreeView() | ||
612 | { | 535 | { | ||
536 | if (configGroup && itemView) { | ||||
537 | // save old zoom settings | ||||
538 | writeIconZoomSettings(*configGroup); | ||||
539 | } | ||||
540 | | ||||
613 | KFile::FileView view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::Tree); | 541 | KFile::FileView view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::Tree); | ||
614 | parent->setView(view); | 542 | parent->setView(view); | ||
615 | } | 543 | } | ||
616 | 544 | | |||
617 | void KDirOperator::Private::_k_slotDetailedTreeView() | 545 | void KDirOperator::Private::_k_slotDetailedTreeView() | ||
618 | { | 546 | { | ||
547 | if (configGroup && itemView) { | ||||
548 | // save old zoom settings | ||||
549 | writeIconZoomSettings(*configGroup); | ||||
550 | } | ||||
551 | | ||||
619 | KFile::FileView view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::DetailTree); | 552 | KFile::FileView view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::DetailTree); | ||
620 | parent->setView(view); | 553 | parent->setView(view); | ||
621 | } | 554 | } | ||
622 | 555 | | |||
556 | void KDirOperator::Private::_k_slotToggleAllowExpansion(bool allow) { | ||||
557 | KFile::FileView view = KFile::Detail; | ||||
558 | if (allow) { | ||||
559 | view = KFile::DetailTree; | ||||
560 | } | ||||
561 | parent->setView(view); | ||||
562 | } | ||||
563 | | ||||
623 | void KDirOperator::Private::_k_slotToggleHidden(bool show) | 564 | void KDirOperator::Private::_k_slotToggleHidden(bool show) | ||
624 | { | 565 | { | ||
625 | dirLister->setShowingDotFiles(show); | 566 | dirLister->setShowingDotFiles(show); | ||
626 | parent->updateDir(); | 567 | parent->updateDir(); | ||
627 | _k_assureVisibleSelection(); | 568 | _k_assureVisibleSelection(); | ||
628 | } | 569 | } | ||
629 | 570 | | |||
630 | void KDirOperator::Private::_k_togglePreview(bool on) | 571 | void KDirOperator::Private::_k_togglePreview(bool on) | ||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Line(s) | |||||
707 | } | 648 | } | ||
708 | 649 | | |||
709 | void KDirOperator::Private::_k_slotToggleDirsFirst() | 650 | void KDirOperator::Private::_k_slotToggleDirsFirst() | ||
710 | { | 651 | { | ||
711 | QDir::SortFlags s = (sorting ^ QDir::DirsFirst); | 652 | QDir::SortFlags s = (sorting ^ QDir::DirsFirst); | ||
712 | updateSorting(s); | 653 | updateSorting(s); | ||
713 | } | 654 | } | ||
714 | 655 | | |||
656 | void KDirOperator::Private::_k_slotToggleIconsView() | ||||
657 | { | ||||
658 | if (configGroup && itemView) { | ||||
659 | // save old zoom settings | ||||
660 | writeIconZoomSettings(*configGroup); | ||||
661 | } | ||||
662 | | ||||
663 | // Put the icons on top | ||||
664 | actionCollection->action(QStringLiteral("decorationAtTop"))->setChecked(true); | ||||
665 | decorationPosition = QStyleOptionViewItem::Top; | ||||
666 | | ||||
667 | // Switch to simple view | ||||
668 | KFile::FileView fileView = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::Simple); | ||||
669 | parent->setView(fileView); | ||||
670 | } | ||||
671 | | ||||
672 | void KDirOperator::Private::_k_slotToggleCompactView() | ||||
673 | { | ||||
674 | if (configGroup && itemView) { | ||||
675 | // save old zoom settings | ||||
676 | writeIconZoomSettings(*configGroup); | ||||
677 | } | ||||
678 | | ||||
679 | // Put the icons on the side | ||||
680 | actionCollection->action(QStringLiteral("decorationAtLeft"))->setChecked(true); | ||||
681 | decorationPosition = QStyleOptionViewItem::Left; | ||||
682 | | ||||
683 | // Switch to simple view | ||||
684 | KFile::FileView fileView = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::Simple); | ||||
685 | parent->setView(fileView); | ||||
686 | } | ||||
687 | | ||||
688 | void KDirOperator::Private::_k_slotToggleDetailsView() | ||||
689 | { | ||||
690 | if (configGroup && itemView) { | ||||
691 | // save old zoom settings | ||||
692 | writeIconZoomSettings(*configGroup); | ||||
693 | } | ||||
694 | | ||||
695 | KFile::FileView view; | ||||
696 | if (actionCollection->action(QStringLiteral("allow expansion"))->isChecked()) { | ||||
697 | view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::DetailTree); | ||||
698 | } else { | ||||
699 | view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::Detail); | ||||
700 | } | ||||
701 | parent->setView(view); | ||||
702 | } | ||||
703 | | ||||
715 | void KDirOperator::Private::_k_slotToggleIgnoreCase() | 704 | void KDirOperator::Private::_k_slotToggleIgnoreCase() | ||
716 | { | 705 | { | ||
717 | // TODO: port to Qt4's QAbstractItemView | 706 | // TODO: port to Qt4's QAbstractItemView | ||
718 | /*if ( !d->fileView ) | 707 | /*if ( !d->fileView ) | ||
719 | return; | 708 | return; | ||
720 | 709 | | |||
721 | QDir::SortFlags sorting = d->fileView->sorting(); | 710 | QDir::SortFlags sorting = d->fileView->sorting(); | ||
722 | if ( !KFile::isSortCaseInsensitive( sorting ) ) | 711 | if ( !KFile::isSortCaseInsensitive( sorting ) ) | ||
▲ Show 20 Lines • Show All 192 Lines • ▼ Show 20 Line(s) | 894 | { | |||
915 | 904 | | |||
916 | if (!d->previewGenerator) { | 905 | if (!d->previewGenerator) { | ||
917 | return; | 906 | return; | ||
918 | } | 907 | } | ||
919 | 908 | | |||
920 | const int maxSize = KIconLoader::SizeEnormous - KIconLoader::SizeSmall; | 909 | const int maxSize = KIconLoader::SizeEnormous - KIconLoader::SizeSmall; | ||
921 | const int val = (maxSize * value / 100) + KIconLoader::SizeSmall; | 910 | const int val = (maxSize * value / 100) + KIconLoader::SizeSmall; | ||
922 | d->itemView->setIconSize(QSize(val, val)); | 911 | d->itemView->setIconSize(QSize(val, val)); | ||
923 | d->updateListViewGrid(); | | |||
924 | d->previewGenerator->updatePreviews(); | 912 | d->previewGenerator->updatePreviews(); | ||
925 | 913 | | |||
926 | emit currentIconSizeChanged(value); | 914 | emit currentIconSizeChanged(value); | ||
927 | } | 915 | } | ||
928 | 916 | | |||
929 | void KDirOperator::close() | 917 | void KDirOperator::close() | ||
930 | { | 918 | { | ||
931 | resetCursor(); | 919 | resetCursor(); | ||
▲ Show 20 Lines • Show All 593 Lines • ▼ Show 20 Line(s) | |||||
1525 | QAbstractItemView *KDirOperator::createView(QWidget *parent, KFile::FileView viewKind) | 1513 | QAbstractItemView *KDirOperator::createView(QWidget *parent, KFile::FileView viewKind) | ||
1526 | { | 1514 | { | ||
1527 | QAbstractItemView *itemView = nullptr; | 1515 | QAbstractItemView *itemView = nullptr; | ||
1528 | if (KFile::isDetailView(viewKind) || KFile::isTreeView(viewKind) || KFile::isDetailTreeView(viewKind)) { | 1516 | if (KFile::isDetailView(viewKind) || KFile::isTreeView(viewKind) || KFile::isDetailTreeView(viewKind)) { | ||
1529 | KDirOperatorDetailView *detailView = new KDirOperatorDetailView(parent); | 1517 | KDirOperatorDetailView *detailView = new KDirOperatorDetailView(parent); | ||
1530 | detailView->setViewMode(viewKind); | 1518 | detailView->setViewMode(viewKind); | ||
1531 | itemView = detailView; | 1519 | itemView = detailView; | ||
1532 | } else { | 1520 | } else { | ||
1533 | itemView = new KDirOperatorIconView(this, parent); | 1521 | itemView = new KDirOperatorIconView(parent, decorationPosition()); | ||
1534 | } | 1522 | } | ||
1535 | 1523 | | |||
1536 | return itemView; | 1524 | return itemView; | ||
1537 | } | 1525 | } | ||
1538 | 1526 | | |||
1539 | void KDirOperator::setAcceptDrops(bool acceptsDrops) | 1527 | void KDirOperator::setAcceptDrops(bool acceptsDrops) | ||
1540 | { | 1528 | { | ||
1541 | QWidget::setAcceptDrops(acceptsDrops); | 1529 | QWidget::setAcceptDrops(acceptsDrops); | ||
▲ Show 20 Lines • Show All 131 Lines • ▼ Show 20 Line(s) | 1614 | { | |||
1673 | 1661 | | |||
1674 | connect(d->itemView, SIGNAL(activated(QModelIndex)), | 1662 | connect(d->itemView, SIGNAL(activated(QModelIndex)), | ||
1675 | this, SLOT(_k_slotActivated(QModelIndex))); | 1663 | this, SLOT(_k_slotActivated(QModelIndex))); | ||
1676 | connect(d->itemView, SIGNAL(customContextMenuRequested(QPoint)), | 1664 | connect(d->itemView, SIGNAL(customContextMenuRequested(QPoint)), | ||
1677 | this, SLOT(_k_openContextMenu(QPoint))); | 1665 | this, SLOT(_k_openContextMenu(QPoint))); | ||
1678 | connect(d->itemView, SIGNAL(entered(QModelIndex)), | 1666 | connect(d->itemView, SIGNAL(entered(QModelIndex)), | ||
1679 | this, SLOT(_k_triggerPreview(QModelIndex))); | 1667 | this, SLOT(_k_triggerPreview(QModelIndex))); | ||
1680 | 1668 | | |||
1681 | updateViewActions(); | | |||
1682 | d->splitter->insertWidget(0, d->itemView); | 1669 | d->splitter->insertWidget(0, d->itemView); | ||
1683 | 1670 | | |||
1684 | d->splitter->resize(size()); | 1671 | d->splitter->resize(size()); | ||
1685 | d->itemView->show(); | 1672 | d->itemView->show(); | ||
1686 | 1673 | | |||
1687 | if (listDir) { | 1674 | if (listDir) { | ||
1688 | QApplication::setOverrideCursor(Qt::WaitCursor); | 1675 | QApplication::setOverrideCursor(Qt::WaitCursor); | ||
1689 | d->openUrl(d->currUrl); | 1676 | d->openUrl(d->currUrl); | ||
Show All 28 Lines | |||||
1718 | const int maxSize = KIconLoader::SizeEnormous - KIconLoader::SizeSmall; | 1705 | const int maxSize = KIconLoader::SizeEnormous - KIconLoader::SizeSmall; | ||
1719 | const int val = (maxSize * d->iconsZoom / 100) + KIconLoader::SizeSmall; | 1706 | const int val = (maxSize * d->iconsZoom / 100) + KIconLoader::SizeSmall; | ||
1720 | d->itemView->setIconSize(previewForcedToTrue ? QSize(KIconLoader::SizeHuge, KIconLoader::SizeHuge) : QSize(val, val)); | 1707 | d->itemView->setIconSize(previewForcedToTrue ? QSize(KIconLoader::SizeHuge, KIconLoader::SizeHuge) : QSize(val, val)); | ||
1721 | d->previewGenerator->setPreviewShown(previewShown); | 1708 | d->previewGenerator->setPreviewShown(previewShown); | ||
1722 | d->actionCollection->action(QStringLiteral("inline preview"))->setChecked(previewShown); | 1709 | d->actionCollection->action(QStringLiteral("inline preview"))->setChecked(previewShown); | ||
1723 | 1710 | | |||
1724 | // ensure we change everything needed | 1711 | // ensure we change everything needed | ||
1725 | d->_k_slotChangeDecorationPosition(); | 1712 | d->_k_slotChangeDecorationPosition(); | ||
1713 | updateViewActions(); | ||||
1726 | 1714 | | |||
1727 | emit viewChanged(view); | 1715 | emit viewChanged(view); | ||
1728 | 1716 | | |||
1729 | const int zoom = previewForcedToTrue ? (KIconLoader::SizeHuge - KIconLoader::SizeSmall + 1) * 100 / maxSize : d->iconSizeForViewType(view); | 1717 | const int zoom = previewForcedToTrue ? (KIconLoader::SizeHuge - KIconLoader::SizeSmall + 1) * 100 / maxSize : d->iconSizeForViewType(view); | ||
1730 | 1718 | | |||
1731 | // this will make d->iconsZoom be updated, since setIconsZoom slot will be called | 1719 | // this will make d->iconsZoom be updated, since setIconsZoom slot will be called | ||
1732 | emit currentIconSizeChanged(zoom); | 1720 | emit currentIconSizeChanged(zoom); | ||
1733 | } | 1721 | } | ||
▲ Show 20 Lines • Show All 261 Lines • ▼ Show 20 Line(s) | 1923 | { | |||
1995 | KToggleAction *descendingAction = new KToggleAction(i18n("Descending"), this); | 1983 | KToggleAction *descendingAction = new KToggleAction(i18n("Descending"), this); | ||
1996 | d->actionCollection->addAction(QStringLiteral("descending"), descendingAction); | 1984 | d->actionCollection->addAction(QStringLiteral("descending"), descendingAction); | ||
1997 | connect(descendingAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotSortReversed(bool))); | 1985 | connect(descendingAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotSortReversed(bool))); | ||
1998 | 1986 | | |||
1999 | KToggleAction *dirsFirstAction = new KToggleAction(i18n("Folders First"), this); | 1987 | KToggleAction *dirsFirstAction = new KToggleAction(i18n("Folders First"), this); | ||
2000 | d->actionCollection->addAction(QStringLiteral("dirs first"), dirsFirstAction); | 1988 | d->actionCollection->addAction(QStringLiteral("dirs first"), dirsFirstAction); | ||
2001 | connect(dirsFirstAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotToggleDirsFirst())); | 1989 | connect(dirsFirstAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotToggleDirsFirst())); | ||
2002 | 1990 | | |||
1991 | // View modes that match those of Dolphin | ||||
1992 | KToggleAction *iconsViewAction = new KToggleAction(i18n("Icons View"), this); | ||||
1993 | iconsViewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-icons"))); | ||||
1994 | d->actionCollection->addAction(QStringLiteral("icons view"), iconsViewAction); | ||||
1995 | connect(iconsViewAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotToggleIconsView())); | ||||
1996 | | ||||
1997 | KToggleAction *compactViewAction = new KToggleAction(i18n("Compact View"), this); | ||||
1998 | compactViewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-details"))); | ||||
1999 | d->actionCollection->addAction(QStringLiteral("compact view"), compactViewAction); | ||||
2000 | connect(compactViewAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotToggleCompactView())); | ||||
2001 | | ||||
2002 | KToggleAction *detailsViewAction = new KToggleAction(i18n("Details View"), this); | ||||
2003 | detailsViewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-tree"))); | ||||
2004 | d->actionCollection->addAction(QStringLiteral("details view"), detailsViewAction); | ||||
2005 | connect(detailsViewAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotToggleDetailsView())); | ||||
2006 | | ||||
2007 | QActionGroup *viewModeGroup = new QActionGroup(this); | ||||
2008 | viewModeGroup->setExclusive(true); | ||||
2009 | iconsViewAction->setActionGroup(viewModeGroup); | ||||
2010 | compactViewAction->setActionGroup(viewModeGroup); | ||||
2011 | detailsViewAction->setActionGroup(viewModeGroup); | ||||
2012 | | ||||
2003 | d->decorationMenu = new KActionMenu(i18n("Icon Position"), this); | 2013 | d->decorationMenu = new KActionMenu(i18n("Icon Position"), this); | ||
2004 | d->actionCollection->addAction(QStringLiteral("decoration menu"), d->decorationMenu); | 2014 | d->actionCollection->addAction(QStringLiteral("decoration menu"), d->decorationMenu); | ||
2005 | 2015 | | |||
2006 | d->leftAction = new KToggleAction(i18n("Next to File Name"), this); | 2016 | d->leftAction = new KToggleAction(i18n("Next to File Name"), this); | ||
2007 | d->actionCollection->addAction(QStringLiteral("decorationAtLeft"), d->leftAction); | 2017 | d->actionCollection->addAction(QStringLiteral("decorationAtLeft"), d->leftAction); | ||
2008 | connect(d->leftAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotChangeDecorationPosition())); | 2018 | connect(d->leftAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotChangeDecorationPosition())); | ||
2009 | 2019 | | |||
2010 | KToggleAction *topAction = new KToggleAction(i18n("Above File Name"), this); | 2020 | KToggleAction *topAction = new KToggleAction(i18n("Above File Name"), this); | ||
2011 | d->actionCollection->addAction(QStringLiteral("decorationAtTop"), topAction); | 2021 | d->actionCollection->addAction(QStringLiteral("decorationAtTop"), topAction); | ||
2012 | connect(topAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotChangeDecorationPosition())); | 2022 | connect(topAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotChangeDecorationPosition())); | ||
2013 | 2023 | | |||
2014 | d->decorationMenu->addAction(d->leftAction); | 2024 | d->decorationMenu->addAction(d->leftAction); | ||
2015 | d->decorationMenu->addAction(topAction); | 2025 | d->decorationMenu->addAction(topAction); | ||
2016 | 2026 | | |||
2017 | QActionGroup *decorationGroup = new QActionGroup(this); | 2027 | QActionGroup *decorationGroup = new QActionGroup(this); | ||
2028 | decorationGroup->setExclusive(true); | ||||
2018 | d->leftAction->setActionGroup(decorationGroup); | 2029 | d->leftAction->setActionGroup(decorationGroup); | ||
2019 | topAction->setActionGroup(decorationGroup); | 2030 | topAction->setActionGroup(decorationGroup); | ||
2020 | 2031 | | |||
2021 | KToggleAction *shortAction = new KToggleAction(i18n("Short View"), this); | 2032 | KToggleAction *shortAction = new KToggleAction(i18n("Short View"), this); | ||
2022 | d->actionCollection->addAction(QStringLiteral("short view"), shortAction); | 2033 | d->actionCollection->addAction(QStringLiteral("short view"), shortAction); | ||
2023 | shortAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-icons"))); | 2034 | shortAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-icons"))); | ||
2024 | connect(shortAction, SIGNAL(triggered()), SLOT(_k_slotSimpleView())); | 2035 | connect(shortAction, SIGNAL(triggered()), SLOT(_k_slotSimpleView())); | ||
2025 | 2036 | | |||
Show All 13 Lines | |||||
2039 | connect(detailedTreeAction, SIGNAL(triggered()), SLOT(_k_slotDetailedTreeView())); | 2050 | connect(detailedTreeAction, SIGNAL(triggered()), SLOT(_k_slotDetailedTreeView())); | ||
2040 | 2051 | | |||
2041 | QActionGroup *viewGroup = new QActionGroup(this); | 2052 | QActionGroup *viewGroup = new QActionGroup(this); | ||
2042 | shortAction->setActionGroup(viewGroup); | 2053 | shortAction->setActionGroup(viewGroup); | ||
2043 | detailedAction->setActionGroup(viewGroup); | 2054 | detailedAction->setActionGroup(viewGroup); | ||
2044 | treeAction->setActionGroup(viewGroup); | 2055 | treeAction->setActionGroup(viewGroup); | ||
2045 | detailedTreeAction->setActionGroup(viewGroup); | 2056 | detailedTreeAction->setActionGroup(viewGroup); | ||
2046 | 2057 | | |||
2058 | KToggleAction *allowExpansionAction = new KToggleAction(i18n("Allow Expansion in Details View"), this); | ||||
2059 | d->actionCollection->addAction(QStringLiteral("allow expansion"), allowExpansionAction); | ||||
2060 | connect(allowExpansionAction, SIGNAL(toggled(bool)), SLOT(_k_slotToggleAllowExpansion(bool))); | ||||
2061 | | ||||
2047 | KToggleAction *showHiddenAction = new KToggleAction(i18n("Show Hidden Files"), this); | 2062 | KToggleAction *showHiddenAction = new KToggleAction(i18n("Show Hidden Files"), this); | ||
2048 | d->actionCollection->addAction(QStringLiteral("show hidden"), showHiddenAction); | 2063 | d->actionCollection->addAction(QStringLiteral("show hidden"), showHiddenAction); | ||
2049 | showHiddenAction->setShortcuts({Qt::ALT + Qt::Key_Period, Qt::CTRL + Qt::Key_H, Qt::Key_F8}); | 2064 | 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))); | 2065 | connect(showHiddenAction, SIGNAL(toggled(bool)), SLOT(_k_slotToggleHidden(bool))); | ||
2051 | 2066 | | |||
2052 | KToggleAction *previewAction = new KToggleAction(i18n("Show Preview Panel"), this); | 2067 | KToggleAction *previewAction = new KToggleAction(i18n("Show Preview Panel"), this); | ||
2053 | d->actionCollection->addAction(QStringLiteral("preview"), previewAction); | 2068 | d->actionCollection->addAction(QStringLiteral("preview"), previewAction); | ||
2054 | previewAction->setShortcut(Qt::Key_F11); | 2069 | previewAction->setShortcut(Qt::Key_F11); | ||
▲ Show 20 Lines • Show All 121 Lines • ▼ Show 20 Line(s) | 2188 | { | |||
2176 | //QAction *separateDirs = d->actionCollection->action("separate dirs"); | 2191 | //QAction *separateDirs = d->actionCollection->action("separate dirs"); | ||
2177 | //separateDirs->setChecked(KFile::isSeparateDirs(fv) && | 2192 | //separateDirs->setChecked(KFile::isSeparateDirs(fv) && | ||
2178 | // separateDirs->isEnabled()); | 2193 | // separateDirs->isEnabled()); | ||
2179 | 2194 | | |||
2180 | d->actionCollection->action(QStringLiteral("short view"))->setChecked(KFile::isSimpleView(fv)); | 2195 | d->actionCollection->action(QStringLiteral("short view"))->setChecked(KFile::isSimpleView(fv)); | ||
2181 | d->actionCollection->action(QStringLiteral("detailed view"))->setChecked(KFile::isDetailView(fv)); | 2196 | d->actionCollection->action(QStringLiteral("detailed view"))->setChecked(KFile::isDetailView(fv)); | ||
2182 | d->actionCollection->action(QStringLiteral("tree view"))->setChecked(KFile::isTreeView(fv)); | 2197 | d->actionCollection->action(QStringLiteral("tree view"))->setChecked(KFile::isTreeView(fv)); | ||
2183 | d->actionCollection->action(QStringLiteral("detailed tree view"))->setChecked(KFile::isDetailTreeView(fv)); | 2198 | d->actionCollection->action(QStringLiteral("detailed tree view"))->setChecked(KFile::isDetailTreeView(fv)); | ||
2199 | | ||||
2200 | // dolphin style views | ||||
2201 | d->actionCollection->action(QStringLiteral("icons view"))->setChecked(KFile::isSimpleView(fv) && d->decorationPosition == QStyleOptionViewItem::Top); | ||||
2202 | d->actionCollection->action(QStringLiteral("compact view"))->setChecked(KFile::isSimpleView(fv) && d->decorationPosition == QStyleOptionViewItem::Left); | ||||
2203 | d->actionCollection->action(QStringLiteral("details view"))->setChecked(KFile::isDetailTreeView(fv) || KFile::isDetailView(fv)); | ||||
2184 | } | 2204 | } | ||
2185 | 2205 | | |||
2186 | void KDirOperator::readConfig(const KConfigGroup &configGroup) | 2206 | void KDirOperator::readConfig(const KConfigGroup &configGroup) | ||
2187 | { | 2207 | { | ||
2188 | d->defaultView = 0; | 2208 | d->defaultView = 0; | ||
2189 | QString viewStyle = configGroup.readEntry("View Style", "DetailTree"); | 2209 | QString viewStyle = configGroup.readEntry("View Style", "DetailTree"); | ||
2190 | if (viewStyle == QLatin1String("Detail")) { | 2210 | if (viewStyle == QLatin1String("Detail")) { | ||
2191 | d->defaultView |= KFile::Detail; | 2211 | d->defaultView |= KFile::Detail; | ||
Show All 15 Lines | |||||
2207 | d->previewWidth = configGroup.readEntry(QStringLiteral("Preview Width"), 100); | 2227 | d->previewWidth = configGroup.readEntry(QStringLiteral("Preview Width"), 100); | ||
2208 | 2228 | | |||
2209 | if (configGroup.readEntry(QStringLiteral("Show hidden files"), | 2229 | if (configGroup.readEntry(QStringLiteral("Show hidden files"), | ||
2210 | DefaultShowHidden)) { | 2230 | DefaultShowHidden)) { | ||
2211 | d->actionCollection->action(QStringLiteral("show hidden"))->setChecked(true); | 2231 | d->actionCollection->action(QStringLiteral("show hidden"))->setChecked(true); | ||
2212 | d->dirLister->setShowingDotFiles(true); | 2232 | d->dirLister->setShowingDotFiles(true); | ||
2213 | } | 2233 | } | ||
2214 | 2234 | | |||
2235 | if (configGroup.readEntry(QStringLiteral("Allow Expansion"), | ||||
2236 | DefaultShowHidden)) { | ||||
2237 | d->actionCollection->action(QStringLiteral("allow expansion"))->setChecked(true); | ||||
2238 | } | ||||
2239 | | ||||
2215 | QDir::SortFlags sorting = QDir::Name; | 2240 | QDir::SortFlags sorting = QDir::Name; | ||
2216 | if (configGroup.readEntry(QStringLiteral("Sort directories first"), | 2241 | if (configGroup.readEntry(QStringLiteral("Sort directories first"), | ||
2217 | DefaultDirsFirst)) { | 2242 | DefaultDirsFirst)) { | ||
2218 | sorting |= QDir::DirsFirst; | 2243 | sorting |= QDir::DirsFirst; | ||
2219 | } | 2244 | } | ||
2220 | QString name = QStringLiteral("Name"); | 2245 | QString name = QStringLiteral("Name"); | ||
2221 | QString sortBy = configGroup.readEntry(QStringLiteral("Sort by"), name); | 2246 | QString sortBy = configGroup.readEntry(QStringLiteral("Sort by"), name); | ||
2222 | if (sortBy == name) { | 2247 | if (sortBy == name) { | ||
2223 | sorting |= QDir::Name; | 2248 | sorting |= QDir::Name; | ||
2224 | } else if (sortBy == QLatin1String("Size")) { | 2249 | } else if (sortBy == QLatin1String("Size")) { | ||
2225 | sorting |= QDir::Size; | 2250 | sorting |= QDir::Size; | ||
2226 | } else if (sortBy == QLatin1String("Date")) { | 2251 | } else if (sortBy == QLatin1String("Date")) { | ||
2227 | sorting |= QDir::Time; | 2252 | sorting |= QDir::Time; | ||
2228 | } else if (sortBy == QLatin1String("Type")) { | 2253 | } else if (sortBy == QLatin1String("Type")) { | ||
2229 | sorting |= QDir::Type; | 2254 | sorting |= QDir::Type; | ||
2230 | } | 2255 | } | ||
2231 | if (configGroup.readEntry(QStringLiteral("Sort reversed"), DefaultSortReversed)) { | 2256 | if (configGroup.readEntry(QStringLiteral("Sort reversed"), DefaultSortReversed)) { | ||
2232 | sorting |= QDir::Reversed; | 2257 | sorting |= QDir::Reversed; | ||
2233 | } | 2258 | } | ||
2234 | d->updateSorting(sorting); | 2259 | d->updateSorting(sorting); | ||
2235 | 2260 | | |||
2236 | if (d->inlinePreviewState == Private::NotForced) { | 2261 | if (d->inlinePreviewState == Private::NotForced) { | ||
2237 | d->showPreviews = configGroup.readEntry(QStringLiteral("Show Inline Previews"), true); | 2262 | d->showPreviews = configGroup.readEntry(QStringLiteral("Show Inline Previews"), true); | ||
2238 | } | 2263 | } | ||
2239 | QStyleOptionViewItem::Position pos = (QStyleOptionViewItem::Position) configGroup.readEntry(QStringLiteral("Decoration position"), (int) QStyleOptionViewItem::Left); | 2264 | QStyleOptionViewItem::Position pos = (QStyleOptionViewItem::Position) configGroup.readEntry(QStringLiteral("Decoration position"), (int) QStyleOptionViewItem::Top); | ||
2240 | setDecorationPosition(pos); | 2265 | setDecorationPosition(pos); | ||
2241 | } | 2266 | } | ||
2242 | 2267 | | |||
2243 | void KDirOperator::writeConfig(KConfigGroup &configGroup) | 2268 | void KDirOperator::writeConfig(KConfigGroup &configGroup) | ||
2244 | { | 2269 | { | ||
2245 | QString sortBy = QStringLiteral("Name"); | 2270 | QString sortBy = QStringLiteral("Name"); | ||
2246 | if (KFile::isSortBySize(d->sorting)) { | 2271 | if (KFile::isSortBySize(d->sorting)) { | ||
2247 | sortBy = QStringLiteral("Size"); | 2272 | sortBy = QStringLiteral("Size"); | ||
Show All 31 Lines | 2300 | if (hasPreview) { | |||
2279 | configGroup.writeEntry(QStringLiteral("Preview Width"), sizes[1]); | 2304 | configGroup.writeEntry(QStringLiteral("Preview Width"), sizes[1]); | ||
2280 | } | 2305 | } | ||
2281 | } | 2306 | } | ||
2282 | } | 2307 | } | ||
2283 | 2308 | | |||
2284 | configGroup.writeEntry(QStringLiteral("Show hidden files"), | 2309 | configGroup.writeEntry(QStringLiteral("Show hidden files"), | ||
2285 | d->actionCollection->action(QStringLiteral("show hidden"))->isChecked()); | 2310 | d->actionCollection->action(QStringLiteral("show hidden"))->isChecked()); | ||
2286 | 2311 | | |||
2312 | configGroup.writeEntry(QStringLiteral("Allow Expansion"), | ||||
2313 | d->actionCollection->action(QStringLiteral("allow expansion"))->isChecked()); | ||||
2314 | | ||||
2287 | KFile::FileView fv = static_cast<KFile::FileView>(d->viewKind); | 2315 | KFile::FileView fv = static_cast<KFile::FileView>(d->viewKind); | ||
2288 | QString style; | 2316 | QString style; | ||
2289 | if (KFile::isDetailView(fv)) { | 2317 | if (KFile::isDetailView(fv)) { | ||
2290 | style = QStringLiteral("Detail"); | 2318 | style = QStringLiteral("Detail"); | ||
2291 | } else if (KFile::isSimpleView(fv)) { | 2319 | } else if (KFile::isSimpleView(fv)) { | ||
2292 | style = QStringLiteral("Simple"); | 2320 | style = QStringLiteral("Simple"); | ||
2293 | } else if (KFile::isTreeView(fv)) { | 2321 | } else if (KFile::isTreeView(fv)) { | ||
2294 | style = QStringLiteral("Tree"); | 2322 | style = QStringLiteral("Tree"); | ||
2295 | } else if (KFile::isDetailTreeView(fv)) { | 2323 | } else if (KFile::isDetailTreeView(fv)) { | ||
2296 | style = QStringLiteral("DetailTree"); | 2324 | style = QStringLiteral("DetailTree"); | ||
2297 | } | 2325 | } | ||
2298 | configGroup.writeEntry(QStringLiteral("View Style"), style); | 2326 | configGroup.writeEntry(QStringLiteral("View Style"), style); | ||
2299 | 2327 | | |||
2300 | if (d->inlinePreviewState == Private::NotForced) { | 2328 | if (d->inlinePreviewState == Private::NotForced) { | ||
2301 | configGroup.writeEntry(QStringLiteral("Show Inline Previews"), d->showPreviews); | 2329 | configGroup.writeEntry(QStringLiteral("Show Inline Previews"), d->showPreviews); | ||
2302 | if (qobject_cast<QListView *>(d->itemView)) { | 2330 | d->writeIconZoomSettings(configGroup); | ||
2303 | configGroup.writeEntry(QStringLiteral("listViewIconSize"), d->iconsZoom); | | |||
2304 | } else { | | |||
2305 | configGroup.writeEntry(QStringLiteral("detailedViewIconSize"), d->iconsZoom); | | |||
2306 | } | | |||
2307 | } | 2331 | } | ||
2308 | 2332 | | |||
2309 | configGroup.writeEntry(QStringLiteral("Decoration position"), (int) d->decorationPosition); | 2333 | configGroup.writeEntry(QStringLiteral("Decoration position"), (int) d->decorationPosition); | ||
2310 | } | 2334 | } | ||
2311 | 2335 | | |||
2336 | void KDirOperator::Private::writeIconZoomSettings(KConfigGroup &configGroup) { | ||||
2337 | // must match behavior of iconSizeForViewType | ||||
2338 | KFile::FileView fv = static_cast<KFile::FileView>(viewKind); | ||||
2339 | | ||||
2340 | if (KFile::isSimpleView(fv)) { | ||||
2341 | if (decorationPosition == QStyleOptionViewItem::Top){ | ||||
2342 | // Simple view decoration above, aka Icons View | ||||
2343 | configGroup.writeEntry("iconViewIconSize", iconsZoom); | ||||
2344 | } else { | ||||
2345 | // Simple view decoration left, aka compact view | ||||
2346 | configGroup.writeEntry("listViewIconSize", iconsZoom); | ||||
2347 | } | ||||
2348 | } else { | ||||
2349 | if (KFile::isTreeView(fv)) { | ||||
2350 | configGroup.writeEntry(QStringLiteral("treeViewIconSize"), iconsZoom); | ||||
2351 | } else if (KFile::isDetailTreeView(fv) || KFile::isDetailView(fv)) { | ||||
2352 | configGroup.writeEntry(QStringLiteral("detailViewIconSize"), iconsZoom); | ||||
2353 | } | ||||
2354 | } | ||||
2355 | } | ||||
2356 | | ||||
2312 | void KDirOperator::resizeEvent(QResizeEvent *) | 2357 | void KDirOperator::resizeEvent(QResizeEvent *) | ||
2313 | { | 2358 | { | ||
2314 | // resize the splitter and assure that the width of | 2359 | // resize the splitter and assure that the width of | ||
2315 | // the preview widget is restored | 2360 | // the preview widget is restored | ||
2316 | QList<int> sizes = d->splitter->sizes(); | 2361 | QList<int> sizes = d->splitter->sizes(); | ||
2317 | const bool hasPreview = (sizes.count() == 2); | 2362 | const bool hasPreview = (sizes.count() == 2); | ||
2318 | 2363 | | |||
2319 | d->splitter->resize(size()); | 2364 | d->splitter->resize(size()); | ||
Show All 9 Lines | |||||
2329 | if (hasPreview) { | 2374 | if (hasPreview) { | ||
2330 | d->previewWidth = sizes[1]; | 2375 | d->previewWidth = sizes[1]; | ||
2331 | } | 2376 | } | ||
2332 | 2377 | | |||
2333 | if (d->progressBar->parent() == this) { | 2378 | if (d->progressBar->parent() == this) { | ||
2334 | // might be reparented into a statusbar | 2379 | // might be reparented into a statusbar | ||
2335 | d->progressBar->move(2, height() - d->progressBar->height() - 2); | 2380 | d->progressBar->move(2, height() - d->progressBar->height() - 2); | ||
2336 | } | 2381 | } | ||
2337 | | ||||
2338 | d->updateListViewGrid(); | | |||
2339 | } | 2382 | } | ||
2340 | 2383 | | |||
2341 | void KDirOperator::setOnlyDoubleClickSelectsFiles(bool enable) | 2384 | void KDirOperator::setOnlyDoubleClickSelectsFiles(bool enable) | ||
2342 | { | 2385 | { | ||
2343 | d->onlyDoubleClickSelectsFiles = enable; | 2386 | d->onlyDoubleClickSelectsFiles = enable; | ||
2344 | // TODO: port to QAbstractItemModel | 2387 | // TODO: port to QAbstractItemModel | ||
2345 | //if (d->itemView != 0) { | 2388 | //if (d->itemView != 0) { | ||
2346 | // d->itemView->setOnlyDoubleClickSelectsFiles(enable); | 2389 | // d->itemView->setOnlyDoubleClickSelectsFiles(enable); | ||
▲ Show 20 Lines • Show All 228 Lines • ▼ Show 20 Line(s) | |||||
2575 | } | 2618 | } | ||
2576 | 2619 | | |||
2577 | void KDirOperator::Private::_k_slotChangeDecorationPosition() | 2620 | void KDirOperator::Private::_k_slotChangeDecorationPosition() | ||
2578 | { | 2621 | { | ||
2579 | if (!itemView) { | 2622 | if (!itemView) { | ||
2580 | return; | 2623 | return; | ||
2581 | } | 2624 | } | ||
2582 | 2625 | | |||
2583 | QListView *view = qobject_cast<QListView *>(itemView); | 2626 | KDirOperatorIconView *view = qobject_cast<KDirOperatorIconView *>(itemView); | ||
2584 | 2627 | | |||
2585 | if (!view) { | 2628 | if (!view) { | ||
2586 | return; | 2629 | return; | ||
2587 | } | 2630 | } | ||
2588 | 2631 | | |||
2589 | const bool leftChecked = actionCollection->action(QStringLiteral("decorationAtLeft"))->isChecked(); | 2632 | const bool leftChecked = actionCollection->action(QStringLiteral("decorationAtLeft"))->isChecked(); | ||
2590 | 2633 | | |||
2591 | if (leftChecked) { | 2634 | if (leftChecked) { | ||
2592 | decorationPosition = QStyleOptionViewItem::Left; | 2635 | view->setDecorationPosition(QStyleOptionViewItem::Left); | ||
2593 | view->setFlow(QListView::TopToBottom); | | |||
2594 | } else { | 2636 | } else { | ||
2595 | decorationPosition = QStyleOptionViewItem::Top; | 2637 | view->setDecorationPosition(QStyleOptionViewItem::Top); | ||
2596 | view->setFlow(QListView::LeftToRight); | | |||
2597 | } | 2638 | } | ||
2598 | 2639 | | |||
2599 | updateListViewGrid(); | | |||
2600 | | ||||
2601 | itemView->update(); | 2640 | itemView->update(); | ||
2602 | } | 2641 | } | ||
2603 | 2642 | | |||
2604 | void KDirOperator::Private::_k_slotExpandToUrl(const QModelIndex &index) | 2643 | void KDirOperator::Private::_k_slotExpandToUrl(const QModelIndex &index) | ||
2605 | { | 2644 | { | ||
2606 | QTreeView *treeView = qobject_cast<QTreeView *>(itemView); | 2645 | QTreeView *treeView = qobject_cast<QTreeView *>(itemView); | ||
2607 | 2646 | | |||
2608 | if (!treeView) { | 2647 | if (!treeView) { | ||
Show All 34 Lines | |||||
2643 | } | 2682 | } | ||
2644 | } | 2683 | } | ||
2645 | 2684 | | |||
2646 | void KDirOperator::Private::_k_slotItemsChanged() | 2685 | void KDirOperator::Private::_k_slotItemsChanged() | ||
2647 | { | 2686 | { | ||
2648 | completeListDirty = true; | 2687 | completeListDirty = true; | ||
2649 | } | 2688 | } | ||
2650 | 2689 | | |||
2651 | void KDirOperator::Private::updateListViewGrid() | 2690 | int KDirOperator::Private::iconSizeForViewType(QAbstractItemView *itemView) const | ||
2652 | { | 2691 | { | ||
2653 | if (!itemView) { | 2692 | // must match behavior of writeIconZoomSettings | ||
2654 | return; | 2693 | if (!itemView || !configGroup) { | ||
2655 | } | 2694 | return 0; | ||
2656 | | ||||
2657 | QListView *view = qobject_cast<QListView *>(itemView); | | |||
2658 | | ||||
2659 | if (!view) { | | |||
2660 | return; | | |||
2661 | } | 2695 | } | ||
2662 | 2696 | | |||
2663 | const bool leftChecked = actionCollection->action(QStringLiteral("decorationAtLeft"))->isChecked(); | 2697 | KFile::FileView fv = static_cast<KFile::FileView>(viewKind); | ||
2664 | 2698 | | |||
2665 | if (leftChecked) { | 2699 | if (KFile::isSimpleView(fv)) { | ||
2666 | view->setGridSize(QSize()); | 2700 | if (decorationPosition == QStyleOptionViewItem::Top){ | ||
2667 | KFileItemDelegate *delegate = qobject_cast<KFileItemDelegate *>(view->itemDelegate()); | 2701 | // Simple view decoration above, aka Icons View | ||
2668 | if (delegate) { | 2702 | // default to 43% aka 64px | ||
2669 | delegate->setMaximumSize(QSize()); | 2703 | return configGroup->readEntry("iconViewIconSize", 43); | ||
2670 | } | | |||
2671 | } else { | 2704 | } else { | ||
2672 | const QFontMetrics metrics(itemView->viewport()->font()); | 2705 | // Simple view decoration left, aka compact view | ||
2673 | 2706 | return configGroup->readEntry("listViewIconSize", 0); | |||
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 | } | 2707 | } | ||
2708 | } else { | ||||
2709 | if (KFile::isTreeView(fv)) { | ||||
2710 | return configGroup->readEntry(QStringLiteral("treeViewIconSize"), 0); | ||||
2711 | } else if (KFile::isDetailView(fv) || KFile::isDetailTreeView(fv)) { | ||||
2712 | return configGroup->readEntry(QStringLiteral("detailViewIconSize"), 0); | ||||
2694 | } | 2713 | } | ||
2695 | } | 2714 | } | ||
2696 | 2715 | | |||
2697 | int KDirOperator::Private::iconSizeForViewType(QAbstractItemView *itemView) const | | |||
2698 | { | | |||
2699 | if (!itemView || !configGroup) { | | |||
2700 | return 0; | 2716 | return 0; | ||
2701 | } | 2717 | } | ||
2702 | 2718 | | |||
2703 | if (qobject_cast<QListView *>(itemView)) { | | |||
2704 | return configGroup->readEntry("listViewIconSize", 0); | | |||
2705 | } else { | | |||
2706 | return configGroup->readEntry("detailedViewIconSize", 0); | | |||
2707 | } | | |||
2708 | } | | |||
2709 | | ||||
2710 | void KDirOperator::setViewConfig(KConfigGroup &configGroup) | 2719 | void KDirOperator::setViewConfig(KConfigGroup &configGroup) | ||
2711 | { | 2720 | { | ||
2712 | delete d->configGroup; | 2721 | delete d->configGroup; | ||
2713 | d->configGroup = new KConfigGroup(configGroup); | 2722 | d->configGroup = new KConfigGroup(configGroup); | ||
2714 | } | 2723 | } | ||
2715 | 2724 | | |||
2716 | KConfigGroup *KDirOperator::viewConfigGroup() const | 2725 | KConfigGroup *KDirOperator::viewConfigGroup() const | ||
2717 | { | 2726 | { | ||
2718 | return d->configGroup; | 2727 | return d->configGroup; | ||
2719 | } | 2728 | } | ||
2720 | 2729 | | |||
meven: Perhaps we could use a more sensible default value for ColumnView.
What would you say about… | |||||
ngraham: That sounds like a good default size. | |||||
2721 | void KDirOperator::setShowHiddenFiles(bool s) | 2730 | void KDirOperator::setShowHiddenFiles(bool s) | ||
2722 | { | 2731 | { | ||
2723 | d->actionCollection->action(QStringLiteral("show hidden"))->setChecked(s); | 2732 | d->actionCollection->action(QStringLiteral("show hidden"))->setChecked(s); | ||
2724 | } | 2733 | } | ||
2725 | 2734 | | |||
2726 | bool KDirOperator::showHiddenFiles() const | 2735 | bool KDirOperator::showHiddenFiles() const | ||
2727 | { | 2736 | { | ||
2728 | return d->actionCollection->action(QStringLiteral("show hidden"))->isChecked(); | 2737 | return d->actionCollection->action(QStringLiteral("show hidden"))->isChecked(); | ||
▲ Show 20 Lines • Show All 41 Lines • Show Last 20 Lines |
Perhaps we could use a more sensible default value for ColumnView.
What would you say about 32px ?