X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/d8669c68e40a6571dfcbdf38e3281a4aeb8c2be6..524eff1a245758f2b1111595a1ef3fc20dabeb1f:/src/dolphiniconsview.cpp diff --git a/src/dolphiniconsview.cpp b/src/dolphiniconsview.cpp index 98d1a05b1..d89bb3650 100644 --- a/src/dolphiniconsview.cpp +++ b/src/dolphiniconsview.cpp @@ -1,6 +1,5 @@ /*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * peter.penz@gmx.at * + * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -19,16 +18,49 @@ ***************************************************************************/ #include "dolphiniconsview.h" -#include "dolphinview.h" +#include "dolphincontroller.h" +#include "dolphinsettings.h" + +#include "dolphin_iconsmodesettings.h" + +#include #include #include -DolphinIconsView::DolphinIconsView(DolphinView* parent) : +#include + +DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controller) : QListView(parent), - m_parentView( parent ) + m_controller(controller) { + assert(controller != 0); + setViewMode(QListView::IconMode); setResizeMode(QListView::Adjust); + + connect(this, SIGNAL(clicked(const QModelIndex&)), + controller, SLOT(triggerItem(const QModelIndex&))); + + // apply the icons mode settings to the widget + const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); + 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); + + if (settings->arrangement() == QListView::TopToBottom) { + setFlow(QListView::TopToBottom); + m_viewOptions.decorationPosition = QStyleOptionViewItem::Top; + } + else { + setFlow(QListView::LeftToRight); + m_viewOptions.decorationPosition = QStyleOptionViewItem::Left; + } } DolphinIconsView::~DolphinIconsView() @@ -37,38 +69,38 @@ DolphinIconsView::~DolphinIconsView() QStyleOptionViewItem DolphinIconsView::viewOptions() const { - return QListView::viewOptions(); - - // TODO: the view options should been read from the settings; - // the following code is just for testing... - //QStyleOptionViewItem options = QListView::viewOptions(); - //options.decorationAlignment = Qt::AlignRight; - //options.decorationPosition = QStyleOptionViewItem::Right; - //options.decorationSize = QSize(100, 100); - //options.showDecorationSelected = true; - //options.state = QStyle::State_MouseOver; - //return options; + return m_viewOptions; } void DolphinIconsView::contextMenuEvent(QContextMenuEvent* event) { QListView::contextMenuEvent(event); + m_controller->triggerContextMenuRequest(event->pos()); +} - KFileItem* item = 0; +void DolphinIconsView::mouseReleaseEvent(QMouseEvent* event) +{ + QListView::mouseReleaseEvent(event); + m_controller->triggerActivation(); +} - const QModelIndex index = indexAt(event->pos()); - if (index.isValid()) { - KDirModel* dirModel = static_cast(model()); - item = dirModel->itemForIndex(index); +void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event) +{ + if (event->mimeData()->hasUrls()) { + event->acceptProposedAction(); } - - m_parentView->openContextMenu(item, event->globalPos()); } -void DolphinIconsView::mouseReleaseEvent(QMouseEvent* event) +void DolphinIconsView::dropEvent(QDropEvent* event) { - QListView::mouseReleaseEvent(event); - m_parentView->declareViewActive(); + const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData()); + if (urls.isEmpty() || (event->source() == this)) { + QListView::dropEvent(event); + } + else { + event->acceptProposedAction(); + m_controller->indicateDroppedUrls(urls, event->pos()); + } } #include "dolphiniconsview.moc"