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 <QMenu> | 40 | #include <QMenu> | ||
| 41 | #include <QMimeData> | | |||
| 42 | #include <QProgressBar> | 41 | #include <QProgressBar> | ||
| 43 | #include <QScrollBar> | | |||
| 44 | #include <QSplitter> | 42 | #include <QSplitter> | ||
| 45 | #include <QWheelEvent> | 43 | #include <QWheelEvent> | ||
| 46 | #include <QTimer> | 44 | #include <QTimer> | ||
| 47 | #include <QDebug> | | |||
| 48 | #include <QMimeDatabase> | 45 | #include <QMimeDatabase> | ||
| 46 | #include <QKeyEvent> | ||||
| 49 | 47 | | |||
| 50 | #include <kdirlister.h> | 48 | #include <kdirlister.h> | ||
| 51 | #include <kfileitemdelegate.h> | 49 | #include <kfileitemdelegate.h> | ||
| 52 | #include <klocalizedstring.h> | 50 | #include <klocalizedstring.h> | ||
| 53 | #include <kmessagebox.h> | 51 | #include <kmessagebox.h> | ||
| 54 | #include <kjobwidgets.h> | 52 | #include <kjobwidgets.h> | ||
| 55 | #include <kio/deletejob.h> | 53 | #include <kio/deletejob.h> | ||
| 56 | #include <kio/copyjob.h> | 54 | #include <kio/copyjob.h> | ||
| 57 | #include <kio/jobuidelegate.h> | 55 | #include <kio/jobuidelegate.h> | ||
| 58 | #include <kio/previewjob.h> | 56 | #include <kio/previewjob.h> | ||
| 59 | #include <KIO/OpenFileManagerWindowJob> | 57 | #include <KIO/OpenFileManagerWindowJob> | ||
| 60 | #include <kfilepreviewgenerator.h> | 58 | #include <kfilepreviewgenerator.h> | ||
| 61 | #include <krun.h> | 59 | #include <krun.h> | ||
| 62 | #include <kpropertiesdialog.h> | 60 | #include <kpropertiesdialog.h> | ||
| 63 | #include <kactioncollection.h> | 61 | #include <kactioncollection.h> | ||
| 64 | #include <kconfiggroup.h> | 62 | #include <kconfiggroup.h> | ||
| 65 | #include <ksharedconfig.h> | 63 | #include <ksharedconfig.h> | ||
| 66 | 64 | | |||
| 67 | template class QHash<QString, KFileItem>; | 65 | template class QHash<QString, KFileItem>; | ||
| 68 | 66 | | |||
| 69 | // QDir::SortByMask is not only undocumented, it also omits QDir::Type which is another | 67 | // QDir::SortByMask is not only undocumented, it also omits QDir::Type which is another | ||
| 70 | // sorting mode. | 68 | // sorting mode. | ||
| 71 | static const int QDirSortMask = QDir::SortByMask | QDir::Type; | 69 | static const int QDirSortMask = QDir::SortByMask | QDir::Type; | ||
| 72 | 70 | | |||
| 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 | 71 | | |||
| 164 | void KDirOperator::keyPressEvent(QKeyEvent *e) | 72 | void KDirOperator::keyPressEvent(QKeyEvent *e) | ||
| 165 | { | 73 | { | ||
| 166 | if (!(e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter)) { | 74 | if (!(e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter)) { | ||
| 167 | QWidget::keyPressEvent(e); | 75 | QWidget::keyPressEvent(e); | ||
| 168 | } else { | 76 | } else { | ||
| 169 | emit keyEnterReturnPressed(); | 77 | emit keyEnterReturnPressed(); | ||
| 170 | } | 78 | } | ||
| Show All 23 Lines | 83 | public: | |||
| 194 | bool isSchemeSupported(const QString &scheme) const; | 102 | bool isSchemeSupported(const QString &scheme) const; | ||
| 195 | 103 | | |||
| 196 | KFile::FileView allViews(); | 104 | KFile::FileView allViews(); | ||
| 197 | 105 | | |||
| 198 | QMetaObject::Connection m_connection; | 106 | QMetaObject::Connection m_connection; | ||
| 199 | 107 | | |||
| 200 | // private slots | 108 | // private slots | ||
| 201 | void _k_slotDetailedView(); | 109 | void _k_slotDetailedView(); | ||
| 202 | void _k_slotSimpleView(); | 110 | void _k_slotIconView(); | ||
| 203 | void _k_slotTreeView(); | 111 | void _k_slotCompactView(); | ||
| 204 | void _k_slotDetailedTreeView(); | 112 | void _k_slotDetailedTreeView(); | ||
| 205 | void _k_slotToggleHidden(bool); | 113 | void _k_slotToggleHidden(bool); | ||
| 206 | void _k_togglePreview(bool); | 114 | void _k_togglePreview(bool); | ||
| 207 | void _k_toggleInlinePreviews(bool); | 115 | void _k_toggleInlinePreviews(bool); | ||
| 208 | void _k_slotOpenFileManager(); | 116 | void _k_slotOpenFileManager(); | ||
| 209 | void _k_slotSortByName(); | 117 | void _k_slotSortByName(); | ||
| 210 | void _k_slotSortBySize(); | 118 | void _k_slotSortBySize(); | ||
| 211 | void _k_slotSortByDate(); | 119 | void _k_slotSortByDate(); | ||
| Show All 11 Lines | |||||
| 223 | void _k_slotActivated(const QModelIndex &); | 131 | void _k_slotActivated(const QModelIndex &); | ||
| 224 | void _k_slotSelectionChanged(); | 132 | void _k_slotSelectionChanged(); | ||
| 225 | void _k_openContextMenu(const QPoint &); | 133 | void _k_openContextMenu(const QPoint &); | ||
| 226 | void _k_triggerPreview(const QModelIndex &); | 134 | void _k_triggerPreview(const QModelIndex &); | ||
| 227 | void _k_showPreview(); | 135 | void _k_showPreview(); | ||
| 228 | void _k_slotSplitterMoved(int, int); | 136 | void _k_slotSplitterMoved(int, int); | ||
| 229 | void _k_assureVisibleSelection(); | 137 | void _k_assureVisibleSelection(); | ||
| 230 | void _k_synchronizeSortingState(int, Qt::SortOrder); | 138 | void _k_synchronizeSortingState(int, Qt::SortOrder); | ||
| 231 | void _k_slotChangeDecorationPosition(); | | |||
| 232 | void _k_slotExpandToUrl(const QModelIndex &); | 139 | void _k_slotExpandToUrl(const QModelIndex &); | ||
| 233 | void _k_slotItemsChanged(); | 140 | void _k_slotItemsChanged(); | ||
| 234 | void _k_slotDirectoryCreated(const QUrl &); | 141 | void _k_slotDirectoryCreated(const QUrl &); | ||
| 235 | 142 | | |||
| 236 | void updateListViewGrid(); | | |||
| 237 | int iconSizeForViewType(QAbstractItemView *itemView) const; | 143 | int iconSizeForViewType(QAbstractItemView *itemView) const; | ||
| 238 | 144 | | |||
| 239 | // private members | 145 | // private members | ||
| 240 | KDirOperator * const parent; | 146 | KDirOperator * const parent; | ||
| 241 | QStack<QUrl *> backStack; ///< Contains all URLs you can reach with the back button. | 147 | 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. | 148 | QStack<QUrl *> forwardStack; ///< Contains all URLs you can reach with the forward button. | ||
| 243 | 149 | | |||
| 244 | QModelIndex lastHoveredIndex; | 150 | QModelIndex lastHoveredIndex; | ||
| 245 | 151 | | |||
| 246 | KDirLister *dirLister; | 152 | KDirLister *dirLister; | ||
| 247 | QUrl currUrl; | 153 | QUrl currUrl; | ||
| 248 | 154 | | |||
| 249 | KCompletion completion; | 155 | KCompletion completion; | ||
| 250 | KCompletion dirCompletion; | 156 | KCompletion dirCompletion; | ||
| 251 | bool completeListDirty; | 157 | bool completeListDirty; | ||
| 252 | QDir::SortFlags sorting; | 158 | QDir::SortFlags sorting; | ||
| 253 | QStyleOptionViewItem::Position decorationPosition; | | |||
| 254 | 159 | | |||
| 255 | QSplitter *splitter; | 160 | QSplitter *splitter; | ||
| 256 | 161 | | |||
| 257 | QAbstractItemView *itemView; | 162 | QAbstractItemView *itemView; | ||
| 258 | KDirModel *dirModel; | 163 | KDirModel *dirModel; | ||
| 259 | KDirSortFilterProxyModel *proxyModel; | 164 | KDirSortFilterProxyModel *proxyModel; | ||
| 260 | 165 | | |||
| 261 | KFileItemList pendingMimeTypes; | 166 | KFileItemList pendingMimeTypes; | ||
| Show All 24 Lines | |||||
| 286 | 191 | | |||
| 287 | KFilePreviewGenerator *previewGenerator; | 192 | KFilePreviewGenerator *previewGenerator; | ||
| 288 | 193 | | |||
| 289 | bool showPreviews; | 194 | bool showPreviews; | ||
| 290 | int iconsZoom; | 195 | int iconsZoom; | ||
| 291 | 196 | | |||
| 292 | bool isSaving; | 197 | bool isSaving; | ||
| 293 | 198 | | |||
| 294 | KActionMenu *decorationMenu; | | |||
| 295 | KToggleAction *leftAction; | | |||
| 296 | QList<QUrl> itemsToBeSetAsCurrent; | 199 | QList<QUrl> itemsToBeSetAsCurrent; | ||
| 297 | bool shouldFetchForItems; | 200 | bool shouldFetchForItems; | ||
| 298 | InlinePreviewState inlinePreviewState; | 201 | InlinePreviewState inlinePreviewState; | ||
| 299 | QStringList supportedSchemes; | 202 | QStringList supportedSchemes; | ||
| 300 | }; | 203 | }; | ||
| 301 | 204 | | |||
| 302 | KDirOperator::Private::Private(KDirOperator *_parent) : | 205 | KDirOperator::Private::Private(KDirOperator *_parent) : | ||
| 303 | parent(_parent), | 206 | parent(_parent), | ||
| 304 | dirLister(nullptr), | 207 | dirLister(nullptr), | ||
| 305 | decorationPosition(QStyleOptionViewItem::Left), | | |||
| 306 | splitter(nullptr), | 208 | splitter(nullptr), | ||
| 307 | itemView(nullptr), | 209 | itemView(nullptr), | ||
| 308 | dirModel(nullptr), | 210 | dirModel(nullptr), | ||
| 309 | proxyModel(nullptr), | 211 | proxyModel(nullptr), | ||
| 310 | progressBar(nullptr), | 212 | progressBar(nullptr), | ||
| 311 | preview(nullptr), | 213 | preview(nullptr), | ||
| 312 | previewUrl(), | 214 | previewUrl(), | ||
| 313 | previewWidth(0), | 215 | previewWidth(0), | ||
| 314 | dirHighlighting(false), | 216 | dirHighlighting(false), | ||
| 315 | onlyDoubleClickSelectsFiles(!qApp->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick)), | 217 | onlyDoubleClickSelectsFiles(!qApp->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick)), | ||
| 316 | progressDelayTimer(nullptr), | 218 | progressDelayTimer(nullptr), | ||
| 317 | dropOptions(0), | 219 | dropOptions(0), | ||
| 318 | actionMenu(nullptr), | 220 | actionMenu(nullptr), | ||
| 319 | actionCollection(nullptr), | 221 | actionCollection(nullptr), | ||
| 320 | newFileMenu(nullptr), | 222 | newFileMenu(nullptr), | ||
| 321 | configGroup(nullptr), | 223 | configGroup(nullptr), | ||
| 322 | previewGenerator(nullptr), | 224 | previewGenerator(nullptr), | ||
| 323 | showPreviews(false), | 225 | showPreviews(false), | ||
| 324 | iconsZoom(0), | 226 | iconsZoom(0), | ||
| 325 | isSaving(false), | 227 | isSaving(false), | ||
| 326 | decorationMenu(nullptr), | | |||
| 327 | leftAction(nullptr), | | |||
| 328 | shouldFetchForItems(false), | 228 | shouldFetchForItems(false), | ||
| 329 | inlinePreviewState(NotForced) | 229 | inlinePreviewState(NotForced) | ||
| 330 | { | 230 | { | ||
| 331 | } | 231 | } | ||
| 332 | 232 | | |||
| 333 | KDirOperator::Private::~Private() | 233 | KDirOperator::Private::~Private() | ||
| 334 | { | 234 | { | ||
| 335 | delete itemView; | 235 | delete itemView; | ||
| Show All 28 Lines | 263 | { | |||
| 364 | d->splitter = new QSplitter(this); | 264 | d->splitter = new QSplitter(this); | ||
| 365 | d->splitter->setChildrenCollapsible(false); | 265 | d->splitter->setChildrenCollapsible(false); | ||
| 366 | connect(d->splitter, SIGNAL(splitterMoved(int,int)), | 266 | connect(d->splitter, SIGNAL(splitterMoved(int,int)), | ||
| 367 | this, SLOT(_k_slotSplitterMoved(int,int))); | 267 | this, SLOT(_k_slotSplitterMoved(int,int))); | ||
| 368 | 268 | | |||
| 369 | d->preview = nullptr; | 269 | d->preview = nullptr; | ||
| 370 | 270 | | |||
| 371 | d->mode = KFile::File; | 271 | d->mode = KFile::File; | ||
| 372 | d->viewKind = KFile::Simple; | 272 | d->viewKind = KFile::Icon; | ||
| 373 | 273 | | |||
| 374 | if (_url.isEmpty()) { // no dir specified -> current dir | 274 | if (_url.isEmpty()) { // no dir specified -> current dir | ||
| 375 | QString strPath = QDir::currentPath(); | 275 | QString strPath = QDir::currentPath(); | ||
| 376 | strPath.append(QLatin1Char('/')); | 276 | strPath.append(QLatin1Char('/')); | ||
| 377 | d->currUrl = QUrl::fromLocalFile(strPath); | 277 | d->currUrl = QUrl::fromLocalFile(strPath); | ||
| 378 | } else { | 278 | } else { | ||
| 379 | d->currUrl = _url; | 279 | d->currUrl = _url; | ||
| 380 | if (d->currUrl.scheme().isEmpty()) { | 280 | if (d->currUrl.scheme().isEmpty()) { | ||
| ▲ Show 20 Lines • Show All 207 Lines • ▼ Show 20 Line(s) | |||||
| 588 | 488 | | |||
| 589 | KActionCollection *KDirOperator::actionCollection() const | 489 | KActionCollection *KDirOperator::actionCollection() const | ||
| 590 | { | 490 | { | ||
| 591 | return d->actionCollection; | 491 | return d->actionCollection; | ||
| 592 | } | 492 | } | ||
| 593 | 493 | | |||
| 594 | KFile::FileView KDirOperator::Private::allViews() | 494 | KFile::FileView KDirOperator::Private::allViews() | ||
| 595 | { | 495 | { | ||
| 596 | return static_cast<KFile::FileView>(KFile::Simple | KFile::Detail | KFile::Tree | KFile::DetailTree); | 496 | return static_cast<KFile::FileView>(KFile::Icon | KFile::Detail | KFile::Compact | KFile::DetailTree); | ||
| 597 | } | 497 | } | ||
| 598 | 498 | | |||
| 599 | void KDirOperator::Private::_k_slotDetailedView() | 499 | void KDirOperator::Private::_k_slotDetailedView() | ||
| 600 | { | 500 | { | ||
| 601 | KFile::FileView view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::Detail); | 501 | KFile::FileView view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::Detail); | ||
| 602 | parent->setView(view); | 502 | parent->setView(view); | ||
| 603 | } | 503 | } | ||
| 604 | 504 | | |||
| 605 | void KDirOperator::Private::_k_slotSimpleView() | 505 | void KDirOperator::Private::_k_slotIconView() | ||
| 606 | { | 506 | { | ||
| 607 | KFile::FileView view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::Simple); | 507 | KFile::FileView view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::Icon); | ||
| 608 | parent->setView(view); | 508 | parent->setView(view); | ||
| 609 | } | 509 | } | ||
| 610 | 510 | | |||
| 611 | void KDirOperator::Private::_k_slotTreeView() | 511 | void KDirOperator::Private::_k_slotCompactView() | ||
| 612 | { | 512 | { | ||
| 613 | KFile::FileView view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::Tree); | 513 | KFile::FileView view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::Compact); | ||
| 614 | parent->setView(view); | 514 | parent->setView(view); | ||
| 615 | } | 515 | } | ||
| 616 | 516 | | |||
| 617 | void KDirOperator::Private::_k_slotDetailedTreeView() | 517 | void KDirOperator::Private::_k_slotDetailedTreeView() | ||
| 618 | { | 518 | { | ||
| 619 | KFile::FileView view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::DetailTree); | 519 | KFile::FileView view = static_cast<KFile::FileView>((viewKind & ~allViews()) | KFile::DetailTree); | ||
| 620 | parent->setView(view); | 520 | parent->setView(view); | ||
| 621 | } | 521 | } | ||
| ▲ Show 20 Lines • Show All 293 Lines • ▼ Show 20 Line(s) | 805 | { | |||
| 915 | 815 | | |||
| 916 | if (!d->previewGenerator) { | 816 | if (!d->previewGenerator) { | ||
| 917 | return; | 817 | return; | ||
| 918 | } | 818 | } | ||
| 919 | 819 | | |||
| 920 | const int maxSize = KIconLoader::SizeEnormous - KIconLoader::SizeSmall; | 820 | const int maxSize = KIconLoader::SizeEnormous - KIconLoader::SizeSmall; | ||
| 921 | const int val = (maxSize * value / 100) + KIconLoader::SizeSmall; | 821 | const int val = (maxSize * value / 100) + KIconLoader::SizeSmall; | ||
| 922 | d->itemView->setIconSize(QSize(val, val)); | 822 | d->itemView->setIconSize(QSize(val, val)); | ||
| 923 | d->updateListViewGrid(); | | |||
| 924 | d->previewGenerator->updatePreviews(); | 823 | d->previewGenerator->updatePreviews(); | ||
| 925 | 824 | | |||
| 926 | emit currentIconSizeChanged(value); | 825 | emit currentIconSizeChanged(value); | ||
| 927 | } | 826 | } | ||
| 928 | 827 | | |||
| 929 | void KDirOperator::close() | 828 | void KDirOperator::close() | ||
| 930 | { | 829 | { | ||
| 931 | resetCursor(); | 830 | resetCursor(); | ||
| ▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Line(s) | 896 | { | |||
| 1057 | 956 | | |||
| 1058 | QAction *backAction = d->actionCollection->action(QStringLiteral("back")); | 957 | QAction *backAction = d->actionCollection->action(QStringLiteral("back")); | ||
| 1059 | backAction->setEnabled(!d->backStack.isEmpty()); | 958 | backAction->setEnabled(!d->backStack.isEmpty()); | ||
| 1060 | 959 | | |||
| 1061 | QAction *upAction = d->actionCollection->action(QStringLiteral("up")); | 960 | QAction *upAction = d->actionCollection->action(QStringLiteral("up")); | ||
| 1062 | upAction->setEnabled(!isRoot()); | 961 | upAction->setEnabled(!isRoot()); | ||
| 1063 | 962 | | |||
| 1064 | d->openUrl(newurl); | 963 | d->openUrl(newurl); | ||
| 964 | d->itemView->update(); | ||||
| 1065 | } | 965 | } | ||
| 1066 | 966 | | |||
| 1067 | void KDirOperator::updateDir() | 967 | void KDirOperator::updateDir() | ||
| 1068 | { | 968 | { | ||
| 1069 | QApplication::setOverrideCursor(Qt::WaitCursor); | 969 | QApplication::setOverrideCursor(Qt::WaitCursor); | ||
| 1070 | d->dirLister->emitChanges(); | 970 | d->dirLister->emitChanges(); | ||
| 1071 | QApplication::restoreOverrideCursor(); | 971 | QApplication::restoreOverrideCursor(); | ||
| 1072 | } | 972 | } | ||
| ▲ Show 20 Lines • Show All 447 Lines • ▼ Show 20 Line(s) | 1365 | { | |||
| 1520 | } | 1420 | } | ||
| 1521 | 1421 | | |||
| 1522 | return false; | 1422 | return false; | ||
| 1523 | } | 1423 | } | ||
| 1524 | 1424 | | |||
| 1525 | QAbstractItemView *KDirOperator::createView(QWidget *parent, KFile::FileView viewKind) | 1425 | QAbstractItemView *KDirOperator::createView(QWidget *parent, KFile::FileView viewKind) | ||
| 1526 | { | 1426 | { | ||
| 1527 | QAbstractItemView *itemView = nullptr; | 1427 | QAbstractItemView *itemView = nullptr; | ||
| 1528 | if (KFile::isDetailView(viewKind) || KFile::isTreeView(viewKind) || KFile::isDetailTreeView(viewKind)) { | 1428 | if (KFile::isDetailView(viewKind) || KFile::isDetailTreeView(viewKind)) { | ||
| 1529 | KDirOperatorDetailView *detailView = new KDirOperatorDetailView(parent); | 1429 | KDirOperatorDetailView *detailView = new KDirOperatorDetailView(parent); | ||
| 1530 | detailView->setViewMode(viewKind); | 1430 | detailView->setViewMode(viewKind); | ||
| 1531 | itemView = detailView; | 1431 | itemView = detailView; | ||
| 1432 | } else if (KFile::isCompactView(viewKind)) { | ||||
| 1433 | itemView = new KDirOperatorIconView(parent, KDirOperatorIconView::Kind::Compact); | ||||
| 1532 | } else { | 1434 | } else { | ||
| 1533 | itemView = new KDirOperatorIconView(this, parent); | 1435 | itemView = new KDirOperatorIconView(parent); | ||
| 1534 | } | 1436 | } | ||
| 1535 | 1437 | | |||
| 1536 | return itemView; | 1438 | return itemView; | ||
| 1537 | } | 1439 | } | ||
| 1538 | 1440 | | |||
| 1539 | void KDirOperator::setAcceptDrops(bool acceptsDrops) | 1441 | void KDirOperator::setAcceptDrops(bool acceptsDrops) | ||
| 1540 | { | 1442 | { | ||
| 1541 | QWidget::setAcceptDrops(acceptsDrops); | 1443 | QWidget::setAcceptDrops(acceptsDrops); | ||
| Show All 17 Lines | |||||
| 1559 | 1461 | | |||
| 1560 | void KDirOperator::setView(KFile::FileView viewKind) | 1462 | void KDirOperator::setView(KFile::FileView viewKind) | ||
| 1561 | { | 1463 | { | ||
| 1562 | bool preview = (KFile::isPreviewInfo(viewKind) || KFile::isPreviewContents(viewKind)); | 1464 | bool preview = (KFile::isPreviewInfo(viewKind) || KFile::isPreviewContents(viewKind)); | ||
| 1563 | 1465 | | |||
| 1564 | if (viewKind == KFile::Default) { | 1466 | if (viewKind == KFile::Default) { | ||
| 1565 | if (KFile::isDetailView((KFile::FileView)d->defaultView)) { | 1467 | if (KFile::isDetailView((KFile::FileView)d->defaultView)) { | ||
| 1566 | viewKind = KFile::Detail; | 1468 | viewKind = KFile::Detail; | ||
| 1567 | } else if (KFile::isTreeView((KFile::FileView)d->defaultView)) { | 1469 | } else if (KFile::isCompactView((KFile::FileView)d->defaultView)) { | ||
| 1568 | viewKind = KFile::Tree; | 1470 | viewKind = KFile::Compact; | ||
| 1569 | } else if (KFile::isDetailTreeView((KFile::FileView)d->defaultView)) { | 1471 | } else if (KFile::isDetailTreeView((KFile::FileView)d->defaultView)) { | ||
| 1570 | viewKind = KFile::DetailTree; | 1472 | viewKind = KFile::DetailTree; | ||
| 1571 | } else { | 1473 | } else { | ||
| 1572 | viewKind = KFile::Simple; | 1474 | viewKind = KFile::Icon; | ||
| 1573 | } | 1475 | } | ||
| 1574 | 1476 | | |||
| 1575 | const KFile::FileView defaultViewKind = static_cast<KFile::FileView>(d->defaultView); | 1477 | const KFile::FileView defaultViewKind = static_cast<KFile::FileView>(d->defaultView); | ||
| 1576 | preview = (KFile::isPreviewInfo(defaultViewKind) || KFile::isPreviewContents(defaultViewKind)) | 1478 | preview = (KFile::isPreviewInfo(defaultViewKind) || KFile::isPreviewContents(defaultViewKind)) | ||
| 1577 | && d->actionCollection->action(QStringLiteral("preview"))->isEnabled(); | 1479 | && d->actionCollection->action(QStringLiteral("preview"))->isEnabled(); | ||
| 1578 | } | 1480 | } | ||
| 1579 | 1481 | | |||
| 1580 | d->viewKind = static_cast<int>(viewKind); | 1482 | d->viewKind = static_cast<int>(viewKind); | ||
| ▲ Show 20 Lines • Show All 115 Lines • ▼ Show 20 Line(s) | 1528 | { | |||
| 1696 | 1598 | | |||
| 1697 | connect(d->itemView->selectionModel(), | 1599 | connect(d->itemView->selectionModel(), | ||
| 1698 | SIGNAL(currentChanged(QModelIndex,QModelIndex)), | 1600 | SIGNAL(currentChanged(QModelIndex,QModelIndex)), | ||
| 1699 | this, SLOT(_k_triggerPreview(QModelIndex))); | 1601 | this, SLOT(_k_triggerPreview(QModelIndex))); | ||
| 1700 | connect(d->itemView->selectionModel(), | 1602 | connect(d->itemView->selectionModel(), | ||
| 1701 | SIGNAL(selectionChanged(QItemSelection,QItemSelection)), | 1603 | SIGNAL(selectionChanged(QItemSelection,QItemSelection)), | ||
| 1702 | this, SLOT(_k_slotSelectionChanged())); | 1604 | this, SLOT(_k_slotSelectionChanged())); | ||
| 1703 | 1605 | | |||
| 1704 | // if we cannot cast it to a QListView, disable the "Icon Position" menu. Note that this check | | |||
| 1705 | // needs to be done here, and not in createView, since we can be set an external view | | |||
| 1706 | d->decorationMenu->setEnabled(qobject_cast<QListView *>(d->itemView)); | | |||
| 1707 | | ||||
| 1708 | d->shouldFetchForItems = qobject_cast<QTreeView *>(view); | 1606 | d->shouldFetchForItems = qobject_cast<QTreeView *>(view); | ||
| 1709 | if (d->shouldFetchForItems) { | 1607 | if (d->shouldFetchForItems) { | ||
| 1710 | connect(d->dirModel, SIGNAL(expand(QModelIndex)), this, SLOT(_k_slotExpandToUrl(QModelIndex))); | 1608 | connect(d->dirModel, SIGNAL(expand(QModelIndex)), this, SLOT(_k_slotExpandToUrl(QModelIndex))); | ||
| 1711 | } else { | 1609 | } else { | ||
| 1712 | d->itemsToBeSetAsCurrent.clear(); | 1610 | d->itemsToBeSetAsCurrent.clear(); | ||
| 1713 | } | 1611 | } | ||
| 1714 | 1612 | | |||
| 1715 | const bool previewForcedToTrue = d->inlinePreviewState == Private::ForcedToTrue; | 1613 | const bool previewForcedToTrue = d->inlinePreviewState == Private::ForcedToTrue; | ||
| 1716 | const bool previewShown = d->inlinePreviewState == Private::NotForced ? d->showPreviews : previewForcedToTrue; | 1614 | const bool previewShown = d->inlinePreviewState == Private::NotForced ? d->showPreviews : previewForcedToTrue; | ||
| 1717 | d->previewGenerator = new KFilePreviewGenerator(d->itemView); | 1615 | d->previewGenerator = new KFilePreviewGenerator(d->itemView); | ||
| 1718 | const int maxSize = KIconLoader::SizeEnormous - KIconLoader::SizeSmall; | 1616 | const int maxSize = KIconLoader::SizeEnormous - KIconLoader::SizeSmall; | ||
| 1719 | const int val = (maxSize * d->iconsZoom / 100) + KIconLoader::SizeSmall; | 1617 | const int val = (maxSize * d->iconsZoom / 100) + KIconLoader::SizeSmall; | ||
| 1720 | d->itemView->setIconSize(previewForcedToTrue ? QSize(KIconLoader::SizeHuge, KIconLoader::SizeHuge) : QSize(val, val)); | 1618 | d->itemView->setIconSize(previewForcedToTrue ? QSize(KIconLoader::SizeHuge, KIconLoader::SizeHuge) : QSize(val, val)); | ||
| 1721 | d->previewGenerator->setPreviewShown(previewShown); | 1619 | d->previewGenerator->setPreviewShown(previewShown); | ||
| 1722 | d->actionCollection->action(QStringLiteral("inline preview"))->setChecked(previewShown); | 1620 | d->actionCollection->action(QStringLiteral("inline preview"))->setChecked(previewShown); | ||
| 1723 | 1621 | | |||
| 1724 | // ensure we change everything needed | | |||
| 1725 | d->_k_slotChangeDecorationPosition(); | | |||
| 1726 | | ||||
| 1727 | emit viewChanged(view); | 1622 | emit viewChanged(view); | ||
| 1728 | 1623 | | |||
| 1729 | const int zoom = previewForcedToTrue ? (KIconLoader::SizeHuge - KIconLoader::SizeSmall + 1) * 100 / maxSize : d->iconSizeForViewType(view); | 1624 | const int zoom = previewForcedToTrue ? (KIconLoader::SizeHuge - KIconLoader::SizeSmall + 1) * 100 / maxSize : d->iconSizeForViewType(view); | ||
| 1730 | 1625 | | |||
| 1731 | // this will make d->iconsZoom be updated, since setIconsZoom slot will be called | 1626 | // this will make d->iconsZoom be updated, since setIconsZoom slot will be called | ||
| 1732 | emit currentIconSizeChanged(zoom); | 1627 | emit currentIconSizeChanged(zoom); | ||
| 1733 | } | 1628 | } | ||
| 1734 | 1629 | | |||
| ▲ Show 20 Lines • Show All 260 Lines • ▼ Show 20 Line(s) | 1830 | { | |||
| 1995 | KToggleAction *descendingAction = new KToggleAction(i18n("Descending"), this); | 1890 | KToggleAction *descendingAction = new KToggleAction(i18n("Descending"), this); | ||
| 1996 | d->actionCollection->addAction(QStringLiteral("descending"), descendingAction); | 1891 | d->actionCollection->addAction(QStringLiteral("descending"), descendingAction); | ||
| 1997 | connect(descendingAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotSortReversed(bool))); | 1892 | connect(descendingAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotSortReversed(bool))); | ||
| 1998 | 1893 | | |||
| 1999 | KToggleAction *dirsFirstAction = new KToggleAction(i18n("Folders First"), this); | 1894 | KToggleAction *dirsFirstAction = new KToggleAction(i18n("Folders First"), this); | ||
| 2000 | d->actionCollection->addAction(QStringLiteral("dirs first"), dirsFirstAction); | 1895 | d->actionCollection->addAction(QStringLiteral("dirs first"), dirsFirstAction); | ||
| 2001 | connect(dirsFirstAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotToggleDirsFirst())); | 1896 | connect(dirsFirstAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotToggleDirsFirst())); | ||
| 2002 | 1897 | | |||
| 2003 | d->decorationMenu = new KActionMenu(i18n("Icon Position"), this); | 1898 | KToggleAction *iconAction = new KToggleAction(i18n("Icons View"), this); | ||
| 2004 | d->actionCollection->addAction(QStringLiteral("decoration menu"), d->decorationMenu); | 1899 | d->actionCollection->addAction(QStringLiteral("icon view"), iconAction); | ||
| 2005 | 1900 | iconAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-icons"))); | |||
| 2006 | d->leftAction = new KToggleAction(i18n("Next to File Name"), this); | 1901 | connect(iconAction, SIGNAL(triggered()), SLOT(_k_slotIconView())); | ||
| 2007 | d->actionCollection->addAction(QStringLiteral("decorationAtLeft"), d->leftAction); | 1902 | | ||
| 2008 | connect(d->leftAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotChangeDecorationPosition())); | 1903 | KToggleAction *compactAction = new KToggleAction(i18n("Compact View"), this); | ||
| 2009 | 1904 | d->actionCollection->addAction(QStringLiteral("compact view"), compactAction); | |||
| 2010 | KToggleAction *topAction = new KToggleAction(i18n("Above File Name"), this); | 1905 | compactAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-details"))); | ||
| 2011 | d->actionCollection->addAction(QStringLiteral("decorationAtTop"), topAction); | 1906 | connect(compactAction, SIGNAL(triggered()), SLOT(_k_slotCompactView())); | ||
| 2012 | connect(topAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotChangeDecorationPosition())); | | |||
| 2013 | | ||||
| 2014 | d->decorationMenu->addAction(d->leftAction); | | |||
| 2015 | d->decorationMenu->addAction(topAction); | | |||
| 2016 | | ||||
| 2017 | QActionGroup *decorationGroup = new QActionGroup(this); | | |||
| 2018 | d->leftAction->setActionGroup(decorationGroup); | | |||
| 2019 | topAction->setActionGroup(decorationGroup); | | |||
| 2020 | | ||||
| 2021 | KToggleAction *shortAction = new KToggleAction(i18n("Short View"), this); | | |||
| 2022 | d->actionCollection->addAction(QStringLiteral("short view"), shortAction); | | |||
| 2023 | shortAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-icons"))); | | |||
| 2024 | connect(shortAction, SIGNAL(triggered()), SLOT(_k_slotSimpleView())); | | |||
| 2025 | 1907 | | |||
| 2026 | KToggleAction *detailedAction = new KToggleAction(i18n("Detailed View"), this); | 1908 | KToggleAction *detailedAction = new KToggleAction(i18n("Detailed View"), this); | ||
| 2027 | d->actionCollection->addAction(QStringLiteral("detailed view"), detailedAction); | 1909 | d->actionCollection->addAction(QStringLiteral("detailed view"), detailedAction); | ||
| 2028 | detailedAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-details"))); | 1910 | detailedAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-details"))); | ||
| 2029 | connect(detailedAction, SIGNAL(triggered()), SLOT(_k_slotDetailedView())); | 1911 | connect(detailedAction, SIGNAL(triggered()), SLOT(_k_slotDetailedView())); | ||
| 2030 | 1912 | | |||
| 2031 | KToggleAction *treeAction = new KToggleAction(i18n("Tree View"), this); | | |||
| 2032 | d->actionCollection->addAction(QStringLiteral("tree view"), treeAction); | | |||
| 2033 | treeAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-tree"))); | | |||
| 2034 | connect(treeAction, SIGNAL(triggered()), SLOT(_k_slotTreeView())); | | |||
| 2035 | | ||||
| 2036 | KToggleAction *detailedTreeAction = new KToggleAction(i18n("Detailed Tree View"), this); | 1913 | KToggleAction *detailedTreeAction = new KToggleAction(i18n("Detailed Tree View"), this); | ||
| 2037 | d->actionCollection->addAction(QStringLiteral("detailed tree view"), detailedTreeAction); | 1914 | d->actionCollection->addAction(QStringLiteral("detailed tree view"), detailedTreeAction); | ||
| 2038 | detailedTreeAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-tree"))); | 1915 | detailedTreeAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-tree"))); | ||
| 2039 | connect(detailedTreeAction, SIGNAL(triggered()), SLOT(_k_slotDetailedTreeView())); | 1916 | connect(detailedTreeAction, SIGNAL(triggered()), SLOT(_k_slotDetailedTreeView())); | ||
| 2040 | 1917 | | |||
| 2041 | QActionGroup *viewGroup = new QActionGroup(this); | 1918 | QActionGroup *viewGroup = new QActionGroup(this); | ||
| 2042 | shortAction->setActionGroup(viewGroup); | 1919 | iconAction->setActionGroup(viewGroup); | ||
| 1920 | compactAction->setActionGroup(viewGroup); | ||||
| 2043 | detailedAction->setActionGroup(viewGroup); | 1921 | detailedAction->setActionGroup(viewGroup); | ||
| 2044 | treeAction->setActionGroup(viewGroup); | | |||
| 2045 | detailedTreeAction->setActionGroup(viewGroup); | 1922 | detailedTreeAction->setActionGroup(viewGroup); | ||
| 2046 | 1923 | | |||
| 2047 | KToggleAction *showHiddenAction = new KToggleAction(i18n("Show Hidden Files"), this); | 1924 | KToggleAction *showHiddenAction = new KToggleAction(i18n("Show Hidden Files"), this); | ||
| 2048 | d->actionCollection->addAction(QStringLiteral("show hidden"), showHiddenAction); | 1925 | d->actionCollection->addAction(QStringLiteral("show hidden"), showHiddenAction); | ||
| 2049 | showHiddenAction->setShortcuts({Qt::ALT + Qt::Key_Period, Qt::CTRL + Qt::Key_H, Qt::Key_F8}); | 1926 | 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))); | 1927 | connect(showHiddenAction, SIGNAL(toggled(bool)), SLOT(_k_slotToggleHidden(bool))); | ||
| 2051 | 1928 | | |||
| 2052 | KToggleAction *previewAction = new KToggleAction(i18n("Show Preview Panel"), this); | 1929 | KToggleAction *previewAction = new KToggleAction(i18n("Show Preview Panel"), this); | ||
| Show All 17 Lines | |||||
| 2070 | d->actionCollection->addAction(QStringLiteral("properties"), action); | 1947 | d->actionCollection->addAction(QStringLiteral("properties"), action); | ||
| 2071 | action->setIcon(QIcon::fromTheme(QStringLiteral("document-properties"))); | 1948 | action->setIcon(QIcon::fromTheme(QStringLiteral("document-properties"))); | ||
| 2072 | action->setShortcut(Qt::ALT + Qt::Key_Return); | 1949 | action->setShortcut(Qt::ALT + Qt::Key_Return); | ||
| 2073 | connect(action, SIGNAL(triggered(bool)), this, SLOT(_k_slotProperties())); | 1950 | connect(action, SIGNAL(triggered(bool)), this, SLOT(_k_slotProperties())); | ||
| 2074 | 1951 | | |||
| 2075 | // the view menu actions | 1952 | // the view menu actions | ||
| 2076 | KActionMenu *viewMenu = new KActionMenu(i18n("&View"), this); | 1953 | KActionMenu *viewMenu = new KActionMenu(i18n("&View"), this); | ||
| 2077 | d->actionCollection->addAction(QStringLiteral("view menu"), viewMenu); | 1954 | d->actionCollection->addAction(QStringLiteral("view menu"), viewMenu); | ||
| 2078 | viewMenu->addAction(shortAction); | 1955 | viewMenu->addAction(iconAction); | ||
| 1956 | viewMenu->addAction(compactAction); | ||||
| 2079 | viewMenu->addAction(detailedAction); | 1957 | viewMenu->addAction(detailedAction); | ||
| 2080 | // Comment following lines to hide the extra two modes | | |||
| 2081 | viewMenu->addAction(treeAction); | | |||
| 2082 | viewMenu->addAction(detailedTreeAction); | 1958 | viewMenu->addAction(detailedTreeAction); | ||
| 2083 | // TODO: QAbstractItemView does not offer an action collection. Provide | 1959 | // TODO: QAbstractItemView does not offer an action collection. Provide | ||
| 2084 | // an interface to add a custom action collection. | 1960 | // an interface to add a custom action collection. | ||
| 2085 | 1961 | | |||
| 2086 | d->newFileMenu = new KNewFileMenu(d->actionCollection, QStringLiteral("new"), this); | 1962 | d->newFileMenu = new KNewFileMenu(d->actionCollection, QStringLiteral("new"), this); | ||
| 2087 | connect(d->newFileMenu, SIGNAL(directoryCreated(QUrl)), this, SLOT(_k_slotDirectoryCreated(QUrl))); | 1963 | connect(d->newFileMenu, SIGNAL(directoryCreated(QUrl)), this, SLOT(_k_slotDirectoryCreated(QUrl))); | ||
| 2088 | 1964 | | |||
| 2089 | d->actionCollection->addAssociatedWidget(this); | 1965 | d->actionCollection->addAssociatedWidget(this); | ||
| ▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Line(s) | |||||
| 2172 | void KDirOperator::updateViewActions() | 2048 | void KDirOperator::updateViewActions() | ||
| 2173 | { | 2049 | { | ||
| 2174 | KFile::FileView fv = static_cast<KFile::FileView>(d->viewKind); | 2050 | KFile::FileView fv = static_cast<KFile::FileView>(d->viewKind); | ||
| 2175 | 2051 | | |||
| 2176 | //QAction *separateDirs = d->actionCollection->action("separate dirs"); | 2052 | //QAction *separateDirs = d->actionCollection->action("separate dirs"); | ||
| 2177 | //separateDirs->setChecked(KFile::isSeparateDirs(fv) && | 2053 | //separateDirs->setChecked(KFile::isSeparateDirs(fv) && | ||
| 2178 | // separateDirs->isEnabled()); | 2054 | // separateDirs->isEnabled()); | ||
| 2179 | 2055 | | |||
| 2180 | d->actionCollection->action(QStringLiteral("short view"))->setChecked(KFile::isSimpleView(fv)); | 2056 | d->actionCollection->action(QStringLiteral("icon view"))->setChecked(KFile::isIconView(fv)); | ||
| 2057 | d->actionCollection->action(QStringLiteral("compact view"))->setChecked(KFile::isCompactView(fv)); | ||||
| 2181 | d->actionCollection->action(QStringLiteral("detailed view"))->setChecked(KFile::isDetailView(fv)); | 2058 | d->actionCollection->action(QStringLiteral("detailed view"))->setChecked(KFile::isDetailView(fv)); | ||
| 2182 | d->actionCollection->action(QStringLiteral("tree view"))->setChecked(KFile::isTreeView(fv)); | | |||
| 2183 | d->actionCollection->action(QStringLiteral("detailed tree view"))->setChecked(KFile::isDetailTreeView(fv)); | 2059 | d->actionCollection->action(QStringLiteral("detailed tree view"))->setChecked(KFile::isDetailTreeView(fv)); | ||
| 2184 | } | 2060 | } | ||
| 2185 | 2061 | | |||
| 2186 | void KDirOperator::readConfig(const KConfigGroup &configGroup) | 2062 | void KDirOperator::readConfig(const KConfigGroup &configGroup) | ||
| 2187 | { | 2063 | { | ||
| 2188 | d->defaultView = 0; | 2064 | d->defaultView = 0; | ||
| 2189 | QString viewStyle = configGroup.readEntry("View Style", "DetailTree"); | 2065 | QString viewStyle = configGroup.readEntry("View Style", "DetailTree"); | ||
| 2190 | if (viewStyle == QLatin1String("Detail")) { | 2066 | if (viewStyle == QLatin1String("Detail")) { | ||
| 2191 | d->defaultView |= KFile::Detail; | 2067 | d->defaultView |= KFile::Detail; | ||
| 2192 | } else if (viewStyle == QLatin1String("Tree")) { | 2068 | } else if (viewStyle == QLatin1String("Compact")) { | ||
| 2193 | d->defaultView |= KFile::Tree; | 2069 | d->defaultView |= KFile::Compact; | ||
| 2194 | } else if (viewStyle == QLatin1String("DetailTree")) { | 2070 | } else if (viewStyle == QLatin1String("DetailTree")) { | ||
| 2195 | d->defaultView |= KFile::DetailTree; | 2071 | d->defaultView |= KFile::DetailTree; | ||
| 2196 | } else { | 2072 | } else { | ||
| 2197 | d->defaultView |= KFile::Simple; | 2073 | d->defaultView |= KFile::Icon; | ||
| 2198 | } | 2074 | } | ||
| 2199 | //if (configGroup.readEntry(QLatin1String("Separate Directories"), | 2075 | //if (configGroup.readEntry(QLatin1String("Separate Directories"), | ||
| 2200 | // DefaultMixDirsAndFiles)) { | 2076 | // DefaultMixDirsAndFiles)) { | ||
| 2201 | // d->defaultView |= KFile::SeparateDirs; | 2077 | // d->defaultView |= KFile::SeparateDirs; | ||
| 2202 | //} | 2078 | //} | ||
| 2203 | if (configGroup.readEntry(QStringLiteral("Show Preview"), false)) { | 2079 | if (configGroup.readEntry(QStringLiteral("Show Preview"), false)) { | ||
| 2204 | d->defaultView |= KFile::PreviewContents; | 2080 | d->defaultView |= KFile::PreviewContents; | ||
| 2205 | } | 2081 | } | ||
| Show All 25 Lines | |||||
| 2231 | if (configGroup.readEntry(QStringLiteral("Sort reversed"), DefaultSortReversed)) { | 2107 | if (configGroup.readEntry(QStringLiteral("Sort reversed"), DefaultSortReversed)) { | ||
| 2232 | sorting |= QDir::Reversed; | 2108 | sorting |= QDir::Reversed; | ||
| 2233 | } | 2109 | } | ||
| 2234 | d->updateSorting(sorting); | 2110 | d->updateSorting(sorting); | ||
| 2235 | 2111 | | |||
| 2236 | if (d->inlinePreviewState == Private::NotForced) { | 2112 | if (d->inlinePreviewState == Private::NotForced) { | ||
| 2237 | d->showPreviews = configGroup.readEntry(QStringLiteral("Show Inline Previews"), true); | 2113 | d->showPreviews = configGroup.readEntry(QStringLiteral("Show Inline Previews"), true); | ||
| 2238 | } | 2114 | } | ||
| 2239 | QStyleOptionViewItem::Position pos = (QStyleOptionViewItem::Position) configGroup.readEntry(QStringLiteral("Decoration position"), (int) QStyleOptionViewItem::Left); | | |||
| 2240 | setDecorationPosition(pos); | | |||
| 2241 | } | 2115 | } | ||
| 2242 | 2116 | | |||
| 2243 | void KDirOperator::writeConfig(KConfigGroup &configGroup) | 2117 | void KDirOperator::writeConfig(KConfigGroup &configGroup) | ||
| 2244 | { | 2118 | { | ||
| 2245 | QString sortBy = QStringLiteral("Name"); | 2119 | QString sortBy = QStringLiteral("Name"); | ||
| 2246 | if (KFile::isSortBySize(d->sorting)) { | 2120 | if (KFile::isSortBySize(d->sorting)) { | ||
| 2247 | sortBy = QStringLiteral("Size"); | 2121 | sortBy = QStringLiteral("Size"); | ||
| 2248 | } else if (KFile::isSortByDate(d->sorting)) { | 2122 | } else if (KFile::isSortByDate(d->sorting)) { | ||
| Show All 34 Lines | |||||
| 2283 | 2157 | | |||
| 2284 | configGroup.writeEntry(QStringLiteral("Show hidden files"), | 2158 | configGroup.writeEntry(QStringLiteral("Show hidden files"), | ||
| 2285 | d->actionCollection->action(QStringLiteral("show hidden"))->isChecked()); | 2159 | d->actionCollection->action(QStringLiteral("show hidden"))->isChecked()); | ||
| 2286 | 2160 | | |||
| 2287 | KFile::FileView fv = static_cast<KFile::FileView>(d->viewKind); | 2161 | KFile::FileView fv = static_cast<KFile::FileView>(d->viewKind); | ||
| 2288 | QString style; | 2162 | QString style; | ||
| 2289 | if (KFile::isDetailView(fv)) { | 2163 | if (KFile::isDetailView(fv)) { | ||
| 2290 | style = QStringLiteral("Detail"); | 2164 | style = QStringLiteral("Detail"); | ||
| 2291 | } else if (KFile::isSimpleView(fv)) { | 2165 | } else if (KFile::isIconView(fv)) { | ||
| 2292 | style = QStringLiteral("Simple"); | 2166 | style = QStringLiteral("Icon"); | ||
| 2293 | } else if (KFile::isTreeView(fv)) { | 2167 | } else if (KFile::isCompactView(fv)) { | ||
| 2294 | style = QStringLiteral("Tree"); | 2168 | style = QStringLiteral("Compact"); | ||
| 2295 | } else if (KFile::isDetailTreeView(fv)) { | 2169 | } else if (KFile::isDetailTreeView(fv)) { | ||
| 2296 | style = QStringLiteral("DetailTree"); | 2170 | style = QStringLiteral("DetailTree"); | ||
| 2297 | } | 2171 | } | ||
| 2298 | configGroup.writeEntry(QStringLiteral("View Style"), style); | 2172 | configGroup.writeEntry(QStringLiteral("View Style"), style); | ||
| 2299 | 2173 | | |||
| 2300 | if (d->inlinePreviewState == Private::NotForced) { | 2174 | if (d->inlinePreviewState == Private::NotForced) { | ||
| 2301 | configGroup.writeEntry(QStringLiteral("Show Inline Previews"), d->showPreviews); | 2175 | configGroup.writeEntry(QStringLiteral("Show Inline Previews"), d->showPreviews); | ||
| 2302 | if (qobject_cast<QListView *>(d->itemView)) { | 2176 | if (qobject_cast<QListView *>(d->itemView)) { | ||
| 2303 | configGroup.writeEntry(QStringLiteral("listViewIconSize"), d->iconsZoom); | 2177 | configGroup.writeEntry(QStringLiteral("listViewIconSize"), d->iconsZoom); | ||
| 2304 | } else { | 2178 | } else { | ||
| 2305 | configGroup.writeEntry(QStringLiteral("detailedViewIconSize"), d->iconsZoom); | 2179 | configGroup.writeEntry(QStringLiteral("detailedViewIconSize"), d->iconsZoom); | ||
| 2306 | } | 2180 | } | ||
| 2307 | } | 2181 | } | ||
| 2308 | | ||||
| 2309 | configGroup.writeEntry(QStringLiteral("Decoration position"), (int) d->decorationPosition); | | |||
| 2310 | } | 2182 | } | ||
| 2311 | 2183 | | |||
| 2312 | void KDirOperator::resizeEvent(QResizeEvent *) | 2184 | void KDirOperator::resizeEvent(QResizeEvent *) | ||
| 2313 | { | 2185 | { | ||
| 2314 | // resize the splitter and assure that the width of | 2186 | // resize the splitter and assure that the width of | ||
| 2315 | // the preview widget is restored | 2187 | // the preview widget is restored | ||
| 2316 | QList<int> sizes = d->splitter->sizes(); | 2188 | QList<int> sizes = d->splitter->sizes(); | ||
| 2317 | const bool hasPreview = (sizes.count() == 2); | 2189 | const bool hasPreview = (sizes.count() == 2); | ||
| Show All 11 Lines | |||||
| 2329 | if (hasPreview) { | 2201 | if (hasPreview) { | ||
| 2330 | d->previewWidth = sizes[1]; | 2202 | d->previewWidth = sizes[1]; | ||
| 2331 | } | 2203 | } | ||
| 2332 | 2204 | | |||
| 2333 | if (d->progressBar->parent() == this) { | 2205 | if (d->progressBar->parent() == this) { | ||
| 2334 | // might be reparented into a statusbar | 2206 | // might be reparented into a statusbar | ||
| 2335 | d->progressBar->move(2, height() - d->progressBar->height() - 2); | 2207 | d->progressBar->move(2, height() - d->progressBar->height() - 2); | ||
| 2336 | } | 2208 | } | ||
| 2337 | | ||||
| 2338 | d->updateListViewGrid(); | | |||
| 2339 | } | 2209 | } | ||
| 2340 | 2210 | | |||
| 2341 | void KDirOperator::setOnlyDoubleClickSelectsFiles(bool enable) | 2211 | void KDirOperator::setOnlyDoubleClickSelectsFiles(bool enable) | ||
| 2342 | { | 2212 | { | ||
| 2343 | d->onlyDoubleClickSelectsFiles = enable; | 2213 | d->onlyDoubleClickSelectsFiles = enable; | ||
| 2344 | // TODO: port to QAbstractItemModel | 2214 | // TODO: port to QAbstractItemModel | ||
| 2345 | //if (d->itemView != 0) { | 2215 | //if (d->itemView != 0) { | ||
| 2346 | // d->itemView->setOnlyDoubleClickSelectsFiles(enable); | 2216 | // d->itemView->setOnlyDoubleClickSelectsFiles(enable); | ||
| ▲ Show 20 Lines • Show All 222 Lines • ▼ Show 20 Line(s) | 2438 | if (order == Qt::DescendingOrder) { | |||
| 2569 | newSort |= QDir::Reversed; | 2439 | newSort |= QDir::Reversed; | ||
| 2570 | } | 2440 | } | ||
| 2571 | 2441 | | |||
| 2572 | updateSorting(newSort); | 2442 | updateSorting(newSort); | ||
| 2573 | 2443 | | |||
| 2574 | QMetaObject::invokeMethod(parent, "_k_assureVisibleSelection", Qt::QueuedConnection); | 2444 | QMetaObject::invokeMethod(parent, "_k_assureVisibleSelection", Qt::QueuedConnection); | ||
| 2575 | } | 2445 | } | ||
| 2576 | 2446 | | |||
| 2577 | void KDirOperator::Private::_k_slotChangeDecorationPosition() | | |||
| 2578 | { | | |||
| 2579 | if (!itemView) { | | |||
| 2580 | return; | | |||
| 2581 | } | | |||
| 2582 | | ||||
| 2583 | QListView *view = qobject_cast<QListView *>(itemView); | | |||
| 2584 | | ||||
| 2585 | if (!view) { | | |||
| 2586 | return; | | |||
| 2587 | } | | |||
| 2588 | | ||||
| 2589 | const bool leftChecked = actionCollection->action(QStringLiteral("decorationAtLeft"))->isChecked(); | | |||
| 2590 | | ||||
| 2591 | if (leftChecked) { | | |||
| 2592 | decorationPosition = QStyleOptionViewItem::Left; | | |||
| 2593 | view->setFlow(QListView::TopToBottom); | | |||
| 2594 | } else { | | |||
| 2595 | decorationPosition = QStyleOptionViewItem::Top; | | |||
| 2596 | view->setFlow(QListView::LeftToRight); | | |||
| 2597 | } | | |||
| 2598 | | ||||
| 2599 | updateListViewGrid(); | | |||
| 2600 | | ||||
| 2601 | itemView->update(); | | |||
| 2602 | } | | |||
| 2603 | | ||||
| 2604 | void KDirOperator::Private::_k_slotExpandToUrl(const QModelIndex &index) | 2447 | void KDirOperator::Private::_k_slotExpandToUrl(const QModelIndex &index) | ||
| 2605 | { | 2448 | { | ||
| 2606 | QTreeView *treeView = qobject_cast<QTreeView *>(itemView); | 2449 | QTreeView *treeView = qobject_cast<QTreeView *>(itemView); | ||
| 2607 | 2450 | | |||
| 2608 | if (!treeView) { | 2451 | if (!treeView) { | ||
| 2609 | return; | 2452 | return; | ||
| 2610 | } | 2453 | } | ||
| 2611 | 2454 | | |||
| Show All 31 Lines | |||||
| 2643 | } | 2486 | } | ||
| 2644 | } | 2487 | } | ||
| 2645 | 2488 | | |||
| 2646 | void KDirOperator::Private::_k_slotItemsChanged() | 2489 | void KDirOperator::Private::_k_slotItemsChanged() | ||
| 2647 | { | 2490 | { | ||
| 2648 | completeListDirty = true; | 2491 | completeListDirty = true; | ||
| 2649 | } | 2492 | } | ||
| 2650 | 2493 | | |||
| 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 | 2494 | int KDirOperator::Private::iconSizeForViewType(QAbstractItemView *itemView) const | ||
| 2698 | { | 2495 | { | ||
| 2699 | if (!itemView || !configGroup) { | 2496 | if (!itemView || !configGroup) { | ||
| 2700 | return 0; | 2497 | return 0; | ||
| 2701 | } | 2498 | } | ||
| 2702 | 2499 | | |||
| 2703 | if (qobject_cast<QListView *>(itemView)) { | 2500 | if (qobject_cast<QListView *>(itemView)) { | ||
| 2704 | return configGroup->readEntry("listViewIconSize", 0); | 2501 | return configGroup->readEntry("listViewIconSize", 0); | ||
| Show All 18 Lines | 2519 | { | |||
| 2723 | d->actionCollection->action(QStringLiteral("show hidden"))->setChecked(s); | 2520 | d->actionCollection->action(QStringLiteral("show hidden"))->setChecked(s); | ||
| 2724 | } | 2521 | } | ||
| 2725 | 2522 | | |||
| 2726 | bool KDirOperator::showHiddenFiles() const | 2523 | bool KDirOperator::showHiddenFiles() const | ||
| 2727 | { | 2524 | { | ||
| 2728 | return d->actionCollection->action(QStringLiteral("show hidden"))->isChecked(); | 2525 | return d->actionCollection->action(QStringLiteral("show hidden"))->isChecked(); | ||
| 2729 | } | 2526 | } | ||
| 2730 | 2527 | | |||
| 2731 | QStyleOptionViewItem::Position KDirOperator::decorationPosition() const | | |||
| 2732 | { | | |||
| 2733 | return d->decorationPosition; | | |||
| 2734 | } | | |||
| 2735 | | ||||
| 2736 | void KDirOperator::setDecorationPosition(QStyleOptionViewItem::Position position) | | |||
| 2737 | { | | |||
| 2738 | d->decorationPosition = position; | | |||
| 2739 | const bool decorationAtLeft = d->decorationPosition == QStyleOptionViewItem::Left; | | |||
| 2740 | d->actionCollection->action(QStringLiteral("decorationAtLeft"))->setChecked(decorationAtLeft); | | |||
| 2741 | d->actionCollection->action(QStringLiteral("decorationAtTop"))->setChecked(!decorationAtLeft); | | |||
| 2742 | } | | |||
| 2743 | | ||||
| 2744 | bool KDirOperator::Private::isReadable(const QUrl &url) | 2528 | bool KDirOperator::Private::isReadable(const QUrl &url) | ||
| 2745 | { | 2529 | { | ||
| 2746 | if (!url.isLocalFile()) { | 2530 | if (!url.isLocalFile()) { | ||
| 2747 | return true; // what else can we say? | 2531 | return true; // what else can we say? | ||
| 2748 | } | 2532 | } | ||
| 2749 | return QDir(url.toLocalFile()).isReadable(); | 2533 | return QDir(url.toLocalFile()).isReadable(); | ||
| 2750 | } | 2534 | } | ||
| 2751 | 2535 | | |||
| Show All 18 Lines | |||||