]>
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"
25 #include "dolphin_iconsmodesettings.h"
27 #include <kdirmodel.h>
28 #include <kfileitem.h>
29 #include <kfileitemdelegate.h>
31 #include <QAbstractProxyModel>
34 DolphinIconsView::DolphinIconsView(QWidget
* parent
, DolphinController
* controller
) :
36 m_controller(controller
)
38 Q_ASSERT(controller
!= 0);
39 setViewMode(QListView::IconMode
);
40 setResizeMode(QListView::Adjust
);
42 viewport()->setAttribute(Qt::WA_Hover
);
44 connect(this, SIGNAL(clicked(const QModelIndex
&)),
45 controller
, SLOT(triggerItem(const QModelIndex
&)));
46 connect(this, SIGNAL(activated(const QModelIndex
&)),
47 controller
, SLOT(triggerItem(const QModelIndex
&)));
48 connect(controller
, SIGNAL(showPreviewChanged(bool)),
49 this, SLOT(updateGridSize(bool)));
50 connect(controller
, SIGNAL(zoomIn()),
51 this, SLOT(zoomIn()));
52 connect(controller
, SIGNAL(zoomOut()),
53 this, SLOT(zoomOut()));
55 // apply the icons mode settings to the widget
56 const IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
57 Q_ASSERT(settings
!= 0);
59 m_viewOptions
= QListView::viewOptions();
61 QFont
font(settings
->fontFamily(), settings
->fontSize());
62 font
.setItalic(settings
->italicFont());
63 font
.setBold(settings
->boldFont());
64 m_viewOptions
.font
= font
;
66 updateGridSize(controller
->showPreview());
68 if (settings
->arrangement() == QListView::TopToBottom
) {
69 setFlow(QListView::LeftToRight
);
70 m_viewOptions
.decorationPosition
= QStyleOptionViewItem::Top
;
73 setFlow(QListView::TopToBottom
);
74 m_viewOptions
.decorationPosition
= QStyleOptionViewItem::Left
;
78 DolphinIconsView::~DolphinIconsView()
82 QStyleOptionViewItem
DolphinIconsView::viewOptions() const
87 void DolphinIconsView::contextMenuEvent(QContextMenuEvent
* event
)
89 QListView::contextMenuEvent(event
);
90 m_controller
->triggerContextMenuRequest(event
->pos());
93 void DolphinIconsView::mouseReleaseEvent(QMouseEvent
* event
)
95 QListView::mouseReleaseEvent(event
);
96 m_controller
->triggerActivation();
99 void DolphinIconsView::dragEnterEvent(QDragEnterEvent
* event
)
101 if (event
->mimeData()->hasUrls()) {
102 event
->acceptProposedAction();
106 void DolphinIconsView::dropEvent(QDropEvent
* event
)
108 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
109 if (!urls
.isEmpty()) {
110 m_controller
->indicateDroppedUrls(urls
,
111 indexAt(event
->pos()),
113 event
->acceptProposedAction();
115 QListView::dropEvent(event
);
118 void DolphinIconsView::updateGridSize(bool showPreview
)
120 const IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
121 Q_ASSERT(settings
!= 0);
123 int gridWidth
= settings
->gridWidth();
124 int gridHeight
= settings
->gridHeight();
125 int size
= settings
->iconSize();
128 const int previewSize
= settings
->previewSize();
129 const int diff
= previewSize
- size
;
138 m_viewOptions
.decorationSize
= QSize(size
, size
);
139 setGridSize(QSize(gridWidth
, gridHeight
));
141 m_controller
->setZoomInPossible(isZoomInPossible());
142 m_controller
->setZoomOutPossible(isZoomOutPossible());
145 void DolphinIconsView::zoomIn()
147 if (isZoomInPossible()) {
148 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
150 const bool showPreview
= m_controller
->showPreview();
152 const int previewSize
= increasedIconSize(settings
->previewSize());
153 settings
->setPreviewSize(previewSize
);
156 const int iconSize
= increasedIconSize(settings
->iconSize());
157 settings
->setIconSize(iconSize
);
158 if (settings
->previewSize() < iconSize
) {
159 // assure that the preview size is always >= the icon size
160 settings
->setPreviewSize(iconSize
);
164 updateGridSize(showPreview
);
168 void DolphinIconsView::zoomOut()
170 if (isZoomOutPossible()) {
171 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
173 const bool showPreview
= m_controller
->showPreview();
175 const int previewSize
= decreasedIconSize(settings
->previewSize());
176 settings
->setPreviewSize(previewSize
);
177 if (settings
->iconSize() > previewSize
) {
178 // assure that the icon size is always <= the preview size
179 settings
->setIconSize(previewSize
);
183 const int iconSize
= decreasedIconSize(settings
->iconSize());
184 settings
->setIconSize(iconSize
);
187 updateGridSize(showPreview
);
191 bool DolphinIconsView::isZoomInPossible() const
193 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
194 const int size
= m_controller
->showPreview() ? settings
->previewSize() : settings
->iconSize();
195 return size
< K3Icon::SizeEnormous
;
198 bool DolphinIconsView::isZoomOutPossible() const
200 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
201 const int size
= m_controller
->showPreview() ? settings
->previewSize() : settings
->iconSize();
202 return size
> K3Icon::SizeSmall
;
205 int DolphinIconsView::increasedIconSize(int size
) const
207 // TODO: get rid of K3Icon sizes
210 case K3Icon::SizeSmall
: incSize
= K3Icon::SizeSmallMedium
; break;
211 case K3Icon::SizeSmallMedium
: incSize
= K3Icon::SizeMedium
; break;
212 case K3Icon::SizeMedium
: incSize
= K3Icon::SizeLarge
; break;
213 case K3Icon::SizeLarge
: incSize
= K3Icon::SizeHuge
; break;
214 case K3Icon::SizeHuge
: incSize
= K3Icon::SizeEnormous
; break;
215 default: Q_ASSERT(false); break;
220 int DolphinIconsView::decreasedIconSize(int size
) const
222 // TODO: get rid of K3Icon sizes
225 case K3Icon::SizeSmallMedium
: decSize
= K3Icon::SizeSmall
; break;
226 case K3Icon::SizeMedium
: decSize
= K3Icon::SizeSmallMedium
; break;
227 case K3Icon::SizeLarge
: decSize
= K3Icon::SizeMedium
; break;
228 case K3Icon::SizeHuge
: decSize
= K3Icon::SizeLarge
; break;
229 case K3Icon::SizeEnormous
: decSize
= K3Icon::SizeHuge
; break;
230 default: Q_ASSERT(false); break;
235 #include "dolphiniconsview.moc"