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>
27 DolphinController::DolphinController(DolphinView
* dolphinView
) :
29 m_zoomInPossible(false),
30 m_zoomOutPossible(false),
33 m_dolphinView(dolphinView
),
38 DolphinController::~DolphinController()
42 void DolphinController::setUrl(const KUrl
& url
)
50 void DolphinController::setItemView(QAbstractItemView
* view
)
52 if (m_itemView
!= 0) {
53 disconnect(m_itemView
, SIGNAL(pressed(const QModelIndex
&)),
54 this, SLOT(updateOpenTabState()));
59 // TODO: this is a workaround until Qt-issue 176832 has been fixed
60 connect(m_itemView
, SIGNAL(pressed(const QModelIndex
&)),
61 this, SLOT(updateOpenTabState()));
64 void DolphinController::triggerUrlChangeRequest(const KUrl
& url
)
67 emit
requestUrlChange(url
);
71 void DolphinController::triggerContextMenuRequest(const QPoint
& pos
)
74 emit
requestContextMenu(pos
);
77 void DolphinController::requestActivation()
82 void DolphinController::indicateDroppedUrls(const KUrl::List
& urls
,
84 const KFileItem
& destItem
)
86 emit
urlsDropped(urls
, destPath
, destItem
);
90 void DolphinController::indicateSortingChange(DolphinView::Sorting sorting
)
92 emit
sortingChanged(sorting
);
95 void DolphinController::indicateSortOrderChange(Qt::SortOrder order
)
97 emit
sortOrderChanged(order
);
100 void DolphinController::indicateAdditionalInfoChange(const KFileItemDelegate::InformationList
& info
)
102 emit
additionalInfoChanged(info
);
105 void DolphinController::indicateActivationChange(bool active
)
107 emit
activationChanged(active
);
110 void DolphinController::triggerZoomIn()
115 void DolphinController::triggerZoomOut()
120 void DolphinController::handleKeyPressEvent(QKeyEvent
* event
)
122 Q_ASSERT(m_itemView
!= 0);
124 const QItemSelectionModel
* selModel
= m_itemView
->selectionModel();
125 const QModelIndex currentIndex
= selModel
->currentIndex();
126 const bool trigger
= currentIndex
.isValid()
127 && (event
->key() == Qt::Key_Return
)
128 && (selModel
->selectedIndexes().count() > 0);
130 const QModelIndexList indexList
= selModel
->selectedIndexes();
131 foreach (const QModelIndex
& index
, indexList
) {
137 void DolphinController::replaceUrlByClipboard()
139 QClipboard
* clipboard
= QApplication::clipboard();
140 const QMimeData
* mimeData
= clipboard
->mimeData();
141 if (mimeData
->hasText()) {
142 const QString text
= mimeData
->text();
143 m_dolphinView
->setUrl(KUrl(text
));
147 KFileItem
DolphinController::itemForIndex(const QModelIndex
& index
) const
149 Q_ASSERT(m_itemView
!= 0);
151 QAbstractProxyModel
* proxyModel
= static_cast<QAbstractProxyModel
*>(m_itemView
->model());
152 KDirModel
* dirModel
= static_cast<KDirModel
*>(proxyModel
->sourceModel());
153 const QModelIndex dirIndex
= proxyModel
->mapToSource(index
);
154 return dirModel
->itemForIndex(dirIndex
);
157 void DolphinController::triggerItem(const QModelIndex
& index
)
159 const bool openTab
= m_openTab
;
162 const KFileItem item
= itemForIndex(index
);
163 if (index
.isValid() && (index
.column() == KDirModel::Name
)) {
164 if (openTab
&& (item
.isDir() || m_dolphinView
->isTabsForFilesEnabled())) {
165 emit
tabRequested(item
.url());
167 emit
itemTriggered(item
);
170 m_itemView
->clearSelection();
172 emit
itemEntered(item
);
177 void DolphinController::emitItemEntered(const QModelIndex
& index
)
179 KFileItem item
= itemForIndex(index
);
180 if (!item
.isNull()) {
181 emit
itemEntered(item
);
185 void DolphinController::emitViewportEntered()
187 emit
viewportEntered();
190 void DolphinController::updateOpenTabState()
192 m_openTab
= QApplication::mouseButtons() & Qt::MidButton
;
195 #include "dolphincontroller.moc"