Changeset View
Changeset View
Standalone View
Standalone View
src/filewidgets/kdiroperator.cpp
Show All 22 Lines | |||||
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 "kdirsortfilterproxymodel.h" | 26 | #include "kdirsortfilterproxymodel.h" | ||
27 | #include "kfileitem.h" | 27 | #include "kfileitem.h" | ||
28 | #include "kfilemetapreview_p.h" | 28 | #include "kfilemetapreview_p.h" | ||
29 | #include "kpreviewwidgetbase.h" | 29 | #include "kpreviewwidgetbase.h" | ||
30 | #include "knewfilemenu.h" | 30 | #include "knewfilemenu.h" | ||
31 | #include <kurlmimedata.h> | ||||
31 | #include "../pathhelpers_p.h" | 32 | #include "../pathhelpers_p.h" | ||
32 | 33 | | |||
33 | #include <config-kiofilewidgets.h> | 34 | #include <config-kiofilewidgets.h> | ||
34 | #include <defaults-kfile.h> // ConfigGroup, DefaultShowHidden, DefaultDirsFirst, DefaultSortReversed | 35 | #include <defaults-kfile.h> // ConfigGroup, DefaultShowHidden, DefaultDirsFirst, DefaultSortReversed | ||
35 | 36 | | |||
36 | #include <QApplication> | 37 | #include <QApplication> | ||
37 | #include <QHeaderView> | 38 | #include <QHeaderView> | ||
38 | #include <QListView> | 39 | #include <QListView> | ||
▲ Show 20 Lines • Show All 370 Lines • ▼ Show 20 Line(s) | 361 | { | |||
409 | // action stuff | 410 | // action stuff | ||
410 | setupActions(); | 411 | setupActions(); | ||
411 | setupMenu(); | 412 | setupMenu(); | ||
412 | 413 | | |||
413 | d->sorting = QDir::NoSort; //so updateSorting() doesn't think nothing has changed | 414 | d->sorting = QDir::NoSort; //so updateSorting() doesn't think nothing has changed | ||
414 | d->updateSorting(QDir::Name | QDir::DirsFirst); | 415 | d->updateSorting(QDir::Name | QDir::DirsFirst); | ||
415 | 416 | | |||
416 | setFocusPolicy(Qt::WheelFocus); | 417 | setFocusPolicy(Qt::WheelFocus); | ||
418 | setAcceptDrops(true); | ||||
apol: This default change should be documented. | |||||
meven: Not sure I have done this correctly. | |||||
ngraham: Yep, I'd say so now. | |||||
meven: Any idea where I should add this information ?
An example would suffice. | |||||
You already did, in the inline function documentation in src/filewidgets/kdiroperator.h ngraham: You already did, in the inline function documentation in `src/filewidgets/kdiroperator.h` | |||||
417 | } | 419 | } | ||
418 | 420 | | |||
419 | KDirOperator::~KDirOperator() | 421 | KDirOperator::~KDirOperator() | ||
420 | { | 422 | { | ||
421 | resetCursor(); | 423 | resetCursor(); | ||
422 | disconnect(d->dirLister, nullptr, this, nullptr); | 424 | disconnect(d->dirLister, nullptr, this, nullptr); | ||
423 | delete d; | 425 | delete d; | ||
424 | } | 426 | } | ||
▲ Show 20 Lines • Show All 949 Lines • ▼ Show 20 Line(s) | 1375 | if (evt->delta() > 0) { | |||
1374 | setIconsZoom(d->iconsZoom + 10); | 1376 | setIconsZoom(d->iconsZoom + 10); | ||
1375 | } else { | 1377 | } else { | ||
1376 | setIconsZoom(d->iconsZoom - 10); | 1378 | setIconsZoom(d->iconsZoom - 10); | ||
1377 | } | 1379 | } | ||
1378 | return true; | 1380 | return true; | ||
1379 | } | 1381 | } | ||
1380 | } | 1382 | } | ||
1381 | break; | 1383 | break; | ||
1384 | case QEvent::DragEnter: { | ||||
1385 | // Accepts drops of one file or folder only | ||||
1386 | QDragEnterEvent *evt = static_cast<QDragEnterEvent *>(event); | ||||
1387 | const QList<QUrl> urls = KUrlMimeData::urlsFromMimeData(evt->mimeData()); | ||||
1388 | event->setAccepted(urls.size() == 1 && evt->mimeData()->hasFormat(QStringLiteral("text/uri-list"))); | ||||
1389 | } | ||||
1390 | break; | ||||
1391 | case QEvent::Drop: { | ||||
1392 | QDropEvent *evt = static_cast<QDropEvent *>(event); | ||||
1393 | if (evt->dropAction() == Qt::CopyAction || evt->dropAction() == Qt::MoveAction) { | ||||
1394 | | ||||
1395 | const QList<QUrl> urls = KUrlMimeData::urlsFromMimeData(evt->mimeData()); | ||||
1396 | | ||||
1397 | if (urls.size() != 1) { | ||||
1398 | // only one file/folder can be dropped at the moment | ||||
1399 | evt->ignore(); | ||||
1400 | } else { | ||||
1401 | const QUrl url = urls.constFirst(); | ||||
apol: .constFirst() maybe reads better? | |||||
1402 | | ||||
ngraham: `this->` not needed | |||||
1403 | // stat the url to get details | ||||
elvisangelaccio: Please use descriptive variable names also here. | |||||
1404 | KIO::StatJob *job = KIO::stat(url, KIO::HideProgressInfo); | ||||
1405 | job->exec(); | ||||
QRegExp should be avoid in new code, can you try to use QRegularExpression instead? elvisangelaccio: QRegExp should be avoid in new code, can you try to use QRegularExpression instead? | |||||
1406 | | ||||
1407 | KIO::UDSEntry entry = job->statResult(); | ||||
1408 | | ||||
1409 | if (entry.isDir()) { | ||||
1410 | setUrl(url, false); | ||||
ngraham: Comment seems unnecessary; the code is clear enough | |||||
1411 | } else { | ||||
1412 | // if the current url is not known | ||||
1413 | if (d->dirLister->findByUrl(url).isNull()) { | ||||
1414 | setUrl(url.adjusted(QUrl::RemoveFilename), false); | ||||
1415 | | ||||
1416 | // Will set the current item once loading has finished | ||||
ngraham: `this->` not needed | |||||
1417 | QMetaObject::Connection connection; | ||||
1418 | auto urlSetterClosure = [this, url, connection](){ | ||||
1419 | this->setCurrentItem(url); | ||||
apol: maybe call the function urlSetter? | |||||
1420 | QObject::disconnect(connection); | ||||
1421 | }; | ||||
ngraham: `this->` not needed | |||||
1422 | connection = connect(this, &KDirOperator::finishedLoading, this, urlSetterClosure); | ||||
1423 | } else { | ||||
1424 | this->setCurrentItem(url); | ||||
1425 | } | ||||
1426 | } | ||||
1427 | evt->accept(); | ||||
1428 | } | ||||
1429 | } else { | ||||
1430 | evt->ignore(); | ||||
1431 | } | ||||
1432 | } | ||||
1433 | break; | ||||
1382 | default: | 1434 | default: | ||
1383 | break; | 1435 | break; | ||
1384 | } | 1436 | } | ||
1385 | 1437 | | |||
1386 | return QWidget::eventFilter(watched, event); | 1438 | return QWidget::eventFilter(watched, event); | ||
1387 | } | 1439 | } | ||
1388 | 1440 | | |||
1389 | bool KDirOperator::Private::checkPreviewInternal() const | 1441 | bool KDirOperator::Private::checkPreviewInternal() const | ||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Line(s) | 1505 | if (KFile::isDetailView(viewKind) || KFile::isTreeView(viewKind) || KFile::isDetailTreeView(viewKind)) { | |||
1456 | itemView = detailView; | 1508 | itemView = detailView; | ||
1457 | } else { | 1509 | } else { | ||
1458 | itemView = new KDirOperatorIconView(this, parent); | 1510 | itemView = new KDirOperatorIconView(this, parent); | ||
1459 | } | 1511 | } | ||
1460 | 1512 | | |||
1461 | return itemView; | 1513 | return itemView; | ||
1462 | } | 1514 | } | ||
1463 | 1515 | | |||
1464 | void KDirOperator::setAcceptDrops(bool b) | 1516 | void KDirOperator::setAcceptDrops(bool acceptsDrops) | ||
1465 | { | 1517 | { | ||
1466 | // TODO: | 1518 | QWidget::setAcceptDrops(acceptsDrops); | ||
1467 | //if (d->fileView) | 1519 | if (view()) { | ||
1468 | // d->fileView->widget()->setAcceptDrops(b); | 1520 | view()->setAcceptDrops(acceptsDrops); | ||
1469 | QWidget::setAcceptDrops(b); | 1521 | if (acceptsDrops) { | ||
1522 | view()->installEventFilter(this); | ||||
apol: Initial this-> isn't necessary, just `view()`.
| |||||
1523 | } else { | ||||
1524 | view()->removeEventFilter(this); | ||||
1525 | } | ||||
1526 | } | ||||
1470 | } | 1527 | } | ||
1471 | 1528 | | |||
1472 | void KDirOperator::setDropOptions(int options) | 1529 | void KDirOperator::setDropOptions(int options) | ||
1473 | { | 1530 | { | ||
1474 | d->dropOptions = options; | 1531 | d->dropOptions = options; | ||
1475 | // TODO: | 1532 | // TODO: | ||
1476 | //if (d->fileView) | 1533 | //if (d->fileView) | ||
1477 | // d->fileView->setDropOptions(options); | 1534 | // d->fileView->setDropOptions(options); | ||
Show All 20 Lines | 1538 | { | |||
1498 | } | 1555 | } | ||
1499 | 1556 | | |||
1500 | d->viewKind = static_cast<int>(viewKind); | 1557 | d->viewKind = static_cast<int>(viewKind); | ||
1501 | viewKind = static_cast<KFile::FileView>(d->viewKind); | 1558 | viewKind = static_cast<KFile::FileView>(d->viewKind); | ||
1502 | 1559 | | |||
1503 | QAbstractItemView *newView = createView(this, viewKind); | 1560 | QAbstractItemView *newView = createView(this, viewKind); | ||
1504 | setView(newView); | 1561 | setView(newView); | ||
1505 | 1562 | | |||
1563 | if (this->acceptDrops()) { | ||||
ngraham: `this->` not needed | |||||
1564 | newView->setAcceptDrops(true); | ||||
1565 | newView->installEventFilter(this); | ||||
1566 | } | ||||
1567 | | ||||
1506 | d->_k_togglePreview(preview); | 1568 | d->_k_togglePreview(preview); | ||
1507 | } | 1569 | } | ||
1508 | 1570 | | |||
1509 | KFile::FileView KDirOperator::viewMode() const | 1571 | KFile::FileView KDirOperator::viewMode() const | ||
1510 | { | 1572 | { | ||
1511 | return static_cast<KFile::FileView>(d->viewKind); | 1573 | return static_cast<KFile::FileView>(d->viewKind); | ||
1512 | } | 1574 | } | ||
1513 | 1575 | | |||
▲ Show 20 Lines • Show All 1171 Lines • Show Last 20 Lines |
This default change should be documented.