***************************************************************************/
#include "dolphincontroller.h"
+#include "zoomlevelinfo.h"
#include <kdirmodel.h>
#include <QAbstractProxyModel>
#include <QClipboard>
#include <QDir>
+Qt::MouseButtons DolphinController::m_mouseButtons = Qt::NoButton;
+
DolphinController::DolphinController(DolphinView* dolphinView) :
QObject(dolphinView),
- m_zoomInPossible(false),
- m_zoomOutPossible(false),
- m_openTab(false),
+ m_zoomLevel(0),
+ m_nameFilter(),
m_url(),
m_dolphinView(dolphinView),
- m_itemView(0)
+ m_itemView(0),
+ m_versionControlActions()
{
}
{
if (m_url != url) {
m_url = url;
+ emit cancelPreviews();
emit urlChanged(url);
}
}
+void DolphinController::redirectToUrl(const KUrl& url)
+{
+ m_url = url;
+}
+
void DolphinController::setItemView(QAbstractItemView* view)
{
if (m_itemView != 0) {
disconnect(m_itemView, SIGNAL(pressed(const QModelIndex&)),
- this, SLOT(updateOpenTabState()));
+ this, SLOT(updateMouseButtonState()));
}
m_itemView = view;
- // TODO: this is a workaround until Qt-issue 176832 has been fixed
- connect(m_itemView, SIGNAL(pressed(const QModelIndex&)),
- this, SLOT(updateOpenTabState()));
+ if (m_itemView != 0) {
+ m_zoomLevel = ZoomLevelInfo::zoomLevelForIconSize(m_itemView->iconSize());
+
+ // TODO: this is a workaround until Qt-issue 176832 has been fixed
+ connect(m_itemView, SIGNAL(pressed(const QModelIndex&)),
+ this, SLOT(updateMouseButtonState()));
+ }
}
void DolphinController::triggerUrlChangeRequest(const KUrl& url)
}
}
-void DolphinController::triggerContextMenuRequest(const QPoint& pos)
+void DolphinController::triggerContextMenuRequest(const QPoint& pos,
+ const QList<QAction*>& customActions)
{
emit activated();
- emit requestContextMenu(pos);
+ emit requestContextMenu(pos, customActions);
}
void DolphinController::requestActivation()
emit activated();
}
-void DolphinController::indicateDroppedUrls(const KUrl::List& urls,
+void DolphinController::indicateDroppedUrls(const KFileItem& destItem,
const KUrl& destPath,
- const KFileItem& destItem)
+ QDropEvent* event)
{
- emit urlsDropped(urls, destPath, destItem);
+ emit urlsDropped(destItem, destPath, event);
}
emit sortOrderChanged(order);
}
+void DolphinController::indicateSortFoldersFirstChange(bool foldersFirst)
+{
+ emit sortFoldersFirstChanged(foldersFirst);
+}
+
void DolphinController::indicateAdditionalInfoChange(const KFileItemDelegate::InformationList& info)
{
emit additionalInfoChanged(info);
emit activationChanged(active);
}
-void DolphinController::triggerZoomIn()
+void DolphinController::setNameFilter(const QString& nameFilter)
+{
+ if (nameFilter != m_nameFilter) {
+ m_nameFilter = nameFilter;
+ emit nameFilterChanged(nameFilter);
+ }
+}
+
+QString DolphinController::nameFilter() const
+{
+ return m_nameFilter;
+}
+
+void DolphinController::setZoomLevel(int level)
+{
+ Q_ASSERT(level >= ZoomLevelInfo::minimumLevel());
+ Q_ASSERT(level <= ZoomLevelInfo::maximumLevel());
+ if (level != m_zoomLevel) {
+ m_zoomLevel = level;
+ emit zoomLevelChanged(m_zoomLevel);
+ }
+}
+
+void DolphinController::setVersionControlActions(QList<QAction*> actions)
{
- emit zoomIn();
+ m_versionControlActions = actions;
}
-void DolphinController::triggerZoomOut()
+QList<QAction*> DolphinController::versionControlActions(const KFileItemList& items)
{
- emit zoomOut();
+ emit requestVersionControlActions(items);
+ // All view implementations are connected with the signal requestVersionControlActions()
+ // (see ViewExtensionFactory) and will invoke DolphinController::setVersionControlActions(),
+ // so that the context dependent actions can be returned.
+ return m_versionControlActions;
}
void DolphinController::handleKeyPressEvent(QKeyEvent* event)
const QItemSelectionModel* selModel = m_itemView->selectionModel();
const QModelIndex currentIndex = selModel->currentIndex();
const bool trigger = currentIndex.isValid()
- && (event->key() == Qt::Key_Return)
- && (selModel->selectedIndexes().count() > 0);
+ && ((event->key() == Qt::Key_Return)
+ || (event->key() == Qt::Key_Enter))
+ && !selModel->selectedIndexes().isEmpty();
if (trigger) {
const QModelIndexList indexList = selModel->selectedIndexes();
foreach (const QModelIndex& index, indexList) {
- triggerItem(index);
+ emit itemTriggered(itemForIndex(index));
}
}
}
}
}
+void DolphinController::emitHideToolTip()
+{
+ emit hideToolTip();
+}
+
+void DolphinController::emitItemTriggered(const KFileItem& item)
+{
+ emit itemTriggered(item);
+}
+
KFileItem DolphinController::itemForIndex(const QModelIndex& index) const
{
Q_ASSERT(m_itemView != 0);
void DolphinController::triggerItem(const QModelIndex& index)
{
- const bool openTab = m_openTab;
- m_openTab = false;
-
- const KFileItem item = itemForIndex(index);
- if (index.isValid() && (index.column() == KDirModel::Name)) {
- if (openTab && (item.isDir() || m_dolphinView->isTabsForFilesEnabled())) {
- emit tabRequested(item.url());
- } else {
+ if (m_mouseButtons & Qt::LeftButton) {
+ const KFileItem item = itemForIndex(index);
+ if (index.isValid() && (index.column() == KDirModel::Name)) {
emit itemTriggered(item);
- }
- } else {
- m_itemView->clearSelection();
- if (!openTab) {
+ } else {
+ m_itemView->clearSelection();
emit itemEntered(KFileItem());
}
}
}
+void DolphinController::requestTab(const QModelIndex& index)
+{
+ if (m_mouseButtons & Qt::MidButton) {
+ const KFileItem item = itemForIndex(index);
+ const bool validRequest = index.isValid() &&
+ (index.column() == KDirModel::Name) &&
+ (item.isDir() || m_dolphinView->isTabsForFilesEnabled());
+ if (validRequest) {
+ emit tabRequested(item.url());
+ }
+ }
+}
+
void DolphinController::emitItemEntered(const QModelIndex& index)
{
KFileItem item = itemForIndex(index);
emit viewportEntered();
}
-void DolphinController::updateOpenTabState()
+void DolphinController::emitSelectionChanged()
+{
+ emit selectionChanged();
+}
+
+void DolphinController::updateMouseButtonState()
{
- m_openTab = QApplication::mouseButtons() & Qt::MidButton;
+ m_mouseButtons = QApplication::mouseButtons();
}
#include "dolphincontroller.moc"