1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "itemeffectsmanager.h"
22 #include <kiconeffect.h>
23 #include <kapplication.h>
27 #include <kglobalsettings.h>
28 #include <qclipboard.h>
33 #include "dolphinstatusbar.h"
35 ItemEffectsManager::ItemEffectsManager()
37 m_pixmapCopy
= new QPixmap();
40 ItemEffectsManager::~ItemEffectsManager()
48 void ItemEffectsManager::zoomIn()
50 Dolphin::mainWin().refreshViews();
53 void ItemEffectsManager::zoomOut()
55 Dolphin::mainWin().refreshViews();
58 void ItemEffectsManager::activateItem(void* context
)
60 KFileItem
* fileInfo
= contextFileInfo(context
);
61 const KUrl
itemURL(fileInfo
->url());
62 if (m_highlightedURL
== itemURL
) {
63 // the item is already highlighted
69 const QPixmap
* itemPixmap
= contextPixmap(context
);
70 if (itemPixmap
!= 0) {
71 // remember the pixmap and item to be able to
72 // restore it to the old state later
73 *m_pixmapCopy
= *itemPixmap
;
74 m_highlightedURL
= itemURL
;
76 // apply an icon effect to the item below the mouse pointer
77 KIconEffect iconEffect
;
78 QPixmap pixmap
= iconEffect
.apply(*itemPixmap
,
81 setContextPixmap(context
, pixmap
);
84 if (!Dolphin::mainWin().activeView()->hasSelection()) {
85 DolphinStatusBar
* statusBar
= Dolphin::mainWin().activeView()->statusBar();
86 statusBar
->setMessage(statusBarText(fileInfo
), DolphinStatusBar::Default
);
90 void ItemEffectsManager::resetActivatedItem()
92 if (m_highlightedURL
.isEmpty()) {
96 for (void* context
= firstContext(); context
!= 0; context
= nextContext(context
)) {
97 KUrl
itemURL(contextFileInfo(context
)->url());
98 if (itemURL
== m_highlightedURL
) {
99 // the highlighted item has been found and is restored to the default state
100 KIconEffect iconEffect
;
101 QPixmap pixmap
= iconEffect
.apply(*m_pixmapCopy
,
103 KIcon::DefaultState
);
105 // TODO: KFileIconView does not emit any signal when the preview has been finished.
106 // Hence check the size to prevent that a preview is hidden by restoring a
107 // non-preview pixmap.
108 const QPixmap
* highlightedPixmap
= contextPixmap(context
);
109 const bool restore
= (pixmap
.width() == highlightedPixmap
->width()) &&
110 (pixmap
.height() == highlightedPixmap
->height());
112 setContextPixmap(context
, pixmap
);
118 m_highlightedURL
= 0;
120 DolphinStatusBar
* statusBar
= Dolphin::mainWin().activeView()->statusBar();
124 void ItemEffectsManager::updateDisabledItems()
126 if (!m_disabledItems
.isEmpty()) {
127 // restore all disabled items with their original pixmap
128 for (void* context
= firstContext(); context
!= 0; context
= nextContext(context
)) {
129 const KFileItem
* fileInfo
= contextFileInfo(context
);
130 const KUrl
& fileURL
= fileInfo
->url();
131 Q3ValueListIterator
<DisabledItem
> it
= m_disabledItems
.begin();
132 while (it
!= m_disabledItems
.end()) {
133 if (fileURL
== (*it
).url
) {
134 setContextPixmap(context
, (*it
).pixmap
);
139 m_disabledItems
.clear();
142 if (!Dolphin::mainWin().clipboardContainsCutData()) {
146 QClipboard
* clipboard
= QApplication::clipboard();
147 QMimeSource
* data
= clipboard
->data();
148 if (!KUrlDrag::canDecode(data
)) {
152 // The clipboard contains items, which have been cutted. Change the pixmaps of all those
153 // items to the disabled state.
155 KUrlDrag::decode(data
, urls
);
156 for (void* context
= firstContext(); context
!= 0; context
= nextContext(context
)) {
157 const KFileItem
* fileInfo
= contextFileInfo(context
);
158 const KUrl
& fileURL
= fileInfo
->url();
159 for(KUrl::List::ConstIterator it
= urls
.begin(); it
!= urls
.end(); ++it
) {
160 if (fileURL
== (*it
)) {
161 const QPixmap
* itemPixmap
= contextPixmap(context
);
162 if (itemPixmap
!= 0) {
163 // remember old pixmap
164 DisabledItem disabledItem
;
165 disabledItem
.url
= fileURL
;
166 disabledItem
.pixmap
= *itemPixmap
;
167 m_disabledItems
.append(disabledItem
);
169 KIconEffect iconEffect
;
170 QPixmap disabledPixmap
= iconEffect
.apply(*itemPixmap
,
172 KIcon::DisabledState
);
173 setContextPixmap(context
, disabledPixmap
);
181 QString
ItemEffectsManager::statusBarText(KFileItem
* fileInfo
) const
183 if (fileInfo
->isDir()) {
184 // KFileItem::getStatusBar() returns "MyDocuments/ Folder" as
185 // status bar text for a folder 'MyDocuments'. This is adjusted
186 // to "MyDocuments (Folder)" in Dolphin.
187 return i18n("%1 (Folder)").arg(fileInfo
->name());
190 return fileInfo
->getStatusBarInfo();