Changeset View
Changeset View
Standalone View
Standalone View
src/radialMap/map.cpp
Show First 20 Lines • Show All 197 Lines • ▼ Show 20 Line(s) | 192 | if ((depth == 0 || Config::showSmallFiles) && hiddenSize >= m_limits[depth] && hiddenFileCount > 0) { | |||
---|---|---|---|---|---|
198 | 198 | | |||
199 | 199 | | |||
200 | (m_signature + depth)->append(new Segment(new File(s.toUtf8().constData(), hiddenSize), a_start, a_end - a_start, true)); | 200 | (m_signature + depth)->append(new Segment(new File(s.toUtf8().constData(), hiddenSize), a_start, a_end - a_start, true)); | ||
201 | } | 201 | } | ||
202 | 202 | | |||
203 | return false; | 203 | return false; | ||
204 | } | 204 | } | ||
205 | 205 | | |||
206 | bool RadialMap::Map::resize(const QRect &newRect) | 206 | bool RadialMap::Map::resize(const QRectF &newRect) | ||
207 | { | 207 | { | ||
208 | //there's a MAP_2MARGIN border | 208 | //there's a MAP_2MARGIN border | ||
209 | 209 | | |||
210 | if (newRect.width() < width() && newRect.height() < height() && !newRect.contains(m_rect)) { | 210 | if (newRect.width() < width() && newRect.height() < height() && !newRect.contains(m_rect)) { | ||
211 | return false; | 211 | return false; | ||
212 | } | 212 | } | ||
213 | 213 | | |||
214 | uint size = qMin(newRect.width(), newRect.height()) - MAP_2MARGIN; | 214 | uint size = qMin(newRect.width(), newRect.height()) - MAP_2MARGIN; | ||
215 | 215 | | |||
216 | //this also causes uneven sizes to always resize when resizing but map is small in that dimension | 216 | //this also causes uneven sizes to always resize when resizing but map is small in that dimension | ||
217 | //size -= size % 2; //even sizes mean less staggered non-antialiased resizing | 217 | //size -= size % 2; //even sizes mean less staggered non-antialiased resizing | ||
218 | 218 | | |||
219 | const uint minSize = MIN_RING_BREADTH * 2 * (m_visibleDepth + 2); | 219 | const uint minSize = MIN_RING_BREADTH * 2 * (m_visibleDepth + 2); | ||
220 | 220 | | |||
221 | if (size < minSize) { | 221 | if (size < minSize) { | ||
222 | size = minSize; | 222 | size = minSize; | ||
223 | } | 223 | } | ||
224 | 224 | | |||
225 | //this QRect is used by paint() | 225 | //this QRectF is used by paint() | ||
226 | m_rect.setRect(0,0,size,size); | 226 | m_rect.setRect(0,0,size,size); | ||
227 | 227 | | |||
228 | m_pixmap = QPixmap(m_rect.size()); | 228 | m_pixmap = QPixmap(m_rect.width() * m_dpr, m_rect.height() * m_dpr); | ||
229 | m_pixmap.setDevicePixelRatio(m_dpr); | ||||
229 | 230 | | |||
230 | //resize the pixmap | 231 | //resize the pixmap | ||
231 | size += MAP_2MARGIN; | 232 | size += MAP_2MARGIN; | ||
232 | 233 | | |||
233 | if (m_signature) { | 234 | if (m_signature) { | ||
234 | setRingBreadth(); | 235 | setRingBreadth(); | ||
235 | paint(); | 236 | paint(); | ||
236 | } | 237 | } | ||
▲ Show 20 Lines • Show All 110 Lines • ▼ Show 20 Line(s) | 243 | { | |||
347 | } | 348 | } | ||
348 | } | 349 | } | ||
349 | 350 | | |||
350 | void RadialMap::Map::paint(bool antialias) | 351 | void RadialMap::Map::paint(bool antialias) | ||
351 | { | 352 | { | ||
352 | KColorScheme scheme(QPalette::Active, KColorScheme::View); | 353 | KColorScheme scheme(QPalette::Active, KColorScheme::View); | ||
353 | 354 | | |||
354 | QPainter paint; | 355 | QPainter paint; | ||
355 | QRect rect = m_rect; | 356 | QRectF rect = m_rect; | ||
356 | 357 | | |||
357 | rect.adjust(MAP_HIDDEN_TRIANGLE_SIZE, MAP_HIDDEN_TRIANGLE_SIZE, -MAP_HIDDEN_TRIANGLE_SIZE, -MAP_HIDDEN_TRIANGLE_SIZE); | 358 | rect.adjust(MAP_HIDDEN_TRIANGLE_SIZE, MAP_HIDDEN_TRIANGLE_SIZE, -MAP_HIDDEN_TRIANGLE_SIZE, -MAP_HIDDEN_TRIANGLE_SIZE); | ||
358 | m_pixmap.fill(Qt::transparent); | 359 | m_pixmap.fill(Qt::transparent); | ||
359 | 360 | | |||
360 | //m_rect.moveRight(1); // Uncommenting this breaks repainting when recreating map from cache | 361 | //m_rect.moveRight(1); // Uncommenting this breaks repainting when recreating map from cache | ||
361 | 362 | | |||
362 | 363 | | |||
363 | //**** best option you can think of is to make the circles slightly less perfect, | 364 | //**** best option you can think of is to make the circles slightly less perfect, | ||
Show All 12 Lines | 375 | if (antialias && Config::antialias) { | |||
376 | paint.setRenderHint(QPainter::Antialiasing); | 377 | paint.setRenderHint(QPainter::Antialiasing); | ||
377 | } | 378 | } | ||
378 | 379 | | |||
379 | int step = m_ringBreadth; | 380 | int step = m_ringBreadth; | ||
380 | int excess = -1; | 381 | int excess = -1; | ||
381 | 382 | | |||
382 | //do intelligent distribution of excess to prevent nasty resizing | 383 | //do intelligent distribution of excess to prevent nasty resizing | ||
383 | if (m_ringBreadth != MAX_RING_BREADTH && m_ringBreadth != MIN_RING_BREADTH) { | 384 | if (m_ringBreadth != MAX_RING_BREADTH && m_ringBreadth != MIN_RING_BREADTH) { | ||
384 | excess = rect.width() % m_ringBreadth; | 385 | excess = int(rect.width()) % m_ringBreadth; | ||
385 | ++step; | 386 | ++step; | ||
386 | } | 387 | } | ||
387 | 388 | | |||
388 | 389 | | |||
389 | for (int x = m_visibleDepth; x >= 0; --x) { | 390 | for (int x = m_visibleDepth; x >= 0; --x) { | ||
390 | int width = rect.width() / 2; | 391 | int width = rect.width() / 2; | ||
391 | //clever geometric trick to find largest angle that will give biggest arrow head | 392 | //clever geometric trick to find largest angle that will give biggest arrow head | ||
392 | uint a_max = int(acos((double)width / double((width + MAP_HIDDEN_TRIANGLE_SIZE))) * (180*16 / M_PI)); | 393 | uint a_max = int(acos((double)width / double((width + MAP_HIDDEN_TRIANGLE_SIZE))) * (180*16 / M_PI)); | ||
393 | 394 | | |||
394 | for (Segment *segment : m_signature[x]) { | 395 | for (Segment *segment : m_signature[x]) { | ||
395 | //draw the pie segments, most of this code is concerned with drawing the little | 396 | //draw the pie segments, most of this code is concerned with drawing the little | ||
396 | //arrows on the ends of segments when they have hidden files | 397 | //arrows on the ends of segments when they have hidden files | ||
397 | paint.setPen(segment->pen()); | 398 | paint.setPen(segment->pen()); | ||
398 | 399 | | |||
399 | paint.setPen(segment->pen()); | 400 | paint.setPen(segment->pen()); | ||
400 | paint.setBrush(segment->brush()); | 401 | paint.setBrush(segment->brush()); | ||
401 | paint.drawPie(rect, segment->start(), segment->length()); | 402 | paint.drawPie(rect, segment->start(), segment->length()); | ||
402 | 403 | | |||
403 | if (!segment->hasHiddenChildren()) { | 404 | if (!segment->hasHiddenChildren()) { | ||
404 | continue; | 405 | continue; | ||
405 | } | 406 | } | ||
406 | 407 | | |||
407 | //draw arrow head to indicate undisplayed files/directories | 408 | //draw arrow head to indicate undisplayed files/directories | ||
408 | QPolygon pts(3); | 409 | QPolygonF pts; | ||
409 | QPoint pos, cpos = rect.center(); | 410 | QPointF pos, cpos = rect.center(); | ||
410 | uint a[3] = { segment->start(), segment->length(), 0 }; | 411 | uint a[3] = { segment->start(), segment->length(), 0 }; | ||
411 | 412 | | |||
412 | a[2] = a[0] + (a[1] / 2); //assign to halfway between | 413 | a[2] = a[0] + (a[1] / 2); //assign to halfway between | ||
413 | if (a[1] > a_max) | 414 | if (a[1] > a_max) | ||
414 | { | 415 | { | ||
415 | a[1] = a_max; | 416 | a[1] = a_max; | ||
416 | a[0] = a[2] - a_max / 2; | 417 | a[0] = a[2] - a_max / 2; | ||
417 | } | 418 | } | ||
418 | 419 | | |||
419 | a[1] += a[0]; | 420 | a[1] += a[0]; | ||
420 | 421 | | |||
421 | for (int i = 0, radius = width; i < 3; ++i) { | 422 | for (int i = 0, radius = width; i < 3; ++i) { | ||
422 | double ra = M_PI/(180*16) * a[i], sinra, cosra; | 423 | double ra = M_PI/(180*16) * a[i], sinra, cosra; | ||
423 | 424 | | |||
424 | if (i == 2) { | 425 | if (i == 2) { | ||
425 | radius += MAP_HIDDEN_TRIANGLE_SIZE; | 426 | radius += MAP_HIDDEN_TRIANGLE_SIZE; | ||
426 | } | 427 | } | ||
427 | 428 | | |||
428 | sincos(ra, &sinra, &cosra); | 429 | sincos(ra, &sinra, &cosra); | ||
429 | pos.rx() = cpos.x() + static_cast<int>(cosra * radius); | 430 | pos.rx() = cpos.x() + cosra * radius; | ||
430 | pos.ry() = cpos.y() - static_cast<int>(sinra * radius); | 431 | pos.ry() = cpos.y() - sinra * radius; | ||
431 | pts.setPoint(i, pos); | 432 | pts << pos; | ||
432 | } | 433 | } | ||
433 | 434 | | |||
434 | paint.setBrush(segment->pen()); | 435 | paint.setBrush(segment->pen()); | ||
435 | paint.drawPolygon(pts); | 436 | paint.drawPolygon(pts); | ||
436 | 437 | | |||
437 | // Draw outline on the arc for hidden children | 438 | // Draw outline on the arc for hidden children | ||
438 | QPen pen = paint.pen(); | 439 | QPen pen = paint.pen(); | ||
439 | pen.setCapStyle(Qt::FlatCap); | 440 | pen.setCapStyle(Qt::FlatCap); | ||
440 | int width = 2; | 441 | int width = 2; | ||
441 | pen.setWidth(width); | 442 | pen.setWidth(width); | ||
442 | paint.setPen(pen); | 443 | paint.setPen(pen); | ||
443 | QRect rect2 = rect; | 444 | QRectF rect2 = rect; | ||
444 | width /= 2; | 445 | width /= 2; | ||
445 | rect2.adjust(width, width, -width, -width); | 446 | rect2.adjust(width, width, -width, -width); | ||
446 | paint.drawArc(rect2, segment->start(), segment->length()); | 447 | paint.drawArc(rect2, segment->start(), segment->length()); | ||
447 | } | 448 | } | ||
448 | 449 | | |||
449 | if (excess >= 0) { //excess allows us to resize more smoothly (still crud tho) | 450 | if (excess >= 0) { //excess allows us to resize more smoothly (still crud tho) | ||
450 | if (excess < 2) //only decrease rect by more if even number of excesses left | 451 | if (excess < 2) //only decrease rect by more if even number of excesses left | ||
451 | --step; | 452 | --step; | ||
Show All 17 Lines |