1 /***********************************************************************
2 * SPDX-FileCopyrightText: 2003-2004 Max Howell <max.howell@methylblue.com>
3 * SPDX-FileCopyrightText: 2008-2009 Martin Sandsmark <martin.sandsmark@kde.org>
4 *
5 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
6 ***********************************************************************/
7 
8 #ifndef WIDGET_H
9 #define WIDGET_H
10 
11 #include <KJob>
12 #include <QUrl>
13 
14 #include <QLabel>
15 #include <QDragEnterEvent>
16 #include <QDropEvent>
17 #include <QMouseEvent>
18 #include <QPaintEvent>
19 #include <QResizeEvent>
20 #include <QWidget>
21 #include <QTimer>
22 
23 #include "map.h"
24 #include "Config.h" // Dirty
25 
26 class Folder;
27 class File;
28 namespace KIO {
29 class Job;
30 }
31 
32 namespace RadialMap
33 {
34 class Segment;
35 
36 class Widget : public QWidget
37 {
38     Q_OBJECT
39 
40 public:
41     explicit Widget(QWidget* = nullptr, bool = false);
42     ~Widget() override;
43     QString path() const;
44     QUrl url(File const * const = nullptr) const;
45 
isValid()46     bool isValid() const {
47         return m_tree != nullptr;
48     }
49 
isSummary()50     bool isSummary() const {
51         return m_isSummary;
52     }
53 
54     friend class Label; //FIXME badness
55 
saveSvg(const QString & path)56     void saveSvg(const QString &path) { m_map.saveSvg(path); }
57 
58 public Q_SLOTS:
59     void zoomIn();
60     void zoomOut();
61     void create(const Folder*);
62     void invalidate();
63     void refresh(const Dirty filth);
64 
65 private Q_SLOTS:
66     void resizeTimeout();
67     void sendFakeMouseEvent();
68     void deleteJobFinished(KJob*);
69     void createFromCache(const Folder*);
70 
71 Q_SIGNALS:
72     void activated(const QUrl&);
73     void invalidated(const QUrl&);
74     void folderCreated(const Folder*);
75     void mouseHover(const QString&);
76     void giveMeTreeFor(const QUrl&);
77     void rescanRequested(const QUrl&);
78 
79 protected:
80     void changeEvent(QEvent*) override;
81     void dragEnterEvent(QDragEnterEvent*) override;
82     void dropEvent(QDropEvent*) override;
83     void mouseMoveEvent(QMouseEvent*) override;
84     void mousePressEvent(QMouseEvent*) override;
85     void paintEvent(QPaintEvent*) override;
86     void resizeEvent(QResizeEvent*) override;
87     void enterEvent(QEvent*) override;
88     void leaveEvent(QEvent*) override;
89 
90 protected:
91     const Segment *segmentAt(QPointF position) const; //FIXME const reference for a library others can use
rootSegment()92     const Segment *rootSegment() const {
93         return m_rootSegment;    ///never == 0
94     }
focusSegment()95     const Segment *focusSegment() const {
96         return m_focus;    ///0 == nothing in focus
97     }
98 
99 private:
100     void paintExplodedLabels(QPainter&) const;
101 
102     const Folder *m_tree;
103     const Segment   *m_focus;
104     QPointF           m_offset;
105     QTimer           m_timer;
106     Map              m_map;
107     Segment          *m_rootSegment;
108     const bool       m_isSummary;
109     const Segment    *m_toBeDeleted;
110     QLabel           m_tooltip;
111 };
112 }
113 
114 #endif
115