]> cloud.milkyroute.net Git - dolphin.git/blob - src/itemeffectsmanager.cpp
Migrated the ViewPropertiesDialog to Qt4.
[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 <klocale.h>
30
31 #include "dolphin.h"
32 #include "dolphinstatusbar.h"
33
34 ItemEffectsManager::ItemEffectsManager()
35 {
36 m_pixmapCopy = new QPixmap();
37 }
38
39 ItemEffectsManager::~ItemEffectsManager()
40 {
41 delete m_pixmapCopy;
42 m_pixmapCopy = 0;
43
44 m_highlightedUrl = 0;
45 }
46
47 void ItemEffectsManager::zoomIn()
48 {
49 Dolphin::mainWin().refreshViews();
50 }
51
52 void ItemEffectsManager::zoomOut()
53 {
54 Dolphin::mainWin().refreshViews();
55 }
56
57 void ItemEffectsManager::activateItem(void* context)
58 {
59 KFileItem* fileInfo = contextFileInfo(context);
60 const KUrl itemUrl(fileInfo->url());
61 if (m_highlightedUrl == itemUrl) {
62 // the item is already highlighted
63 return;
64 }
65
66 resetActivatedItem();
67
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;
74
75 // apply an icon effect to the item below the mouse pointer
76 KIconEffect iconEffect;
77 QPixmap pixmap = iconEffect.apply(*itemPixmap,
78 K3Icon::Desktop,
79 K3Icon::ActiveState);
80 setContextPixmap(context, pixmap);
81 }
82
83 if (!Dolphin::mainWin().activeView()->hasSelection()) {
84 DolphinStatusBar* statusBar = Dolphin::mainWin().activeView()->statusBar();
85 statusBar->setMessage(statusBarText(fileInfo), DolphinStatusBar::Default);
86 }
87 }
88
89 void ItemEffectsManager::resetActivatedItem()
90 {
91 if (m_highlightedUrl.isEmpty()) {
92 return;
93 }
94
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,
101 K3Icon::Desktop,
102 K3Icon::DefaultState);
103
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());
110 if (restore) {
111 setContextPixmap(context, pixmap);
112 }
113 break;
114 }
115 }
116
117 m_highlightedUrl = 0;
118
119 DolphinStatusBar* statusBar = Dolphin::mainWin().activeView()->statusBar();
120 statusBar->clear();
121 }
122
123 void ItemEffectsManager::updateDisabledItems()
124 {
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);
134 }
135 ++it;
136 }
137 }
138 m_disabledItems.clear();
139 }
140
141 if (!Dolphin::mainWin().clipboardContainsCutData()) {
142 return;
143 }
144
145 QClipboard* clipboard = QApplication::clipboard();
146 const QMimeData* data = clipboard->mimeData();
147 KUrl::List urls = KUrl::List::fromMimeData(data);
148 if (urls.isEmpty()) {
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 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);
166
167 KIconEffect iconEffect;
168 QPixmap disabledPixmap = iconEffect.apply(*itemPixmap,
169 K3Icon::Desktop,
170 K3Icon::DisabledState);
171 setContextPixmap(context, disabledPixmap);
172 }
173 break;
174 }
175 }
176 }
177 }
178
179 QString ItemEffectsManager::statusBarText(KFileItem* fileInfo) const
180 {
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());
186 }
187
188 return fileInfo->getStatusBarInfo();
189 }