]>
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 setMouseTracking(true);
44 viewport()->setAttribute(Qt::WA_Hover
);
46 if (KGlobalSettings::singleClick()) {
47 connect(this, SIGNAL(clicked(const QModelIndex
&)),
48 controller
, SLOT(triggerItem(const QModelIndex
&)));
50 connect(this, SIGNAL(doubleClicked(const QModelIndex
&)),
51 controller
, SLOT(triggerItem(const QModelIndex
&)));
53 connect(this, SIGNAL(activated(const QModelIndex
&)),
54 controller
, SLOT(triggerItem(const QModelIndex
&)));
55 connect(this, SIGNAL(entered(const QModelIndex
&)),
56 controller
, SLOT(emitItemEntered(const QModelIndex
&)));
57 connect(this, SIGNAL(viewportEntered()),
58 controller
, SLOT(emitViewportEntered()));
59 connect(controller
, SIGNAL(showPreviewChanged(bool)),
60 this, SLOT(slotShowPreviewChanged(bool)));
61 connect(controller
, SIGNAL(showAdditionalInfoChanged(bool)),
62 this, SLOT(slotShowAdditionalInfoChanged(bool)));
63 connect(controller
, SIGNAL(zoomIn()),
64 this, SLOT(zoomIn()));
65 connect(controller
, SIGNAL(zoomOut()),
66 this, SLOT(zoomOut()));
68 // apply the icons mode settings to the widget
69 const IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
70 Q_ASSERT(settings
!= 0);
72 m_viewOptions
= KListView::viewOptions();
73 m_viewOptions
.showDecorationSelected
= true;
75 QFont
font(settings
->fontFamily(), settings
->fontSize());
76 font
.setItalic(settings
->italicFont());
77 font
.setBold(settings
->boldFont());
78 m_viewOptions
.font
= font
;
80 setWordWrap(settings
->numberOfTextlines() > 1);
81 updateGridSize(controller
->showPreview(), controller
->showAdditionalInfo());
83 if (settings
->arrangement() == QListView::TopToBottom
) {
84 setFlow(QListView::LeftToRight
);
85 m_viewOptions
.decorationPosition
= QStyleOptionViewItem::Top
;
87 setFlow(QListView::TopToBottom
);
88 m_viewOptions
.decorationPosition
= QStyleOptionViewItem::Left
;
89 m_viewOptions
.displayAlignment
= Qt::AlignLeft
| Qt::AlignVCenter
;
93 DolphinIconsView::~DolphinIconsView()
97 QStyleOptionViewItem
DolphinIconsView::viewOptions() const
102 void DolphinIconsView::contextMenuEvent(QContextMenuEvent
* event
)
104 KListView::contextMenuEvent(event
);
105 m_controller
->triggerContextMenuRequest(event
->pos());
108 void DolphinIconsView::mouseReleaseEvent(QMouseEvent
* event
)
110 KListView::mouseReleaseEvent(event
);
111 m_controller
->triggerActivation();
114 void DolphinIconsView::dragEnterEvent(QDragEnterEvent
* event
)
116 if (event
->mimeData()->hasUrls()) {
117 event
->acceptProposedAction();
121 void DolphinIconsView::dropEvent(QDropEvent
* event
)
123 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
124 if (!urls
.isEmpty()) {
125 m_controller
->indicateDroppedUrls(urls
,
126 indexAt(event
->pos()),
128 event
->acceptProposedAction();
130 KListView::dropEvent(event
);
133 void DolphinIconsView::slotShowPreviewChanged(bool showPreview
)
135 updateGridSize(showPreview
, m_controller
->showAdditionalInfo());
138 void DolphinIconsView::slotShowAdditionalInfoChanged(bool showAdditionalInfo
)
140 updateGridSize(m_controller
->showPreview(), showAdditionalInfo
);
143 void DolphinIconsView::zoomIn()
145 if (isZoomInPossible()) {
146 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
148 const int oldIconSize
= settings
->iconSize();
149 int newIconSize
= oldIconSize
;
151 const bool showPreview
= m_controller
->showPreview();
153 const int previewSize
= increasedIconSize(settings
->previewSize());
154 settings
->setPreviewSize(previewSize
);
156 newIconSize
= increasedIconSize(oldIconSize
);
157 settings
->setIconSize(newIconSize
);
158 if (settings
->previewSize() < newIconSize
) {
159 // assure that the preview size is always >= the icon size
160 settings
->setPreviewSize(newIconSize
);
164 // increase also the grid size
165 const int diff
= newIconSize
- oldIconSize
;
166 settings
->setItemWidth(settings
->itemWidth() + diff
);
167 settings
->setItemHeight(settings
->itemHeight() + diff
);
169 updateGridSize(showPreview
, m_controller
->showAdditionalInfo());
173 void DolphinIconsView::zoomOut()
175 if (isZoomOutPossible()) {
176 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
178 const int oldIconSize
= settings
->iconSize();
179 int newIconSize
= oldIconSize
;
181 const bool showPreview
= m_controller
->showPreview();
183 const int previewSize
= decreasedIconSize(settings
->previewSize());
184 settings
->setPreviewSize(previewSize
);
185 if (settings
->iconSize() > previewSize
) {
186 // assure that the icon size is always <= the preview size
187 newIconSize
= previewSize
;
188 settings
->setIconSize(newIconSize
);
191 newIconSize
= decreasedIconSize(settings
->iconSize());
192 settings
->setIconSize(newIconSize
);
195 // decrease also the grid size
196 const int diff
= oldIconSize
- newIconSize
;
197 settings
->setItemWidth(settings
->itemWidth() - diff
);
198 settings
->setItemHeight(settings
->itemHeight() - diff
);
200 updateGridSize(showPreview
, m_controller
->showAdditionalInfo());
204 bool DolphinIconsView::isZoomInPossible() const
206 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
207 const int size
= m_controller
->showPreview() ? settings
->previewSize() : settings
->iconSize();
208 return size
< K3Icon::SizeEnormous
;
211 bool DolphinIconsView::isZoomOutPossible() const
213 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
214 const int size
= m_controller
->showPreview() ? settings
->previewSize() : settings
->iconSize();
215 return size
> K3Icon::SizeSmall
;
218 int DolphinIconsView::increasedIconSize(int size
) const
220 // TODO: get rid of K3Icon sizes
223 case K3Icon::SizeSmall
: incSize
= K3Icon::SizeSmallMedium
; break;
224 case K3Icon::SizeSmallMedium
: incSize
= K3Icon::SizeMedium
; break;
225 case K3Icon::SizeMedium
: incSize
= K3Icon::SizeLarge
; break;
226 case K3Icon::SizeLarge
: incSize
= K3Icon::SizeHuge
; break;
227 case K3Icon::SizeHuge
: incSize
= K3Icon::SizeEnormous
; break;
228 default: Q_ASSERT(false); break;
233 int DolphinIconsView::decreasedIconSize(int size
) const
235 // TODO: get rid of K3Icon sizes
238 case K3Icon::SizeSmallMedium
: decSize
= K3Icon::SizeSmall
; break;
239 case K3Icon::SizeMedium
: decSize
= K3Icon::SizeSmallMedium
; break;
240 case K3Icon::SizeLarge
: decSize
= K3Icon::SizeMedium
; break;
241 case K3Icon::SizeHuge
: decSize
= K3Icon::SizeLarge
; break;
242 case K3Icon::SizeEnormous
: decSize
= K3Icon::SizeHuge
; break;
243 default: Q_ASSERT(false); break;
248 void DolphinIconsView::updateGridSize(bool showPreview
, bool showAdditionalInfo
)
250 const IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
251 Q_ASSERT(settings
!= 0);
253 int itemWidth
= settings
->itemWidth();
254 int itemHeight
= settings
->itemHeight();
255 int size
= settings
->iconSize();
258 const int previewSize
= settings
->previewSize();
259 const int diff
= previewSize
- size
;
267 if (showAdditionalInfo
) {
268 itemHeight
+= m_viewOptions
.font
.pointSize() * 2;
271 if (settings
->arrangement() == QListView::TopToBottom
) {
272 // The decoration width indirectly defines the maximum
273 // width for the text wrapping. To use the maximum item width
274 // for text wrapping, it is used as decoration width.
275 m_viewOptions
.decorationSize
= QSize(itemWidth
, size
);
277 m_viewOptions
.decorationSize
= QSize(size
, size
);
280 const int spacing
= settings
->gridSpacing();
281 setGridSize(QSize(itemWidth
+ spacing
, itemHeight
+ spacing
));
283 m_controller
->setZoomInPossible(isZoomInPossible());
284 m_controller
->setZoomOutPossible(isZoomOutPossible());
287 #include "dolphiniconsview.moc"