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