summaryrefslogtreecommitdiffstats
path: root/krusader/DiskUsage/dufilelight.cpp
blob: 57922db78dda18c029cce7f3238211be77f8cae0 (plain)
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
/***************************************************************************
                       dufilelight.cpp  -  description
                             -------------------
    copyright            : (C) 2004 by Csaba Karai
    e-mail               : krusader@users.sourceforge.net
    web site             : http://krusader.sourceforge.net
 ---------------------------------------------------------------------------
  Description
 ***************************************************************************

  A

     db   dD d8888b. db    db .d8888.  .d8b.  d8888b. d88888b d8888b.
     88 ,8P' 88  `8D 88    88 88'  YP d8' `8b 88  `8D 88'     88  `8D
     88,8P   88oobY' 88    88 `8bo.   88ooo88 88   88 88ooooo 88oobY'
     88`8b   88`8b   88    88   `Y8b. 88~~~88 88   88 88~~~~~ 88`8b
     88 `88. 88 `88. 88b  d88 db   8D 88   88 88  .8D 88.     88 `88.
     YP   YD 88   YD ~Y8888P' `8888Y' YP   YP Y8888D' Y88888P 88   YD

                                                     S o u r c e    F i l e

 ***************************************************************************
 *                                                                         *
 *   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) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "dufilelight.h"
#include "radialMap/radialMap.h"
#include <kpopupmenu.h>
#include <klocale.h>
#include <kinputdialog.h>

#define SCHEME_POPUP_ID    6730

DUFilelight::DUFilelight( DiskUsage *usage, const char *name )
  : RadialMap::Widget( usage, name ), diskUsage( usage ), currentDir( 0 ), refreshNeeded( true )
{
   setFocusPolicy( TQ_StrongFocus );

   connect( diskUsage, TQT_SIGNAL( enteringDirectory( Directory * ) ), this, TQT_SLOT( slotDirChanged( Directory * ) ) );
   connect( diskUsage, TQT_SIGNAL( clearing() ), this, TQT_SLOT( clear() ) );
   connect( diskUsage, TQT_SIGNAL( changed( File * ) ), this, TQT_SLOT( slotChanged( File * ) ) );
   connect( diskUsage, TQT_SIGNAL( deleted( File * ) ), this, TQT_SLOT( slotChanged( File * ) ) );
   connect( diskUsage, TQT_SIGNAL( changeFinished()  ), this, TQT_SLOT( slotRefresh() ) );
   connect( diskUsage, TQT_SIGNAL( deleteFinished()  ), this, TQT_SLOT( slotRefresh() ) );
   connect( diskUsage, TQT_SIGNAL( aboutToShow( TQWidget * ) ), this, TQT_SLOT( slotAboutToShow( TQWidget * ) ) );
}

void DUFilelight::slotDirChanged( Directory *dir )
{
  if( diskUsage->visibleWidget() != this )
    return;
    
  if( currentDir != dir )
  {
    currentDir = dir;
    
    tqinvalidate( false );
    create( dir );
    refreshNeeded = false;
  }
}

void DUFilelight::clear()
{
  tqinvalidate( false );
  currentDir = 0;
}

File * DUFilelight::getCurrentFile()
{
  const RadialMap::Segment * focus = focusSegment();
     
  if( !focus || focus->isFake() || focus->file() == currentDir )
    return 0;
    
  return (File *)focus->file();
}

void DUFilelight::mousePressEvent( TQMouseEvent *event )
{
   if( event->button() == Qt::RightButton )
   {
     File * file = 0;
     
     const RadialMap::Segment * focus = focusSegment();
     
     if( focus && !focus->isFake() && focus->file() != currentDir )
       file = (File *)focus->file();

     KPopupMenu filelightPopup;
     filelightPopup.insertItem( i18n("Zoom In"),  this, TQT_SLOT( zoomIn() ), Key_Plus );
     filelightPopup.insertItem( i18n("Zoom Out"), this, TQT_SLOT( zoomOut() ), Key_Minus );
     
     KPopupMenu schemePopup;           
     schemePopup.insertItem( i18n("Rainbow"),       this, TQT_SLOT( schemeRainbow() ) );
     schemePopup.insertItem( i18n("High Contrast"), this, TQT_SLOT( schemeHighContrast() ) );
     schemePopup.insertItem( i18n("KDE"),           this, TQT_SLOT( schemeKDE() ) );

     filelightPopup.insertItem( TQPixmap(), &schemePopup, SCHEME_POPUP_ID );
     filelightPopup.changeItem( SCHEME_POPUP_ID, i18n( "Scheme" ) );     

     filelightPopup.insertItem( i18n("Increase contrast"), this, TQT_SLOT( increaseContrast() ) );
     filelightPopup.insertItem( i18n("Decrease contrast"), this, TQT_SLOT( decreaseContrast() ) );
          
     int aid = filelightPopup.insertItem( i18n("Use anti-aliasing" ), this, TQT_SLOT( changeAntiAlias() ) );
     filelightPopup.setItemChecked( aid, Filelight::Config::antiAliasFactor > 1 );
     
     int sid = filelightPopup.insertItem( i18n("Show small files" ), this, TQT_SLOT( showSmallFiles() ) );
     filelightPopup.setItemChecked( sid, Filelight::Config::showSmallFiles );
     
     int vid = filelightPopup.insertItem( i18n("Vary label font sizes" ), this, TQT_SLOT( varyLabelFontSizes() ) );
     filelightPopup.setItemChecked( vid, Filelight::Config::varyLabelFontSizes );

     filelightPopup.insertItem( i18n("Minimum font size"), this, TQT_SLOT( minFontSize() ) );     
          
     diskUsage->rightClickMenu( file, &filelightPopup, i18n( "Filelight" ) );
     return;     
   }else if( event->button() == Qt::LeftButton )
   {
     const RadialMap::Segment * focus = focusSegment();
     
     if( focus && !focus->isFake() && focus->file() == currentDir )
     {
       diskUsage->dirUp();
       return;
     }
     else if( focus && !focus->isFake() && focus->file()->isDir() )
     {
       diskUsage->changeDirectory( (Directory *)focus->file() );
       return;
     }
   }
   
   RadialMap::Widget::mousePressEvent( event );
}
  
void DUFilelight::setScheme( Filelight::MapScheme scheme )
{
  Filelight::Config::scheme = scheme;
  Filelight::Config::write();    
  slotRefresh();
}

void DUFilelight::increaseContrast()
{
  if( ( Filelight::Config::contrast += 10 ) > 100 )
    Filelight::Config::contrast = 100;
  
  Filelight::Config::write();    
  slotRefresh();
}

void DUFilelight::decreaseContrast()
{
  if( ( Filelight::Config::contrast -= 10 ) > 100 )
    Filelight::Config::contrast = 0;
  
  Filelight::Config::write();
  slotRefresh();
}

void DUFilelight::changeAntiAlias()
{
  Filelight::Config::antiAliasFactor = 1 + ( Filelight::Config::antiAliasFactor == 1 );
  Filelight::Config::write();    
  slotRefresh();
}

void DUFilelight::showSmallFiles()
{
  Filelight::Config::showSmallFiles = !Filelight::Config::showSmallFiles;
  Filelight::Config::write();    
  slotRefresh();
}

void DUFilelight::varyLabelFontSizes()
{
  Filelight::Config::varyLabelFontSizes = !Filelight::Config::varyLabelFontSizes;
  Filelight::Config::write();    
  slotRefresh();
}

void DUFilelight::minFontSize()
{
  bool ok = false;
  
  int result = KInputDialog::getInteger( i18n( "Krusader::Filelight" ),
    i18n( "Minimum font size" ), (int)Filelight::Config::minFontPitch, 1, 100, 1, &ok, this );

  if ( ok )
  {
    Filelight::Config::minFontPitch = (uint)result;
    
    Filelight::Config::write();    
    slotRefresh();
  }
}

void DUFilelight::slotAboutToShow( TQWidget *widget )
{ 
  if( widget == this && ( diskUsage->getCurrentDir() != currentDir || refreshNeeded ) )
  {
    refreshNeeded = false;
    if( ( currentDir = diskUsage->getCurrentDir() ) != 0 )
    {
      tqinvalidate( false );
      create( currentDir );
    }
  }
}

void DUFilelight::slotRefresh() 
{ 
  if( diskUsage->visibleWidget() != this )
    return;

  refreshNeeded = false;
  if( currentDir && currentDir == diskUsage->getCurrentDir() )
  {
    tqinvalidate( false );
    create( currentDir );
  }
}

void DUFilelight::slotChanged( File * )
{
   if( !refreshNeeded )
     refreshNeeded = true;
}

#include "dufilelight.moc"