24 #include <QtCore/QTimeLine>
25 #include <QtCore/QTimer>
26 #include <QtGui/QPainter>
27 #include <QtGui/QAbstractItemDelegate>
28 #include <QtGui/QKeyEvent>
29 #include <QtGui/QApplication>
30 #include <QtGui/QScrollBar>
56 #define LATERAL_MARGIN 4
57 #define CAPACITYBAR_HEIGHT 6
59 class KFilePlacesViewDelegate :
public QAbstractItemDelegate
63 virtual ~KFilePlacesViewDelegate();
64 virtual QSize sizeHint(
const QStyleOptionViewItem &option,
65 const QModelIndex &index)
const;
66 virtual void paint(QPainter *painter,
67 const QStyleOptionViewItem &option,
68 const QModelIndex &index)
const;
71 void setIconSize(
int newSize);
73 void addAppearingItem(
const QModelIndex &index);
74 void setAppearingItemProgress(qreal value);
75 void addDisappearingItem(
const QModelIndex &index);
76 void setDisappearingItemProgress(qreal value);
78 void setShowHoverIndication(
bool show);
80 void addFadeAnimation(
const QModelIndex &index, QTimeLine *timeLine);
81 void removeFadeAnimation(
const QModelIndex &index);
82 QModelIndex indexForFadeAnimation(QTimeLine *timeLine)
const;
83 QTimeLine *fadeAnimationForIndex(
const QModelIndex &index)
const;
85 qreal contentsOpacity(
const QModelIndex &index)
const;
91 QList<QPersistentModelIndex> m_appearingItems;
92 int m_appearingIconSize;
93 qreal m_appearingOpacity;
95 QList<QPersistentModelIndex> m_disappearingItems;
96 int m_disappearingIconSize;
97 qreal m_disappearingOpacity;
99 bool m_showHoverIndication;
105 KFilePlacesViewDelegate::KFilePlacesViewDelegate(
KFilePlacesView *parent) :
106 QAbstractItemDelegate(parent),
109 m_appearingIconSize(0),
110 m_appearingOpacity(0.0),
111 m_disappearingIconSize(0),
112 m_disappearingOpacity(0.0),
113 m_showHoverIndication(true)
117 KFilePlacesViewDelegate::~KFilePlacesViewDelegate()
121 QSize KFilePlacesViewDelegate::sizeHint(
const QStyleOptionViewItem &option,
122 const QModelIndex &index)
const
124 int iconSize = m_iconSize;
125 if (m_appearingItems.contains(index)) {
126 iconSize = m_appearingIconSize;
127 }
else if (m_disappearingItems.contains(index)) {
128 iconSize = m_disappearingIconSize;
134 return QSize(option.rect.width(), option.fontMetrics.height() / 2 + qMax(iconSize, option.fontMetrics.height()));
137 void KFilePlacesViewDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index)
const
141 if (m_appearingItems.contains(index)) {
142 painter->setOpacity(m_appearingOpacity);
143 }
else if (m_disappearingItems.contains(index)) {
144 painter->setOpacity(m_disappearingOpacity);
147 QStyleOptionViewItemV4 opt = option;
148 if (!m_showHoverIndication) {
149 opt.state &= ~QStyle::State_MouseOver;
151 QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter);
154 bool isLTR = option.direction == Qt::LeftToRight;
156 QIcon icon = index.model()->
data(index, Qt::DecorationRole).value<QIcon>();
157 QPixmap pm = icon.pixmap(m_iconSize, m_iconSize);
159 : option.rect.right() -
LATERAL_MARGIN - m_iconSize, option.rect.top() + (option.rect.height() - m_iconSize) / 2);
160 painter->drawPixmap(point, pm);
162 if (option.state & QStyle::State_Selected) {
163 QPalette::ColorGroup cg = QPalette::Active;
164 if (!(option.state & QStyle::State_Enabled)) {
165 cg = QPalette::Disabled;
166 }
else if (!(option.state & QStyle::State_Active)) {
167 cg = QPalette::Inactive;
169 painter->setPen(option.palette.color(cg, QPalette::HighlightedText));
175 KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo(mountPointPath);
176 bool drawCapacityBar = info.size() != 0 &&
179 if (drawCapacityBar && contentsOpacity(index) > 0)
182 painter->setOpacity(painter->opacity() * contentsOpacity(index));
186 : 0, option.rect.top() + (option.rect.height() / 2 - height / 2), option.rect.width() - m_iconSize -
LATERAL_MARGIN * 2, option.fontMetrics.height());
187 painter->drawText(rectText, Qt::AlignLeft | Qt::AlignTop, option.fontMetrics.elidedText(index.model()->data(index).toString(), Qt::ElideRight, rectText.width()));
190 capacityBar.setValue((info.used() * 100) / info.size());
191 capacityBar.drawCapacityBar(painter, capacityRect);
196 painter->setOpacity(painter->opacity() * (1 - contentsOpacity(index)));
199 rectText =
QRect(isLTR ? m_iconSize + LATERAL_MARGIN * 2 + option.rect.left()
200 : 0, option.rect.top(), option.rect.width() - m_iconSize - LATERAL_MARGIN * 2, option.rect.height());
201 painter->drawText(rectText, Qt::AlignLeft | Qt::AlignVCenter, option.fontMetrics.elidedText(index.model()->data(index).toString(), Qt::ElideRight, rectText.width()));
203 if (drawCapacityBar && contentsOpacity(index) > 0) {
210 int KFilePlacesViewDelegate::iconSize()
const
215 void KFilePlacesViewDelegate::setIconSize(
int newSize)
217 m_iconSize = newSize;
220 void KFilePlacesViewDelegate::addAppearingItem(
const QModelIndex &index)
222 m_appearingItems << index;
225 void KFilePlacesViewDelegate::setAppearingItemProgress(qreal value)
228 m_appearingOpacity = 0.0;
229 m_appearingIconSize = iconSize()*value*4;
231 if (m_appearingIconSize>=m_iconSize) {
232 m_appearingIconSize = m_iconSize;
235 m_appearingIconSize = m_iconSize;
236 m_appearingOpacity = (value-0.25)*4/3;
239 m_appearingItems.clear();
244 void KFilePlacesViewDelegate::addDisappearingItem(
const QModelIndex &index)
246 m_disappearingItems << index;
249 void KFilePlacesViewDelegate::setDisappearingItemProgress(qreal value)
254 m_disappearingOpacity = 0.0;
255 m_disappearingIconSize = iconSize()*value*4;
257 if (m_disappearingIconSize>=m_iconSize) {
258 m_disappearingIconSize = m_iconSize;
262 m_disappearingItems.clear();
265 m_disappearingIconSize = m_iconSize;
266 m_disappearingOpacity = (value-0.25)*4/3;
270 void KFilePlacesViewDelegate::setShowHoverIndication(
bool show)
272 m_showHoverIndication = show;
275 void KFilePlacesViewDelegate::addFadeAnimation(
const QModelIndex &index, QTimeLine *timeLine)
277 m_timeLineMap.insert(index, timeLine);
278 m_timeLineInverseMap.insert(timeLine, index);
281 void KFilePlacesViewDelegate::removeFadeAnimation(
const QModelIndex &index)
283 QTimeLine *timeLine = m_timeLineMap.value(index, 0);
284 m_timeLineMap.remove(index);
285 m_timeLineInverseMap.remove(timeLine);
288 QModelIndex KFilePlacesViewDelegate::indexForFadeAnimation(QTimeLine *timeLine)
const
290 return m_timeLineInverseMap.value(timeLine, QModelIndex());
293 QTimeLine *KFilePlacesViewDelegate::fadeAnimationForIndex(
const QModelIndex &index)
const
295 return m_timeLineMap.value(index, 0);
298 qreal KFilePlacesViewDelegate::contentsOpacity(
const QModelIndex &index)
const
300 QTimeLine *timeLine = fadeAnimationForIndex(index);
302 return timeLine->currentValue();
320 bool autoResizeItems;
322 bool smoothItemResizing;
326 QPersistentModelIndex lastClickedIndex;
330 void setCurrentIndex(
const QModelIndex &index);
331 void adaptItemSize();
332 void updateHiddenRows();
333 bool insertAbove(
const QRect &itemRect,
const QPoint &pos)
const;
334 bool insertBelow(
const QRect &itemRect,
const QPoint &pos)
const;
335 int insertIndicatorHeight(
int itemHeight)
const;
336 void fadeCapacityBar(
const QModelIndex &index, FadeType fadeType);
338 void _k_placeClicked(
const QModelIndex &index);
339 void _k_placeEntered(
const QModelIndex &index);
340 void _k_placeLeft(
const QModelIndex &index);
341 void _k_storageSetupDone(
const QModelIndex &index,
bool success);
342 void _k_adaptItemsUpdate(qreal value);
343 void _k_itemAppearUpdate(qreal value);
344 void _k_itemDisappearUpdate(qreal value);
345 void _k_enableSmoothItemResizing();
346 void _k_trashUpdated(
KJob *job);
347 void _k_capacityBarFadeValueChanged();
348 void _k_triggerDevicePolling();
350 QTimeLine adaptItemsTimeline;
351 int oldSize, endSize;
353 QTimeLine itemAppearTimeline;
354 QTimeLine itemDisappearTimeline;
357 KFilePlacesViewDelegate *delegate;
359 int pollingRequestCount;
363 :
QListView(parent), d(new Private(this))
366 d->smoothItemResizing =
false;
367 d->dropOnPlace =
false;
368 d->autoResizeItems =
true;
370 d->lastClickedStorage = 0;
371 d->pollingRequestCount = 0;
372 d->delegate =
new KFilePlacesViewDelegate(
this);
374 setSelectionRectVisible(
false);
375 setSelectionMode(SingleSelection);
377 setDragEnabled(
true);
378 setAcceptDrops(
true);
379 setMouseTracking(
true);
380 setDropIndicatorShown(
false);
381 setFrameStyle(QFrame::NoFrame);
383 setResizeMode(Adjust);
384 setItemDelegate(d->delegate);
386 QPalette palette = viewport()->palette();
387 palette.setColor(viewport()->backgroundRole(), Qt::transparent);
388 palette.setColor(viewport()->foregroundRole(), palette.color(QPalette::WindowText));
389 viewport()->setPalette(palette);
391 connect(
this, SIGNAL(clicked(QModelIndex)),
392 this, SLOT(_k_placeClicked(QModelIndex)));
397 connect(&d->adaptItemsTimeline, SIGNAL(valueChanged(qreal)),
398 this, SLOT(_k_adaptItemsUpdate(qreal)));
399 d->adaptItemsTimeline.setDuration(500);
400 d->adaptItemsTimeline.setUpdateInterval(5);
401 d->adaptItemsTimeline.setCurveShape(QTimeLine::EaseInOutCurve);
403 connect(&d->itemAppearTimeline, SIGNAL(valueChanged(qreal)),
404 this, SLOT(_k_itemAppearUpdate(qreal)));
405 d->itemAppearTimeline.setDuration(500);
406 d->itemAppearTimeline.setUpdateInterval(5);
407 d->itemAppearTimeline.setCurveShape(QTimeLine::EaseInOutCurve);
409 connect(&d->itemDisappearTimeline, SIGNAL(valueChanged(qreal)),
410 this, SLOT(_k_itemDisappearUpdate(qreal)));
411 d->itemDisappearTimeline.setDuration(500);
412 d->itemDisappearTimeline.setUpdateInterval(5);
413 d->itemDisappearTimeline.setCurveShape(QTimeLine::EaseInOutCurve);
415 viewport()->installEventFilter(d->watcher);
416 connect(d->watcher, SIGNAL(entryEntered(QModelIndex)),
417 this, SLOT(_k_placeEntered(QModelIndex)));
418 connect(d->watcher, SIGNAL(entryLeft(QModelIndex)),
419 this, SLOT(_k_placeLeft(QModelIndex)));
421 d->pollDevices.setInterval(5000);
422 connect(&d->pollDevices, SIGNAL(
timeout()),
this, SLOT(_k_triggerDevicePolling()));
429 verticalScrollBar()->setAttribute(Qt::WA_OpaquePaintEvent,
false);
439 d->dropOnPlace = enabled;
444 return d->dropOnPlace;
449 d->autoResizeItems = enabled;
454 return d->autoResizeItems;
459 KUrl oldUrl = d->currentUrl;
462 if (placesModel==0)
return;
465 QModelIndex current = selectionModel()->currentIndex();
467 if (index.isValid()) {
468 if (current!=index && placesModel->
isHidden(current) && !d->showAll) {
469 KFilePlacesViewDelegate *delegate =
dynamic_cast<KFilePlacesViewDelegate*
>(itemDelegate());
470 delegate->addDisappearingItem(current);
472 if (d->itemDisappearTimeline.state()!=QTimeLine::Running) {
473 delegate->setDisappearingItemProgress(0.0);
474 d->itemDisappearTimeline.start();
478 if (current!=index && placesModel->
isHidden(index) && !d->showAll) {
479 KFilePlacesViewDelegate *delegate =
dynamic_cast<KFilePlacesViewDelegate*
>(itemDelegate());
480 delegate->addAppearingItem(index);
482 if (d->itemAppearTimeline.state()!=QTimeLine::Running) {
483 delegate->setAppearingItemProgress(0.0);
484 d->itemAppearTimeline.start();
487 setRowHidden(index.row(),
false);
491 selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect);
493 d->currentUrl =
KUrl();
494 selectionModel()->clear();
497 if (!current.isValid()) {
498 d->updateHiddenRows();
506 if (placesModel==0)
return;
508 d->showAll = showAll;
510 KFilePlacesViewDelegate *delegate =
dynamic_cast<KFilePlacesViewDelegate*
>(itemDelegate());
512 int rowCount = placesModel->
rowCount();
513 QModelIndex current = placesModel->
closestItem(d->currentUrl);
516 d->updateHiddenRows();
518 for (
int i=0; i<rowCount; ++i) {
519 QModelIndex index = placesModel->
index(i, 0);
520 if (index!=current && placesModel->
isHidden(index)) {
521 delegate->addAppearingItem(index);
525 if (d->itemAppearTimeline.state()!=QTimeLine::Running) {
526 delegate->setAppearingItemProgress(0.0);
527 d->itemAppearTimeline.start();
530 for (
int i=0; i<rowCount; ++i) {
531 QModelIndex index = placesModel->
index(i, 0);
532 if (index!=current && placesModel->
isHidden(index)) {
533 delegate->addDisappearingItem(index);
537 if (d->itemDisappearTimeline.state()!=QTimeLine::Running) {
538 delegate->setDisappearingItemProgress(0.0);
539 d->itemDisappearTimeline.start();
547 if ((event->key() == Qt::Key_Return) || (event->key() == Qt::Key_Enter)) {
548 d->_k_placeClicked(currentIndex());
555 KFilePlacesViewDelegate *delegate =
dynamic_cast<KFilePlacesViewDelegate*
>(itemDelegate());
557 if (placesModel==0)
return;
559 QModelIndex index = indexAt(event->pos());
572 if (index.isValid()) {
573 if (!placesModel->
isDevice(index)) {
574 if (placesModel->
url(index) ==
KUrl(
"trash:/")) {
575 emptyTrash = menu.addAction(
KIcon(
"trash-empty"),
i18nc(
"@action:inmenu",
"Empty Trash"));
577 emptyTrash->setEnabled(!trashConfig.
group(
"Status").
readEntry(
"Empty",
true));
580 add = menu.addAction(
KIcon(
"document-new"),
i18n(
"Add Entry..."));
581 mainSeparator = menu.addSeparator();
582 edit = menu.addAction(
KIcon(
"document-properties"),
i18n(
"&Edit Entry '%1'...", label));
586 eject->setParent(&menu);
587 menu.addAction(eject);
592 teardown->setParent(&menu);
593 menu.addAction(teardown);
596 if (teardown!=0 || eject!=0) {
597 mainSeparator = menu.addSeparator();
601 add = menu.addAction(
KIcon(
"document-new"),
i18n(
"Add Entry..."));
604 hide = menu.addAction(
i18n(
"&Hide Entry '%1'", label));
605 hide->setCheckable(
true);
606 hide->setChecked(placesModel->
isHidden(index));
608 add = menu.addAction(
KIcon(
"document-new"),
i18n(
"Add Entry..."));
613 showAll =
new QAction(
i18n(
"&Show All Entries"), &menu);
614 showAll->setCheckable(
true);
615 showAll->setChecked(d->showAll);
616 if (mainSeparator == 0) {
617 mainSeparator = menu.addSeparator();
619 menu.insertAction(mainSeparator, showAll);
623 if (index.isValid() && !placesModel->
isDevice(index)) {
624 remove = menu.addAction(
KIcon(
"edit-delete"),
i18n(
"&Remove Entry '%1'", label));
627 menu.addActions(actions());
629 if (menu.isEmpty()) {
633 QAction *result = menu.exec(event->globalPos());
635 if (emptyTrash != 0 && result == emptyTrash) {
636 const QString text =
i18nc(
"@info",
"Do you really want to empty the Trash? All items will be deleted.");
644 QByteArray packedArgs;
645 QDataStream stream(&packedArgs, QIODevice::WriteOnly);
650 connect(job, SIGNAL(result(
KJob*)), SLOT(_k_trashUpdated(
KJob*)));
652 }
else if (edit != 0 && result == edit) {
657 bool appLocal = !bookmark.
metaDataItem(
"OnlyInApp").isEmpty();
660 iconName,
false, appLocal, 64,
this))
665 placesModel->
editPlace(index, label, url, iconName, appName);
668 }
else if (
remove != 0 && result ==
remove) {
670 }
else if (hide != 0 && result == hide) {
672 QModelIndex current = placesModel->
closestItem(d->currentUrl);
674 if (index!=current && !d->showAll && hide->isChecked()) {
675 delegate->addDisappearingItem(index);
677 if (d->itemDisappearTimeline.state()!=QTimeLine::Running) {
678 delegate->setDisappearingItemProgress(0.0);
679 d->itemDisappearTimeline.start();
682 }
else if (showAll != 0 && result == showAll) {
684 }
else if (teardown != 0 && result == teardown) {
686 }
else if (eject != 0 && result == eject) {
688 }
else if (add != 0 && result == add) {
689 KUrl url = d->currentUrl;
692 bool appLocal =
true;
694 iconName,
true, appLocal, 64,
this))
699 placesModel->
addPlace(label, url, iconName, appName, index);
704 selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect);
716 QTimer::singleShot(100,
this, SLOT(_k_enableSmoothItemResizing()));
722 d->smoothItemResizing =
false;
730 KFilePlacesViewDelegate *delegate =
dynamic_cast<KFilePlacesViewDelegate*
>(itemDelegate());
731 delegate->setShowHoverIndication(
false);
733 d->dropRect =
QRect();
741 KFilePlacesViewDelegate *delegate =
dynamic_cast<KFilePlacesViewDelegate*
>(itemDelegate());
742 delegate->setShowHoverIndication(
true);
744 setDirtyRegion(d->dropRect);
752 const QPoint pos =
event->pos();
753 const QModelIndex index = indexAt(pos);
754 setDirtyRegion(d->dropRect);
755 if (index.isValid()) {
756 const QRect rect = visualRect(index);
757 const int gap = d->insertIndicatorHeight(rect.height());
758 if (d->insertAbove(rect, pos)) {
760 d->dropRect =
QRect(rect.left(), rect.top() - gap / 2,
762 }
else if (d->insertBelow(rect, pos)) {
764 d->dropRect =
QRect(rect.left(), rect.bottom() + 1 - gap / 2,
772 setDirtyRegion(d->dropRect);
777 const QPoint pos =
event->pos();
778 const QModelIndex index = indexAt(pos);
779 if (index.isValid()) {
780 const QRect rect = visualRect(index);
781 if (!d->insertAbove(rect, pos) && !d->insertBelow(rect, pos)) {
783 Q_ASSERT(placesModel != 0);
785 event->acceptProposedAction();
792 KFilePlacesViewDelegate *delegate =
dynamic_cast<KFilePlacesViewDelegate*
>(itemDelegate());
793 delegate->setShowHoverIndication(
true);
799 if (d->dragging && !d->dropRect.isEmpty()) {
801 QPainter painter(viewport());
803 const QModelIndex index = indexAt(d->dropRect.topLeft());
804 const QRect itemRect = visualRect(index);
805 const bool drawInsertIndicator = !d->dropOnPlace ||
806 d->dropRect.height() <= d->insertIndicatorHeight(itemRect.height());
808 if (drawInsertIndicator) {
810 QBrush blendedBrush = viewOptions().palette.brush(QPalette::Normal, QPalette::Highlight);
811 QColor color = blendedBrush.color();
813 const int y = (d->dropRect.top() + d->dropRect.bottom()) / 2;
814 const int thickness = d->dropRect.height() / 2;
815 Q_ASSERT(thickness >= 1);
817 const int alphaDec = alpha / (thickness + 1);
818 for (
int i = 0; i < thickness; i++) {
819 color.setAlpha(alpha);
821 painter.setPen(color);
822 painter.drawLine(d->dropRect.left(), y - i, d->dropRect.right(), y - i);
823 painter.drawLine(d->dropRect.left(), y + i, d->dropRect.right(), y + i);
827 QStyleOptionViewItemV4 opt;
830 opt.state = QStyle::State_Enabled | QStyle::State_MouseOver;
831 style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, &painter,
this);
839 d->updateHiddenRows();
844 connect(model, SIGNAL(rowsRemoved(QModelIndex,
int,
int)),
845 this, SLOT(adaptItemSize()), Qt::QueuedConnection);
846 connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
847 d->watcher, SLOT(currentIndexChanged(QModelIndex)));
855 KFilePlacesViewDelegate *delegate =
dynamic_cast<KFilePlacesViewDelegate*
>(itemDelegate());
858 for (
int i=start; i<=end; ++i) {
859 QModelIndex index = placesModel->
index(i, 0, parent);
860 if (d->showAll || !placesModel->
isHidden(index)) {
861 delegate->addAppearingItem(index);
863 setRowHidden(i,
true);
867 if (d->itemAppearTimeline.state()!=QTimeLine::Running) {
868 delegate->setAppearingItemProgress(0.0);
869 d->itemAppearTimeline.start();
882 QFontMetrics fm = d->q->fontMetrics();
885 for (
int i=0; i<placesModel->
rowCount(); ++i) {
886 QModelIndex index = placesModel->
index(i, 0);
888 textWidth = qMax(textWidth,fm.width(index.data(Qt::DisplayRole).toString()));
892 return QSize(iconSize + textWidth + fm.height() / 2, height);
895 void KFilePlacesView::Private::setCurrentIndex(
const QModelIndex &index)
899 if (placesModel==0)
return;
901 KUrl url = placesModel->
url(index);
906 emit q->urlChanged(url);
908 q->setShowAll(
false);
911 q->setUrl(currentUrl);
915 void KFilePlacesView::Private::adaptItemSize()
917 KFilePlacesViewDelegate *delegate =
dynamic_cast<KFilePlacesViewDelegate*
>(q->itemDelegate());
918 if (!delegate)
return;
920 if (!autoResizeItems) {
921 int size = q->iconSize().width();
922 delegate->setIconSize(size);
923 q->scheduleDelayedItemsLayout();
929 if (placesModel==0)
return;
931 int rowCount = placesModel->
rowCount();
936 QModelIndex current = placesModel->
closestItem(currentUrl);
938 if (placesModel->
isHidden(current)) {
943 if (rowCount==0)
return;
945 const int minSize = 16;
946 const int maxSize = 64;
949 QFontMetrics fm = q->fontMetrics();
950 for (
int i=0; i<placesModel->
rowCount(); ++i) {
951 QModelIndex index = placesModel->
index(i, 0);
954 textWidth = qMax(textWidth,fm.width(index.data(Qt::DisplayRole).toString()));
957 const int margin = q->style()->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, q) + 1;
958 const int maxWidth = q->viewport()->width() - textWidth - 4 * margin - 1;
959 const int maxHeight = ((q->height() - (fm.height() / 2) * rowCount) / rowCount) - 1;
961 int size = qMin(maxHeight, maxWidth);
965 }
else if (size>maxSize) {
972 if (size==delegate->iconSize())
return;
974 if (smoothItemResizing) {
975 oldSize = delegate->iconSize();
977 if (adaptItemsTimeline.state()!=QTimeLine::Running) {
978 adaptItemsTimeline.start();
981 delegate->setIconSize(size);
982 q->scheduleDelayedItemsLayout();
986 void KFilePlacesView::Private::updateHiddenRows()
990 if (placesModel==0)
return;
992 int rowCount = placesModel->
rowCount();
993 QModelIndex current = placesModel->
closestItem(currentUrl);
995 for (
int i=0; i<rowCount; ++i) {
996 QModelIndex index = placesModel->
index(i, 0);
997 if (index!=current && placesModel->
isHidden(index) && !showAll) {
998 q->setRowHidden(i,
true);
1000 q->setRowHidden(i,
false);
1007 bool KFilePlacesView::Private::insertAbove(
const QRect &itemRect,
const QPoint &pos)
const
1010 return pos.y() < itemRect.top() + insertIndicatorHeight(itemRect.height()) / 2;
1013 return pos.y() < itemRect.top() + (itemRect.height() / 2);
1016 bool KFilePlacesView::Private::insertBelow(
const QRect &itemRect,
const QPoint &pos)
const
1019 return pos.y() > itemRect.bottom() - insertIndicatorHeight(itemRect.height()) / 2;
1022 return pos.y() >= itemRect.top() + (itemRect.height() / 2);
1025 int KFilePlacesView::Private::insertIndicatorHeight(
int itemHeight)
const
1030 int height = itemHeight / 4;
1033 }
else if (height > max) {
1039 void KFilePlacesView::Private::fadeCapacityBar(
const QModelIndex &index, FadeType fadeType)
1041 QTimeLine *timeLine = delegate->fadeAnimationForIndex(index);
1043 delegate->removeFadeAnimation(index);
1044 timeLine =
new QTimeLine(250, q);
1045 connect(timeLine, SIGNAL(valueChanged(qreal)), q, SLOT(_k_capacityBarFadeValueChanged()));
1046 if (fadeType == FadeIn) {
1047 timeLine->setDirection(QTimeLine::Forward);
1048 timeLine->setCurrentTime(0);
1050 timeLine->setDirection(QTimeLine::Backward);
1051 timeLine->setCurrentTime(250);
1053 delegate->addFadeAnimation(index, timeLine);
1057 void KFilePlacesView::Private::_k_placeClicked(
const QModelIndex &index)
1061 if (placesModel==0)
return;
1063 lastClickedIndex = QPersistentModelIndex();
1066 QObject::connect(placesModel, SIGNAL(setupDone(QModelIndex,
bool)),
1067 q, SLOT(_k_storageSetupDone(QModelIndex,
bool)));
1069 lastClickedIndex = index;
1074 setCurrentIndex(index);
1077 void KFilePlacesView::Private::_k_placeEntered(
const QModelIndex &index)
1079 fadeCapacityBar(index, FadeIn);
1080 pollingRequestCount++;
1081 if (pollingRequestCount == 1) {
1082 pollDevices.start();
1086 void KFilePlacesView::Private::_k_placeLeft(
const QModelIndex &index)
1088 fadeCapacityBar(index, FadeOut);
1089 pollingRequestCount--;
1090 if (!pollingRequestCount) {
1095 void KFilePlacesView::Private::_k_storageSetupDone(
const QModelIndex &index,
bool success)
1097 if (index!=lastClickedIndex) {
1103 QObject::disconnect(placesModel, SIGNAL(setupDone(QModelIndex,
bool)),
1104 q, SLOT(_k_storageSetupDone(QModelIndex,
bool)));
1107 setCurrentIndex(lastClickedIndex);
1109 q->setUrl(currentUrl);
1112 lastClickedIndex = QPersistentModelIndex();
1115 void KFilePlacesView::Private::_k_adaptItemsUpdate(qreal value)
1117 int add = (endSize-oldSize)*value;
1119 int size = oldSize+add;
1121 KFilePlacesViewDelegate *delegate =
dynamic_cast<KFilePlacesViewDelegate*
>(q->itemDelegate());
1122 delegate->setIconSize(size);
1123 q->scheduleDelayedItemsLayout();
1126 void KFilePlacesView::Private::_k_itemAppearUpdate(qreal value)
1128 KFilePlacesViewDelegate *delegate =
dynamic_cast<KFilePlacesViewDelegate*
>(q->itemDelegate());
1130 delegate->setAppearingItemProgress(value);
1131 q->scheduleDelayedItemsLayout();
1134 void KFilePlacesView::Private::_k_itemDisappearUpdate(qreal value)
1136 KFilePlacesViewDelegate *delegate =
dynamic_cast<KFilePlacesViewDelegate*
>(q->itemDelegate());
1138 delegate->setDisappearingItemProgress(value);
1144 q->scheduleDelayedItemsLayout();
1147 void KFilePlacesView::Private::_k_enableSmoothItemResizing()
1149 smoothItemResizing =
true;
1152 void KFilePlacesView::Private::_k_trashUpdated(
KJob *job)
1155 static_cast<KIO::Job*
>(job)->ui()->showErrorMessage();
1157 org::kde::KDirNotify::emitFilesAdded(
"trash:/");
1160 void KFilePlacesView::Private::_k_capacityBarFadeValueChanged()
1162 const QModelIndex index = delegate->indexForFadeAnimation(static_cast<QTimeLine*>(q->sender()));
1163 if (!index.isValid()) {
1169 void KFilePlacesView::Private::_k_triggerDevicePolling()
1171 const QModelIndex hoveredIndex = watcher->hoveredIndex();
1172 if (hoveredIndex.isValid()) {
1174 if (placesModel->
isDevice(hoveredIndex)) {
1175 q->update(hoveredIndex);
1178 const QModelIndex focusedIndex = watcher->focusedIndex();
1179 if (focusedIndex.isValid() && focusedIndex != hoveredIndex) {
1181 if (placesModel->
isDevice(focusedIndex)) {
1182 q->update(focusedIndex);
1193 #include "kfileplacesview.moc"
1194 #include "kfileplacesview_p.moc"