widget.cpp 5.19 KB
Newer Older
1
2
/***********************************************************************
* Copyright 2003-2004  Max Howell <max.howell@methylblue.com>
3
* Copyright 2008-2009  Martin Sandsmark <martin.sandsmark@kde.org>
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
***********************************************************************/

22
23
#include "widget.h"

24
25
#include "part/Config.h"
#include "part/fileTree.h"
26
#include "radialMap.h" //constants
27
#include "map.h"
28

29
#include <KCursor>        //ctor
30
#include <QUrl>
31

32
33
34
35
36
#include <QApplication>   //sendEvent
#include <QBitmap>        //ctor - finding cursor size
#include <QCursor>        //slotPostMouseEvent()
#include <QTimer>         //member
#include <QWidget>
37

38

39
RadialMap::Widget::Widget(QWidget *parent, bool isSummary)
40
41
42
        : QWidget(parent)
        , m_tree(0)
        , m_focus(0)
43
        , m_map(isSummary)
44
        , m_rootSegment(0) //TODO we don't delete it, *shrug*
45
        , m_isSummary(isSummary)
46
        , m_toBeDeleted(0)
47
{
48
    setAcceptDrops(true);
49
    setMinimumSize(350, 250);
50

51
52
    connect(this, &Widget::folderCreated, this, &Widget::sendFakeMouseEvent);
    connect(&m_timer, &QTimer::timeout, this, &Widget::resizeTimeout);
53
54
}

55
56
57
58
59
60
RadialMap::Widget::~Widget()
{
    delete m_rootSegment;
}


61
QString RadialMap::Widget::path() const
62
{
63
    return m_tree->fullPath();
64
65
}

66
QUrl RadialMap::Widget::url(File const * const file) const
67
{
68
    return QUrl::fromUserInput(file ? file->fullPath() : m_tree->fullPath());
69
70
}

71
void RadialMap::Widget::invalidate()
72
{
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
    if (isValid())
    {
        //**** have to check that only way to invalidate is this function frankly
        //**** otherwise you may get bugs..

        //disable mouse tracking
        setMouseTracking(false);

        //ensure this class won't think we have a map still
        m_tree  = 0;
        m_focus = 0;

        delete m_rootSegment;
        m_rootSegment = 0;

        //FIXME move this disablement thing no?
        //      it is confusing in other areas, like the whole createFromCache() thing
90
91
        m_map.invalidate();
        update();
92
93
94
95

        //tell rest of Filelight
        emit invalidated(url());
    }
96
97
98
}

void
99
RadialMap::Widget::create(const Folder *tree)
100
{
101
102
    //it is not the responsibility of create() to invalidate first
    //skip invalidation at your own risk
103

104
    //FIXME make it the responsibility of create to invalidate first
105

106
107
    if (tree)
    {
108
        m_focus = 0;
109
110
        //generate the filemap image
        m_map.make(tree);
111

112
113
        //this is the inner circle in the center
        m_rootSegment = new Segment(tree, 0, 16*360);
114

115
116
        setMouseTracking(true);
    }
117

118
    m_tree = tree;
119

120
    //tell rest of Filelight
121
    emit folderCreated(tree);
122
123
124
}

void
125
RadialMap::Widget::createFromCache(const Folder *tree)
126
127
{
    //no scan was necessary, use cached tree, however we MUST still emit invalidate
128
    invalidate();
129
    create(tree);
130
131
132
133
134
}

void
RadialMap::Widget::sendFakeMouseEvent() //slot
{
135
136
    QMouseEvent me(QEvent::MouseMove, mapFromGlobal(QCursor::pos()), Qt::NoButton, Qt::NoButton, Qt::NoModifier);
    QApplication::sendEvent(this, &me);
137
    update();
138
139
140
141
142
}

void
RadialMap::Widget::resizeTimeout() //slot
{
143
144
145
146
147
148
    // the segments are about to erased!
    // this was a horrid bug, and proves the OO programming should be obeyed always!
    m_focus = 0;
    if (m_tree)
        m_map.make(m_tree, true);
    update();
149
150
151
}

void
152
RadialMap::Widget::refresh(int filth)
153
{
154
155
156
157
158
159
160
    //TODO consider a more direct connection

    if (!m_map.isNull())
    {
        switch (filth)
        {
        case 1:
161
            m_focus=0;
162
            m_map.make(m_tree, true); //true means refresh only
163
164
165
            break;

        case 2:
166
            m_map.paint(true); //antialiased painting
167
168
169
170
171
172
173
174
175
176
177
178
179
            break;

        case 3:
            m_map.colorise(); //FALL THROUGH!
        case 4:
            m_map.paint();

        default:
            break;
        }

        update();
    }
180
181
182
183
184
}

void
RadialMap::Widget::zoomIn() //slot
{
185
186
187
    if (m_map.m_visibleDepth > MIN_RING_DEPTH)
    {
        --m_map.m_visibleDepth;
188
        m_focus = 0;
189
190
191
192
        m_map.make(m_tree);
        Config::defaultRingDepth = m_map.m_visibleDepth;
        update();
    }
193
194
195
196
197
}

void
RadialMap::Widget::zoomOut() //slot
{
198
    m_focus = 0;
199
200
201
202
203
    ++m_map.m_visibleDepth;
    m_map.make(m_tree);
    if (m_map.m_visibleDepth > Config::defaultRingDepth)
        Config::defaultRingDepth = m_map.m_visibleDepth;
    update();
204
205
206
207
208
}


RadialMap::Segment::~Segment()
{
209
210
    if (isFake())
        delete m_file; //created by us in Builder::build()
211
212
}

213