29 #include <KIconLoader>
32 #include <KIO/DeleteJob>
33 #include <KIO/JobUiDelegate>
35 #include <KMessageBox>
38 #include <KToolInvocation>
41 #include <QtGui/QApplication>
42 #include <QtGui/QClipboard>
43 #include <QtGui/QPainter>
44 #include <QtCore/QTimer>
45 #include <QtGui/QDropEvent>
46 #include <QtGui/QPaintEvent>
47 #include <QtGui/QResizeEvent>
48 #include <QtGui/QMouseEvent>
49 #include <QtGui/QDragEnterEvent>
50 #include <QtGui/QToolTip>
56 if (
m_map.resize(rect()))
57 m_timer.setSingleShot(
true);
61 m_offset.rx() = (width() -
m_map.width()) / 2;
62 m_offset.ry() = (height() -
m_map.height()) / 2;
71 paint.drawPixmap(m_offset,
m_map.pixmap());
74 paint.drawText(rect(), 0, i18nc(
"We messed up, the user needs to initiate a rescan.",
"Internal representation is invalid,\nplease rescan."));
79 if (!
m_map.isNull() && !m_timer.isActive())
81 if (Config::antialias) {
82 paint.setRenderHint(QPainter::Antialiasing);
84 paint.translate(0.5, 0.5);
86 paintExplodedLabels(paint);
96 if (!
m_map.m_signature)
99 if (e.x() <=
m_map.width() && e.y() <=
m_map.height())
102 e.rx() -=
m_map.width() / 2;
103 e.ry() =
m_map.height() / 2 - e.y();
105 double length = hypot(e.x(), e.y());
107 if (length >=
m_map.m_innerRadius)
109 uint depth = ((int)length -
m_map.m_innerRadius) /
m_map.m_ringBreadth;
111 if (depth <=
m_map.m_visibleDepth)
118 uint a = (uint)(acos((
double)e.x() /
length) * 916.736);
121 if (e.y() < 0) a = 5760 - a;
123 #define ring (m_map.m_signature + depth)
125 if ((*it)->intersects(a))
130 else return m_rootSegment;
140 Segment const *
const oldFocus = m_focus;
143 m_focus = segmentAt(p);
147 if (m_focus != oldFocus)
149 setCursor(Qt::PointingHandCursor);
151 QString
string = m_focus->file()->fullPath(m_tree)
153 + m_focus->file()->humanReadableSize()
156 if (m_focus->file()->isFolder()) {
157 int files =
static_cast<const Folder*
>(m_focus->file())->children();
158 const uint percent = uint((100 * files) / (
double)m_tree->children());
159 string += i18np(
"File: %1",
"Files: %1", files);
161 if (percent > 0)
string += QString(QLatin1String(
" (%1%)" )).arg(KGlobal::locale()->formatNumber(percent, 0));
165 if (m_focus == m_rootSegment && url != url.upUrl()) {
166 string += i18n(
"\nClick to go up to parent directory");
169 QToolTip::showText(e->globalPos(), string,
this);
171 emit mouseHover(m_focus->file()->fullPath());
175 else if (oldFocus && oldFocus->
file() != m_tree)
180 emit mouseHover(QString());
186 if (!m_focus)
return;
188 setCursor(Qt::PointingHandCursor);
189 emit mouseHover(m_focus->file()->fullPath());
200 if (m_focus && !m_focus->isFake())
203 const bool isDir = m_focus->file()->isFolder();
206 QAction* openFileManager = 0;
207 QAction* openTerminal = 0;
208 QAction* centerMap = 0;
209 QAction* openFile = 0;
210 QAction* copyClipboard = 0;
211 QAction* deleteItem = 0;
213 if (e->button() == Qt::RightButton)
216 popup.addTitle(m_focus->file()->fullPath(m_tree));
219 openFileManager = popup.addAction(KIcon(QLatin1String(
"system-file-manager" )), i18n(
"Open &File Manager Here"));
221 if (url.protocol() == QLatin1String(
"file" ))
222 openTerminal = popup.addAction(KIcon(QLatin1String(
"utilities-terminal" )), i18n(
"Open &Terminal Here"));
224 if (m_focus->file() != m_tree) {
225 popup.addSeparator();
226 centerMap = popup.addAction(KIcon(QLatin1String(
"zoom-in" )), i18n(
"&Center Map Here"));
230 openFile = popup.addAction(KIcon(QLatin1String(
"document-open" )), i18nc(
"Scan/open the path of the selected element",
"&Open"));
232 popup.addSeparator();
233 copyClipboard = popup.addAction(KIcon(QLatin1String(
"edit-copy" )), i18n(
"&Copy to clipboard"));
235 popup.addSeparator();
236 deleteItem = popup.addAction(KIcon(QLatin1String(
"edit-delete" )), i18n(
"&Delete"));
238 QAction* clicked = popup.exec(e->globalPos(), 0);
240 if (openFileManager && clicked == openFileManager) {
241 KRun::runUrl(url.url(),QLatin1String(
"inode/directory" ),
this);
242 }
else if (openTerminal && clicked == openTerminal) {
243 KToolInvocation::invokeTerminal(QString(),url.path());
244 }
else if (centerMap && clicked == centerMap) {
246 }
else if (openFile && clicked == openFile) {
248 }
else if (clicked == copyClipboard) {
249 QMimeData* mimedata =
new QMimeData();
250 url.populateMimeData(mimedata);
251 QApplication::clipboard()->setMimeData(mimedata , QClipboard::Clipboard);
252 }
else if (clicked == deleteItem) {
253 m_toBeDeleted = m_focus;
254 const KUrl url =
Widget::url(m_toBeDeleted->file());
255 const QString message = m_toBeDeleted->file()->isFolder()
256 ? i18n(
"<qt>The folder at <i>'%1'</i> will be <b>recursively</b> and <b>permanently</b> deleted.</qt>", url.prettyUrl())
257 : i18n(
"<qt><i>'%1'</i> will be <b>permanently</b> deleted.</qt>", url.prettyUrl());
258 const int userIntention = KMessageBox::warningContinueCancel(
260 QString(), KGuiItem(i18n(
"&Delete"), QLatin1String(
"edit-delete" )));
262 if (userIntention == KMessageBox::Continue) {
263 KIO::Job *job = KIO::del(url);
264 job->ui()->setWindow(
this);
265 connect(job, SIGNAL(finished(KJob*)),
this, SLOT(deleteJobFinished(KJob*)));
266 QApplication::setOverrideCursor(Qt::BusyCursor);
271 sendFakeMouseEvent();
277 const QRect rect(e->x() - 20, e->y() - 20, 40, 40);
279 if (!isDir || e->button() == Qt::MidButton) {
281 new KRun(url,
this,
true);
283 else if (m_focus->file() != m_tree) {
286 createFromCache((
Folder *)m_focus->file());
288 else if (url.upUrl() != url)
289 emit giveMeTreeFor(url.upUrl());
294 void RadialMap::Widget::deleteJobFinished(KJob *job)
296 QApplication::restoreOverrideCursor();
298 if (!job->error() && m_toBeDeleted) {
299 m_toBeDeleted->file()->parent()->remove(m_toBeDeleted->file());
300 delete m_toBeDeleted->file();
303 m_map.make(m_tree,
true);
306 KMessageBox::error(
this, job->errorString(), i18n(
"Error while deleting"));
311 KUrl::List uriList = KUrl::List::fromMimeData(e->mimeData());
312 if (!uriList.isEmpty())
313 emit giveMeTreeFor(uriList.first());
318 KUrl::List uriList = KUrl::List::fromMimeData(e->mimeData());
319 e->setAccepted(!uriList.isEmpty());
324 if (e->type() == QEvent::ApplicationPaletteChange ||
325 e->type() == QEvent::PaletteChange)
const File * file() const
static const int length[]
http QObject const QList< QVariant > m_map(0)