#include "dolphin_iconsmodesettings.h"
-#include <kdirmodel.h>
-#include <kfileitem.h>
-#include <kfileitemdelegate.h>
+#include <kdialog.h>
-#include <QtGui/QAbstractProxyModel>
-#include <QtCore/QPoint>
+#include <QAbstractProxyModel>
+#include <QApplication>
+#include <QPainter>
+#include <QPoint>
DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controller) :
- KListView(parent),
- m_controller(controller)
+ KCategorizedView(parent),
+ m_controller(controller),
+ m_itemSize(),
+ m_dragging(false),
+ m_dropRect()
{
Q_ASSERT(controller != 0);
setViewMode(QListView::IconMode);
setResizeMode(QListView::Adjust);
-
+ setSpacing(KDialog::spacingHint());
setMouseTracking(true);
viewport()->setAttribute(Qt::WA_Hover);
connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
controller, SLOT(triggerItem(const QModelIndex&)));
}
- connect(this, SIGNAL(activated(const QModelIndex&)),
- controller, SLOT(triggerItem(const QModelIndex&)));
connect(this, SIGNAL(entered(const QModelIndex&)),
controller, SLOT(emitItemEntered(const QModelIndex&)));
connect(this, SIGNAL(viewportEntered()),
const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
Q_ASSERT(settings != 0);
- m_viewOptions = KListView::viewOptions();
+ m_viewOptions = KCategorizedView::viewOptions();
m_viewOptions.showDecorationSelected = true;
QFont font(settings->fontFamily(), settings->fontSize());
{
}
+QRect DolphinIconsView::visualRect(const QModelIndex& index) const
+{
+ const bool leftToRightFlow = (flow() == QListView::LeftToRight);
+
+ QRect itemRect = KCategorizedView::visualRect(index);
+ const int maxWidth = m_itemSize.width();
+ const int maxHeight = m_itemSize.height();
+
+ if (itemRect.width() > maxWidth) {
+ // assure that the maximum item width is not exceeded
+ if (leftToRightFlow) {
+ const int left = itemRect.left() + (itemRect.width() - maxWidth) / 2;
+ itemRect.setLeft(left);
+ }
+ itemRect.setWidth(maxWidth);
+ }
+
+ if (itemRect.height() > maxHeight) {
+ // assure that the maximum item height is not exceeded
+ if (!leftToRightFlow) {
+ const int top = itemRect.top() + (itemRect.height() - maxHeight) / 2;
+ itemRect.setTop(top);
+ }
+ itemRect.setHeight(maxHeight);
+ }
+
+ return itemRect;
+}
+
QStyleOptionViewItem DolphinIconsView::viewOptions() const
{
return m_viewOptions;
void DolphinIconsView::contextMenuEvent(QContextMenuEvent* event)
{
- KListView::contextMenuEvent(event);
+ KCategorizedView::contextMenuEvent(event);
m_controller->triggerContextMenuRequest(event->pos());
}
-void DolphinIconsView::mouseReleaseEvent(QMouseEvent* event)
+void DolphinIconsView::mousePressEvent(QMouseEvent* event)
{
- KListView::mouseReleaseEvent(event);
m_controller->triggerActivation();
+ if (!indexAt(event->pos()).isValid()) {
+ const Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
+ if (!(modifier & Qt::ShiftModifier) && !(modifier & Qt::ControlModifier)) {
+ clearSelection();
+ }
+ }
+
+ KCategorizedView::mousePressEvent(event);
}
void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event)
if (event->mimeData()->hasUrls()) {
event->acceptProposedAction();
}
+ m_dragging = true;
+}
+
+void DolphinIconsView::dragLeaveEvent(QDragLeaveEvent* event)
+{
+ KCategorizedView::dragLeaveEvent(event);
+
+ // TODO: remove this code when the issue #160611 is solved in Qt 4.4
+ m_dragging = false;
+ setDirtyRegion(m_dropRect);
+}
+
+void DolphinIconsView::dragMoveEvent(QDragMoveEvent* event)
+{
+ KCategorizedView::dragMoveEvent(event);
+
+ // TODO: remove this code when the issue #160611 is solved in Qt 4.4
+ const QModelIndex index = indexAt(event->pos());
+ setDirtyRegion(m_dropRect);
+ m_dropRect = visualRect(index);
+ setDirtyRegion(m_dropRect);
}
void DolphinIconsView::dropEvent(QDropEvent* event)
{
- const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
- if (!urls.isEmpty()) {
- m_controller->indicateDroppedUrls(urls,
- indexAt(event->pos()),
- event->source());
- event->acceptProposedAction();
+ if (!selectionModel()->isSelected(indexAt(event->pos()))) {
+ const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
+ if (!urls.isEmpty()) {
+ m_controller->indicateDroppedUrls(urls,
+ indexAt(event->pos()),
+ event->source());
+ event->acceptProposedAction();
+ }
+ }
+ KCategorizedView::dropEvent(event);
+ m_dragging = false;
+}
+
+void DolphinIconsView::paintEvent(QPaintEvent* event)
+{
+ KCategorizedView::paintEvent(event);
+
+ // TODO: remove this code when the issue #160611 is solved in Qt 4.4
+ if (m_dragging) {
+ const QBrush& brush = m_viewOptions.palette.brush(QPalette::Normal, QPalette::Highlight);
+ DolphinController::drawHoverIndication(viewport(), m_dropRect, brush);
}
- KListView::dropEvent(event);
}
void DolphinIconsView::slotShowPreviewChanged(bool showPreview)
const int spacing = settings->gridSpacing();
setGridSize(QSize(itemWidth + spacing, itemHeight + spacing));
+ m_itemSize = QSize(itemWidth, itemHeight);
+
m_controller->setZoomInPossible(isZoomInPossible());
m_controller->setZoomOutPossible(isZoomOutPossible());
}