]> cloud.milkyroute.net Git - dolphin.git/blob - src/itemeffectsmanager.cpp
commited initial version of Dolphin
[dolphin.git] / src / itemeffectsmanager.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
3 * peter.penz@gmx.at *
4 * *
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. *
9 * *
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. *
14 * *
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 ***************************************************************************/
20
21 #include "itemeffectsmanager.h"
22 #include <kiconeffect.h>
23 #include <kapplication.h>
24 #include <qobject.h>
25 //Added by qt3to4:
26 #include <QPixmap>
27 #include <kglobalsettings.h>
28 #include <qclipboard.h>
29 #include <kurldrag.h>
30 #include <klocale.h>
31
32 #include "dolphin.h"
33 #include "dolphinstatusbar.h"
34
35 ItemEffectsManager::ItemEffectsManager()
36 {
37 m_pixmapCopy = new QPixmap();
38 }
39
40 ItemEffectsManager::~ItemEffectsManager()
41 {
42 delete m_pixmapCopy;
43 m_pixmapCopy = 0;
44
45 m_highlightedURL = 0;
46 }
47
48 void ItemEffectsManager::zoomIn()
49 {
50 Dolphin::mainWin().refreshViews();
51 }
52
53 void ItemEffectsManager::zoomOut()
54 {
55 Dolphin::mainWin().refreshViews();
56 }
57
58 void ItemEffectsManager::activateItem(void* context)
59 {
60 KFileItem* fileInfo = contextFileInfo(context);
61 const KUrl itemURL(fileInfo->url());
62 if (m_highlightedURL == itemURL) {
63 // the item is already highlighted
64 return;
65 }
66
67 resetActivatedItem();
68
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;
75
76 // apply an icon effect to the item below the mouse pointer
77 KIconEffect iconEffect;
78 QPixmap pixmap = iconEffect.apply(*itemPixmap,
79 KIcon::Desktop,
80 KIcon::ActiveState);
81 setContextPixmap(context, pixmap);
82 }
83
84 if (!Dolphin::mainWin().activeView()->hasSelection()) {
85 DolphinStatusBar* statusBar = Dolphin::mainWin().activeView()->statusBar();
86 statusBar->setMessage(statusBarText(fileInfo), DolphinStatusBar::Default);
87 }
88 }
89
90 void ItemEffectsManager::resetActivatedItem()
91 {
92 if (m_highlightedURL.isEmpty()) {
93 return;
94 }
95
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,
102 KIcon::Desktop,
103 KIcon::DefaultState);
104
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());
111 if (restore) {
112 setContextPixmap(context, pixmap);
113 }
114 break;
115 }
116 }
117
118 m_highlightedURL = 0;
119
120 DolphinStatusBar* statusBar = Dolphin::mainWin().activeView()->statusBar();
121 statusBar->clear();
122 }
123
124 void ItemEffectsManager::updateDisabledItems()
125 {
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);
135 }
136 ++it;
137 }
138 }
139 m_disabledItems.clear();
140 }
141
142 if (!Dolphin::mainWin().clipboardContainsCutData()) {
143 return;
144 }
145
146 QClipboard* clipboard = QApplication::clipboard();
147 QMimeSource* data = clipboard->data();
148 if (!KUrlDrag::canDecode(data)) {
149 return;
150 }
151
152 // The clipboard contains items, which have been cutted. Change the pixmaps of all those
153 // items to the disabled state.
154 KUrl::List urls;
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);
168
169 KIconEffect iconEffect;
170 QPixmap disabledPixmap = iconEffect.apply(*itemPixmap,
171 KIcon::Desktop,
172 KIcon::DisabledState);
173 setContextPixmap(context, disabledPixmap);
174 }
175 break;
176 }
177 }
178 }
179 }
180
181 QString ItemEffectsManager::statusBarText(KFileItem* fileInfo) const
182 {
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());
188 }
189
190 return fileInfo->getStatusBarInfo();
191 }