1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "dolphincontroller.h"
22 #include <kdirmodel.h>
23 #include <QAbstractProxyModel>
24 #include <QApplication>
26 DolphinController::DolphinController(DolphinView
* dolphinView
) :
28 m_zoomInPossible(false),
29 m_zoomOutPossible(false),
32 m_dolphinView(dolphinView
),
37 DolphinController::~DolphinController()
41 void DolphinController::setUrl(const KUrl
& url
)
49 void DolphinController::setItemView(QAbstractItemView
* view
)
51 if (m_itemView
!= 0) {
52 disconnect(m_itemView
, SIGNAL(pressed(const QModelIndex
&)),
53 this, SLOT(updateOpenTabState()));
58 // TODO: this is a workaround until Qt-issue 176832 has been fixed
59 connect(m_itemView
, SIGNAL(pressed(const QModelIndex
&)),
60 this, SLOT(updateOpenTabState()));
63 void DolphinController::triggerUrlChangeRequest(const KUrl
& url
)
66 emit
requestUrlChange(url
);
70 void DolphinController::triggerContextMenuRequest(const QPoint
& pos
)
73 emit
requestContextMenu(pos
);
76 void DolphinController::requestActivation()
81 void DolphinController::indicateDroppedUrls(const KUrl::List
& urls
,
83 const KFileItem
& destItem
)
85 emit
urlsDropped(urls
, destPath
, destItem
);
89 void DolphinController::indicateSortingChange(DolphinView::Sorting sorting
)
91 emit
sortingChanged(sorting
);
94 void DolphinController::indicateSortOrderChange(Qt::SortOrder order
)
96 emit
sortOrderChanged(order
);
99 void DolphinController::indicateAdditionalInfoChange(const KFileItemDelegate::InformationList
& info
)
101 emit
additionalInfoChanged(info
);
104 void DolphinController::indicateActivationChange(bool active
)
106 emit
activationChanged(active
);
109 void DolphinController::triggerZoomIn()
114 void DolphinController::triggerZoomOut()
119 void DolphinController::handleKeyPressEvent(QKeyEvent
* event
)
121 Q_ASSERT(m_itemView
!= 0);
123 const QItemSelectionModel
* selModel
= m_itemView
->selectionModel();
124 const QModelIndex currentIndex
= selModel
->currentIndex();
125 const bool trigger
= currentIndex
.isValid()
126 && (event
->key() == Qt::Key_Return
)
127 && (selModel
->selectedIndexes().count() > 0);
129 const QModelIndexList indexList
= selModel
->selectedIndexes();
130 foreach (const QModelIndex
& index
, indexList
) {
136 KFileItem
DolphinController::itemForIndex(const QModelIndex
& index
) const
138 Q_ASSERT(m_itemView
!= 0);
140 QAbstractProxyModel
* proxyModel
= static_cast<QAbstractProxyModel
*>(m_itemView
->model());
141 KDirModel
* dirModel
= static_cast<KDirModel
*>(proxyModel
->sourceModel());
142 const QModelIndex dirIndex
= proxyModel
->mapToSource(index
);
143 return dirModel
->itemForIndex(dirIndex
);
146 void DolphinController::triggerItem(const QModelIndex
& index
)
148 const bool openTab
= m_openTab
;
151 const KFileItem item
= itemForIndex(index
);
152 if (index
.isValid() && (index
.column() == KDirModel::Name
)) {
153 if (openTab
&& (item
.isDir() || m_dolphinView
->isTabsForFilesEnabled())) {
154 emit
tabRequested(item
.url());
156 emit
itemTriggered(item
);
159 m_itemView
->clearSelection();
161 emit
itemEntered(item
);
166 void DolphinController::emitItemEntered(const QModelIndex
& index
)
168 KFileItem item
= itemForIndex(index
);
169 if (!item
.isNull()) {
170 emit
itemEntered(item
);
174 void DolphinController::emitViewportEntered()
176 emit
viewportEntered();
179 void DolphinController::updateOpenTabState()
181 m_openTab
= QApplication::mouseButtons() & Qt::MidButton
;
184 #include "dolphincontroller.moc"