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>
32 #include "dolphinstatusbar.h"
34 ItemEffectsManager::ItemEffectsManager()
36 m_pixmapCopy
= new QPixmap();
39 ItemEffectsManager::~ItemEffectsManager()
47 void ItemEffectsManager::zoomIn()
49 Dolphin::mainWin().refreshViews();
52 void ItemEffectsManager::zoomOut()
54 Dolphin::mainWin().refreshViews();
57 void ItemEffectsManager::activateItem(void* context
)
59 KFileItem
* fileInfo
= contextFileInfo(context
);
60 const KUrl
itemUrl(fileInfo
->url());
61 if (m_highlightedUrl
== itemUrl
) {
62 // the item is already highlighted
68 const QPixmap
* itemPixmap
= contextPixmap(context
);
69 if (itemPixmap
!= 0) {
70 // remember the pixmap and item to be able to
71 // restore it to the old state later
72 *m_pixmapCopy
= *itemPixmap
;
73 m_highlightedUrl
= itemUrl
;
75 // apply an icon effect to the item below the mouse pointer
76 KIconEffect iconEffect
;
77 QPixmap pixmap
= iconEffect
.apply(*itemPixmap
,
80 setContextPixmap(context
, pixmap
);
83 if (!Dolphin::mainWin().activeView()->hasSelection()) {
84 DolphinStatusBar
* statusBar
= Dolphin::mainWin().activeView()->statusBar();
85 statusBar
->setMessage(statusBarText(fileInfo
), DolphinStatusBar::Default
);
89 void ItemEffectsManager::resetActivatedItem()
91 if (m_highlightedUrl
.isEmpty()) {
95 for (void* context
= firstContext(); context
!= 0; context
= nextContext(context
)) {
96 KUrl
itemUrl(contextFileInfo(context
)->url());
97 if (itemUrl
== m_highlightedUrl
) {
98 // the highlighted item has been found and is restored to the default state
99 KIconEffect iconEffect
;
100 QPixmap pixmap
= iconEffect
.apply(*m_pixmapCopy
,
102 K3Icon::DefaultState
);
104 // TODO: KFileIconView does not emit any signal when the preview has been finished.
105 // Hence check the size to prevent that a preview is hidden by restoring a
106 // non-preview pixmap.
107 const QPixmap
* highlightedPixmap
= contextPixmap(context
);
108 const bool restore
= (pixmap
.width() == highlightedPixmap
->width()) &&
109 (pixmap
.height() == highlightedPixmap
->height());
111 setContextPixmap(context
, pixmap
);
117 m_highlightedUrl
= 0;
119 DolphinStatusBar
* statusBar
= Dolphin::mainWin().activeView()->statusBar();
123 void ItemEffectsManager::updateDisabledItems()
125 if (!m_disabledItems
.isEmpty()) {
126 // restore all disabled items with their original pixmap
127 for (void* context
= firstContext(); context
!= 0; context
= nextContext(context
)) {
128 const KFileItem
* fileInfo
= contextFileInfo(context
);
129 const KUrl
& fileUrl
= fileInfo
->url();
130 Q3ValueListIterator
<DisabledItem
> it
= m_disabledItems
.begin();
131 while (it
!= m_disabledItems
.end()) {
132 if (fileUrl
== (*it
).url
) {
133 setContextPixmap(context
, (*it
).pixmap
);
138 m_disabledItems
.clear();
141 if (!Dolphin::mainWin().clipboardContainsCutData()) {
145 QClipboard
* clipboard
= QApplication::clipboard();
146 const QMimeData
* data
= clipboard
->mimeData();
147 KUrl::List urls
= KUrl::List::fromMimeData(data
);
148 if (urls
.isEmpty()) {
152 // The clipboard contains items, which have been cutted. Change the pixmaps of all those
153 // items to the disabled state.
154 for (void* context
= firstContext(); context
!= 0; context
= nextContext(context
)) {
155 const KFileItem
* fileInfo
= contextFileInfo(context
);
156 const KUrl
& fileUrl
= fileInfo
->url();
157 for(KUrl::List::ConstIterator it
= urls
.begin(); it
!= urls
.end(); ++it
) {
158 if (fileUrl
== (*it
)) {
159 const QPixmap
* itemPixmap
= contextPixmap(context
);
160 if (itemPixmap
!= 0) {
161 // remember old pixmap
162 DisabledItem disabledItem
;
163 disabledItem
.url
= fileUrl
;
164 disabledItem
.pixmap
= *itemPixmap
;
165 m_disabledItems
.append(disabledItem
);
167 KIconEffect iconEffect
;
168 QPixmap disabledPixmap
= iconEffect
.apply(*itemPixmap
,
170 K3Icon::DisabledState
);
171 setContextPixmap(context
, disabledPixmap
);
179 QString
ItemEffectsManager::statusBarText(KFileItem
* fileInfo
) const
181 if (fileInfo
->isDir()) {
182 // KFileItem::getStatusBar() returns "MyDocuments/ Folder" as
183 // status bar text for a folder 'MyDocuments'. This is adjusted
184 // to "MyDocuments (Folder)" in Dolphin.
185 return i18n("%1 (Folder)",fileInfo
->name());
188 return fileInfo
->getStatusBarInfo();