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"
21 #include "zoomlevelinfo.h"
23 #include <kdirmodel.h>
24 #include <QAbstractProxyModel>
25 #include <QApplication>
29 DolphinController::DolphinController(DolphinView
* dolphinView
) :
34 m_dolphinView(dolphinView
),
39 DolphinController::~DolphinController()
43 void DolphinController::setUrl(const KUrl
& url
)
51 void DolphinController::setItemView(QAbstractItemView
* view
)
53 if (m_itemView
!= 0) {
54 disconnect(m_itemView
, SIGNAL(pressed(const QModelIndex
&)),
55 this, SLOT(updateOpenTabState()));
60 if (m_itemView
!= 0) {
61 m_zoomLevel
= ZoomLevelInfo::zoomLevelForIconSize(m_itemView
->iconSize());
63 // TODO: this is a workaround until Qt-issue 176832 has been fixed
64 connect(m_itemView
, SIGNAL(pressed(const QModelIndex
&)),
65 this, SLOT(updateOpenTabState()));
69 void DolphinController::triggerUrlChangeRequest(const KUrl
& url
)
72 emit
requestUrlChange(url
);
76 void DolphinController::triggerContextMenuRequest(const QPoint
& pos
)
79 emit
requestContextMenu(pos
);
82 void DolphinController::requestActivation()
87 void DolphinController::indicateDroppedUrls(const KFileItem
& destItem
,
91 emit
urlsDropped(destItem
, destPath
, event
);
95 void DolphinController::indicateSortingChange(DolphinView::Sorting sorting
)
97 emit
sortingChanged(sorting
);
100 void DolphinController::indicateSortOrderChange(Qt::SortOrder order
)
102 emit
sortOrderChanged(order
);
105 void DolphinController::indicateAdditionalInfoChange(const KFileItemDelegate::InformationList
& info
)
107 emit
additionalInfoChanged(info
);
110 void DolphinController::indicateActivationChange(bool active
)
112 emit
activationChanged(active
);
115 void DolphinController::setZoomLevel(int level
)
117 Q_ASSERT(level
>= ZoomLevelInfo::minimumLevel());
118 Q_ASSERT(level
<= ZoomLevelInfo::maximumLevel());
119 if (level
!= m_zoomLevel
) {
121 emit
zoomLevelChanged(m_zoomLevel
);
125 void DolphinController::handleKeyPressEvent(QKeyEvent
* event
)
127 Q_ASSERT(m_itemView
!= 0);
129 const QItemSelectionModel
* selModel
= m_itemView
->selectionModel();
130 const QModelIndex currentIndex
= selModel
->currentIndex();
131 const bool trigger
= currentIndex
.isValid()
132 && (event
->key() == Qt::Key_Return
)
133 && (selModel
->selectedIndexes().count() > 0);
135 const QModelIndexList indexList
= selModel
->selectedIndexes();
136 foreach (const QModelIndex
& index
, indexList
) {
142 void DolphinController::replaceUrlByClipboard()
144 const QClipboard
* clipboard
= QApplication::clipboard();
146 if (clipboard
->mimeData(QClipboard::Selection
)->hasText()) {
147 text
= clipboard
->mimeData(QClipboard::Selection
)->text();
148 } else if (clipboard
->mimeData(QClipboard::Clipboard
)->hasText()) {
149 text
= clipboard
->mimeData(QClipboard::Clipboard
)->text();
151 if (!text
.isEmpty() && QDir::isAbsolutePath(text
)) {
152 m_dolphinView
->setUrl(KUrl(text
));
156 KFileItem
DolphinController::itemForIndex(const QModelIndex
& index
) const
158 Q_ASSERT(m_itemView
!= 0);
160 QAbstractProxyModel
* proxyModel
= static_cast<QAbstractProxyModel
*>(m_itemView
->model());
161 KDirModel
* dirModel
= static_cast<KDirModel
*>(proxyModel
->sourceModel());
162 const QModelIndex dirIndex
= proxyModel
->mapToSource(index
);
163 return dirModel
->itemForIndex(dirIndex
);
166 void DolphinController::triggerItem(const QModelIndex
& index
)
168 const bool openTab
= m_openTab
;
171 const KFileItem item
= itemForIndex(index
);
172 if (index
.isValid() && (index
.column() == KDirModel::Name
)) {
173 if (openTab
&& (item
.isDir() || m_dolphinView
->isTabsForFilesEnabled())) {
174 emit
tabRequested(item
.url());
176 emit
itemTriggered(item
);
179 m_itemView
->clearSelection();
181 emit
itemEntered(KFileItem());
186 void DolphinController::emitItemEntered(const QModelIndex
& index
)
188 KFileItem item
= itemForIndex(index
);
189 if (!item
.isNull()) {
190 emit
itemEntered(item
);
194 void DolphinController::emitViewportEntered()
196 emit
viewportEntered();
199 void DolphinController::updateOpenTabState()
201 m_openTab
= QApplication::mouseButtons() & Qt::MidButton
;
204 #include "dolphincontroller.moc"