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>
25 DolphinController::DolphinController(DolphinView
* dolphinView
) :
27 m_zoomInPossible(false),
28 m_zoomOutPossible(false),
30 m_dolphinView(dolphinView
),
35 DolphinController::~DolphinController()
39 void DolphinController::setUrl(const KUrl
& url
)
47 void DolphinController::setItemView(QAbstractItemView
* view
)
52 void DolphinController::triggerUrlChangeRequest(const KUrl
& url
)
55 emit
requestUrlChange(url
);
59 void DolphinController::triggerContextMenuRequest(const QPoint
& pos
)
62 emit
requestContextMenu(pos
);
65 void DolphinController::requestActivation()
70 void DolphinController::indicateDroppedUrls(const KUrl::List
& urls
,
72 const KFileItem
& destItem
)
74 emit
urlsDropped(urls
, destPath
, destItem
);
78 void DolphinController::indicateSortingChange(DolphinView::Sorting sorting
)
80 emit
sortingChanged(sorting
);
83 void DolphinController::indicateSortOrderChange(Qt::SortOrder order
)
85 emit
sortOrderChanged(order
);
88 void DolphinController::indicateAdditionalInfoChange(const KFileItemDelegate::InformationList
& info
)
90 emit
additionalInfoChanged(info
);
93 void DolphinController::indicateActivationChange(bool active
)
95 emit
activationChanged(active
);
98 void DolphinController::triggerZoomIn()
103 void DolphinController::triggerZoomOut()
108 void DolphinController::handleKeyPressEvent(QKeyEvent
* event
)
110 Q_ASSERT(m_itemView
!= 0);
112 const QItemSelectionModel
* selModel
= m_itemView
->selectionModel();
113 const QModelIndex currentIndex
= selModel
->currentIndex();
114 const bool trigger
= currentIndex
.isValid()
115 && (event
->key() == Qt::Key_Return
)
116 && (selModel
->selectedIndexes().count() > 0);
118 const QModelIndexList indexList
= selModel
->selectedIndexes();
119 foreach (const QModelIndex
& index
, indexList
) {
125 KFileItem
DolphinController::itemForIndex(const QModelIndex
& index
) const
127 Q_ASSERT(m_itemView
!= 0);
129 QAbstractProxyModel
* proxyModel
= static_cast<QAbstractProxyModel
*>(m_itemView
->model());
130 KDirModel
* dirModel
= static_cast<KDirModel
*>(proxyModel
->sourceModel());
131 const QModelIndex dirIndex
= proxyModel
->mapToSource(index
);
132 return dirModel
->itemForIndex(dirIndex
);
135 void DolphinController::triggerItem(const QModelIndex
& index
)
137 const KFileItem item
= itemForIndex(index
);
138 if (index
.isValid() && (index
.column() == KDirModel::Name
)) {
139 emit
itemTriggered(item
);
141 m_itemView
->clearSelection();
142 emit
itemEntered(item
);
146 void DolphinController::emitItemEntered(const QModelIndex
& index
)
148 KFileItem item
= itemForIndex(index
);
149 if (!item
.isNull()) {
150 emit
itemEntered(item
);
154 void DolphinController::emitViewportEntered()
156 emit
viewportEntered();
159 #include "dolphincontroller.moc"