#include "dolphincolumnview.h"
#include "dolphincontroller.h"
#include "dolphinsortfilterproxymodel.h"
+#include "draganddrophelper.h"
#include "settings/dolphinsettings.h"
#include "dolphin_columnmodesettings.h"
m_contentX(0),
m_columns(),
m_emptyViewport(0),
- m_animation(0)
+ m_animation(0),
+ m_dragSource(0)
{
Q_ASSERT(controller != 0);
setFrameShape(QFrame::NoFrame);
setLayoutDirection(Qt::LeftToRight);
- //connect(this, SIGNAL(viewportEntered()),
- // controller, SLOT(emitViewportEntered()));
connect(controller, SIGNAL(activationChanged(bool)),
this, SLOT(updateColumnsBackground(bool)));
DolphinColumnViewContainer::~DolphinColumnViewContainer()
{
+ delete m_dragSource;
+ m_dragSource = 0;
}
KUrl DolphinColumnViewContainer::rootUrl() const
void DolphinColumnViewContainer::deleteColumn(DolphinColumnView* column)
{
- if (column != 0) {
- if (m_controller->itemView() == column) {
- m_controller->setItemView(0);
+ if (column == 0) {
+ return;
+ }
+
+ if (m_controller->itemView() == column) {
+ m_controller->setItemView(0);
+ }
+ // deleteWhenNotDragSource(column) does not necessarily delete column,
+ // and we want its preview generator destroyed immediately.
+ column->hide();
+ // Prevent automatic destruction of column when this DolphinColumnViewContainer
+ // is destroyed.
+ column->setParent(0);
+ column->disconnect();
+
+ if (DragAndDropHelper::instance().isDragSource(column)) {
+ // The column is a drag source (the feature "Open folders
+ // during drag operations" is used). Deleting the view
+ // during an ongoing drag operation is not allowed, so
+ // this will postponed.
+ if (m_dragSource != 0) {
+ // the old stored view is obviously not the drag source anymore
+ m_dragSource->deleteLater();
+ m_dragSource = 0;
}
- // deleteWhenNotDragSource(column) does not necessarily delete column,
- // and we want its preview generator destroyed immediately.
column->hide();
- // Prevent automatic destruction of column when this DolphinColumnViewContainer
- // is destroyed.
column->setParent(0);
column->disconnect();
- //emit requestColumnDeletion(column);
+ m_dragSource = column;
+ } else {
column->deleteLater();
}
}
*/
void showColumn(const KUrl& url);
-signals:
- /**
- * Requests that the given column be deleted at the discretion
- * of the receiver of the signal.
- */
- void requestColumnDeletion(QAbstractItemView* column);
-
protected:
virtual void mousePressEvent(QMouseEvent* event);
virtual void keyPressEvent(QKeyEvent* event);
QList<DolphinColumnView*> m_columns;
QFrame* m_emptyViewport;
QTimeLine* m_animation;
+ QAbstractItemView* m_dragSource;
friend class DolphinColumnView;
};
m_extensionsFactory = new ViewExtensionsFactory(this, controller);
m_extensionsFactory->fileItemDelegate()->setMinimizedNameColumn(true);
+ m_extensionsFactory->setAutoFolderExpandingEnabled(settings->expandableFolders());
updateDecorationSize(view->showPreview());
}
#include "dolphiniconsview.h"
#include "dolphin_generalsettings.h"
#include "draganddrophelper.h"
-#include "folderexpander.h"
#include "renamedialog.h"
#include "settings/dolphinsettings.h"
#include "viewproperties.h"
m_activeItemUrl(),
m_createdItemUrl(),
m_selectedItems(),
- m_newFileNames(),
- m_expandedDragSource(0)
+ m_newFileNames()
{
m_topLayout = new QVBoxLayout(this);
m_topLayout->setSpacing(0);
DolphinView::~DolphinView()
{
- delete m_expandedDragSource;
- m_expandedDragSource = 0;
}
const KUrl& DolphinView::url() const
}
break;
- case QEvent::MouseButtonPress:
- if ((watched == m_viewAccessor.itemView()->viewport()) && (m_expandedDragSource != 0)) {
- // Listening to a mousebutton press event to delete expanded views is a
- // workaround, as it seems impossible for the FolderExpander to know when
- // a dragging outside a view has been finished. However it works quite well:
- // A mousebutton press event indicates that a drag operation must be
- // finished already.
- m_expandedDragSource->deleteLater();
- m_expandedDragSource = 0;
- }
- break;
-
case QEvent::DragEnter:
if (watched == m_viewAccessor.itemView()->viewport()) {
setActive(true);
return m_viewAccessor.itemsExpandable();
}
-void DolphinView::deleteWhenNotDragSource(QAbstractItemView *view)
-{
- if (view == 0)
- return;
-
- if (DragAndDropHelper::instance().isDragSource(view)) {
- // We must store for later deletion.
- if (m_expandedDragSource != 0) {
- // The old stored view is obviously not the drag source anymore.
- m_expandedDragSource->deleteLater();
- m_expandedDragSource = 0;
- }
- view->hide();
- m_expandedDragSource = view;
- }
- else {
- view->deleteLater();
- }
-}
-
void DolphinView::observeCreatedItem(const KUrl& url)
{
m_createdItemUrl = url;
view->installEventFilter(this);
view->viewport()->installEventFilter(this);
-
- /* TODO: enable folder expanding again later
-
- if (m_mode != ColumnView) {
- // Give the view the ability to auto-expand its directories on hovering
- // (the column view takes care about this itself). If the details view
- // uses expandable folders, the auto-expanding should be used always.
- FolderExpander* folderExpander = new FolderExpander(view, m_viewAccessor.proxyModel());
- folderExpander->setEnabled(m_viewAccessor.hasExpandableFolders());
- connect(folderExpander, SIGNAL(enterDir(const QModelIndex&)),
- m_controller, SLOT(triggerItem(const QModelIndex&)));
-
- }
- else {
- // Listen out for requests to delete the current column.
- connect(m_viewAccessor.columnsContainer(), SIGNAL(requestColumnDeletion(QAbstractItemView*)),
- this, SLOT(deleteWhenNotDragSource(QAbstractItemView*)));
- }*/
-
m_controller->setItemView(view);
+ connect(m_controller, SIGNAL(selectionChanged()),
+ this, SLOT(emitDelayedSelectionChangedSignal()));
// When changing the view mode, the selection is lost due to reinstantiating
// a new item view with a custom selection model. Pass the ownership of the
}
m_selectionModel->setParent(this);
- connect(m_controller, SIGNAL(selectionChanged()),
- this, SLOT(emitDelayedSelectionChangedSignal()));
connect(view->verticalScrollBar(), SIGNAL(valueChanged(int)),
this, SLOT(emitContentsMoved()));
connect(view->horizontalScrollBar(), SIGNAL(valueChanged(int)),
m_controller->disconnect(view);
view->disconnect();
- // TODO: move this code into ViewAccessor::deleteView()
- deleteWhenNotDragSource(view);
- view = 0;
-
m_viewAccessor.deleteView();
}
}
m_iconsView(0),
m_detailsView(0),
m_columnsContainer(0),
- m_proxyModel(proxyModel)
+ m_proxyModel(proxyModel),
+ m_dragSource(0)
{
}
+DolphinView::ViewAccessor::~ViewAccessor()
+{
+ delete m_dragSource;
+ m_dragSource = 0;
+}
+
void DolphinView::ViewAccessor::createView(QWidget* parent,
DolphinController* controller,
Mode mode)
void DolphinView::ViewAccessor::deleteView()
{
- // TODO: Move the deleteWhenNotDragSource() code into the view
- // accessor, so that creating and deleting is fully done by
- // the view accessor.
+ QAbstractItemView* view = itemView();
+ if (view != 0) {
+ if (DragAndDropHelper::instance().isDragSource(view)) {
+ // The view is a drag source (the feature "Open folders
+ // during drag operations" is used). Deleting the view
+ // during an ongoing drag operation is not allowed, so
+ // this will postponed.
+ if (m_dragSource != 0) {
+ // the old stored view is obviously not the drag source anymore
+ m_dragSource->deleteLater();
+ m_dragSource = 0;
+ }
+ view->hide();
+ m_dragSource = view;
+ } else {
+ view->deleteLater();
+ }
+ }
+
m_iconsView = 0;
m_detailsView = 0;
return m_iconsView != 0;
}
-bool DolphinView::ViewAccessor::hasExpandableFolders() const
-{
- const DolphinSettings& settings = DolphinSettings::instance();
- return settings.generalSettings()->autoExpandFolders() ||
- ((m_detailsView != 0) && settings.detailsModeSettings()->expandableFolders());
-}
-
bool DolphinView::ViewAccessor::itemsExpandable() const
{
return (m_detailsView != 0) && m_detailsView->itemsExpandable();
return m_detailsView != 0;
}
-
DolphinModel* DolphinView::ViewAccessor::dirModel() const
{
return static_cast<DolphinModel*>(proxyModel()->sourceModel());
*/
void slotRefreshItems();
- /**
- * If \a view can be positively identified as not being the source for the
- * current drag operation, deleteLater() it immediately. Else stores
- * it for later deletion.
- */
- void deleteWhenNotDragSource(QAbstractItemView* view);
-
/**
* Observes the item with the URL \a url. As soon as the directory
* model indicates that the item is available, the item will
{
public:
ViewAccessor(DolphinSortFilterProxyModel* proxyModel);
+ ~ViewAccessor();
void createView(QWidget* parent, DolphinController* controller, Mode mode);
void deleteView();
KUrl rootUrl() const;
bool supportsCategorizedSorting() const;
- bool hasExpandableFolders() const;
bool itemsExpandable() const;
/**
DolphinDetailsView* m_detailsView;
DolphinColumnViewContainer* m_columnsContainer;
DolphinSortFilterProxyModel* m_proxyModel;
+ QAbstractItemView* m_dragSource;
};
bool m_active : 1;
* slotDirListerCompleted().
*/
QSet<QString> m_newFileNames;
-
- QAbstractItemView* m_expandedDragSource; // TODO: move to ViewAccessor
};
/// Allow using DolphinView::Mode in QVariant
***************************************************************************/
#include "folderexpander.h"
-#include "dolphinview.h"
-
-#include "settings/dolphinsettings.h"
-#include "dolphin_generalsettings.h"
#include <QtCore/QTimer>
#include <QtGui/QAbstractItemView>
m_autoExpandTriggerTimer(0),
m_autoExpandPos()
{
- // Validation. If these fail, the event filter is never
- // installed on the view and the FolderExpander is inactive.
if (m_view == 0) {
- kWarning() << "Need a view!";
- return; // Not valid.
+ return;
}
if (m_proxyModel == 0) {
- kWarning() << "Need a proxyModel!";
- return; // Not valid.
+ return;
}
- KDirModel *m_dirModel = qobject_cast< KDirModel* >( m_proxyModel->sourceModel() );
+ KDirModel *m_dirModel = qobject_cast<KDirModel*>(m_proxyModel->sourceModel());
if (m_dirModel == 0) {
- kWarning() << "Expected m_proxyModel's sourceModel() to be a KDirModel!";
- return; // Not valid.
+ return;
}
// Initialise auto-expand timer.
#include "dolphinsortfilterproxymodel.h"
#include "dolphinview.h"
#include "dolphinviewautoscroller.h"
+#include "folderexpander.h"
#include "selectionmanager.h"
#include "settings/dolphinsettings.h"
#include "tooltips/tooltipmanager.h"
connect(view->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
controller, SLOT(emitSelectionChanged()));
+ // Give the view the ability to auto-expand its directories on hovering
+ // (the column view takes care about this itself). If the details view
+ // uses expandable folders, the auto-expanding should be used always.
+ m_folderExpander = new FolderExpander(view, proxyModel());
+ m_folderExpander->setEnabled(settings->autoExpandFolders());
+ connect(m_folderExpander, SIGNAL(enterDir(const QModelIndex&)),
+ controller, SLOT(triggerItem(const QModelIndex&)));
+
+ // react on namefilter changes
connect(controller, SIGNAL(nameFilterChanged(const QString&)),
this, SLOT(slotNameFilterChanged(const QString&)));
return m_fileItemDelegate;
}
+void ViewExtensionsFactory::setAutoFolderExpandingEnabled(bool enabled)
+{
+ m_folderExpander->setEnabled(enabled);
+}
+
+bool ViewExtensionsFactory::autoFolderExpandingEnabled() const
+{
+ return m_folderExpander->enabled();
+}
+
bool ViewExtensionsFactory::eventFilter(QObject* watched, QEvent* event)
{
Q_UNUSED(watched);
class DolphinSortFilterProxyModel;
class DolphinViewAutoScroller;
class KFilePreviewGenerator;
+class FolderExpander;
class QModelIndex;
class SelectionManager;
class ToolTipManager;
DolphinFileItemDelegate* fileItemDelegate() const;
+ /**
+ * Enables the automatically expanding of a folder when dragging
+ * items above the folder.
+ */
+ void setAutoFolderExpandingEnabled(bool enabled);
+ bool autoFolderExpandingEnabled() const;
+
protected:
virtual bool eventFilter(QObject* watched, QEvent* event);
DolphinViewAutoScroller* m_autoScroller;
DolphinFileItemDelegate* m_fileItemDelegate;
VersionControlObserver* m_versionControlObserver;
+ FolderExpander* m_folderExpander;
};
#endif