m_previewGenerator(0),
m_toolTipManager(0),
m_rootUrl(),
- m_currentItemUrl()
+ m_currentItemUrl(),
+ m_expandedViews()
{
m_topLayout = new QVBoxLayout(this);
m_topLayout->setSpacing(0);
DolphinView::~DolphinView()
{
+ deleteExpandedViews();
}
const KUrl& DolphinView::url() const
bool DolphinView::eventFilter(QObject* watched, QEvent* event)
{
- if ((watched == itemView()) && (event->type() == QEvent::FocusIn)) {
- m_controller->requestActivation();
+ switch (event->type()) {
+ case QEvent::FocusIn:
+ if (watched == itemView()) {
+ m_controller->requestActivation();
+ }
+ break;
+
+ case QEvent::MouseButtonPress:
+ if ((watched == itemView()->viewport()) && (m_expandedViews.count() > 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.
+ deleteExpandedViews();
+ }
+ break;
+ default:
+ break;
}
return QWidget::eventFilter(watched, event);
}
}
+void DolphinView::enterDir(const QModelIndex& index, QAbstractItemView* view)
+{
+ // Deleting a view that is the root of a drag operation is not allowed, otherwise
+ // the dragging gets automatically cancelled by Qt. So before entering a new
+ // directory, the current view is remembered in m_expandedViews and deleted
+ // later when the drag operation has been finished (see DolphinView::eventFilter()).
+ m_expandedViews.append(view);
+ m_controller->triggerItem(index);
+}
+
void DolphinView::loadDirectory(const KUrl& url, bool reload)
{
if (!url.isValid()) {
Q_ASSERT(view != 0);
view->installEventFilter(this);
+ view->viewport()->installEventFilter(this);
if (m_mode != ColumnView) {
// Give the view the ability to auto-expand its directories on hovering
FolderExpander* folderExpander = new FolderExpander(view, m_proxyModel);
folderExpander->setEnabled(enabled);
- connect(folderExpander, SIGNAL(enterDir(const QModelIndex&)),
- m_controller, SLOT(triggerItem(const QModelIndex&)));
+ connect(folderExpander, SIGNAL(enterDir(const QModelIndex&, QAbstractItemView*)),
+ this, SLOT(enterDir(const QModelIndex&, QAbstractItemView*)));
}
m_controller->setItemView(view);
m_topLayout->removeWidget(view);
view->close();
- view->deleteLater();
+
+ bool deleteView = true;
+ foreach (const QAbstractItemView* expandedView, m_expandedViews) {
+ if (view == expandedView) {
+ // the current view got already expanded and must stay alive
+ // until the dragging has been completed
+ deleteView = false;
+ break;
+ }
+ }
+ if (deleteView) {
+ view->deleteLater();
+ }
view = 0;
+
m_iconsView = 0;
m_detailsView = 0;
m_columnView = 0;
return list;
}
+void DolphinView::deleteExpandedViews()
+{
+ const QAbstractItemView* view = itemView();
+ foreach (QAbstractItemView* expandedView, m_expandedViews) {
+ if (expandedView != view) {
+ expandedView->deleteLater();
+ }
+ }
+ m_expandedViews.clear();
+}
+
bool DolphinView::itemsExpandable() const
{
return (m_detailsView != 0) && m_detailsView->itemsExpandable();
* to m_currentItemUrl.
*/
void restoreCurrentItem();
+
+ /**
+ * Is connected to the enterDir() signal from the FolderExpander
+ * and triggers the entering of the directory indicated by \a index.
+ */
+ void enterDir(const QModelIndex& index, QAbstractItemView* view);
private:
void loadDirectory(const KUrl& url, bool reload = false);
* this method has been introduced for convenience.
*/
bool isColumnViewActive() const;
+
+ /**
+ * Deletes all views from m_expandedViews except if the view
+ * is currently shown.
+ */
+ void deleteExpandedViews();
private:
bool m_active : 1;
KUrl m_rootUrl;
KUrl m_currentItemUrl;
+
+ QList<QAbstractItemView*> m_expandedViews;
};
inline bool DolphinView::isColumnViewActive() const