Mercurial > hg > svgui
comparison view/View.cpp @ 287:cd2492c5fe45
* Add SingleColourLayer to manage colours for layers that have a single
predominant colour (i.e. most of them).
author | Chris Cannam |
---|---|
date | Thu, 12 Jul 2007 16:14:59 +0000 |
parents | 86a112b5b319 |
children | 24fc90078754 |
comparison
equal
deleted
inserted
replaced
286:7554ae119882 | 287:cd2492c5fe45 |
---|---|
19 #include "base/ZoomConstraint.h" | 19 #include "base/ZoomConstraint.h" |
20 #include "base/Profiler.h" | 20 #include "base/Profiler.h" |
21 #include "base/Pitch.h" | 21 #include "base/Pitch.h" |
22 | 22 |
23 #include "layer/TimeRulerLayer.h" //!!! damn, shouldn't be including that here | 23 #include "layer/TimeRulerLayer.h" //!!! damn, shouldn't be including that here |
24 #include "layer/SingleColourLayer.h" | |
24 #include "data/model/PowerOfSqrtTwoZoomConstraint.h" //!!! likewise | 25 #include "data/model/PowerOfSqrtTwoZoomConstraint.h" //!!! likewise |
25 | 26 |
26 #include <QPainter> | 27 #include <QPainter> |
27 #include <QPaintEvent> | 28 #include <QPaintEvent> |
28 #include <QRect> | 29 #include <QRect> |
432 } | 433 } |
433 | 434 |
434 bool | 435 bool |
435 View::hasLightBackground() const | 436 View::hasLightBackground() const |
436 { | 437 { |
438 bool darkPalette = false; | |
439 | |
440 QColor windowBg = palette().color(QPalette::Window); | |
441 if (windowBg.red() + windowBg.green() + windowBg.blue() < 384) { | |
442 darkPalette = true; | |
443 } | |
444 | |
445 Layer::ColourSignificance maxSignificance = Layer::ColourAbsent; | |
446 bool mostSignificantHasDarkBackground = false; | |
447 | |
437 for (LayerList::const_iterator i = m_layers.begin(); | 448 for (LayerList::const_iterator i = m_layers.begin(); |
438 i != m_layers.end(); ++i) { | 449 i != m_layers.end(); ++i) { |
439 if (!(*i)->hasLightBackground()) return false; | 450 |
440 } | 451 Layer::ColourSignificance s = (*i)->getLayerColourSignificance(); |
441 return true; | 452 bool light = (*i)->hasLightBackground(); |
453 | |
454 if (int(s) > int(maxSignificance)) { | |
455 maxSignificance = s; | |
456 mostSignificantHasDarkBackground = !light; | |
457 } else if (s == maxSignificance && !light) { | |
458 mostSignificantHasDarkBackground = true; | |
459 } | |
460 } | |
461 | |
462 if (int(maxSignificance) >= int(Layer::ColourAndBackgroundSignificant)) { | |
463 return !mostSignificantHasDarkBackground; | |
464 } else { | |
465 return !darkPalette; | |
466 } | |
467 } | |
468 | |
469 QColor | |
470 View::getBackground() const | |
471 { | |
472 bool light = hasLightBackground(); | |
473 | |
474 QColor widgetbg = palette().window().color(); | |
475 bool widgetLight = | |
476 (widgetbg.red() + widgetbg.green() + widgetbg.blue()) > 384; | |
477 | |
478 if (widgetLight == light) return widgetbg; | |
479 else if (light) return Qt::white; | |
480 else return Qt::black; | |
481 } | |
482 | |
483 QColor | |
484 View::getForeground() const | |
485 { | |
486 bool light = hasLightBackground(); | |
487 | |
488 QColor widgetfg = palette().text().color(); | |
489 bool widgetLight = | |
490 (widgetfg.red() + widgetfg.green() + widgetfg.blue()) > 384; | |
491 | |
492 if (widgetLight != light) return widgetfg; | |
493 else if (light) return Qt::black; | |
494 else return Qt::white; | |
442 } | 495 } |
443 | 496 |
444 View::LayerProgressBar::LayerProgressBar(QWidget *parent) : | 497 View::LayerProgressBar::LayerProgressBar(QWidget *parent) : |
445 QProgressBar(parent) | 498 QProgressBar(parent) |
446 { | 499 { |
452 void | 505 void |
453 View::addLayer(Layer *layer) | 506 View::addLayer(Layer *layer) |
454 { | 507 { |
455 delete m_cache; | 508 delete m_cache; |
456 m_cache = 0; | 509 m_cache = 0; |
510 | |
511 SingleColourLayer *scl = dynamic_cast<SingleColourLayer *>(layer); | |
512 if (scl) scl->setDefaultColourFor(this); | |
457 | 513 |
458 m_layers.push_back(layer); | 514 m_layers.push_back(layer); |
459 | 515 |
460 m_progressBars[layer] = new LayerProgressBar(this); | 516 m_progressBars[layer] = new LayerProgressBar(this); |
461 m_progressBars[layer]->setMinimum(0); | 517 m_progressBars[layer]->setMinimum(0); |
622 | 678 |
623 paint.save(); | 679 paint.save(); |
624 | 680 |
625 QColor penColour, surroundColour; | 681 QColor penColour, surroundColour; |
626 | 682 |
627 if (hasLightBackground()) { | 683 penColour = getForeground(); |
628 penColour = Qt::black; | 684 surroundColour = getBackground(); |
629 surroundColour = Qt::white; | 685 |
630 } else { | |
631 penColour = Qt::white; | |
632 surroundColour = Qt::black; | |
633 } | |
634 | |
635 /* | |
636 QColor origPenColour = paint.pen().color(); | |
637 QColor penColour = origPenColour; | |
638 QColor surroundColour = Qt::white; //palette().background().color(); | |
639 | |
640 if (!hasLightBackground()) { | |
641 int h, s, v; | |
642 penColour.getHsv(&h, &s, &v); | |
643 penColour = QColor::fromHsv(h, s, 255 - v); | |
644 surroundColour = Qt::black; | |
645 } | |
646 */ | |
647 paint.setPen(surroundColour); | 686 paint.setPen(surroundColour); |
648 | 687 |
649 for (int dx = -1; dx <= 1; ++dx) { | 688 for (int dx = -1; dx <= 1; ++dx) { |
650 for (int dy = -1; dy <= 1; ++dy) { | 689 for (int dy = -1; dy <= 1; ++dy) { |
651 if (!(dx || dy)) continue; | 690 if (!(dx || dy)) continue; |
654 } | 693 } |
655 | 694 |
656 paint.setPen(penColour); | 695 paint.setPen(penColour); |
657 | 696 |
658 paint.drawText(x, y, text); | 697 paint.drawText(x, y, text); |
659 /* | 698 |
660 paint.setPen(origPenColour); | |
661 */ | |
662 paint.restore(); | 699 paint.restore(); |
663 | 700 |
664 } else { | 701 } else { |
665 | 702 |
666 std::cerr << "ERROR: View::drawVisibleText: Boxed style not yet implemented!" << std::endl; | 703 std::cerr << "ERROR: View::drawVisibleText: Boxed style not yet implemented!" << std::endl; |
1122 | 1159 |
1123 bool | 1160 bool |
1124 View::areLayerColoursSignificant() const | 1161 View::areLayerColoursSignificant() const |
1125 { | 1162 { |
1126 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) { | 1163 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) { |
1127 if ((*i)->isLayerColourSignificant()) return true; | 1164 if ((*i)->getLayerColourSignificance() == |
1165 Layer::ColourHasMeaningfulValue) return true; | |
1128 if ((*i)->isLayerOpaque()) break; | 1166 if ((*i)->isLayerOpaque()) break; |
1129 } | 1167 } |
1130 return false; | 1168 return false; |
1131 } | 1169 } |
1132 | 1170 |
1400 | 1438 |
1401 if (repaintCache) paint.begin(m_cache); | 1439 if (repaintCache) paint.begin(m_cache); |
1402 else paint.begin(this); | 1440 else paint.begin(this); |
1403 | 1441 |
1404 paint.setClipRect(cacheRect); | 1442 paint.setClipRect(cacheRect); |
1405 | 1443 |
1406 if (hasLightBackground()) { | 1444 paint.setPen(getBackground()); |
1407 paint.setPen(Qt::white); | 1445 paint.setBrush(getBackground()); |
1408 paint.setBrush(Qt::white); | |
1409 } else { | |
1410 paint.setPen(Qt::black); | |
1411 paint.setBrush(Qt::black); | |
1412 } | |
1413 paint.drawRect(cacheRect); | 1446 paint.drawRect(cacheRect); |
1414 | 1447 |
1415 paint.setPen(Qt::black); | 1448 paint.setPen(getForeground()); |
1416 paint.setBrush(Qt::NoBrush); | 1449 paint.setBrush(Qt::NoBrush); |
1417 | 1450 |
1418 for (LayerList::iterator i = scrollables.begin(); i != scrollables.end(); ++i) { | 1451 for (LayerList::iterator i = scrollables.begin(); i != scrollables.end(); ++i) { |
1419 paint.setRenderHint(QPainter::Antialiasing, false); | 1452 paint.setRenderHint(QPainter::Antialiasing, false); |
1420 paint.save(); | 1453 paint.save(); |
1446 | 1479 |
1447 paint.begin(this); | 1480 paint.begin(this); |
1448 paint.setClipRect(nonCacheRect); | 1481 paint.setClipRect(nonCacheRect); |
1449 | 1482 |
1450 if (scrollables.empty()) { | 1483 if (scrollables.empty()) { |
1451 if (hasLightBackground()) { | 1484 paint.setPen(getBackground()); |
1452 paint.setPen(Qt::white); | 1485 paint.setBrush(getBackground()); |
1453 paint.setBrush(Qt::white); | |
1454 } else { | |
1455 paint.setPen(Qt::black); | |
1456 paint.setBrush(Qt::black); | |
1457 } | |
1458 paint.drawRect(nonCacheRect); | 1486 paint.drawRect(nonCacheRect); |
1459 } | 1487 } |
1460 | 1488 |
1461 paint.setPen(Qt::black); | 1489 paint.setPen(getForeground()); |
1462 paint.setBrush(Qt::NoBrush); | 1490 paint.setBrush(Qt::NoBrush); |
1463 | 1491 |
1464 for (LayerList::iterator i = nonScrollables.begin(); i != nonScrollables.end(); ++i) { | 1492 for (LayerList::iterator i = nonScrollables.begin(); i != nonScrollables.end(); ++i) { |
1465 // Profiler profiler2("View::paintEvent non-cacheable"); | 1493 // Profiler profiler2("View::paintEvent non-cacheable"); |
1466 (*i)->paint(this, paint, nonCacheRect); | 1494 (*i)->paint(this, paint, nonCacheRect); |
1492 | 1520 |
1493 paint.begin(this); | 1521 paint.begin(this); |
1494 | 1522 |
1495 int playx = getXForFrame(m_playPointerFrame); | 1523 int playx = getXForFrame(m_playPointerFrame); |
1496 | 1524 |
1497 paint.setPen(Qt::black); | 1525 paint.setPen(getForeground()); |
1498 paint.drawLine(playx - 1, 0, playx - 1, height() - 1); | 1526 paint.drawLine(playx - 1, 0, playx - 1, height() - 1); |
1499 paint.drawLine(playx + 1, 0, playx + 1, height() - 1); | 1527 paint.drawLine(playx + 1, 0, playx + 1, height() - 1); |
1500 paint.drawPoint(playx, 0); | 1528 paint.drawPoint(playx, 0); |
1501 paint.drawPoint(playx, height() - 1); | 1529 paint.drawPoint(playx, height() - 1); |
1502 paint.setPen(Qt::white); | 1530 paint.setPen(getBackground()); |
1503 paint.drawLine(playx, 1, playx, height() - 2); | 1531 paint.drawLine(playx, 1, playx, height() - 2); |
1504 | 1532 |
1505 paint.end(); | 1533 paint.end(); |
1506 } | 1534 } |
1507 | 1535 |
1575 paint.drawRect(p0, 0, p1 - p0, height() - 1); | 1603 paint.drawRect(p0, 0, p1 - p0, height() - 1); |
1576 } | 1604 } |
1577 | 1605 |
1578 if (illuminateThis) { | 1606 if (illuminateThis) { |
1579 paint.save(); | 1607 paint.save(); |
1580 if (hasLightBackground()) { | 1608 paint.setPen(QPen(getForeground(), 2)); |
1581 paint.setPen(QPen(Qt::black, 2)); | |
1582 } else { | |
1583 paint.setPen(QPen(Qt::white, 2)); | |
1584 } | |
1585 if (closeToLeft) { | 1609 if (closeToLeft) { |
1586 paint.drawLine(p0, 1, p1, 1); | 1610 paint.drawLine(p0, 1, p1, 1); |
1587 paint.drawLine(p0, 0, p0, height()); | 1611 paint.drawLine(p0, 0, p0, height()); |
1588 paint.drawLine(p0, height() - 1, p1, height() - 1); | 1612 paint.drawLine(p0, height() - 1, p1, height() - 1); |
1589 } else if (closeToRight) { | 1613 } else if (closeToRight) { |
1939 | 1963 |
1940 m_centreFrame = f0 + (x + width()/2) * m_zoomLevel; | 1964 m_centreFrame = f0 + (x + width()/2) * m_zoomLevel; |
1941 | 1965 |
1942 QRect chunk(0, 0, width(), height()); | 1966 QRect chunk(0, 0, width(), height()); |
1943 | 1967 |
1944 if (hasLightBackground()) { | 1968 paint.setPen(getBackground()); |
1945 paint.setPen(Qt::white); | 1969 paint.setBrush(getBackground()); |
1946 paint.setBrush(Qt::white); | |
1947 } else { | |
1948 paint.setPen(Qt::black); | |
1949 paint.setBrush(Qt::black); | |
1950 } | |
1951 | 1970 |
1952 paint.drawRect(QRect(xorigin + x, 0, width(), height())); | 1971 paint.drawRect(QRect(xorigin + x, 0, width(), height())); |
1953 | 1972 |
1954 paint.setPen(Qt::black); | 1973 paint.setPen(getForeground()); |
1955 paint.setBrush(Qt::NoBrush); | 1974 paint.setBrush(Qt::NoBrush); |
1956 | 1975 |
1957 for (LayerList::iterator i = m_layers.begin(); | 1976 for (LayerList::iterator i = m_layers.begin(); |
1958 i != m_layers.end(); ++i) { | 1977 i != m_layers.end(); ++i) { |
1959 | 1978 |