Changeset View
Changeset View
Standalone View
Standalone View
src/filewidgets/kdiroperator.cpp
Show First 20 Lines • Show All 100 Lines • ▼ Show 20 Line(s) | 84 | public: | |||
---|---|---|---|---|---|
101 | 101 | | |||
102 | static bool isReadable(const QUrl &url); | 102 | static bool isReadable(const QUrl &url); | ||
103 | bool isSchemeSupported(const QString &scheme) const; | 103 | bool isSchemeSupported(const QString &scheme) const; | ||
104 | 104 | | |||
105 | KFile::FileView allViews(); | 105 | KFile::FileView allViews(); | ||
106 | 106 | | |||
107 | QMetaObject::Connection m_connection; | 107 | QMetaObject::Connection m_connection; | ||
108 | 108 | | |||
109 | // A pair to store zoom settings for view kinds | ||||
110 | struct ZoomSettingsForView { | ||||
111 | QString name; | ||||
112 | int defaultValue; | ||||
113 | }; | ||||
114 | | ||||
109 | // private slots | 115 | // private slots | ||
110 | void _k_slotDetailedView(); | 116 | void _k_slotDetailedView(); | ||
111 | void _k_slotSimpleView(); | 117 | void _k_slotSimpleView(); | ||
112 | void _k_slotTreeView(); | 118 | void _k_slotTreeView(); | ||
113 | void _k_slotDetailedTreeView(); | 119 | void _k_slotDetailedTreeView(); | ||
120 | void _k_slotIconsView(); | ||||
121 | void _k_slotCompactView(); | ||||
122 | void _k_slotDetailsView(); | ||||
114 | void _k_slotToggleHidden(bool); | 123 | void _k_slotToggleHidden(bool); | ||
115 | void _k_slotToggleAllowExpansion(bool); | 124 | void _k_slotToggleAllowExpansion(bool); | ||
116 | void _k_togglePreview(bool); | 125 | void _k_togglePreview(bool); | ||
117 | void _k_toggleInlinePreviews(bool); | 126 | void _k_toggleInlinePreviews(bool); | ||
118 | void _k_slotOpenFileManager(); | 127 | void _k_slotOpenFileManager(); | ||
119 | void _k_slotSortByName(); | 128 | void _k_slotSortByName(); | ||
120 | void _k_slotSortBySize(); | 129 | void _k_slotSortBySize(); | ||
121 | void _k_slotSortByDate(); | 130 | void _k_slotSortByDate(); | ||
Show All 20 Lines | |||||
142 | void _k_assureVisibleSelection(); | 151 | void _k_assureVisibleSelection(); | ||
143 | void _k_synchronizeSortingState(int, Qt::SortOrder); | 152 | void _k_synchronizeSortingState(int, Qt::SortOrder); | ||
144 | void _k_slotChangeDecorationPosition(); | 153 | void _k_slotChangeDecorationPosition(); | ||
145 | void _k_slotExpandToUrl(const QModelIndex &); | 154 | void _k_slotExpandToUrl(const QModelIndex &); | ||
146 | void _k_slotItemsChanged(); | 155 | void _k_slotItemsChanged(); | ||
147 | void _k_slotDirectoryCreated(const QUrl &); | 156 | void _k_slotDirectoryCreated(const QUrl &); | ||
148 | 157 | | |||
149 | int iconSizeForViewType(QAbstractItemView *itemView) const; | 158 | int iconSizeForViewType(QAbstractItemView *itemView) const; | ||
159 | void writeIconZoomSettingsIfNeeded(); | ||||
160 | ZoomSettingsForView zoomSettingsForViewForView() const; | ||||
150 | 161 | | |||
151 | // private members | 162 | // private members | ||
152 | KDirOperator * const parent; | 163 | KDirOperator * const parent; | ||
153 | QStack<QUrl *> backStack; ///< Contains all URLs you can reach with the back button. | 164 | QStack<QUrl *> backStack; ///< Contains all URLs you can reach with the back button. | ||
154 | QStack<QUrl *> forwardStack; ///< Contains all URLs you can reach with the forward button. | 165 | QStack<QUrl *> forwardStack; ///< Contains all URLs you can reach with the forward button. | ||
155 | 166 | | |||
156 | QModelIndex lastHoveredIndex; | 167 | QModelIndex lastHoveredIndex; | ||
157 | 168 | | |||
▲ Show 20 Lines • Show All 347 Lines • ▼ Show 20 Line(s) | |||||
505 | 516 | | |||
506 | KFile::FileView KDirOperator::Private::allViews() | 517 | KFile::FileView KDirOperator::Private::allViews() | ||
507 | { | 518 | { | ||
508 | return static_cast<KFile::FileView>(KFile::Simple | KFile::Detail | KFile::Tree | KFile::DetailTree); | 519 | return static_cast<KFile::FileView>(KFile::Simple | KFile::Detail | KFile::Tree | KFile::DetailTree); | ||
509 | } | 520 | } | ||
510 | 521 | | |||
511 | void KDirOperator::Private::_k_slotDetailedView() | 522 | void KDirOperator::Private::_k_slotDetailedView() | ||
512 | { | 523 | { | ||
524 | // save old zoom settings | ||||
525 | writeIconZoomSettingsIfNeeded(); | ||||
526 | | ||||
513 | KFile::FileView view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::Detail); | 527 | KFile::FileView view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::Detail); | ||
514 | parent->setView(view); | 528 | parent->setView(view); | ||
515 | } | 529 | } | ||
516 | 530 | | |||
517 | void KDirOperator::Private::_k_slotSimpleView() | 531 | void KDirOperator::Private::_k_slotSimpleView() | ||
518 | { | 532 | { | ||
533 | // save old zoom settings | ||||
534 | writeIconZoomSettingsIfNeeded(); | ||||
535 | | ||||
519 | KFile::FileView view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::Simple); | 536 | KFile::FileView view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::Simple); | ||
520 | parent->setView(view); | 537 | parent->setView(view); | ||
521 | } | 538 | } | ||
522 | 539 | | |||
523 | void KDirOperator::Private::_k_slotTreeView() | 540 | void KDirOperator::Private::_k_slotTreeView() | ||
524 | { | 541 | { | ||
542 | // save old zoom settings | ||||
543 | writeIconZoomSettingsIfNeeded(); | ||||
544 | | ||||
525 | KFile::FileView view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::Tree); | 545 | KFile::FileView view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::Tree); | ||
526 | parent->setView(view); | 546 | parent->setView(view); | ||
527 | } | 547 | } | ||
528 | 548 | | |||
529 | void KDirOperator::Private::_k_slotDetailedTreeView() | 549 | void KDirOperator::Private::_k_slotDetailedTreeView() | ||
530 | { | 550 | { | ||
551 | // save old zoom settings | ||||
552 | writeIconZoomSettingsIfNeeded(); | ||||
553 | | ||||
531 | KFile::FileView view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::DetailTree); | 554 | KFile::FileView view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::DetailTree); | ||
532 | parent->setView(view); | 555 | parent->setView(view); | ||
533 | } | 556 | } | ||
534 | 557 | | |||
535 | void KDirOperator::Private::_k_slotToggleAllowExpansion(bool allow) { | 558 | void KDirOperator::Private::_k_slotToggleAllowExpansion(bool allow) { | ||
536 | KFile::FileView view = KFile::Detail; | 559 | KFile::FileView view = KFile::Detail; | ||
537 | if (allow) { | 560 | if (allow) { | ||
538 | view = KFile::DetailTree; | 561 | view = KFile::DetailTree; | ||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Line(s) | |||||
627 | } | 650 | } | ||
628 | 651 | | |||
629 | void KDirOperator::Private::_k_slotToggleDirsFirst() | 652 | void KDirOperator::Private::_k_slotToggleDirsFirst() | ||
630 | { | 653 | { | ||
631 | QDir::SortFlags s = (sorting ^ QDir::DirsFirst); | 654 | QDir::SortFlags s = (sorting ^ QDir::DirsFirst); | ||
632 | updateSorting(s); | 655 | updateSorting(s); | ||
633 | } | 656 | } | ||
634 | 657 | | |||
635 | void KDirOperator::Private::_k_slotToggleIconsView() | 658 | void KDirOperator::Private::_k_slotIconsView() | ||
636 | { | 659 | { | ||
660 | // save old zoom settings | ||||
661 | writeIconZoomSettingsIfNeeded(); | ||||
662 | | ||||
637 | // Put the icons on top | 663 | // Put the icons on top | ||
638 | actionCollection->action(QStringLiteral("decorationAtTop"))->setChecked(true); | 664 | actionCollection->action(QStringLiteral("decorationAtTop"))->setChecked(true); | ||
639 | decorationPosition = QStyleOptionViewItem::Top; | 665 | decorationPosition = QStyleOptionViewItem::Top; | ||
640 | 666 | | |||
641 | // Switch to simple view | 667 | // Switch to simple view | ||
642 | KFile::FileView fileView = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::Simple); | 668 | KFile::FileView fileView = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::Simple); | ||
643 | parent->setView(fileView); | 669 | parent->setView(fileView); | ||
644 | } | 670 | } | ||
645 | 671 | | |||
646 | void KDirOperator::Private::_k_slotToggleCompactView() | 672 | void KDirOperator::Private::_k_slotCompactView() | ||
647 | { | 673 | { | ||
674 | // save old zoom settings | ||||
675 | writeIconZoomSettingsIfNeeded(); | ||||
676 | | ||||
648 | // Put the icons on the side | 677 | // Put the icons on the side | ||
649 | actionCollection->action(QStringLiteral("decorationAtLeft"))->setChecked(true); | 678 | actionCollection->action(QStringLiteral("decorationAtLeft"))->setChecked(true); | ||
650 | decorationPosition = QStyleOptionViewItem::Left; | 679 | decorationPosition = QStyleOptionViewItem::Left; | ||
651 | 680 | | |||
652 | // Switch to simple view | 681 | // Switch to simple view | ||
653 | KFile::FileView fileView = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::Simple); | 682 | KFile::FileView fileView = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::Simple); | ||
654 | parent->setView(fileView); | 683 | parent->setView(fileView); | ||
655 | } | 684 | } | ||
656 | 685 | | |||
657 | void KDirOperator::Private::_k_slotToggleDetailsView() | 686 | void KDirOperator::Private::_k_slotDetailsView() | ||
658 | { | 687 | { | ||
688 | // save old zoom settings | ||||
689 | writeIconZoomSettingsIfNeeded(); | ||||
690 | | ||||
659 | KFile::FileView view; | 691 | KFile::FileView view; | ||
660 | if (actionCollection->action(QStringLiteral("allow expansion"))->isChecked()) { | 692 | if (actionCollection->action(QStringLiteral("allow expansion"))->isChecked()) { | ||
661 | view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::DetailTree); | 693 | view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::DetailTree); | ||
662 | } else { | 694 | } else { | ||
663 | view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::Detail); | 695 | view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::Detail); | ||
664 | } | 696 | } | ||
665 | parent->setView(view); | 697 | parent->setView(view); | ||
666 | } | 698 | } | ||
▲ Show 20 Lines • Show All 1284 Lines • ▼ Show 20 Line(s) | 1919 | { | |||
1951 | KToggleAction *dirsFirstAction = new KToggleAction(i18n("Folders First"), this); | 1983 | KToggleAction *dirsFirstAction = new KToggleAction(i18n("Folders First"), this); | ||
1952 | d->actionCollection->addAction(QStringLiteral("dirs first"), dirsFirstAction); | 1984 | d->actionCollection->addAction(QStringLiteral("dirs first"), dirsFirstAction); | ||
1953 | connect(dirsFirstAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotToggleDirsFirst())); | 1985 | connect(dirsFirstAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotToggleDirsFirst())); | ||
1954 | 1986 | | |||
1955 | // View modes that match those of Dolphin | 1987 | // View modes that match those of Dolphin | ||
1956 | KToggleAction *iconsViewAction = new KToggleAction(i18n("Icons View"), this); | 1988 | KToggleAction *iconsViewAction = new KToggleAction(i18n("Icons View"), this); | ||
1957 | iconsViewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-icons"))); | 1989 | iconsViewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-icons"))); | ||
1958 | d->actionCollection->addAction(QStringLiteral("icons view"), iconsViewAction); | 1990 | d->actionCollection->addAction(QStringLiteral("icons view"), iconsViewAction); | ||
1959 | connect(iconsViewAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotToggleIconsView())); | 1991 | connect(iconsViewAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotIconsView())); | ||
1960 | 1992 | | |||
1961 | KToggleAction *compactViewAction = new KToggleAction(i18n("Compact View"), this); | 1993 | KToggleAction *compactViewAction = new KToggleAction(i18n("Compact View"), this); | ||
1962 | compactViewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-details"))); | 1994 | compactViewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-details"))); | ||
1963 | d->actionCollection->addAction(QStringLiteral("compact view"), compactViewAction); | 1995 | d->actionCollection->addAction(QStringLiteral("compact view"), compactViewAction); | ||
1964 | connect(compactViewAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotToggleCompactView())); | 1996 | connect(compactViewAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotCompactView())); | ||
1965 | 1997 | | |||
1966 | KToggleAction *detailsViewAction = new KToggleAction(i18n("Details View"), this); | 1998 | KToggleAction *detailsViewAction = new KToggleAction(i18n("Details View"), this); | ||
1967 | detailsViewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-tree"))); | 1999 | detailsViewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-tree"))); | ||
1968 | d->actionCollection->addAction(QStringLiteral("details view"), detailsViewAction); | 2000 | d->actionCollection->addAction(QStringLiteral("details view"), detailsViewAction); | ||
1969 | connect(detailsViewAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotToggleDetailsView())); | 2001 | connect(detailsViewAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotDetailsView())); | ||
1970 | 2002 | | |||
1971 | QActionGroup *viewModeGroup = new QActionGroup(this); | 2003 | QActionGroup *viewModeGroup = new QActionGroup(this); | ||
1972 | viewModeGroup->setExclusive(true); | 2004 | viewModeGroup->setExclusive(true); | ||
1973 | iconsViewAction->setActionGroup(viewModeGroup); | 2005 | iconsViewAction->setActionGroup(viewModeGroup); | ||
1974 | compactViewAction->setActionGroup(viewModeGroup); | 2006 | compactViewAction->setActionGroup(viewModeGroup); | ||
1975 | detailsViewAction->setActionGroup(viewModeGroup); | 2007 | detailsViewAction->setActionGroup(viewModeGroup); | ||
1976 | 2008 | | |||
1977 | QActionGroup *sortGroup = new QActionGroup(this); | 2009 | QActionGroup *sortGroup = new QActionGroup(this); | ||
▲ Show 20 Lines • Show All 314 Lines • ▼ Show 20 Line(s) | 2323 | } else if (KFile::isTreeView(fv)) { | |||
2292 | style = QStringLiteral("Tree"); | 2324 | style = QStringLiteral("Tree"); | ||
2293 | } else if (KFile::isDetailTreeView(fv)) { | 2325 | } else if (KFile::isDetailTreeView(fv)) { | ||
2294 | style = QStringLiteral("DetailTree"); | 2326 | style = QStringLiteral("DetailTree"); | ||
2295 | } | 2327 | } | ||
2296 | configGroup.writeEntry(QStringLiteral("View Style"), style); | 2328 | configGroup.writeEntry(QStringLiteral("View Style"), style); | ||
2297 | 2329 | | |||
2298 | if (d->inlinePreviewState == Private::NotForced) { | 2330 | if (d->inlinePreviewState == Private::NotForced) { | ||
2299 | configGroup.writeEntry(QStringLiteral("Show Inline Previews"), d->showPreviews); | 2331 | configGroup.writeEntry(QStringLiteral("Show Inline Previews"), d->showPreviews); | ||
2300 | if (qobject_cast<QListView *>(d->itemView)) { | 2332 | d->writeIconZoomSettingsIfNeeded(); | ||
2301 | configGroup.writeEntry(QStringLiteral("listViewIconSize"), d->iconsZoom); | | |||
2302 | } else { | | |||
2303 | configGroup.writeEntry(QStringLiteral("detailedViewIconSize"), d->iconsZoom); | | |||
2304 | } | | |||
2305 | } | 2333 | } | ||
2306 | 2334 | | |||
2307 | configGroup.writeEntry(QStringLiteral("Decoration position"), (int) d->decorationPosition); | 2335 | configGroup.writeEntry(QStringLiteral("Decoration position"), (int) d->decorationPosition); | ||
2308 | } | 2336 | } | ||
2309 | 2337 | | |||
2338 | void KDirOperator::Private::writeIconZoomSettingsIfNeeded() { | ||||
2339 | // must match behavior of iconSizeForViewType | ||||
2340 | if (configGroup && itemView) { | ||||
2341 | ZoomSettingsForView zoomSettings = zoomSettingsForViewForView(); | ||||
2342 | configGroup->writeEntry(zoomSettings.name, iconsZoom); | ||||
2343 | } | ||||
2344 | } | ||||
2310 | 2345 | | |||
2311 | void KDirOperator::resizeEvent(QResizeEvent *) | 2346 | void KDirOperator::resizeEvent(QResizeEvent *) | ||
2312 | { | 2347 | { | ||
2313 | // resize the splitter and assure that the width of | 2348 | // resize the splitter and assure that the width of | ||
2314 | // the preview widget is restored | 2349 | // the preview widget is restored | ||
2315 | QList<int> sizes = d->splitter->sizes(); | 2350 | QList<int> sizes = d->splitter->sizes(); | ||
2316 | const bool hasPreview = (sizes.count() == 2); | 2351 | const bool hasPreview = (sizes.count() == 2); | ||
2317 | 2352 | | |||
▲ Show 20 Lines • Show All 320 Lines • ▼ Show 20 Line(s) | |||||
2638 | 2673 | | |||
2639 | void KDirOperator::Private::_k_slotItemsChanged() | 2674 | void KDirOperator::Private::_k_slotItemsChanged() | ||
2640 | { | 2675 | { | ||
2641 | completeListDirty = true; | 2676 | completeListDirty = true; | ||
2642 | } | 2677 | } | ||
2643 | 2678 | | |||
2644 | int KDirOperator::Private::iconSizeForViewType(QAbstractItemView *itemView) const | 2679 | int KDirOperator::Private::iconSizeForViewType(QAbstractItemView *itemView) const | ||
2645 | { | 2680 | { | ||
2681 | // must match behavior of writeIconZoomSettingsIfNeeded | ||||
2646 | if (!itemView || !configGroup) { | 2682 | if (!itemView || !configGroup) { | ||
2647 | return 0; | 2683 | return 0; | ||
2648 | } | 2684 | } | ||
2649 | 2685 | | |||
2650 | if (qobject_cast<QListView *>(itemView)) { | 2686 | ZoomSettingsForView ZoomSettingsForView = zoomSettingsForViewForView(); | ||
2651 | return configGroup->readEntry("listViewIconSize", 0); | 2687 | return configGroup->readEntry(ZoomSettingsForView.name, ZoomSettingsForView.defaultValue); | ||
2688 | } | ||||
2689 | | ||||
2690 | KDirOperator::Private::ZoomSettingsForView KDirOperator::Private::zoomSettingsForViewForView() const { | ||||
2691 | KFile::FileView fv = static_cast<KFile::FileView>(viewKind); | ||||
2692 | if (KFile::isSimpleView(fv)) { | ||||
2693 | if (decorationPosition == QStyleOptionViewItem::Top){ | ||||
2694 | // Simple view decoration above, aka Icons View | ||||
2695 | // default to 43% aka 64px | ||||
2696 | return {QStringLiteral("iconViewIconSize"), 43}; | ||||
2652 | } else { | 2697 | } else { | ||
2653 | return configGroup->readEntry("detailedViewIconSize", 0); | 2698 | // Simple view decoration left, aka compact view | ||
2699 | // default to 15% aka 32px | ||||
2700 | return {QStringLiteral("listViewIconSize"), 15}; | ||||
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. | |||||
2701 | } | ||||
2702 | } else { | ||||
2703 | if (KFile::isTreeView(fv)) { | ||||
2704 | return {QStringLiteral("treeViewIconSize"), 0}; | ||||
2705 | } else { | ||||
2706 | // DetailView and DetailTreeView | ||||
2707 | return {QStringLiteral("detailViewIconSize"), 0}; | ||||
2708 | } | ||||
2654 | } | 2709 | } | ||
2655 | } | 2710 | } | ||
2656 | 2711 | | |||
2657 | void KDirOperator::setViewConfig(KConfigGroup &configGroup) | 2712 | void KDirOperator::setViewConfig(KConfigGroup &configGroup) | ||
2658 | { | 2713 | { | ||
2659 | delete d->configGroup; | 2714 | delete d->configGroup; | ||
2660 | d->configGroup = new KConfigGroup(configGroup); | 2715 | d->configGroup = new KConfigGroup(configGroup); | ||
2661 | } | 2716 | } | ||
▲ Show 20 Lines • Show All 55 Lines • Show Last 20 Lines |
Perhaps we could use a more sensible default value for ColumnView.
What would you say about 32px ?