#include "dolphincontroller.h"
DolphinController::DolphinController(QObject* parent) :
- QObject(parent)
+ QObject(parent),
+ m_showPreview(false)
{
}
emit sortOrderChanged(order);
}
+void DolphinController::setShowPreview(bool showPreview)
+{
+ if (m_showPreview != showPreview) {
+ m_showPreview = showPreview;
+ emit showPreviewChanged(showPreview);
+ }
+}
+
void DolphinController::triggerItem(const QModelIndex& index)
{
emit itemTriggered(index);
void indicateSortOrderChange(Qt::SortOrder order);
+ void setShowPreview(bool showPreview);
+ bool showPreview() const { return m_showPreview; }
+
public slots:
void triggerItem(const QModelIndex& index);
void indicateSelectionChange();
/** Is emitted if the sort order has been changed to \a sort order. */
void sortOrderChanged(Qt::SortOrder order);
+ /**
+ * Is emitted if the state for showing previews has been
+ * changed to \a showPreview.
+ */
+ void showPreviewChanged(bool showPreview);
+
/**
* Is emitted if the item with the index \a index should be triggered.
* Usually triggering on a directory opens the directory, triggering
void selectionChanged();
private:
+ bool m_showPreview;
KUrl m_url;
};
connect(this, SIGNAL(clicked(const QModelIndex&)),
controller, SLOT(triggerItem(const QModelIndex&)));
- // apply the details mode settings to the widget
+ // apply the details mode settings to the widget
const DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
assert(settings != 0);
QListView(parent),
m_controller(controller)
{
- assert(controller != 0);
+ Q_ASSERT(controller != 0);
setViewMode(QListView::IconMode);
setResizeMode(QListView::Adjust);
connect(this, SIGNAL(clicked(const QModelIndex&)),
controller, SLOT(triggerItem(const QModelIndex&)));
+ connect(controller, SIGNAL(showPreviewChanged(bool)),
+ this, SLOT(updateGridSize(bool)));
// apply the icons mode settings to the widget
const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
- assert(settings != 0);
+ Q_ASSERT(settings != 0);
- setGridSize(QSize(settings->gridWidth(), settings->gridHeight()));
setSpacing(settings->gridSpacing());
m_viewOptions = QListView::viewOptions();
m_viewOptions.font = QFont(settings->fontFamily(), settings->fontSize());
- const int iconSize = settings->iconSize();
- m_viewOptions.decorationSize = QSize(iconSize, iconSize);
+ updateGridSize(controller->showPreview());
if (settings->arrangement() == QListView::TopToBottom) {
setFlow(QListView::LeftToRight);
}
}
+void DolphinIconsView::updateGridSize(bool showPreview)
+{
+ const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
+ Q_ASSERT(settings != 0);
+
+ int gridWidth = settings->gridWidth();
+ int gridHeight = settings->gridHeight();
+ int size = settings->iconSize();
+
+ if (showPreview) {
+ const int previewSize = settings->previewSize();
+ const int diff = previewSize - size;
+ Q_ASSERT(diff >= 0);
+ gridWidth += diff;
+ gridHeight += diff;
+
+ size = previewSize;
+ }
+
+
+ m_viewOptions.decorationSize = QSize(size, size);
+ setGridSize(QSize(gridWidth, gridHeight));
+}
+
#include "dolphiniconsview.moc"
virtual void dragEnterEvent(QDragEnterEvent* event);
virtual void dropEvent(QDropEvent* event);
+private slots:
+ /**
+ * Updates the size of the grid
+ * depending on the state of \a showPreview.
+ */
+ void updateGridSize(bool showPreview);
+
private:
DolphinController* m_controller;
QStyleOptionViewItem m_viewOptions;
updateViewActions();\r
}\r
\r
+void DolphinMainWindow::slowShowPreviewChanged()\r
+{\r
+ KToggleAction* showPreviewAction =\r
+ static_cast<KToggleAction*>(actionCollection()->action("show_preview"));\r
+ showPreviewAction->setChecked(m_activeView->showPreview());\r
+}\r
+\r
void DolphinMainWindow::slotShowHiddenFilesChanged()\r
{\r
KToggleAction* showHiddenFilesAction =\r
static_cast<KToggleAction*>(actionCollection()->action("show_filter_bar"));\r
showFilterBarAction->setChecked(m_activeView->isFilterBarVisible());\r
\r
+ KToggleAction* showPreviewAction =\r
+ static_cast<KToggleAction*>(actionCollection()->action("show_preview"));\r
+ showPreviewAction->setChecked(m_activeView->showPreview());\r
+\r
KToggleAction* showHiddenFilesAction =\r
static_cast<KToggleAction*>(actionCollection()->action("show_hidden_files"));\r
showHiddenFilesAction->setChecked(m_activeView->showHiddenFiles());\r
DolphinView* view = m_view[viewIndex];\r
connect(view, SIGNAL(modeChanged()),\r
this, SLOT(slotViewModeChanged()));\r
+ connect(view, SIGNAL(showPreviewChanged()),\r
+ this, SLOT(slowShowPreviewChanged()));\r
connect(view, SIGNAL(showHiddenFilesChanged()),\r
this, SLOT(slotShowHiddenFilesChanged()));\r
connect(view, SIGNAL(sortingChanged(DolphinView::Sorting)),\r
/** Updates the state of all 'View' menu actions. */
void slotViewModeChanged();
+ /** Updates the state of the 'Show preview' menu action. */
+ void slowShowPreviewChanged();
+
/** Updates the state of the 'Show hidden files' menu action. */
void slotShowHiddenFilesChanged();
#include <klocale.h>
#include <kio/netaccess.h>
#include <kio/renamedialog.h>
+#include <kio/previewjob.h>
#include <kmimetyperesolver.h>
#include <konq_operations.h>
#include <kurl.h>
this, SLOT(updateStatusBar()));
connect(m_dirLister, SIGNAL(completed()),
this, SLOT(updateItemCount()));
+ connect(m_dirLister, SIGNAL(newItems(const KFileItemList&)),
+ this, SLOT(generatePreviews(const KFileItemList&)));
connect(m_dirLister, SIGNAL(infoMessage(const QString&)),
this, SLOT(showInfoMessage(const QString&)));
connect(m_dirLister, SIGNAL(errorMessage(const QString&)),
ViewProperties props(m_urlNavigator->url());
props.setShowPreview(show);
- // TODO: wait until previews are possible with KFileItemDelegate
+ m_controller->setShowPreview(show);
emit showPreviewChanged();
+ reload();
}
bool DolphinView::showPreview() const
{
- // TODO: wait until previews are possible with KFileItemDelegate
- return true;
+ return m_controller->showPreview();
}
void DolphinView::setShowHiddenFiles(bool show)
// Our view has a selection, we will map them back to the DirModel
// and then fill the KFileItemList.
- assert((view != 0) && (view->selectionModel() != 0));
+ Q_ASSERT((view != 0) && (view->selectionModel() != 0));
const QItemSelection selection = m_proxyModel->mapSelectionToSource(view->selectionModel()->selection());
KFileItemList itemList;
const QModelIndexList indexList = selection.indexes();
QModelIndexList::const_iterator end = indexList.end();
for (QModelIndexList::const_iterator it = indexList.begin(); it != end; ++it) {
- assert((*it).isValid());
+ Q_ASSERT((*it).isValid());
KFileItem* item = m_dirModel->itemForIndex(*it);
if (item != 0) {
emit sortOrderChanged(sortOrder);
}
- // TODO: handle previews (props.showPreview())
+ const bool showPreview = props.showPreview();
+ if (showPreview != m_controller->showPreview()) {
+ m_controller->setShowPreview(showPreview);
+ emit showPreviewChanged();
+ }
startDirLister(url);
emit urlChanged(url);
QTimer::singleShot(0, this, SLOT(restoreContentsPos()));
}
+void DolphinView::generatePreviews(const KFileItemList& items)
+{
+ if (m_controller->showPreview()) {
+ KIO::PreviewJob* job = KIO::filePreview(items, 128);
+ connect(job, SIGNAL(gotPreview(const KFileItem*, const QPixmap&)),
+ this, SLOT(showPreview(const KFileItem*, const QPixmap&)));
+ }
+}
+
+void DolphinView::showPreview(const KFileItem* item, const QPixmap& pixmap)
+{
+ const QModelIndex idx = m_dirModel->indexForItem(item);
+ Q_ASSERT(idx.isValid());
+ Q_ASSERT(idx.column() == 0);
+ m_dirModel->setData(idx, pixmap, Qt::DecorationRole);
+}
+
void DolphinView::restoreContentsPos()
{
int index = 0;
QAbstractItemView* DolphinView::itemView() const
{
- assert((m_iconsView == 0) || (m_detailsView == 0));
+ Q_ASSERT((m_iconsView == 0) || (m_detailsView == 0));
if (m_detailsView != 0) {
return m_detailsView;
}
*/
void updateItemCount();
+ /**
+ * Generates a preview image for each file item in \a items.
+ * The current preview settings (maximum size, 'Show Preview' menu)
+ * are respected.
+ */
+ void generatePreviews(const KFileItemList& items);
+
+ /**
+ * Replaces the icon of the item \a item by the preview pixmap
+ * \a pixmap.
+ */
+ void showPreview(const KFileItem* item, const QPixmap& pixmap);
+
/**
* Restores the x- and y-position of the contents if the
* current view is part of the history.
const int defaultSize = iconSize(m_iconSizeSlider->value());
settings->setIconSize(defaultSize);
- int previewSize = //(m_mode == DolphinIconsView::Previews) ?
- //iconSize(m_previewSizeSlider->value()) :
- defaultSize;
+ int previewSize = iconSize(m_previewSizeSlider->value());
if (previewSize < defaultSize) {
// assure that the preview size is never smaller than the icon size
previewSize = defaultSize;