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 "dolphiniconsview.h"
22 #include "dolphincontroller.h"
23 #include "dolphinsettings.h"
25 #include "dolphin_iconsmodesettings.h"
27 #include <kdirmodel.h>
28 #include <kfileitem.h>
29 #include <kfileitemdelegate.h>
31 #include <QAbstractProxyModel>
33 DolphinIconsView::DolphinIconsView(QWidget
* parent
, DolphinController
* controller
) :
35 m_controller(controller
)
37 Q_ASSERT(controller
!= 0);
38 setViewMode(QListView::IconMode
);
39 setResizeMode(QListView::Adjust
);
41 connect(this, SIGNAL(clicked(const QModelIndex
&)),
42 controller
, SLOT(triggerItem(const QModelIndex
&)));
43 connect(controller
, SIGNAL(showPreviewChanged(bool)),
44 this, SLOT(updateGridSize(bool)));
45 connect(controller
, SIGNAL(zoomIn()),
46 this, SLOT(zoomIn()));
47 connect(controller
, SIGNAL(zoomOut()),
48 this, SLOT(zoomOut()));
50 // apply the icons mode settings to the widget
51 const IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
52 Q_ASSERT(settings
!= 0);
54 m_viewOptions
= QListView::viewOptions();
55 m_viewOptions
.font
= QFont(settings
->fontFamily(), settings
->fontSize());
57 updateGridSize(controller
->showPreview());
59 if (settings
->arrangement() == QListView::TopToBottom
) {
60 setFlow(QListView::LeftToRight
);
61 m_viewOptions
.decorationPosition
= QStyleOptionViewItem::Top
;
64 setFlow(QListView::TopToBottom
);
65 m_viewOptions
.decorationPosition
= QStyleOptionViewItem::Left
;
68 KFileItemDelegate
* delegate
= new KFileItemDelegate(parent
);
69 const KFileItemDelegate::AdditionalInformation info
=
70 static_cast<KFileItemDelegate::AdditionalInformation
>(settings
->additionalInfo());
71 delegate
->setAdditionalInformation(info
);
72 setItemDelegate(delegate
);
75 DolphinIconsView::~DolphinIconsView()
79 QStyleOptionViewItem
DolphinIconsView::viewOptions() const
84 void DolphinIconsView::contextMenuEvent(QContextMenuEvent
* event
)
86 QListView::contextMenuEvent(event
);
87 m_controller
->triggerContextMenuRequest(event
->pos());
90 void DolphinIconsView::mouseReleaseEvent(QMouseEvent
* event
)
92 QListView::mouseReleaseEvent(event
);
93 m_controller
->triggerActivation();
96 void DolphinIconsView::dragEnterEvent(QDragEnterEvent
* event
)
98 if (event
->mimeData()->hasUrls()) {
99 event
->acceptProposedAction();
103 void DolphinIconsView::dropEvent(QDropEvent
* event
)
105 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
106 if (urls
.isEmpty() || (event
->source() == this)) {
107 QListView::dropEvent(event
);
110 event
->acceptProposedAction();
111 m_controller
->indicateDroppedUrls(urls
, event
->pos());
115 void DolphinIconsView::updateGridSize(bool showPreview
)
117 const IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
118 Q_ASSERT(settings
!= 0);
120 int gridWidth
= settings
->gridWidth();
121 int gridHeight
= settings
->gridHeight();
122 int size
= settings
->iconSize();
125 const int previewSize
= settings
->previewSize();
126 const int diff
= previewSize
- size
;
135 m_viewOptions
.decorationSize
= QSize(size
, size
);
136 setGridSize(QSize(gridWidth
, gridHeight
));
138 m_controller
->setZoomInPossible(isZoomInPossible());
139 m_controller
->setZoomOutPossible(isZoomOutPossible());
142 void DolphinIconsView::zoomIn()
144 if (isZoomInPossible()) {
145 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
147 const bool showPreview
= m_controller
->showPreview();
149 const int previewSize
= increasedIconSize(settings
->previewSize());
150 settings
->setPreviewSize(previewSize
);
153 const int iconSize
= increasedIconSize(settings
->iconSize());
154 settings
->setIconSize(iconSize
);
157 updateGridSize(showPreview
);
161 void DolphinIconsView::zoomOut()
163 if (isZoomOutPossible()) {
164 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
166 const bool showPreview
= m_controller
->showPreview();
168 const int previewSize
= decreasedIconSize(settings
->previewSize());
169 settings
->setPreviewSize(previewSize
);
172 const int iconSize
= decreasedIconSize(settings
->iconSize());
173 settings
->setIconSize(iconSize
);
176 updateGridSize(showPreview
);
180 bool DolphinIconsView::isZoomInPossible() const
182 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
183 const int size
= m_controller
->showPreview() ? settings
->previewSize() : settings
->iconSize();
184 return size
< K3Icon::SizeEnormous
;
187 bool DolphinIconsView::isZoomOutPossible() const
189 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
190 const int size
= m_controller
->showPreview() ? settings
->previewSize() : settings
->iconSize();
191 return size
> K3Icon::SizeSmall
;
194 int DolphinIconsView::increasedIconSize(int size
) const
196 // TODO: get rid of K3Icon sizes
199 case K3Icon::SizeSmall
: incSize
= K3Icon::SizeSmallMedium
; break;
200 case K3Icon::SizeSmallMedium
: incSize
= K3Icon::SizeMedium
; break;
201 case K3Icon::SizeMedium
: incSize
= K3Icon::SizeLarge
; break;
202 case K3Icon::SizeLarge
: incSize
= K3Icon::SizeHuge
; break;
203 case K3Icon::SizeHuge
: incSize
= K3Icon::SizeEnormous
; break;
204 default: Q_ASSERT(false); break;
209 int DolphinIconsView::decreasedIconSize(int size
) const
211 // TODO: get rid of K3Icon sizes
214 case K3Icon::SizeSmallMedium
: decSize
= K3Icon::SizeSmall
; break;
215 case K3Icon::SizeMedium
: decSize
= K3Icon::SizeSmallMedium
; break;
216 case K3Icon::SizeLarge
: decSize
= K3Icon::SizeMedium
; break;
217 case K3Icon::SizeHuge
: decSize
= K3Icon::SizeLarge
; break;
218 case K3Icon::SizeEnormous
: decSize
= K3Icon::SizeHuge
; break;
219 default: Q_ASSERT(false); break;
224 #include "dolphiniconsview.moc"