KFilePreviewGenerator::KFilePreviewGenerator(QAbstractItemView* parent, KDirSortFilterProxyModel* model) :
QObject(parent),
- m_showPreview(false),
+ m_showPreview(true),
m_clearItemQueues(true),
m_hasCutSelection(false),
m_pendingVisiblePreviews(0),
m_pendingItems(),
m_dispatchedItems()
{
- Q_ASSERT(m_view->iconSize().isValid()); // each view must provide its current icon size
+ if (!m_view->iconSize().isValid()) {
+ m_showPreview = false;
+ }
m_dirModel = static_cast<KDirModel*>(m_proxyModel->sourceModel());
connect(m_dirModel->dirLister(), SIGNAL(newItems(const KFileItemList&)),
void KFilePreviewGenerator::setShowPreview(bool show)
{
+ if (show && !m_view->iconSize().isValid()) {
+ // the view must provide an icon size, otherwise the showing
+ // off previews will get ignored
+ return;
+ }
+
if (m_showPreview != show) {
m_showPreview = show;
m_cutItemsCache.clear();
class QAbstractItemView;
/**
- * @brief Manages the icon state of a directory model.
+ * @brief Generates previews for files of an item view.
*
* Per default a preview is generated for each item.
* Additionally the clipboard is checked for cut items.
Q_OBJECT
public:
+ /**
+ * @param parent Item view containing the file items where previews should
+ * be generated. It is mandatory that the item view specifies
+ * an icon size by QAbstractItemView::setIconSize(), otherwise
+ * no previews will be generated.
+ * @param model Model of the item view.
+ */
KFilePreviewGenerator(QAbstractItemView* parent, KDirSortFilterProxyModel* model);
virtual ~KFilePreviewGenerator();
+
+ /**
+ * If \a show is set to true, a preview is generated for each item. If \a show
+ * is false, the MIME type icon of the item is shown instead. Per default showing
+ * of the preview is turned on. Note that it is mandatory that the item view
+ * specifies an icon size by QAbstractItemView::setIconSize(), otherwise
+ * KFilePreviewGenerator::showPreview() will always return false.
+ */
void setShowPreview(bool show);
bool showPreview() const;
/**
- * Updates the previews for all already available items. It is only necessary
- * to invoke this method when the icon size of the abstract item view has
- * been changed.
+ * Updates the previews for all already available items. Usually It is only
+ * necessary to invoke this method when the icon size of the abstract item view
+ * has been changed by QAbstractItemView::setIconSize().
*/
void updatePreviews();
- /**
- * Cancels all pending previews. Should be invoked when the URL of the item
- * view has been changed.
- */
+ /** Cancels all pending previews. */
void cancelPreviews();
private slots: