]>
cloud.milkyroute.net Git - dolphin.git/blob - src/dolphiniconsview.cpp
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"
24 #include "dolphinitemcategorizer.h"
26 #include "dolphin_iconsmodesettings.h"
28 #include <kdirmodel.h>
29 #include <kfileitem.h>
30 #include <kfileitemdelegate.h>
32 #include <QtGui/QAbstractProxyModel>
33 #include <QtCore/QPoint>
35 DolphinIconsView::DolphinIconsView(QWidget
* parent
, DolphinController
* controller
) :
37 m_controller(controller
)
39 Q_ASSERT(controller
!= 0);
40 setViewMode(QListView::IconMode
);
41 setResizeMode(QListView::Adjust
);
43 viewport()->setAttribute(Qt::WA_Hover
);
45 if (KGlobalSettings::singleClick()) {
46 connect(this, SIGNAL(clicked(const QModelIndex
&)),
47 controller
, SLOT(triggerItem(const QModelIndex
&)));
49 connect(this, SIGNAL(doubleClicked(const QModelIndex
&)),
50 controller
, SLOT(triggerItem(const QModelIndex
&)));
52 connect(this, SIGNAL(activated(const QModelIndex
&)),
53 controller
, SLOT(triggerItem(const QModelIndex
&)));
54 connect(controller
, SIGNAL(showPreviewChanged(bool)),
55 this, SLOT(updateGridSize(bool)));
56 connect(controller
, SIGNAL(zoomIn()),
57 this, SLOT(zoomIn()));
58 connect(controller
, SIGNAL(zoomOut()),
59 this, SLOT(zoomOut()));
61 // apply the icons mode settings to the widget
62 const IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
63 Q_ASSERT(settings
!= 0);
65 m_viewOptions
= KListView::viewOptions();
66 m_viewOptions
.showDecorationSelected
= true;
68 QFont
font(settings
->fontFamily(), settings
->fontSize());
69 font
.setItalic(settings
->italicFont());
70 font
.setBold(settings
->boldFont());
71 m_viewOptions
.font
= font
;
73 updateGridSize(controller
->showPreview());
75 if (settings
->arrangement() == QListView::TopToBottom
) {
76 setFlow(QListView::LeftToRight
);
77 m_viewOptions
.decorationPosition
= QStyleOptionViewItem::Top
;
79 setFlow(QListView::TopToBottom
);
80 m_viewOptions
.decorationPosition
= QStyleOptionViewItem::Left
;
84 DolphinIconsView::~DolphinIconsView()
88 QStyleOptionViewItem
DolphinIconsView::viewOptions() const
93 void DolphinIconsView::contextMenuEvent(QContextMenuEvent
* event
)
95 KListView::contextMenuEvent(event
);
96 m_controller
->triggerContextMenuRequest(event
->pos());
99 void DolphinIconsView::mouseReleaseEvent(QMouseEvent
* event
)
101 KListView::mouseReleaseEvent(event
);
102 m_controller
->triggerActivation();
105 void DolphinIconsView::dragEnterEvent(QDragEnterEvent
* event
)
107 if (event
->mimeData()->hasUrls()) {
108 event
->acceptProposedAction();
112 void DolphinIconsView::dropEvent(QDropEvent
* event
)
114 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
115 if (!urls
.isEmpty()) {
116 m_controller
->indicateDroppedUrls(urls
,
117 indexAt(event
->pos()),
119 event
->acceptProposedAction();
121 KListView::dropEvent(event
);
124 void DolphinIconsView::updateGridSize(bool showPreview
)
126 const IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
127 Q_ASSERT(settings
!= 0);
129 int gridWidth
= settings
->gridWidth();
130 int gridHeight
= settings
->gridHeight();
131 int size
= settings
->iconSize();
134 const int previewSize
= settings
->previewSize();
135 const int diff
= previewSize
- size
;
143 m_viewOptions
.decorationSize
= QSize(size
, size
);
144 setGridSize(QSize(gridWidth
, gridHeight
));
146 m_controller
->setZoomInPossible(isZoomInPossible());
147 m_controller
->setZoomOutPossible(isZoomOutPossible());
150 void DolphinIconsView::zoomIn()
152 if (isZoomInPossible()) {
153 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
155 const int oldIconSize
= settings
->iconSize();
156 int newIconSize
= oldIconSize
;
158 const bool showPreview
= m_controller
->showPreview();
160 const int previewSize
= increasedIconSize(settings
->previewSize());
161 settings
->setPreviewSize(previewSize
);
163 newIconSize
= increasedIconSize(oldIconSize
);
164 settings
->setIconSize(newIconSize
);
165 if (settings
->previewSize() < newIconSize
) {
166 // assure that the preview size is always >= the icon size
167 settings
->setPreviewSize(newIconSize
);
171 // increase also the grid size
172 const int diff
= newIconSize
- oldIconSize
;
173 settings
->setGridWidth(settings
->gridWidth() + diff
);
174 settings
->setGridHeight(settings
->gridHeight() + diff
);
176 updateGridSize(showPreview
);
180 void DolphinIconsView::zoomOut()
182 if (isZoomOutPossible()) {
183 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
185 const int oldIconSize
= settings
->iconSize();
186 int newIconSize
= oldIconSize
;
188 const bool showPreview
= m_controller
->showPreview();
190 const int previewSize
= decreasedIconSize(settings
->previewSize());
191 settings
->setPreviewSize(previewSize
);
192 if (settings
->iconSize() > previewSize
) {
193 // assure that the icon size is always <= the preview size
194 newIconSize
= previewSize
;
195 settings
->setIconSize(newIconSize
);
198 newIconSize
= decreasedIconSize(settings
->iconSize());
199 settings
->setIconSize(newIconSize
);
202 // decrease also the grid size
203 const int diff
= oldIconSize
- newIconSize
;
204 settings
->setGridWidth(settings
->gridWidth() - diff
);
205 settings
->setGridHeight(settings
->gridHeight() - diff
);
207 updateGridSize(showPreview
);
211 bool DolphinIconsView::isZoomInPossible() const
213 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
214 const int size
= m_controller
->showPreview() ? settings
->previewSize() : settings
->iconSize();
215 return size
< K3Icon::SizeEnormous
;
218 bool DolphinIconsView::isZoomOutPossible() const
220 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
221 const int size
= m_controller
->showPreview() ? settings
->previewSize() : settings
->iconSize();
222 return size
> K3Icon::SizeSmall
;
225 int DolphinIconsView::increasedIconSize(int size
) const
227 // TODO: get rid of K3Icon sizes
230 case K3Icon::SizeSmall
: incSize
= K3Icon::SizeSmallMedium
; break;
231 case K3Icon::SizeSmallMedium
: incSize
= K3Icon::SizeMedium
; break;
232 case K3Icon::SizeMedium
: incSize
= K3Icon::SizeLarge
; break;
233 case K3Icon::SizeLarge
: incSize
= K3Icon::SizeHuge
; break;
234 case K3Icon::SizeHuge
: incSize
= K3Icon::SizeEnormous
; break;
235 default: Q_ASSERT(false); break;
240 int DolphinIconsView::decreasedIconSize(int size
) const
242 // TODO: get rid of K3Icon sizes
245 case K3Icon::SizeSmallMedium
: decSize
= K3Icon::SizeSmall
; break;
246 case K3Icon::SizeMedium
: decSize
= K3Icon::SizeSmallMedium
; break;
247 case K3Icon::SizeLarge
: decSize
= K3Icon::SizeMedium
; break;
248 case K3Icon::SizeHuge
: decSize
= K3Icon::SizeLarge
; break;
249 case K3Icon::SizeEnormous
: decSize
= K3Icon::SizeHuge
; break;
250 default: Q_ASSERT(false); break;
255 #include "dolphiniconsview.moc"