// #define KFILEITEMLISTVIEW_DEBUG
namespace {
+ // If the visible index range changes, KFileItemModelRolesUpdater is not
+ // informed immediatetly, but with a short delay. This ensures that scrolling
+ // always feels smooth and is not interrupted by icon loading (which can be
+ // quite expensive if a disk access is required to determine the final icon).
const int ShortInterval = 50;
+
+ // If the icon size changes, a longer delay is used. This prevents that
+ // the expensive re-generation of all previews is triggered repeatedly when
+ // chaning the zoom level.
const int LongInterval = 300;
}
m_updateIconSizeTimer = new QTimer(this);
m_updateIconSizeTimer->setSingleShot(true);
- m_updateIconSizeTimer->setInterval(ShortInterval);
+ m_updateIconSizeTimer->setInterval(LongInterval);
connect(m_updateIconSizeTimer, SIGNAL(timeout()), this, SLOT(updateIconSize()));
setVisibleRoles(QList<QByteArray>() << "text");
void KFileItemListView::slotItemsRemoved(const KItemRangeList& itemRanges)
{
KStandardItemListView::slotItemsRemoved(itemRanges);
- updateTimersInterval();
}
void KFileItemListView::slotSortRoleChanged(const QByteArray& current, const QByteArray& previous)
return;
}
m_modelRolesUpdater->setPaused(true);
- m_updateVisibleIndexRangeTimer->start();
+
+ // If the icon size has been changed recently, wait until
+ // m_updateIconSizeTimer expires.
+ if (!m_updateIconSizeTimer->isActive()) {
+ m_updateVisibleIndexRangeTimer->start();
+ }
}
void KFileItemListView::updateVisibleIndexRange()
const int count = lastVisibleIndex() - index + 1;
m_modelRolesUpdater->setMaximumVisibleItems(maximumVisibleItems());
m_modelRolesUpdater->setVisibleIndexRange(index, count);
-
- if (m_updateIconSizeTimer->isActive()) {
- // If the icon-size update is pending do an immediate update
- // of the icon-size before unpausing m_modelRolesUpdater. This prevents
- // an unnecessary expensive recreation of all previews afterwards.
- m_updateIconSizeTimer->stop();
- m_modelRolesUpdater->setIconSize(availableIconSize());
- }
-
m_modelRolesUpdater->setPaused(isTransactionActive());
- updateTimersInterval();
}
void KFileItemListView::triggerIconSizeUpdate()
}
m_modelRolesUpdater->setPaused(true);
m_updateIconSizeTimer->start();
+
+ // The visible index range will be updated when m_updateIconSizeTimer expires.
+ // Stop m_updateVisibleIndexRangeTimer to prevent an expensive re-generation
+ // of all previews (note that the user might change the icon size again soon).
+ m_updateVisibleIndexRangeTimer->stop();
}
void KFileItemListView::updateIconSize()
m_modelRolesUpdater->setIconSize(availableIconSize());
- if (m_updateVisibleIndexRangeTimer->isActive()) {
- // If the visibility-index-range update is pending do an immediate update
- // of the range before unpausing m_modelRolesUpdater. This prevents
- // an unnecessary expensive recreation of all previews afterwards.
- m_updateVisibleIndexRangeTimer->stop();
- const int index = firstVisibleIndex();
- const int count = lastVisibleIndex() - index + 1;
- m_modelRolesUpdater->setVisibleIndexRange(index, count);
- }
+ // Update the visible index range (which has most likely changed after the
+ // icon size change) before unpausing m_modelRolesUpdater.
+ const int index = firstVisibleIndex();
+ const int count = lastVisibleIndex() - index + 1;
+ m_modelRolesUpdater->setVisibleIndexRange(index, count);
m_modelRolesUpdater->setPaused(isTransactionActive());
- updateTimersInterval();
-}
-
-void KFileItemListView::updateTimersInterval()
-{
- if (!model()) {
- return;
- }
-
- // The ShortInterval is used for cases like switching the directory: If the
- // model is empty and filled later the creation of the previews should be done
- // as soon as possible. The LongInterval is used when the model already contains
- // items and assures that operations like zooming don't result in too many temporary
- // recreations of the previews.
-
- const int interval = (model()->count() <= 0) ? ShortInterval : LongInterval;
- m_updateVisibleIndexRangeTimer->setInterval(interval);
- m_updateIconSizeTimer->setInterval(interval);
}
void KFileItemListView::applyRolesToModel()
#include "statusbarspaceinfo.h"
#include <QApplication>
-#include <QClipboard>
#include <QHBoxLayout>
#include <QLabel>
#include <QProgressBar>
KMenu menu(this);
- QAction* copyAction = menu.addAction(i18nc("@action:inmenu", "Copy Text"));
QAction* showZoomSliderAction = menu.addAction(i18nc("@action:inmenu", "Show Zoom Slider"));
showZoomSliderAction->setCheckable(true);
showZoomSliderAction->setChecked(GeneralSettings::showZoomSlider());
showSpaceInfoAction->setChecked(GeneralSettings::showSpaceInfo());
const QAction* action = menu.exec(QCursor::pos());
- if (action == copyAction) {
- QMimeData* mimeData = new QMimeData();
- mimeData->setText(text());
- QApplication::clipboard()->setMimeData(mimeData);
- } else if (action == showZoomSliderAction) {
+ if (action == showZoomSliderAction) {
const bool visible = showZoomSliderAction->isChecked();
GeneralSettings::setShowZoomSlider(visible);
m_zoomSlider->setVisible(visible);