62
62
QColor KRPie::colors[ 12 ] = {Qt::red, Qt::blue, Qt::green, Qt::cyan, Qt::magenta, Qt::gray,
63
63
Qt::black, Qt::white, Qt::darkRed, Qt::darkBlue, Qt::darkMagenta,
66
67
//////////////////////////////////////////////////////////////////////////////
67
68
/////////////// KRFSDisplay - Filesystem / Freespace Display /////////////////
68
69
//////////////////////////////////////////////////////////////////////////////
69
70
// This is the full constructor: use it for a mounted filesystem
70
KRFSDisplay::KRFSDisplay( QWidget *parent, QString _alias, QString _realName,
71
KIO::filesize_t _total, KIO::filesize_t _free ) : QWidget( parent ), totalSpace( _total ),
72
freeSpace( _free ), alias( _alias ), realName( _realName ), mounted( true ),
73
empty( false ), supermount( false ) {
71
KRFSDisplay::KRFSDisplay(QWidget *parent, QString _alias, QString _realName,
72
KIO::filesize_t _total, KIO::filesize_t _free) : QWidget(parent), totalSpace(_total),
73
freeSpace(_free), alias(_alias), realName(_realName), mounted(true),
74
empty(false), supermount(false)
75
int leftMargin, topMargin, rightMargin, bottomMargin;
76
getContentsMargins ( &leftMargin, &topMargin, &rightMargin, &bottomMargin );
77
resize( 150 + leftMargin + rightMargin, 200 + topMargin + bottomMargin);
78
setMinimumSize( 150 + leftMargin + rightMargin, 200 + topMargin + bottomMargin);
77
int leftMargin, topMargin, rightMargin, bottomMargin;
78
getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin);
79
resize(150 + leftMargin + rightMargin, 200 + topMargin + bottomMargin);
80
setMinimumSize(150 + leftMargin + rightMargin, 200 + topMargin + bottomMargin);
82
84
// Use this one for an unmounted filesystem
83
KRFSDisplay::KRFSDisplay( QWidget *parent, QString _alias, QString _realName, bool sm ) :
84
QWidget( parent ), alias( _alias ), realName( _realName ), mounted( false ),
85
empty( false ), supermount( sm ) {
85
KRFSDisplay::KRFSDisplay(QWidget *parent, QString _alias, QString _realName, bool sm) :
86
QWidget(parent), alias(_alias), realName(_realName), mounted(false),
87
empty(false), supermount(sm)
87
int leftMargin, topMargin, rightMargin, bottomMargin;
88
getContentsMargins ( &leftMargin, &topMargin, &rightMargin, &bottomMargin );
89
resize( 150 + leftMargin + rightMargin, 200 + topMargin + bottomMargin);
90
setMinimumSize( 150 + leftMargin + rightMargin, 200 + topMargin + bottomMargin);
90
int leftMargin, topMargin, rightMargin, bottomMargin;
91
getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin);
92
resize(150 + leftMargin + rightMargin, 200 + topMargin + bottomMargin);
93
setMinimumSize(150 + leftMargin + rightMargin, 200 + topMargin + bottomMargin);
94
97
// This is used only when an empty widget needs to be displayed (for example:
95
98
// when filesystem statistics haven't been calculated yet)
96
KRFSDisplay::KRFSDisplay( QWidget *parent ) : QWidget( parent ), empty( true ) {
99
KRFSDisplay::KRFSDisplay(QWidget *parent) : QWidget(parent), empty(true)
98
int leftMargin, topMargin, rightMargin, bottomMargin;
99
getContentsMargins ( &leftMargin, &topMargin, &rightMargin, &bottomMargin );
100
resize( 150 + leftMargin + rightMargin, 200 + topMargin + bottomMargin);
101
setMinimumSize( 150 + leftMargin + rightMargin, 200 + topMargin + bottomMargin);
102
int leftMargin, topMargin, rightMargin, bottomMargin;
103
getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin);
104
resize(150 + leftMargin + rightMargin, 200 + topMargin + bottomMargin);
105
setMinimumSize(150 + leftMargin + rightMargin, 200 + topMargin + bottomMargin);
106
110
// The main painter!
107
void KRFSDisplay::paintEvent( QPaintEvent * ) {
108
QPainter paint( this );
110
int leftMargin, topMargin, rightMargin, bottomMargin;
111
getContentsMargins ( &leftMargin, &topMargin, &rightMargin, &bottomMargin );
113
// first, name and location
114
paint.setFont( QFont( "helvetica", 12, QFont::Bold ) );
115
paint.drawText( leftMargin + 10, topMargin + 20, alias );
116
paint.setFont( QFont( "helvetica", 12, QFont::Normal ) );
117
paint.drawText( leftMargin + 10, topMargin + 37, "(" + realName + ")" );
118
if ( mounted ) { // incase the filesystem is already mounted
119
// second, the capacity
120
paint.drawText( leftMargin + 10, topMargin + 70, i18n( "Capacity: " ) + KIO::convertSizeFromKiB( totalSpace ) );
121
// third, the 2 boxes (used, free)
122
QPen systemPen = paint.pen();
123
paint.setPen( Qt::black );
124
paint.drawRect( leftMargin + 10, topMargin + 90, 10, 10 );
125
paint.fillRect( leftMargin + 11, topMargin + 91, 8, 8, QBrush( Qt::gray ) );
126
paint.drawRect( leftMargin + 10, topMargin + 110, 10, 10 );
127
paint.fillRect( leftMargin + 11, topMargin + 111, 8, 8, QBrush( Qt::white ) );
128
// now, the text for the boxes
129
paint.setPen( systemPen );
130
paint.drawText( leftMargin + 25, topMargin + 100, i18n( "Used: " ) + KIO::convertSizeFromKiB( totalSpace - freeSpace ) );
131
paint.drawText( leftMargin + 25, topMargin + 120, i18n( "Free: " ) + KIO::convertSizeFromKiB( freeSpace ) );
132
// first, create the empty pie
134
paint.setPen( Qt::black );
135
paint.setBrush( Qt::white );
136
paint.drawPie( leftMargin + LEFT, topMargin + BOTTOM, WIDTH, HEIGHT, STARTANGLE, DEG( 360 ) );
138
paint.setPen( Qt::lightGray );
139
for ( int i = 1; i < Z_HEIGHT; ++i )
140
paint.drawPie( leftMargin + LEFT, topMargin + BOTTOM - i, WIDTH, HEIGHT, STARTANGLE, DEG( 360 ) );
142
paint.setPen( Qt::black );
143
paint.drawLine( leftMargin + LEFT, topMargin + BOTTOM + HEIGHT / 2, LEFT, BOTTOM + HEIGHT / 2 - Z_HEIGHT );
144
paint.drawLine( leftMargin + LEFT + WIDTH, topMargin + BOTTOM + HEIGHT / 2, LEFT + WIDTH, BOTTOM + HEIGHT / 2 - Z_HEIGHT );
146
paint.drawPie( leftMargin + LEFT, topMargin + BOTTOM - Z_HEIGHT, WIDTH, HEIGHT, STARTANGLE, DEG( 360 ) );
147
// the "used space" slice
148
float i = ( ( float ) ( totalSpace - freeSpace ) / ( totalSpace ) ) * 360.0;
149
paint.setBrush( Qt::gray );
150
paint.drawPie( leftMargin + LEFT, topMargin + BOTTOM - Z_HEIGHT, WIDTH, HEIGHT, STARTANGLE, ( int ) DEG( i ) );
151
// if we need to draw a 3d stripe ...
153
for ( int j = 1; j < Z_HEIGHT; ++j )
154
paint.drawArc( leftMargin + LEFT, topMargin + BOTTOM - j, WIDTH, HEIGHT, STARTANGLE - 16 * 180, ( int ) ( DEG( i - 180.0 ) ) );
156
} else { // if the filesystem is unmounted...
157
paint.setFont( QFont( "helvetica", 12, QFont::Bold ) );
158
paint.drawText( leftMargin + 10, topMargin + 60, i18n( "Not mounted." ) );
160
} else { // if the widget is in empty situation...
111
void KRFSDisplay::paintEvent(QPaintEvent *)
113
QPainter paint(this);
115
int leftMargin, topMargin, rightMargin, bottomMargin;
116
getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin);
118
// first, name and location
119
paint.setFont(QFont("helvetica", 12, QFont::Bold));
120
paint.drawText(leftMargin + 10, topMargin + 20, alias);
121
paint.setFont(QFont("helvetica", 12, QFont::Normal));
122
paint.drawText(leftMargin + 10, topMargin + 37, '(' + realName + ')');
123
if (mounted) { // incase the filesystem is already mounted
124
// second, the capacity
125
paint.drawText(leftMargin + 10, topMargin + 70, i18n("Capacity: ") + KIO::convertSizeFromKiB(totalSpace));
126
// third, the 2 boxes (used, free)
127
QPen systemPen = paint.pen();
128
paint.setPen(Qt::black);
129
paint.drawRect(leftMargin + 10, topMargin + 90, 10, 10);
130
paint.fillRect(leftMargin + 11, topMargin + 91, 8, 8, QBrush(Qt::gray));
131
paint.drawRect(leftMargin + 10, topMargin + 110, 10, 10);
132
paint.fillRect(leftMargin + 11, topMargin + 111, 8, 8, QBrush(Qt::white));
133
// now, the text for the boxes
134
paint.setPen(systemPen);
135
paint.drawText(leftMargin + 25, topMargin + 100, i18n("Used: ") + KIO::convertSizeFromKiB(totalSpace - freeSpace));
136
paint.drawText(leftMargin + 25, topMargin + 120, i18n("Free: ") + KIO::convertSizeFromKiB(freeSpace));
137
// first, create the empty pie
139
paint.setPen(Qt::black);
140
paint.setBrush(Qt::white);
141
paint.drawPie(leftMargin + LEFT, topMargin + BOTTOM, WIDTH, HEIGHT, STARTANGLE, DEG(360));
143
paint.setPen(Qt::lightGray);
144
for (int i = 1; i < Z_HEIGHT; ++i)
145
paint.drawPie(leftMargin + LEFT, topMargin + BOTTOM - i, WIDTH, HEIGHT, STARTANGLE, DEG(360));
147
paint.setPen(Qt::black);
148
paint.drawLine(leftMargin + LEFT, topMargin + BOTTOM + HEIGHT / 2, LEFT, BOTTOM + HEIGHT / 2 - Z_HEIGHT);
149
paint.drawLine(leftMargin + LEFT + WIDTH, topMargin + BOTTOM + HEIGHT / 2, LEFT + WIDTH, BOTTOM + HEIGHT / 2 - Z_HEIGHT);
151
paint.drawPie(leftMargin + LEFT, topMargin + BOTTOM - Z_HEIGHT, WIDTH, HEIGHT, STARTANGLE, DEG(360));
152
// the "used space" slice
153
float i = ((float)(totalSpace - freeSpace) / (totalSpace)) * 360.0;
154
paint.setBrush(Qt::gray);
155
paint.drawPie(leftMargin + LEFT, topMargin + BOTTOM - Z_HEIGHT, WIDTH, HEIGHT, STARTANGLE, (int) DEG(i));
156
// if we need to draw a 3d stripe ...
158
for (int j = 1; j < Z_HEIGHT; ++j)
159
paint.drawArc(leftMargin + LEFT, topMargin + BOTTOM - j, WIDTH, HEIGHT, STARTANGLE - 16 * 180, (int)(DEG(i - 180.0)));
161
} else { // if the filesystem is unmounted...
162
paint.setFont(QFont("helvetica", 12, QFont::Bold));
163
paint.drawText(leftMargin + 10, topMargin + 60, i18n("Not mounted."));
165
} else { // if the widget is in empty situation...
165
170
////////////////////////////////////////////////////////////////////////////////
166
KRPie::KRPie( KIO::filesize_t _totalSize, QWidget *parent ) : QWidget( parent ), totalSize( _totalSize ) {
167
slices.push_back( KRPieSlice( 100, Qt::yellow, "DEFAULT" ) );
168
sizeLeft = totalSize;
172
void KRPie::paintEvent( QPaintEvent * ) {
173
QPainter paint( this );
174
// now create the slices
175
float sAngle = STARTANGLE;
176
for ( int ndx=0; ndx != slices.count(); ndx++ ) {
177
paint.setBrush( slices[ndx].getColor() );
178
paint.setPen( slices[ndx].getColor() );
179
// angles are negative to create a clock-wise drawing of slices
180
float angle = -( slices[ndx].getPerct() / 100 * 360 ) * 16;
181
for ( int i = 1; i < Z_HEIGHT; ++i )
182
paint.drawPie( LEFT, BOTTOM + i, WIDTH, HEIGHT, ( int ) sAngle, ( int ) angle );
185
paint.setPen( Qt::yellow ); // pen
186
paint.setBrush( Qt::yellow ); // fill
187
// for (int i=1; i<Z_HEIGHT; ++i)
188
// paint.drawPie(LEFT,BOTTOM+i,WIDTH,HEIGHT,sAngle,360*16-(STARTANGLE-sAngle));
190
for ( int ndx=0; ndx != slices.count(); ndx++ ) {
191
paint.setBrush( slices[ndx].getColor() );
192
paint.setPen( slices[ndx].getColor() );
193
// angles are negative to create a clock-wise drawing of slices
194
float angle = -( slices[ndx].getPerct() / 100 * 360 ) * 16;
195
paint.drawPie( LEFT, BOTTOM, WIDTH, HEIGHT, ( int ) sAngle, ( int ) angle );
200
paint.setPen( Qt::black );
202
// paint.drawPie(LEFT,BOTTOM,WIDTH,HEIGHT,STARTANGLE,360*16);
203
///////////////////////// end of empty pie /////////////////////////
204
// now, the pie is ready to draw slices on...
205
// to make a good look on the perimiter, draw another black circle
206
paint.setPen( Qt::black );
207
paint.drawArc( LEFT, BOTTOM, WIDTH, HEIGHT, STARTANGLE, 360 * 16 );
211
void KRPie::addSlice( KIO::filesize_t size, QString label ) {
212
int i = ( slices.count() % 12 );
214
slices.push_back( KRPieSlice( size * 100 / totalSize, colors[ i ], label ) );
216
slices.push_back( KRPieSlice( sizeLeft * 100 / totalSize, Qt::yellow, "DEFAULT" ) );
171
KRPie::KRPie(KIO::filesize_t _totalSize, QWidget *parent) : QWidget(parent), totalSize(_totalSize)
173
slices.push_back(KRPieSlice(100, Qt::yellow, "DEFAULT"));
174
sizeLeft = totalSize;
178
void KRPie::paintEvent(QPaintEvent *)
180
QPainter paint(this);
181
// now create the slices
182
float sAngle = STARTANGLE;
183
for (int ndx = 0; ndx != slices.count(); ndx++) {
184
paint.setBrush(slices[ndx].getColor());
185
paint.setPen(slices[ndx].getColor());
186
// angles are negative to create a clock-wise drawing of slices
187
float angle = -(slices[ndx].getPerct() / 100 * 360) * 16;
188
for (int i = 1; i < Z_HEIGHT; ++i)
189
paint.drawPie(LEFT, BOTTOM + i, WIDTH, HEIGHT, (int) sAngle, (int) angle);
192
paint.setPen(Qt::yellow); // pen
193
paint.setBrush(Qt::yellow); // fill
194
// for (int i=1; i<Z_HEIGHT; ++i)
195
// paint.drawPie(LEFT,BOTTOM+i,WIDTH,HEIGHT,sAngle,360*16-(STARTANGLE-sAngle));
197
for (int ndx = 0; ndx != slices.count(); ndx++) {
198
paint.setBrush(slices[ndx].getColor());
199
paint.setPen(slices[ndx].getColor());
200
// angles are negative to create a clock-wise drawing of slices
201
float angle = -(slices[ndx].getPerct() / 100 * 360) * 16;
202
paint.drawPie(LEFT, BOTTOM, WIDTH, HEIGHT, (int) sAngle, (int) angle);
207
paint.setPen(Qt::black);
209
// paint.drawPie(LEFT,BOTTOM,WIDTH,HEIGHT,STARTANGLE,360*16);
210
///////////////////////// end of empty pie /////////////////////////
211
// now, the pie is ready to draw slices on...
212
// to make a good look on the perimiter, draw another black circle
213
paint.setPen(Qt::black);
214
paint.drawArc(LEFT, BOTTOM, WIDTH, HEIGHT, STARTANGLE, 360 * 16);
218
void KRPie::addSlice(KIO::filesize_t size, QString label)
220
int i = (slices.count() % 12);
222
slices.push_back(KRPieSlice(size * 100 / totalSize, colors[ i ], label));
224
slices.push_back(KRPieSlice(sizeLeft * 100 / totalSize, Qt::yellow, "DEFAULT"));
219
227
////////////////////////////////////////////////////
220
228
/////////////////// KrQuickSearch /////////////////
221
229
////////////////////////////////////////////////////
222
KrQuickSearch::KrQuickSearch( QWidget *parent ) : KLineEdit( parent )
227
void KrQuickSearch::myKeyPressEvent( QKeyEvent *e ) {
228
switch ( e->key() ) {
240
otherMatching( text(), 1 );
243
otherMatching( text(), -1 );
255
void KrQuickSearch::setMatch( bool match ) {
256
KConfigGroup gc( krConfig, "Colors");
258
QString foreground, background;
263
foreground = "Quicksearch Match Foreground";
264
background = "Quicksearch Match Background";
266
back = QColor( 192, 255, 192 );
268
foreground = "Quicksearch Non-match Foreground";
269
background = "Quicksearch Non-match Background";
271
back = QColor(255,192,192);
274
if( gc.readEntry( foreground, QString() ) == "KDE default" )
275
fore = KColorScheme(QPalette::Active, KColorScheme::View).foreground().color();
276
else if( !gc.readEntry( foreground, QString() ).isEmpty() )
277
fore = gc.readEntry( foreground, fore );
279
if( gc.readEntry( background, QString() ) == "KDE default" )
280
back = KColorScheme(QPalette::Active, KColorScheme::View).background().color();
281
else if( !gc.readEntry( background, QString() ).isEmpty() )
282
back = gc.readEntry( background, back );
284
QPalette pal = palette();
285
pal.setColor( QPalette::Base, back);
286
pal.setColor( QPalette::Text, fore);
230
KrQuickSearch::KrQuickSearch(QWidget *parent) : KLineEdit(parent)
235
void KrQuickSearch::myKeyPressEvent(QKeyEvent *e)
249
otherMatching(text(), 1);
252
otherMatching(text(), -1);
264
void KrQuickSearch::setMatch(bool match)
266
KConfigGroup gc(krConfig, "Colors");
268
QString foreground, background;
272
foreground = "Quicksearch Match Foreground";
273
background = "Quicksearch Match Background";
275
back = QColor(192, 255, 192);
277
foreground = "Quicksearch Non-match Foreground";
278
background = "Quicksearch Non-match Background";
280
back = QColor(255, 192, 192);
283
if (gc.readEntry(foreground, QString()) == "KDE default")
284
fore = KColorScheme(QPalette::Active, KColorScheme::View).foreground().color();
285
else if (!gc.readEntry(foreground, QString()).isEmpty())
286
fore = gc.readEntry(foreground, fore);
288
if (gc.readEntry(background, QString()) == "KDE default")
289
back = KColorScheme(QPalette::Active, KColorScheme::View).background().color();
290
else if (!gc.readEntry(background, QString()).isEmpty())
291
back = gc.readEntry(background, back);
293
QPalette pal = palette();
294
pal.setColor(QPalette::Base, back);
295
pal.setColor(QPalette::Text, fore);
290
299
#include "krspecialwidgets.moc"