1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
|
//Author: Max Howell <max.howell@methylblue.com>, (C) 2003-4
//Copyright: See COPYING file that comes with this distribution
#include "fileTree.h"
#include "radialMap.h" //class Segment
#include "widget.h"
#include <cmath> //::segmentAt()
#include <kcursor.h> //::mouseMoveEvent()
#include <kiconeffect.h> //::mousePressEvent()
#include <kiconloader.h> //::mousePressEvent()
#include <kio/job.h> //::mousePressEvent()
#include <klocale.h>
#include <kmessagebox.h> //::mousePressEvent()
#include <kpopupmenu.h> //::mousePressEvent()
#include <krun.h> //::mousePressEvent()
#include <kurldrag.h>
#include <tqapplication.h>//TQApplication::setOverrideCursor()
#include <clipboard.h>
#include <tqpainter.h>
#include <tqtimer.h> //::resizeEvent()
void
RadialMap::Widget::resizeEvent( TQResizeEvent* )
{
if( m_map.resize( rect() ) )
m_timer.start( 500, true ); //will cause signature to rebuild for new size
//always do these as they need to be initialised on creation
m_offset.rx() = (width() - m_map.width()) / 2;
m_offset.ry() = (height() - m_map.height()) / 2;
}
void
RadialMap::Widget::paintEvent( TQPaintEvent* )
{
//bltBit for some TQt setups will bitBlt _after_ the labels are painted. Which buggers things up!
//shame as bitBlt is faster, possibly TQt bug? Should report the bug? - seems to be race condition
//bitBlt( this, m_offset, &m_map );
TQPainter paint( this );
paint.drawPixmap( m_offset, m_map );
//vertical strips
if( m_map.width() < width() )
{
paint.eraseRect( 0, 0, m_offset.x(), height() );
paint.eraseRect( m_map.width() + m_offset.x(), 0, m_offset.x() + 1, height() );
}
//horizontal strips
if( m_map.height() < height() )
{
paint.eraseRect( 0, 0, width(), m_offset.y() );
paint.eraseRect( 0, m_map.height() + m_offset.y(), width(), m_offset.y() + 1 );
}
//exploded labels
if( !m_map.isNull() && !m_timer.isActive() )
paintExplodedLabels( paint );
}
const RadialMap::Segment*
RadialMap::Widget::segmentAt( TQPoint &e ) const
{
//determine which segment TQPoint e is above
e -= m_offset;
if( !m_map.m_signature )
return 0;
if( e.x() <= m_map.width() && e.y() <= m_map.height() )
{
//transform to cartesian coords
e.rx() -= m_map.width() / 2; //should be an int
e.ry() = m_map.height() / 2 - e.y();
double length = hypot( e.x(), e.y() );
if( length >= m_map.m_innerRadius ) //not hovering over inner circle
{
uint depth = ((int)length - m_map.m_innerRadius) / m_map.m_ringBreadth;
if( depth <= m_map.m_visibleDepth ) //**** do earlier since you can //** check not outside of range
{
//vector calculation, reduces to simple trigonometry
//cos angle = (aibi + ajbj) / albl
//ai = x, bi=1, aj=y, bj=0
//cos angle = x / (length)
uint a = (uint)(acos( (double)e.x() / length ) * 916.736); //916.7324722 = #radians in circle * 16
//acos only understands 0-180 degrees
if( e.y() < 0 ) a = 5760 - a;
#define ring (m_map.m_signature + depth)
for( ConstIterator<Segment> it = ring->constIterator(); it != ring->end(); ++it )
if( (*it)->intersects( a ) )
return *it;
#undef ring
}
}
else return m_rootSegment; //hovering over inner circle
}
return 0;
}
void
RadialMap::Widget::mouseMoveEvent( TQMouseEvent *e )
{
//set m_focus to what we hover over, update UI if it's a new segment
Segment const * const oldFocus = m_focus;
TQPoint p = e->pos();
m_focus = segmentAt( p ); //NOTE p is passed by non-const reference
if( m_focus && m_focus->file() != m_tree )
{
if( m_focus != oldFocus ) //if not same as last time
{
setCursor( KCursor::handCursor() );
m_tip->updateTip( m_focus->file(), m_tree );
emit mouseHover( m_focus->file()->fullPath() );
//repaint required to update labels now before transparency is generated
repaint( false );
}
m_tip->moveTo( e->globalPos(), *this, ( p.y() < 0 ) ); //updates tooltip psuedo-tranparent background
}
else if( oldFocus && oldFocus->file() != m_tree )
{
unsetCursor();
m_tip->hide();
update();
emit mouseHover( TQString() );
}
}
void
RadialMap::Widget::mousePressEvent( TQMouseEvent *e )
{
//m_tip is hidden already by event filter
//m_focus is set correctly (I've been strict, I assure you it is correct!)
enum { Konqueror, Konsole, Center, Open, Copy, Delete };
if (m_focus && !m_focus->isFake())
{
const KURL url = Widget::url( m_focus->file() );
const bool isDir = m_focus->file()->isDirectory();
if( e->button() == Qt::RightButton )
{
KPopupMenu popup;
popup.insertTitle( m_focus->file()->fullPath( m_tree ) );
if (isDir) {
popup.insertItem( SmallIconSet( "konqueror" ), i18n( "Open &Konqueror Here" ), Konqueror );
if( url.protocol() == "file" )
popup.insertItem( SmallIconSet( "konsole" ), i18n( "Open &Konsole Here" ), Konsole );
if (m_focus->file() != m_tree) {
popup.insertSeparator();
popup.insertItem( SmallIconSet( "viewmag" ), i18n( "&Center Map Here" ), Center );
}
}
else
popup.insertItem( SmallIconSet( "fileopen" ), i18n( "&Open" ), Open );
popup.insertSeparator();
popup.insertItem( SmallIconSet( "editcopy" ), i18n( "&Copy to clipboard" ), Copy );
popup.insertSeparator();
popup.insertItem( SmallIconSet( "editdelete" ), i18n( "&Delete" ), Delete );
switch (popup.exec( e->globalPos(), 1 )) {
case Konqueror:
//KRun::runCommand will show an error message if there was trouble
KRun::runCommand( TQString( "kfmclient openURL \"%1\"" ).arg( url.url() ) );
break;
case Konsole:
// --workdir only works for local file paths
KRun::runCommand( TQString( "konsole --workdir \"%1\"" ).arg( url.path() ) );
break;
case Center:
case Open:
goto section_two;
case Copy:
TQApplication::clipboard()->setData( new KURLDrag( KURL::List( url ) ) );
break;
case Delete:
{
const KURL url = Widget::url( m_focus->file() );
const TQString message = m_focus->file()->isDirectory()
? i18n( "<qt>The directory at <i>'%1'</i> will be <b>recursively</b> and <b>permanently</b> deleted." )
: i18n( "<qt><i>'%1'</i> will be <b>permanently</b> deleted." );
const int userIntention = KMessageBox::warningContinueCancel(
this, message.arg( url.prettyURL() ),
TQString(), KGuiItem( i18n("&Delete"), "editdelete" ) );
if (userIntention == KMessageBox::Continue) {
KIO::Job *job = KIO::del( url );
job->setWindow( this );
connect( job, TQT_SIGNAL(result( KIO::Job* )), TQT_SLOT(deleteJobFinished( KIO::Job* )) );
TQApplication::setOverrideCursor( KCursor::workingCursor() );
}
}
default:
//ensure m_focus is set for new mouse position
sendFakeMouseEvent();
}
}
else { // not right mouse button
section_two:
const TQRect rect( e->x() - 20, e->y() - 20, 40, 40 );
m_tip->hide(); // user expects this
if (!isDir || e->button() == Qt::MidButton) {
KIconEffect::visualActivate( this, rect );
new KRun( url, this, true ); //FIXME see above
}
else if (m_focus->file() != m_tree) { // is left click
KIconEffect::visualActivate( this, rect );
emit activated( url ); //activate first, this will cause UI to prepare itself
createFromCache( (Directory *)m_focus->file() );
}
else
emit giveMeTreeFor( url.upURL() );
}
}
}
void
RadialMap::Widget::deleteJobFinished( KIO::Job *job )
{
TQApplication::restoreOverrideCursor();
if( !job->error() )
invalidate();
else
job->showErrorDialog( this );
}
#include "debug.h"
void
RadialMap::Widget::dropEvent( TQDropEvent *e )
{
DEBUG_ANNOUNCE
KURL::List urls;
if (KURLDrag::decode( e, urls ) && urls.count())
emit giveMeTreeFor( urls.first() );
}
void
RadialMap::Widget::dragEnterEvent( TQDragEnterEvent *e )
{
DEBUG_ANNOUNCE
e->accept( KURLDrag::canDecode( e ) );
}
|