]>
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(slotShowPreviewChanged(bool)));
56 connect(controller
, SIGNAL(showAdditionalInfoChanged(bool)),
57 this, SLOT(slotShowAdditionalInfoChanged(bool)));
58 connect(controller
, SIGNAL(zoomIn()),
59 this, SLOT(zoomIn()));
60 connect(controller
, SIGNAL(zoomOut()),
61 this, SLOT(zoomOut()));
63 // apply the icons mode settings to the widget
64 const IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
65 Q_ASSERT(settings
!= 0);
67 m_viewOptions
= KListView::viewOptions();
68 m_viewOptions
.showDecorationSelected
= true;
70 QFont
font(settings
->fontFamily(), settings
->fontSize());
71 font
.setItalic(settings
->italicFont());
72 font
.setBold(settings
->boldFont());
73 m_viewOptions
.font
= font
;
74 if (settings
->numberOfTextlines() > 1) {
75 m_viewOptions
.textElideMode
= Qt::ElideNone
;
76 m_viewOptions
.features
= QStyleOptionViewItemV2::WrapText
;
79 updateGridSize(controller
->showPreview(), controller
->showAdditionalInfo());
81 if (settings
->arrangement() == QListView::TopToBottom
) {
82 setFlow(QListView::LeftToRight
);
83 m_viewOptions
.decorationPosition
= QStyleOptionViewItem::Top
;
85 setFlow(QListView::TopToBottom
);
86 m_viewOptions
.decorationPosition
= QStyleOptionViewItem::Left
;
90 DolphinIconsView::~DolphinIconsView()
94 QStyleOptionViewItem
DolphinIconsView::viewOptions() const
99 void DolphinIconsView::contextMenuEvent(QContextMenuEvent
* event
)
101 KListView::contextMenuEvent(event
);
102 m_controller
->triggerContextMenuRequest(event
->pos());
105 void DolphinIconsView::mouseReleaseEvent(QMouseEvent
* event
)
107 KListView::mouseReleaseEvent(event
);
108 m_controller
->triggerActivation();
111 void DolphinIconsView::dragEnterEvent(QDragEnterEvent
* event
)
113 if (event
->mimeData()->hasUrls()) {
114 event
->acceptProposedAction();
118 void DolphinIconsView::dropEvent(QDropEvent
* event
)
120 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
121 if (!urls
.isEmpty()) {
122 m_controller
->indicateDroppedUrls(urls
,
123 indexAt(event
->pos()),
125 event
->acceptProposedAction();
127 KListView::dropEvent(event
);
130 void DolphinIconsView::slotShowPreviewChanged(bool showPreview
)
132 updateGridSize(showPreview
, m_controller
->showAdditionalInfo());
135 void DolphinIconsView::slotShowAdditionalInfoChanged(bool showAdditionalInfo
)
137 updateGridSize(m_controller
->showPreview(), showAdditionalInfo
);
140 void DolphinIconsView::zoomIn()
142 if (isZoomInPossible()) {
143 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
145 const int oldIconSize
= settings
->iconSize();
146 int newIconSize
= oldIconSize
;
148 const bool showPreview
= m_controller
->showPreview();
150 const int previewSize
= increasedIconSize(settings
->previewSize());
151 settings
->setPreviewSize(previewSize
);
153 newIconSize
= increasedIconSize(oldIconSize
);
154 settings
->setIconSize(newIconSize
);
155 if (settings
->previewSize() < newIconSize
) {
156 // assure that the preview size is always >= the icon size
157 settings
->setPreviewSize(newIconSize
);
161 // increase also the grid size
162 const int diff
= newIconSize
- oldIconSize
;
163 settings
->setGridWidth(settings
->gridWidth() + diff
);
164 settings
->setGridHeight(settings
->gridHeight() + diff
);
166 updateGridSize(showPreview
, m_controller
->showAdditionalInfo());
170 void DolphinIconsView::zoomOut()
172 if (isZoomOutPossible()) {
173 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
175 const int oldIconSize
= settings
->iconSize();
176 int newIconSize
= oldIconSize
;
178 const bool showPreview
= m_controller
->showPreview();
180 const int previewSize
= decreasedIconSize(settings
->previewSize());
181 settings
->setPreviewSize(previewSize
);
182 if (settings
->iconSize() > previewSize
) {
183 // assure that the icon size is always <= the preview size
184 newIconSize
= previewSize
;
185 settings
->setIconSize(newIconSize
);
188 newIconSize
= decreasedIconSize(settings
->iconSize());
189 settings
->setIconSize(newIconSize
);
192 // decrease also the grid size
193 const int diff
= oldIconSize
- newIconSize
;
194 settings
->setGridWidth(settings
->gridWidth() - diff
);
195 settings
->setGridHeight(settings
->gridHeight() - diff
);
197 updateGridSize(showPreview
, m_controller
->showAdditionalInfo());
201 bool DolphinIconsView::isZoomInPossible() const
203 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
204 const int size
= m_controller
->showPreview() ? settings
->previewSize() : settings
->iconSize();
205 return size
< K3Icon::SizeEnormous
;
208 bool DolphinIconsView::isZoomOutPossible() const
210 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
211 const int size
= m_controller
->showPreview() ? settings
->previewSize() : settings
->iconSize();
212 return size
> K3Icon::SizeSmall
;
215 int DolphinIconsView::increasedIconSize(int size
) const
217 // TODO: get rid of K3Icon sizes
220 case K3Icon::SizeSmall
: incSize
= K3Icon::SizeSmallMedium
; break;
221 case K3Icon::SizeSmallMedium
: incSize
= K3Icon::SizeMedium
; break;
222 case K3Icon::SizeMedium
: incSize
= K3Icon::SizeLarge
; break;
223 case K3Icon::SizeLarge
: incSize
= K3Icon::SizeHuge
; break;
224 case K3Icon::SizeHuge
: incSize
= K3Icon::SizeEnormous
; break;
225 default: Q_ASSERT(false); break;
230 int DolphinIconsView::decreasedIconSize(int size
) const
232 // TODO: get rid of K3Icon sizes
235 case K3Icon::SizeSmallMedium
: decSize
= K3Icon::SizeSmall
; break;
236 case K3Icon::SizeMedium
: decSize
= K3Icon::SizeSmallMedium
; break;
237 case K3Icon::SizeLarge
: decSize
= K3Icon::SizeMedium
; break;
238 case K3Icon::SizeHuge
: decSize
= K3Icon::SizeLarge
; break;
239 case K3Icon::SizeEnormous
: decSize
= K3Icon::SizeHuge
; break;
240 default: Q_ASSERT(false); break;
245 void DolphinIconsView::updateGridSize(bool showPreview
, bool showAdditionalInfo
)
247 const IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
248 Q_ASSERT(settings
!= 0);
250 int gridWidth
= settings
->gridWidth();
251 int gridHeight
= settings
->gridHeight();
252 int size
= settings
->iconSize();
255 const int previewSize
= settings
->previewSize();
256 const int diff
= previewSize
- size
;
264 if (showAdditionalInfo
) {
265 gridHeight
+= m_viewOptions
.font
.pointSize() * 2;
268 m_viewOptions
.decorationSize
= QSize(size
, size
);
269 setGridSize(QSize(gridWidth
, gridHeight
));
271 m_controller
->setZoomInPossible(isZoomInPossible());
272 m_controller
->setZoomOutPossible(isZoomOutPossible());
275 #include "dolphiniconsview.moc"