Changeset View
Changeset View
Standalone View
Standalone View
krusader/DiskUsage/dulines.cpp
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | |||||
43 | #include <KConfigCore/KSharedConfig> | 43 | #include <KConfigCore/KSharedConfig> | ||
44 | #include <KI18n/KLocalizedString> | 44 | #include <KI18n/KLocalizedString> | ||
45 | 45 | | |||
46 | 46 | | |||
47 | class DULinesItemDelegate : public QItemDelegate | 47 | class DULinesItemDelegate : public QItemDelegate | ||
48 | { | 48 | { | ||
49 | public: | 49 | public: | ||
50 | 50 | | |||
51 | explicit DULinesItemDelegate(QObject *parent = 0) : QItemDelegate(parent) {} | 51 | explicit DULinesItemDelegate(QObject *parent = nullptr) : QItemDelegate(parent) {} | ||
52 | 52 | | |||
53 | virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE { | 53 | void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE { | ||
54 | QItemDelegate::paint(painter, option, index); | 54 | QItemDelegate::paint(painter, option, index); | ||
55 | 55 | | |||
56 | QVariant value = index.data(Qt::UserRole); | 56 | QVariant value = index.data(Qt::UserRole); | ||
57 | if (value.isValid()) { | 57 | if (value.isValid()) { | ||
58 | QString text = value.toString(); | 58 | QString text = value.toString(); | ||
59 | 59 | | |||
60 | value = index.data(Qt::DisplayRole); | 60 | value = index.data(Qt::DisplayRole); | ||
61 | QString display; | 61 | QString display; | ||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Line(s) | |||||
119 | painter->restore(); | 119 | painter->restore(); | ||
120 | } | 120 | } | ||
121 | } | 121 | } | ||
122 | }; | 122 | }; | ||
123 | 123 | | |||
124 | class DULinesItem : public QTreeWidgetItem | 124 | class DULinesItem : public QTreeWidgetItem | ||
125 | { | 125 | { | ||
126 | public: | 126 | public: | ||
127 | DULinesItem(DiskUsage *diskUsageIn, File *fileItem, QTreeWidget * parent, QString label1, | 127 | DULinesItem(DiskUsage *diskUsageIn, File *fileItem, QTreeWidget * parent, const QString& label1, | ||
128 | QString label2, QString label3) : QTreeWidgetItem(parent), | 128 | const QString& label2, const QString& label3) : QTreeWidgetItem(parent), | ||
129 | diskUsage(diskUsageIn), file(fileItem) { | 129 | diskUsage(diskUsageIn), file(fileItem) { | ||
130 | setText(0, label1); | 130 | setText(0, label1); | ||
131 | setText(1, label2); | 131 | setText(1, label2); | ||
132 | setText(2, label3); | 132 | setText(2, label3); | ||
133 | 133 | | |||
134 | setTextAlignment(1, Qt::AlignRight); | 134 | setTextAlignment(1, Qt::AlignRight); | ||
135 | } | 135 | } | ||
136 | DULinesItem(DiskUsage *diskUsageIn, File *fileItem, QTreeWidget * parent, QTreeWidgetItem * after, | 136 | DULinesItem(DiskUsage *diskUsageIn, File *fileItem, QTreeWidget * parent, QTreeWidgetItem * after, | ||
137 | QString label1, QString label2, QString label3) : QTreeWidgetItem(parent, after), | 137 | const QString& label1, const QString& label2, const QString& label3) : QTreeWidgetItem(parent, after), | ||
138 | diskUsage(diskUsageIn), file(fileItem) { | 138 | diskUsage(diskUsageIn), file(fileItem) { | ||
139 | setText(0, label1); | 139 | setText(0, label1); | ||
140 | setText(1, label2); | 140 | setText(1, label2); | ||
141 | setText(2, label3); | 141 | setText(2, label3); | ||
142 | 142 | | |||
143 | setTextAlignment(1, Qt::AlignRight); | 143 | setTextAlignment(1, Qt::AlignRight); | ||
144 | } | 144 | } | ||
145 | 145 | | |||
146 | virtual bool operator<(const QTreeWidgetItem &other) const Q_DECL_OVERRIDE { | 146 | bool operator<(const QTreeWidgetItem &other) const Q_DECL_OVERRIDE { | ||
147 | int column = treeWidget() ? treeWidget()->sortColumn() : 0; | 147 | int column = treeWidget() ? treeWidget()->sortColumn() : 0; | ||
148 | 148 | | |||
149 | if (text(0) == "..") | 149 | if (text(0) == "..") | ||
150 | return true; | 150 | return true; | ||
151 | 151 | | |||
152 | const DULinesItem *compWith = dynamic_cast< const DULinesItem * >(&other); | 152 | const auto *compWith = dynamic_cast< const DULinesItem * >(&other); | ||
153 | if (compWith == 0) | 153 | if (compWith == nullptr) | ||
154 | return false; | 154 | return false; | ||
155 | 155 | | |||
156 | switch (column) { | 156 | switch (column) { | ||
157 | case 0: | 157 | case 0: | ||
158 | case 1: | 158 | case 1: | ||
159 | return file->size() > compWith->file->size(); | 159 | return file->size() > compWith->file->size(); | ||
160 | default: | 160 | default: | ||
161 | return text(column) < other.text(column); | 161 | return text(column) < other.text(column); | ||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Line(s) | 227 | { | |||
230 | 230 | | |||
231 | delete itemDelegate; | 231 | delete itemDelegate; | ||
232 | } | 232 | } | ||
233 | 233 | | |||
234 | bool DULines::event(QEvent * event) | 234 | bool DULines::event(QEvent * event) | ||
235 | { | 235 | { | ||
236 | switch (event->type()) { | 236 | switch (event->type()) { | ||
237 | case QEvent::ToolTip: { | 237 | case QEvent::ToolTip: { | ||
238 | QHelpEvent *he = static_cast<QHelpEvent*>(event); | 238 | auto *he = dynamic_cast<QHelpEvent*>(event); | ||
239 | 239 | | |||
240 | if (viewport()) { | 240 | if (viewport()) { | ||
241 | QPoint pos = viewport()->mapFromGlobal(he->globalPos()); | 241 | QPoint pos = viewport()->mapFromGlobal(he->globalPos()); | ||
242 | 242 | | |||
243 | QTreeWidgetItem * item = itemAt(pos); | 243 | QTreeWidgetItem * item = itemAt(pos); | ||
244 | 244 | | |||
245 | int column = columnAt(pos.x()); | 245 | int column = columnAt(pos.x()); | ||
246 | 246 | | |||
Show All 10 Lines | |||||
257 | } | 257 | } | ||
258 | return KrTreeWidget::event(event); | 258 | return KrTreeWidget::event(event); | ||
259 | } | 259 | } | ||
260 | 260 | | |||
261 | void DULines::slotDirChanged(Directory *dirEntry) | 261 | void DULines::slotDirChanged(Directory *dirEntry) | ||
262 | { | 262 | { | ||
263 | clear(); | 263 | clear(); | ||
264 | 264 | | |||
265 | QTreeWidgetItem * lastItem = 0; | 265 | QTreeWidgetItem * lastItem = nullptr; | ||
266 | 266 | | |||
267 | if (!(dirEntry->parent() == 0)) { | 267 | if (!(dirEntry->parent() == nullptr)) { | ||
268 | lastItem = new QTreeWidgetItem(this); | 268 | lastItem = new QTreeWidgetItem(this); | ||
269 | lastItem->setText(0, ".."); | 269 | lastItem->setText(0, ".."); | ||
270 | lastItem->setIcon(0, Icon("go-up")); | 270 | lastItem->setIcon(0, Icon("go-up")); | ||
271 | lastItem->setFlags(lastItem->flags() & (~Qt::ItemIsSelectable)); | 271 | lastItem->setFlags(lastItem->flags() & (~Qt::ItemIsSelectable)); | ||
272 | } | 272 | } | ||
273 | 273 | | |||
274 | int maxPercent = -1; | 274 | int maxPercent = -1; | ||
275 | for (Iterator<File> it = dirEntry->iterator(); it != dirEntry->end(); ++it) { | 275 | for (Iterator<File> it = dirEntry->iterator(); it != dirEntry->end(); ++it) { | ||
276 | File *item = *it; | 276 | File *item = *it; | ||
277 | if (!item->isExcluded() && item->intPercent() > maxPercent) | 277 | if (!item->isExcluded() && item->intPercent() > maxPercent) | ||
278 | maxPercent = item->intPercent(); | 278 | maxPercent = item->intPercent(); | ||
279 | } | 279 | } | ||
280 | 280 | | |||
281 | for (Iterator<File> it = dirEntry->iterator(); it != dirEntry->end(); ++it) { | 281 | for (Iterator<File> it = dirEntry->iterator(); it != dirEntry->end(); ++it) { | ||
282 | File *item = *it; | 282 | File *item = *it; | ||
283 | 283 | | |||
284 | QString fileName = item->name(); | 284 | QString fileName = item->name(); | ||
285 | 285 | | |||
286 | if (lastItem == 0) | 286 | if (lastItem == nullptr) | ||
287 | lastItem = new DULinesItem(diskUsage, item, this, "", item->percent() + " ", fileName); | 287 | lastItem = new DULinesItem(diskUsage, item, this, "", item->percent() + " ", fileName); | ||
288 | else | 288 | else | ||
289 | lastItem = new DULinesItem(diskUsage, item, this, lastItem, "", item->percent() + " ", fileName); | 289 | lastItem = new DULinesItem(diskUsage, item, this, lastItem, "", item->percent() + " ", fileName); | ||
290 | 290 | | |||
291 | if (item->isExcluded()) | 291 | if (item->isExcluded()) | ||
292 | lastItem->setHidden(true); | 292 | lastItem->setHidden(true); | ||
293 | 293 | | |||
294 | int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1; | 294 | int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1; | ||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Line(s) | |||||
364 | } | 364 | } | ||
365 | 365 | | |||
366 | void DULines::sectionResized(int column) | 366 | void DULines::sectionResized(int column) | ||
367 | { | 367 | { | ||
368 | if (topLevelItemCount() == 0 || column != 0) | 368 | if (topLevelItemCount() == 0 || column != 0) | ||
369 | return; | 369 | return; | ||
370 | 370 | | |||
371 | Directory * currentDir = diskUsage->getCurrentDir(); | 371 | Directory * currentDir = diskUsage->getCurrentDir(); | ||
372 | if (currentDir == 0) | 372 | if (currentDir == nullptr) | ||
373 | return; | 373 | return; | ||
374 | 374 | | |||
375 | int maxPercent = -1; | 375 | int maxPercent = -1; | ||
376 | for (Iterator<File> it = currentDir->iterator(); it != currentDir->end(); ++it) { | 376 | for (Iterator<File> it = currentDir->iterator(); it != currentDir->end(); ++it) { | ||
377 | File *item = *it; | 377 | File *item = *it; | ||
378 | 378 | | |||
379 | if (!item->isExcluded() && item->intPercent() > maxPercent) | 379 | if (!item->isExcluded() && item->intPercent() > maxPercent) | ||
380 | maxPercent = item->intPercent(); | 380 | maxPercent = item->intPercent(); | ||
381 | } | 381 | } | ||
382 | 382 | | |||
383 | QTreeWidgetItemIterator it2(this); | 383 | QTreeWidgetItemIterator it2(this); | ||
384 | while (*it2) { | 384 | while (*it2) { | ||
385 | QTreeWidgetItem *lvitem = *it2; | 385 | QTreeWidgetItem *lvitem = *it2; | ||
386 | if (lvitem->text(0) != "..") { | 386 | if (lvitem->text(0) != "..") { | ||
387 | DULinesItem *duItem = dynamic_cast< DULinesItem *>(lvitem); | 387 | auto *duItem = dynamic_cast< DULinesItem *>(lvitem); | ||
388 | if (duItem) { | 388 | if (duItem) { | ||
389 | int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1; | 389 | int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1; | ||
390 | duItem->setData(0, Qt::DecorationRole, createPixmap(duItem->getFile()->intPercent(), maxPercent, header()->sectionSize(0) - 2 * textMargin)); | 390 | duItem->setData(0, Qt::DecorationRole, createPixmap(duItem->getFile()->intPercent(), maxPercent, header()->sectionSize(0) - 2 * textMargin)); | ||
391 | QSize size = duItem->sizeHint(0); | 391 | QSize size = duItem->sizeHint(0); | ||
392 | size.setWidth(16); | 392 | size.setWidth(16); | ||
393 | duItem->setSizeHint(0, size); | 393 | duItem->setSizeHint(0, size); | ||
394 | } | 394 | } | ||
395 | } | 395 | } | ||
396 | it2++; | 396 | it2++; | ||
397 | } | 397 | } | ||
398 | } | 398 | } | ||
399 | 399 | | |||
400 | bool DULines::doubleClicked(QTreeWidgetItem * item) | 400 | bool DULines::doubleClicked(QTreeWidgetItem * item) | ||
401 | { | 401 | { | ||
402 | if (item) { | 402 | if (item) { | ||
403 | if (item->text(0) != "..") { | 403 | if (item->text(0) != "..") { | ||
404 | File *fileItem = ((DULinesItem *)item)->getFile(); | 404 | File *fileItem = ((DULinesItem *)item)->getFile(); | ||
405 | if (fileItem->isDir()) | 405 | if (fileItem->isDir()) | ||
406 | diskUsage->changeDirectory(dynamic_cast<Directory *>(fileItem)); | 406 | diskUsage->changeDirectory(dynamic_cast<Directory *>(fileItem)); | ||
407 | return true; | 407 | return true; | ||
408 | } else { | 408 | } else { | ||
409 | Directory *upDir = (Directory *)diskUsage->getCurrentDir()->parent(); | 409 | auto *upDir = (Directory *)diskUsage->getCurrentDir()->parent(); | ||
410 | 410 | | |||
411 | if (upDir) | 411 | if (upDir) | ||
412 | diskUsage->changeDirectory(upDir); | 412 | diskUsage->changeDirectory(upDir); | ||
413 | return true; | 413 | return true; | ||
414 | } | 414 | } | ||
415 | } | 415 | } | ||
416 | return false; | 416 | return false; | ||
417 | } | 417 | } | ||
Show All 33 Lines | 450 | case Qt::Key_Delete : | |||
451 | e->ignore(); | 451 | e->ignore(); | ||
452 | return; | 452 | return; | ||
453 | } | 453 | } | ||
454 | KrTreeWidget::keyPressEvent(e); | 454 | KrTreeWidget::keyPressEvent(e); | ||
455 | } | 455 | } | ||
456 | 456 | | |||
457 | void DULines::slotRightClicked(QTreeWidgetItem *item, const QPoint &pos) | 457 | void DULines::slotRightClicked(QTreeWidgetItem *item, const QPoint &pos) | ||
458 | { | 458 | { | ||
459 | File * file = 0; | 459 | File * file = nullptr; | ||
460 | 460 | | |||
461 | if (item && item->text(0) != "..") | 461 | if (item && item->text(0) != "..") | ||
462 | file = ((DULinesItem *)item)->getFile(); | 462 | file = ((DULinesItem *)item)->getFile(); | ||
463 | 463 | | |||
464 | QMenu linesPopup; | 464 | QMenu linesPopup; | ||
465 | QAction *act = linesPopup.addAction(i18n("Show file sizes"), this, SLOT(slotShowFileSizes())); | 465 | QAction *act = linesPopup.addAction(i18n("Show file sizes"), this, SLOT(slotShowFileSizes())); | ||
466 | act->setChecked(showFileSize); | 466 | act->setChecked(showFileSize); | ||
467 | 467 | | |||
468 | diskUsage->rightClickMenu(pos, file, &linesPopup, i18n("Lines")); | 468 | diskUsage->rightClickMenu(pos, file, &linesPopup, i18n("Lines")); | ||
469 | } | 469 | } | ||
470 | 470 | | |||
471 | void DULines::slotShowFileSizes() | 471 | void DULines::slotShowFileSizes() | ||
472 | { | 472 | { | ||
473 | showFileSize = !showFileSize; | 473 | showFileSize = !showFileSize; | ||
474 | slotDirChanged(diskUsage->getCurrentDir()); | 474 | slotDirChanged(diskUsage->getCurrentDir()); | ||
475 | } | 475 | } | ||
476 | 476 | | |||
477 | File * DULines::getCurrentFile() | 477 | File * DULines::getCurrentFile() | ||
478 | { | 478 | { | ||
479 | QTreeWidgetItem *item = currentItem(); | 479 | QTreeWidgetItem *item = currentItem(); | ||
480 | 480 | | |||
481 | if (item == 0 || item->text(0) == "..") | 481 | if (item == nullptr || item->text(0) == "..") | ||
482 | return 0; | 482 | return nullptr; | ||
483 | 483 | | |||
484 | return ((DULinesItem *)item)->getFile(); | 484 | return ((DULinesItem *)item)->getFile(); | ||
485 | } | 485 | } | ||
486 | 486 | | |||
487 | void DULines::slotChanged(File * item) | 487 | void DULines::slotChanged(File * item) | ||
488 | { | 488 | { | ||
489 | QTreeWidgetItemIterator it(this); | 489 | QTreeWidgetItemIterator it(this); | ||
490 | while (*it) { | 490 | while (*it) { | ||
491 | QTreeWidgetItem *lvitem = *it; | 491 | QTreeWidgetItem *lvitem = *it; | ||
492 | it++; | 492 | it++; | ||
493 | 493 | | |||
494 | if (lvitem->text(0) != "..") { | 494 | if (lvitem->text(0) != "..") { | ||
495 | DULinesItem *duItem = (DULinesItem *)(lvitem); | 495 | auto *duItem = (DULinesItem *)(lvitem); | ||
496 | if (duItem->getFile() == item) { | 496 | if (duItem->getFile() == item) { | ||
497 | setSortingEnabled(false); | 497 | setSortingEnabled(false); | ||
498 | duItem->setHidden(item->isExcluded()); | 498 | duItem->setHidden(item->isExcluded()); | ||
499 | duItem->setText(1, item->percent()); | 499 | duItem->setText(1, item->percent()); | ||
500 | if (!refreshNeeded) { | 500 | if (!refreshNeeded) { | ||
501 | refreshNeeded = true; | 501 | refreshNeeded = true; | ||
502 | QTimer::singleShot(0, this, SLOT(slotRefresh())); | 502 | QTimer::singleShot(0, this, SLOT(slotRefresh())); | ||
503 | } | 503 | } | ||
504 | break; | 504 | break; | ||
505 | } | 505 | } | ||
506 | } | 506 | } | ||
507 | } | 507 | } | ||
508 | } | 508 | } | ||
509 | 509 | | |||
510 | void DULines::slotDeleted(File * item) | 510 | void DULines::slotDeleted(File * item) | ||
511 | { | 511 | { | ||
512 | QTreeWidgetItemIterator it(this); | 512 | QTreeWidgetItemIterator it(this); | ||
513 | while (*it) { | 513 | while (*it) { | ||
514 | QTreeWidgetItem *lvitem = *it; | 514 | QTreeWidgetItem *lvitem = *it; | ||
515 | it++; | 515 | it++; | ||
516 | 516 | | |||
517 | if (lvitem->text(0) != "..") { | 517 | if (lvitem->text(0) != "..") { | ||
518 | DULinesItem *duItem = (DULinesItem *)(lvitem); | 518 | auto *duItem = (DULinesItem *)(lvitem); | ||
519 | if (duItem->getFile() == item) { | 519 | if (duItem->getFile() == item) { | ||
520 | delete duItem; | 520 | delete duItem; | ||
521 | break; | 521 | break; | ||
522 | } | 522 | } | ||
523 | } | 523 | } | ||
524 | } | 524 | } | ||
525 | } | 525 | } | ||
526 | 526 | | |||
Show All 9 Lines |