#include <QApplication>
#include <QPoint>
#include <QScrollBar>
+#include <QTimer>
#include <QTimeLine>
/**
&& (event->key() == Qt::Key_Return)
&& (selModel->selectedIndexes().count() <= 1);
if (triggerItem) {
- m_view->triggerItem(currentIndex);
+ m_view->m_controller->triggerItem(currentIndex);
}
}
// necessary connecting the signal 'singleClick()' or 'doubleClick'.
if (KGlobalSettings::singleClick()) {
connect(this, SIGNAL(clicked(const QModelIndex&)),
- m_view, SLOT(triggerItem(const QModelIndex&)));
+ m_view->m_controller, SLOT(triggerItem(const QModelIndex&)));
} else {
connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
- m_view, SLOT(triggerItem(const QModelIndex&)));
+ m_view->m_controller, SLOT(triggerItem(const QModelIndex&)));
}
const QColor bgColor = KColorScheme(QPalette::Active, KColorScheme::View).background().color();
// necessary connecting the signal 'singleClick()' or 'doubleClick'.
if (KGlobalSettings::singleClick()) {
disconnect(this, SIGNAL(clicked(const QModelIndex&)),
- m_view, SLOT(triggerItem(const QModelIndex&)));
+ m_view->m_controller, SLOT(triggerItem(const QModelIndex&)));
} else {
disconnect(this, SIGNAL(doubleClicked(const QModelIndex&)),
- m_view, SLOT(triggerItem(const QModelIndex&)));
+ m_view->m_controller, SLOT(triggerItem(const QModelIndex&)));
}
const QPalette palette = m_view->viewport()->palette();
QAbstractItemView(parent),
m_controller(controller),
m_restoreActiveColumnFocus(false),
- m_initializedDirLister(false),
+ m_dirListerCompleted(false),
m_index(-1),
m_contentX(0),
m_columns(),
connect(m_dolphinModel, SIGNAL(expand(const QModelIndex&)),
this, SLOT(triggerReloadColumns(const QModelIndex&)));
+ KDirLister* dirLister = m_dolphinModel->dirLister();
+ connect(dirLister, SIGNAL(started(const KUrl&)),
+ this, SLOT(slotDirListerStarted(const KUrl&)));
+ connect(dirLister, SIGNAL(completed()),
+ this, SLOT(slotDirListerCompleted()));
+
activeColumn()->setModel(model);
QAbstractItemView::setModel(model);
}
connect(dirLister, SIGNAL(completed()),
this, SLOT(expandToActiveUrl()));
const KUrl& rootUrl = m_columns[0]->url();
- m_initializedDirLister = dirLister->openUrl(m_columns[0]->url(), false, true);
+ dirLister->openUrl(rootUrl, false, true);
reloadColumns();
}
m_index = columnIndex;
activeColumn()->setActive(true);
- if (m_initializedDirLister) {
- // expanding the active URL may only be done if the directory lister
- // has been initialized
- QMetaObject::invokeMethod(this, "expandToActiveUrl", Qt::QueuedConnection);
- } else {
- QMetaObject::invokeMethod(this, "reload", Qt::QueuedConnection);
- }
+ reloadColumns();
+
+ // reloadColumns() is enough for simple use cases where only one column is added.
+ // However when exchanging several columns a more complex synchronization must be
+ // done by invoking synchronize(). The delay is an optimization for default use
+ // cases and gives the directory lister the chance to be already finished when
+ // synchronize() is invoked, which assures zero flickering.
+ QTimer::singleShot(1000, this, SLOT(synchronize()));
}
void DolphinColumnView::selectAll()
const bool expand = rootUrl.isParentOf(activeUrl)
&& !rootUrl.equals(activeUrl, KUrl::CompareWithoutTrailingSlash);
if (expand) {
+ Q_ASSERT(m_dirListerCompleted);
m_dolphinModel->expandToUrl(activeUrl);
}
reloadColumns();
assureVisibleActiveColumn();
}
-void DolphinColumnView::triggerItem(const QModelIndex& index)
+void DolphinColumnView::synchronize()
+{
+ if (m_dirListerCompleted) {
+ // expanding the active URL may only be done if the directory lister
+ // has been completed the loading
+ expandToActiveUrl();
+ } else {
+ reload();
+ }
+}
+
+
+void DolphinColumnView::slotDirListerStarted(const KUrl& url)
+{
+ Q_UNUSED(url);
+ m_dirListerCompleted = false;
+}
+
+void DolphinColumnView::slotDirListerCompleted()
{
- m_initializedDirLister = true;
- m_controller->triggerItem(index);
+ m_dirListerCompleted = true;
}
bool DolphinColumnView::isZoomInPossible() const
/** Inverts the selection of the currently active column. */
void invertSelection();
-public slots:
/**
* Reloads the content of all columns. In opposite to non-hierarchical views
* it is not enough to reload the KDirLister, instead this method must be explicitly
*/
void reload();
+public slots:
/**
* Shows the column which represents the URL \a url. If the column
* is already shown, it gets activated, otherwise it will be created.
*/
void reloadColumns();
- void triggerItem(const QModelIndex& index);
+ /**
+ * Synchronizes the current state of the directory lister with
+ * the currently shown columns. This is required if the directory
+ * lister has been changed from outside without user interaction.
+ */
+ void synchronize();
+
+ /**
+ * Is invoked when the directory lister has started the loading
+ * of the URL \a url and sets the internal m_dirListerCompleted
+ * state to false.
+ */
+ void slotDirListerStarted(const KUrl& url);
+
+ /**
+ * Is invoked when the directory lister has completed the loading
+ * and sets the internal m_dirListerCompleted state to true.
+ */
+ void slotDirListerCompleted();
private:
bool isZoomInPossible() const;
private:
DolphinController* m_controller;
bool m_restoreActiveColumnFocus;
- bool m_initializedDirLister;
+ bool m_dirListerCompleted;
int m_index;
int m_contentX;
QList<ColumnWidget*> m_columns;