Changeset View
Changeset View
Standalone View
Standalone View
src/view/kateviewhelpers.cpp
Show First 20 Lines • Show All 91 Lines • ▼ Show 20 Line(s) | 1424 | KateIconBorder::KateIconBorder(KateViewInternal *internalView, QWidget *parent) | |||
---|---|---|---|---|---|
1428 | , m_viewInternal(internalView) | 1428 | , m_viewInternal(internalView) | ||
1429 | , m_iconBorderOn(false) | 1429 | , m_iconBorderOn(false) | ||
1430 | , m_lineNumbersOn(false) | 1430 | , m_lineNumbersOn(false) | ||
1431 | , m_relLineNumbersOn(false) | 1431 | , m_relLineNumbersOn(false) | ||
1432 | , m_updateRelLineNumbers(false) | 1432 | , m_updateRelLineNumbers(false) | ||
1433 | , m_foldingMarkersOn(false) | 1433 | , m_foldingMarkersOn(false) | ||
1434 | , m_dynWrapIndicatorsOn(false) | 1434 | , m_dynWrapIndicatorsOn(false) | ||
1435 | , m_annotationBorderOn(false) | 1435 | , m_annotationBorderOn(false) | ||
1436 | , m_dynWrapIndicators(0) | 1436 | , m_updatePositionToArea(true) | ||
1437 | , m_lastClickedLine(-1) | | |||
1438 | , m_cachedLNWidth(0) | | |||
1439 | , m_maxCharWidth(0.0) | | |||
1440 | , iconPaneWidth(16) | | |||
1441 | , m_annotationBorderWidth(6) | | |||
1442 | , m_annotationItemDelegate(new KateAnnotationItemDelegate(m_viewInternal, this)) | 1437 | , m_annotationItemDelegate(new KateAnnotationItemDelegate(m_viewInternal, this)) | ||
1443 | , m_foldingPreview(nullptr) | 1438 | , m_foldingPreview(nullptr) | ||
1444 | , m_foldingRange(nullptr) | 1439 | , m_foldingRange(nullptr) | ||
1445 | , m_nextHighlightBlock(-2) | 1440 | , m_nextHighlightBlock(-2) | ||
1446 | , m_currentBlockLine(-1) | 1441 | , m_currentBlockLine(-1) | ||
1447 | { | 1442 | { | ||
1448 | setAcceptDrops(true); | 1443 | setAcceptDrops(true); | ||
1449 | setAttribute(Qt::WA_StaticContents); | 1444 | setAttribute(Qt::WA_StaticContents); | ||
Show All 24 Lines | |||||
1474 | void KateIconBorder::setIconBorderOn(bool enable) | 1469 | void KateIconBorder::setIconBorderOn(bool enable) | ||
1475 | { | 1470 | { | ||
1476 | if (enable == m_iconBorderOn) { | 1471 | if (enable == m_iconBorderOn) { | ||
1477 | return; | 1472 | return; | ||
1478 | } | 1473 | } | ||
1479 | 1474 | | |||
1480 | m_iconBorderOn = enable; | 1475 | m_iconBorderOn = enable; | ||
1481 | 1476 | | |||
1482 | updateGeometry(); | 1477 | m_updatePositionToArea = true; | ||
1483 | 1478 | | |||
1484 | QTimer::singleShot(0, this, SLOT(update())); | 1479 | QTimer::singleShot(0, this, SLOT(update())); | ||
1485 | } | 1480 | } | ||
1486 | 1481 | | |||
1487 | void KateIconBorder::setAnnotationBorderOn(bool enable) | 1482 | void KateIconBorder::setAnnotationBorderOn(bool enable) | ||
1488 | { | 1483 | { | ||
1489 | if (enable == m_annotationBorderOn) { | 1484 | if (enable == m_annotationBorderOn) { | ||
1490 | return; | 1485 | return; | ||
1491 | } | 1486 | } | ||
1492 | 1487 | | |||
1493 | m_annotationBorderOn = enable; | 1488 | m_annotationBorderOn = enable; | ||
1494 | 1489 | | |||
1495 | // make sure the tooltip is hidden | 1490 | // make sure the tooltip is hidden | ||
1496 | if (!m_annotationBorderOn && !m_hoveredAnnotationGroupIdentifier.isEmpty()) { | 1491 | if (!m_annotationBorderOn && !m_hoveredAnnotationGroupIdentifier.isEmpty()) { | ||
1497 | m_hoveredAnnotationGroupIdentifier.clear(); | 1492 | m_hoveredAnnotationGroupIdentifier.clear(); | ||
1498 | hideAnnotationTooltip(); | 1493 | hideAnnotationTooltip(); | ||
1499 | } | 1494 | } | ||
1500 | 1495 | | |||
1501 | emit m_view->annotationBorderVisibilityChanged(m_view, enable); | 1496 | emit m_view->annotationBorderVisibilityChanged(m_view, enable); | ||
1502 | 1497 | | |||
1503 | updateGeometry(); | 1498 | m_updatePositionToArea = true; | ||
1504 | 1499 | | |||
1505 | QTimer::singleShot(0, this, SLOT(update())); | 1500 | QTimer::singleShot(0, this, SLOT(update())); | ||
1506 | } | 1501 | } | ||
1507 | 1502 | | |||
1508 | void KateIconBorder::removeAnnotationHovering() | 1503 | void KateIconBorder::removeAnnotationHovering() | ||
1509 | { | 1504 | { | ||
1510 | // remove hovering if it's still there | 1505 | // remove hovering if it's still there | ||
1511 | if (m_annotationBorderOn && !m_hoveredAnnotationGroupIdentifier.isEmpty()) { | 1506 | if (m_annotationBorderOn && !m_hoveredAnnotationGroupIdentifier.isEmpty()) { | ||
1512 | m_hoveredAnnotationGroupIdentifier.clear(); | 1507 | m_hoveredAnnotationGroupIdentifier.clear(); | ||
1513 | QTimer::singleShot(0, this, SLOT(update())); | 1508 | QTimer::singleShot(0, this, SLOT(update())); | ||
1514 | } | 1509 | } | ||
1515 | } | 1510 | } | ||
1516 | 1511 | | |||
1517 | void KateIconBorder::setLineNumbersOn(bool enable) | 1512 | void KateIconBorder::setLineNumbersOn(bool enable) | ||
1518 | { | 1513 | { | ||
1519 | if (enable == m_lineNumbersOn) { | 1514 | if (enable == m_lineNumbersOn) { | ||
1520 | return; | 1515 | return; | ||
1521 | } | 1516 | } | ||
1522 | 1517 | | |||
1523 | m_lineNumbersOn = enable; | 1518 | m_lineNumbersOn = enable; | ||
1524 | m_dynWrapIndicatorsOn = (m_dynWrapIndicators == 1) ? enable : m_dynWrapIndicators; | 1519 | m_dynWrapIndicatorsOn = (m_dynWrapIndicators == 1) ? enable : m_dynWrapIndicators; | ||
1525 | 1520 | | |||
1526 | updateGeometry(); | 1521 | m_updatePositionToArea = true; | ||
1527 | 1522 | | |||
1528 | QTimer::singleShot(0, this, SLOT(update())); | 1523 | QTimer::singleShot(0, this, SLOT(update())); | ||
1529 | } | 1524 | } | ||
1530 | 1525 | | |||
1531 | void KateIconBorder::setRelLineNumbersOn(bool enable) | 1526 | void KateIconBorder::setRelLineNumbersOn(bool enable) | ||
1532 | { | 1527 | { | ||
1533 | if (enable == m_relLineNumbersOn) { | 1528 | if (enable == m_relLineNumbersOn) { | ||
1534 | return; | 1529 | return; | ||
1535 | } | 1530 | } | ||
1536 | 1531 | | |||
1537 | m_relLineNumbersOn = enable; | 1532 | m_relLineNumbersOn = enable; | ||
1538 | /* | 1533 | /* | ||
1539 | * We don't have to touch the m_dynWrapIndicatorsOn because | 1534 | * We don't have to touch the m_dynWrapIndicatorsOn because | ||
1540 | * we already got it right from the m_lineNumbersOn | 1535 | * we already got it right from the m_lineNumbersOn | ||
1541 | */ | 1536 | */ | ||
1542 | updateGeometry(); | 1537 | m_updatePositionToArea = true; | ||
1543 | 1538 | | |||
1544 | QTimer::singleShot( 0, this, SLOT(update()) ); | 1539 | QTimer::singleShot( 0, this, SLOT(update()) ); | ||
1545 | } | 1540 | } | ||
1546 | 1541 | | |||
1547 | void KateIconBorder::updateForCursorLineChange() | 1542 | void KateIconBorder::updateForCursorLineChange() | ||
1548 | { | 1543 | { | ||
1549 | if (m_relLineNumbersOn) { | 1544 | if (m_relLineNumbersOn) { | ||
1550 | m_updateRelLineNumbers = true; | 1545 | m_updateRelLineNumbers = true; | ||
1551 | } | 1546 | } | ||
1552 | 1547 | | |||
1553 | // always do normal update, e.g. for different current line color! | 1548 | // always do normal update, e.g. for different current line color! | ||
1554 | update(); | 1549 | update(); | ||
1555 | } | 1550 | } | ||
1556 | 1551 | | |||
1557 | void KateIconBorder::setDynWrapIndicators(int state) | 1552 | void KateIconBorder::setDynWrapIndicators(int state) | ||
1558 | { | 1553 | { | ||
1559 | if (state == m_dynWrapIndicators) { | 1554 | if (state == m_dynWrapIndicators) { | ||
1560 | return; | 1555 | return; | ||
1561 | } | 1556 | } | ||
1562 | 1557 | | |||
1563 | m_dynWrapIndicators = state; | 1558 | m_dynWrapIndicators = state; | ||
1564 | m_dynWrapIndicatorsOn = (state == 1) ? m_lineNumbersOn : state; | 1559 | m_dynWrapIndicatorsOn = (state == 1) ? m_lineNumbersOn : state; | ||
1565 | 1560 | | |||
1566 | updateGeometry(); | 1561 | m_updatePositionToArea = true; | ||
1567 | 1562 | | |||
1568 | QTimer::singleShot(0, this, SLOT(update())); | 1563 | QTimer::singleShot(0, this, SLOT(update())); | ||
1569 | } | 1564 | } | ||
1570 | 1565 | | |||
1571 | void KateIconBorder::setFoldingMarkersOn(bool enable) | 1566 | void KateIconBorder::setFoldingMarkersOn(bool enable) | ||
1572 | { | 1567 | { | ||
1573 | if (enable == m_foldingMarkersOn) { | 1568 | if (enable == m_foldingMarkersOn) { | ||
1574 | return; | 1569 | return; | ||
1575 | } | 1570 | } | ||
1576 | 1571 | | |||
1577 | m_foldingMarkersOn = enable; | 1572 | m_foldingMarkersOn = enable; | ||
1578 | 1573 | | |||
1579 | updateGeometry(); | 1574 | m_updatePositionToArea = true; | ||
1580 | 1575 | | |||
1581 | QTimer::singleShot(0, this, SLOT(update())); | 1576 | QTimer::singleShot(0, this, SLOT(update())); | ||
1582 | } | 1577 | } | ||
1583 | 1578 | | |||
1584 | QSize KateIconBorder::sizeHint() const | 1579 | QSize KateIconBorder::sizeHint() const | ||
1585 | { | 1580 | { | ||
1586 | int w = 0; | 1581 | int w = 1; // Must be any value != 0 or we will never painted! | ||
1587 | | ||||
1588 | if (m_iconBorderOn) { | | |||
1589 | w += iconPaneWidth + 2; | | |||
1590 | } | | |||
1591 | | ||||
1592 | if (m_annotationBorderOn) { | | |||
1593 | w += m_annotationBorderWidth + 2; | | |||
1594 | } | | |||
1595 | | ||||
1596 | if (m_lineNumbersOn || (m_dynWrapIndicatorsOn && m_view->config()->dynWordWrap())) { | | |||
1597 | w += lineNumberWidth() + 2; | | |||
1598 | } | | |||
1599 | 1582 | | |||
1600 | if (m_foldingMarkersOn) { | 1583 | const int i = m_positionToArea.size(); | ||
1601 | w += iconPaneWidth; | 1584 | if (i > 0) { | ||
1585 | w = m_positionToArea.at(i - 1).first; | ||||
1602 | } | 1586 | } | ||
1603 | 1587 | | |||
1604 | // space for the line modification system border | | |||
1605 | if (m_view->config()->lineModification()) { | | |||
1606 | w += 3; | | |||
1607 | } | | |||
1608 | | ||||
1609 | // two pixel space | | |||
1610 | w += 2; | | |||
1611 | | ||||
1612 | return QSize(w, 0); | 1588 | return QSize(w, 0); | ||
1613 | } | 1589 | } | ||
1614 | 1590 | | |||
1615 | // This function (re)calculates the maximum width of any of the digit characters (0 -> 9) | 1591 | // This function (re)calculates the maximum width of any of the digit characters (0 -> 9) | ||
1616 | // for graceful handling of variable-width fonts as the linenumber font. | 1592 | // for graceful handling of variable-width fonts as the linenumber font. | ||
1617 | void KateIconBorder::updateFont() | 1593 | void KateIconBorder::updateFont() | ||
1618 | { | 1594 | { | ||
1619 | const QFontMetricsF &fm = m_view->renderer()->config()->fontMetrics(); | 1595 | const QFontMetricsF &fm = m_view->renderer()->config()->fontMetrics(); | ||
1620 | m_maxCharWidth = 0.0; | 1596 | m_maxCharWidth = 0.0; | ||
1621 | // Loop to determine the widest numeric character in the current font. | 1597 | // Loop to determine the widest numeric character in the current font. | ||
1622 | // 48 is ascii '0' | 1598 | // 48 is ascii '0' | ||
1623 | for (int i = 48; i < 58; i++) { | 1599 | for (int i = 48; i < 58; i++) { | ||
1624 | const qreal charWidth = ceil(fm.width(QChar(i))); | 1600 | const qreal charWidth = ceil(fm.width(QChar(i))); | ||
1625 | m_maxCharWidth = qMax(m_maxCharWidth, charWidth); | 1601 | m_maxCharWidth = qMax(m_maxCharWidth, charWidth); | ||
1626 | } | 1602 | } | ||
1627 | 1603 | | |||
1628 | // NOTE/TODO(or not) Take size of m_dynWrapIndicatorChar into account. | 1604 | // NOTE/TODO(or not) Take size of m_dynWrapIndicatorChar into account. | ||
1629 | // It's a multi-char and it's reported size is, even with a mono-space font, | 1605 | // It's a multi-char and it's reported size is, even with a mono-space font, | ||
1630 | // bigger than each digit, e.g. 10 vs 12. Currently it seems to work even with | 1606 | // bigger than each digit, e.g. 10 vs 12. Currently it seems to work even with | ||
1631 | // "Line Numbers Off" but all these width calculating looks slightly hacky | 1607 | // "Line Numbers Off" but all these width calculating looks slightly hacky | ||
1632 | 1608 | | |||
1633 | // the icon pane scales with the font... | 1609 | // the icon pane scales with the font... | ||
1634 | iconPaneWidth = fm.height(); | 1610 | m_iconAreaWidth = fm.height(); | ||
1611 | | ||||
1612 | // Only for now, later may that become an own value | ||||
1613 | m_foldingAreaWidth = m_iconAreaWidth; | ||||
1635 | 1614 | | |||
1636 | calcAnnotationBorderWidth(); | 1615 | calcAnnotationBorderWidth(); | ||
1637 | 1616 | | |||
1638 | updateGeometry(); | 1617 | m_updatePositionToArea = true; | ||
1639 | 1618 | | |||
1640 | QTimer::singleShot(0, this, SLOT(update())); | 1619 | QTimer::singleShot(0, this, SLOT(update())); | ||
1641 | } | 1620 | } | ||
1642 | 1621 | | |||
1643 | int KateIconBorder::lineNumberWidth() const | 1622 | int KateIconBorder::lineNumberWidth() const | ||
1644 | { | 1623 | { | ||
1645 | // width = (number of digits + 1) * char width | 1624 | // width = (number of digits + 1) * char width | ||
1646 | const int digits = (int) ceil(log10((double)(m_view->doc()->lines() + 1))); | 1625 | const int digits = (int) ceil(log10((double)(m_view->doc()->lines() + 1))); | ||
Show All 29 Lines | |||||
1676 | } | 1655 | } | ||
1677 | 1656 | | |||
1678 | static void paintTriangle(QPainter &painter, QColor c, int xOffset, int yOffset, int width, int height, bool open) | 1657 | static void paintTriangle(QPainter &painter, QColor c, int xOffset, int yOffset, int width, int height, bool open) | ||
1679 | { | 1658 | { | ||
1680 | painter.setRenderHint(QPainter::Antialiasing); | 1659 | painter.setRenderHint(QPainter::Antialiasing); | ||
1681 | 1660 | | |||
1682 | qreal size = qMin(width, height); | 1661 | qreal size = qMin(width, height); | ||
1683 | 1662 | | |||
1684 | if (KColorUtils::luma(c) > 0.25) { | 1663 | if (open) { | ||
1685 | c = KColorUtils::darken(c); | 1664 | // Paint unfolded icon less pushy | ||
1665 | if (KColorUtils::luma(c) < 0.25) { | ||||
1666 | c = KColorUtils::darken(c); | ||||
1667 | } else { | ||||
1668 | c = KColorUtils::shade(c, 0.1); | ||||
1669 | } | ||||
1670 | | ||||
1686 | } else { | 1671 | } else { | ||
1687 | c = KColorUtils::shade(c, 0.1); | 1672 | // Paint folded icon in contrast to popup highlighting | ||
1673 | if (KColorUtils::luma(c) > 0.25) { | ||||
1674 | c = KColorUtils::darken(c); | ||||
1675 | } else { | ||||
1676 | c = KColorUtils::shade(c, 0.1); | ||||
1677 | } | ||||
1688 | } | 1678 | } | ||
1689 | 1679 | | |||
1690 | QPen pen; | 1680 | QPen pen; | ||
1691 | pen.setJoinStyle(Qt::RoundJoin); | 1681 | pen.setJoinStyle(Qt::RoundJoin); | ||
1692 | pen.setColor(c); | 1682 | pen.setColor(c); | ||
1693 | pen.setWidthF(1.5); | 1683 | pen.setWidthF(1.5); | ||
1694 | painter.setPen(pen); | 1684 | painter.setPen(pen); | ||
1695 | | ||||
1696 | painter.setBrush(c); | 1685 | painter.setBrush(c); | ||
1697 | 1686 | | |||
1698 | // let some border, if possible | 1687 | // let some border, if possible | ||
1699 | size *= 0.6; | 1688 | size *= 0.6; | ||
1700 | 1689 | | |||
1701 | qreal halfSize = size / 2; | 1690 | qreal halfSize = size / 2; | ||
1702 | qreal halfSizeP = halfSize * 0.6; | 1691 | qreal halfSizeP = halfSize * 0.6; | ||
1703 | QPointF middle(xOffset + (qreal)width / 2, yOffset + (qreal)height / 2); | 1692 | QPointF middle(xOffset + (qreal)width / 2, yOffset + (qreal)height / 2); | ||
▲ Show 20 Lines • Show All 182 Lines • ▼ Show 20 Line(s) | 1849 | { | |||
1919 | 1908 | | |||
1920 | m_lastAnnotationGroupIdentifier = m_nextAnnotationGroupIdentifier; | 1909 | m_lastAnnotationGroupIdentifier = m_nextAnnotationGroupIdentifier; | ||
1921 | m_isSameAnnotationGroupsSinceLast = isSameAnnotationGroupsSinceThis; | 1910 | m_isSameAnnotationGroupsSinceLast = isSameAnnotationGroupsSinceThis; | ||
1922 | } | 1911 | } | ||
1923 | 1912 | | |||
1924 | 1913 | | |||
1925 | void KateIconBorder::paintBorder(int /*x*/, int y, int /*width*/, int height) | 1914 | void KateIconBorder::paintBorder(int /*x*/, int y, int /*width*/, int height) | ||
1926 | { | 1915 | { | ||
1927 | uint h = m_view->renderer()->lineHeight(); | 1916 | const uint h = m_view->renderer()->lineHeight(); | ||
1928 | uint startz = (y / h); | 1917 | const uint startz = (y / h); | ||
1929 | uint endz = startz + 1 + (height / h); | 1918 | const uint endz = qMin(startz + 1 + (height / h), static_cast<uint>(m_viewInternal->cache()->viewCacheLineCount())); | ||
1930 | uint lineRangesSize = m_viewInternal->cache()->viewCacheLineCount(); | 1919 | const uint currentLine = m_view->cursorPosition().line(); | ||
1931 | uint currentLine = m_view->cursorPosition().line(); | | |||
1932 | 1920 | | |||
1933 | // center the folding boxes | 1921 | // center the folding boxes | ||
1934 | int m_px = (h - 11) / 2; | 1922 | int m_px = (h - 11) / 2; | ||
1935 | if (m_px < 0) { | 1923 | if (m_px < 0) { | ||
1936 | m_px = 0; | 1924 | m_px = 0; | ||
1937 | } | 1925 | } | ||
1938 | 1926 | | |||
1939 | int lnWidth(0); | 1927 | if (m_updatePositionToArea) { | ||
1940 | if (m_lineNumbersOn || m_dynWrapIndicatorsOn) { // avoid calculating unless needed ;-) | 1928 | m_lineNumberAreaWidth = lineNumberWidth(); | ||
1941 | lnWidth = lineNumberWidth(); | 1929 | m_positionToArea.clear(); | ||
1942 | if (lnWidth != m_cachedLNWidth || m_oldBackgroundColor != m_view->renderer()->config()->iconBarColor()) { | | |||
1943 | // we went from n0 ->n9 lines or vice versa | | |||
1944 | // this causes an extra updateGeometry() first time the line numbers | | |||
1945 | // are displayed, but sizeHint() is supposed to be const so we can't set | | |||
1946 | // the cached value there. | | |||
1947 | m_cachedLNWidth = lnWidth; | | |||
1948 | m_oldBackgroundColor = m_view->renderer()->config()->iconBarColor(); | | |||
1949 | updateGeometry(); | | |||
1950 | update(); | | |||
1951 | return; | | |||
1952 | } | | |||
1953 | } | 1930 | } | ||
1954 | 1931 | | |||
1955 | int w(this->width()); // sane value/calc only once | | |||
1956 | | ||||
1957 | QPainter p(this); | 1932 | QPainter p(this); | ||
1958 | p.setRenderHints(QPainter::TextAntialiasing); | 1933 | p.setRenderHints(QPainter::TextAntialiasing); | ||
1959 | p.setFont(m_view->renderer()->config()->font()); // for line numbers | 1934 | p.setFont(m_view->renderer()->config()->font()); // for line numbers | ||
1960 | 1935 | | |||
1961 | KTextEditor::AnnotationModel *model = m_view->annotationModel() ? | 1936 | KTextEditor::AnnotationModel *model = m_view->annotationModel() ? | ||
1962 | m_view->annotationModel() : m_doc->annotationModel(); | 1937 | m_view->annotationModel() : m_doc->annotationModel(); | ||
1963 | KateAnnotationGroupPositionState annotationGroupPositionState(m_viewInternal, model, | 1938 | KateAnnotationGroupPositionState annotationGroupPositionState(m_viewInternal, model, | ||
1964 | m_hoveredAnnotationGroupIdentifier, | 1939 | m_hoveredAnnotationGroupIdentifier, | ||
1965 | startz, m_annotationBorderOn); | 1940 | startz, m_annotationBorderOn); | ||
1966 | 1941 | | |||
1967 | for (uint z = startz; z <= endz; z++) { | 1942 | // Fetch often used data only once, improve readability | ||
1968 | int y = h * z; | 1943 | const int w = width(); | ||
1969 | int realLine = -1; | 1944 | const QColor iconBarColor = m_view->renderer()->config()->iconBarColor(); // Effective our background | ||
1970 | 1945 | const QColor lineNumberColor = m_view->renderer()->config()->lineNumberColor(); | |||
1971 | if (z < lineRangesSize) { | 1946 | const QColor backgroundColor = m_view->renderer()->config()->backgroundColor(); // Of the edit area | ||
1972 | realLine = m_viewInternal->cache()->viewLine(z).line(); | 1947 | | ||
1948 | // Paint the border in chunks line by line | ||||
1949 | for (uint z = startz; z < endz; z++) { | ||||
1950 | // Painting coordinates, lineHeight * lineNumber | ||||
1951 | const uint y = h * z; | ||||
1952 | // Paint the border in chunks left->right, remember used width | ||||
1953 | uint lnX = 0; | ||||
1954 | | ||||
1955 | // Paint background over full width... | ||||
1956 | p.fillRect(lnX, y, w, h, iconBarColor); | ||||
1957 | // ...and overpaint again the end to simulate some margin to the edit area, | ||||
1958 | // so that the text not looks like stuck to the border | ||||
1959 | p.fillRect(w - m_separatorWidth, y, w, h, backgroundColor); | ||||
1960 | | ||||
1961 | const KateTextLayout lineLayout = m_viewInternal->cache()->viewLine(z); | ||||
1962 | int realLine = lineLayout.line(); | ||||
1963 | if (realLine < 0) { | ||||
1964 | // We have reached the end of the document, just paint background | ||||
1965 | continue; | ||||
1973 | } | 1966 | } | ||
1974 | 1967 | | |||
1975 | int lnX = 0; | | |||
1976 | | ||||
1977 | p.fillRect(0, y, w - 5, h, m_view->renderer()->config()->iconBarColor()); | | |||
1978 | p.fillRect(w - 5, y, 5, h, m_view->renderer()->config()->backgroundColor()); | | |||
1979 | | ||||
1980 | // icon pane | 1968 | // icon pane | ||
1981 | if (m_iconBorderOn) { | 1969 | if (m_iconBorderOn) { | ||
1982 | p.setPen(m_view->renderer()->config()->separatorColor()); | 1970 | p.setPen(m_view->renderer()->config()->separatorColor()); | ||
1983 | p.setBrush(m_view->renderer()->config()->separatorColor()); | 1971 | p.setBrush(m_view->renderer()->config()->separatorColor()); | ||
1984 | p.drawLine(lnX + iconPaneWidth + 1, y, lnX + iconPaneWidth + 1, y + h); | 1972 | p.drawLine(lnX + m_iconAreaWidth, y, lnX + m_iconAreaWidth, y + h); | ||
1985 | 1973 | | |||
1986 | if ((realLine > -1) && (m_viewInternal->cache()->viewLine(z).startCol() == 0)) { | 1974 | const uint mrk(m_doc->mark(realLine)); // call only once | ||
1987 | uint mrk(m_doc->mark(realLine)); // call only once | 1975 | if (mrk && lineLayout.startCol() == 0) { | ||
1988 | 1976 | for (uint bit = 0; bit < 32; bit++) { | |||
1989 | if (mrk) { | 1977 | MarkInterface::MarkTypes markType = (MarkInterface::MarkTypes)(1 << bit); | ||
1990 | for (uint bit = 0; bit < 32; bit++) { | 1978 | if (mrk & markType) { | ||
1991 | MarkInterface::MarkTypes markType = (MarkInterface::MarkTypes)(1 << bit); | 1979 | QPixmap px_mark(m_doc->markPixmap(markType)); | ||
1992 | if (mrk & markType) { | 1980 | px_mark.setDevicePixelRatio(devicePixelRatioF()); | ||
1993 | QPixmap px_mark(m_doc->markPixmap(markType)); | 1981 | | ||
1994 | px_mark.setDevicePixelRatio(devicePixelRatioF()); | 1982 | if (!px_mark.isNull() && h > 0 && m_iconAreaWidth > 0) { | ||
1995 | 1983 | // scale up to a usable size | |||
1996 | if (!px_mark.isNull() && h > 0 && iconPaneWidth > 0) { | 1984 | px_mark = px_mark.scaled(m_iconAreaWidth * devicePixelRatio(), h * devicePixelRatio(), Qt::KeepAspectRatio); | ||
1997 | // scale up to a usable size | 1985 | | ||
1998 | px_mark = px_mark.scaled(iconPaneWidth * devicePixelRatio(), h * devicePixelRatio(), Qt::KeepAspectRatio); | 1986 | // center the mark pixmap | ||
1999 | 1987 | int x_px = (m_iconAreaWidth - px_mark.width()/ devicePixelRatio()) / 2; | |||
2000 | // center the mark pixmap | 1988 | if (x_px < 0) { | ||
2001 | int x_px = (iconPaneWidth - px_mark.width()/ devicePixelRatio()) / 2; | 1989 | x_px = 0; | ||
2002 | if (x_px < 0) { | | |||
2003 | x_px = 0; | | |||
2004 | } | | |||
2005 | | ||||
2006 | int y_px = (h - px_mark.height() / devicePixelRatio()) / 2; | | |||
2007 | if (y_px < 0) { | | |||
2008 | y_px = 0; | | |||
2009 | } | | |||
2010 | | ||||
2011 | p.drawPixmap(lnX + x_px, y + y_px, px_mark); | | |||
2012 | } | 1990 | } | ||
1991 | | ||||
1992 | int y_px = (h - px_mark.height() / devicePixelRatio()) / 2; | ||||
1993 | if (y_px < 0) { | ||||
1994 | y_px = 0; | ||||
1995 | } | ||||
1996 | | ||||
1997 | p.drawPixmap(lnX + x_px, y + y_px, px_mark); | ||||
2013 | } | 1998 | } | ||
2014 | } | 1999 | } | ||
2015 | } | 2000 | } | ||
2016 | } | 2001 | } | ||
2017 | 2002 | | |||
2018 | lnX += iconPaneWidth + 2; | 2003 | lnX += m_iconAreaWidth + m_separatorWidth; | ||
2004 | if (m_updatePositionToArea) { | ||||
2005 | m_positionToArea.append(AreaPosition(lnX, IconBorder)); | ||||
2006 | } | ||||
2019 | } | 2007 | } | ||
2020 | 2008 | | |||
2021 | // annotation information | 2009 | // annotation information | ||
2022 | if (m_annotationBorderOn) { | 2010 | if (m_annotationBorderOn) { | ||
2023 | // Draw a border line between annotations and the line numbers | 2011 | // Draw a border line between annotations and the line numbers | ||
2024 | p.setPen(m_view->renderer()->config()->lineNumberColor()); | 2012 | p.setPen(lineNumberColor); | ||
2025 | p.setBrush(m_view->renderer()->config()->lineNumberColor()); | 2013 | p.setBrush(lineNumberColor); | ||
2026 | 2014 | | |||
2027 | const qreal borderX = lnX + m_annotationBorderWidth + 0.5; | 2015 | const qreal borderX = lnX + m_annotationAreaWidth + 0.5; | ||
2028 | p.drawLine(QPointF(borderX, y+0.5), QPointF(borderX, y + h - 0.5)); | 2016 | p.drawLine(QPointF(borderX, y+0.5), QPointF(borderX, y + h - 0.5)); | ||
2029 | 2017 | | |||
2030 | if ((realLine > -1) && model) { | 2018 | if (model) { | ||
2031 | KTextEditor::StyleOptionAnnotationItem styleOption; | 2019 | KTextEditor::StyleOptionAnnotationItem styleOption; | ||
2032 | initStyleOption(&styleOption); | 2020 | initStyleOption(&styleOption); | ||
2033 | styleOption.rect.setRect(lnX, y, m_annotationBorderWidth, h); | 2021 | styleOption.rect.setRect(lnX, y, m_annotationAreaWidth, h); | ||
2034 | annotationGroupPositionState.nextLine(styleOption, z, realLine); | 2022 | annotationGroupPositionState.nextLine(styleOption, z, realLine); | ||
2035 | 2023 | | |||
2036 | m_annotationItemDelegate->paint(&p, styleOption, model, realLine); | 2024 | m_annotationItemDelegate->paint(&p, styleOption, model, realLine); | ||
2037 | } | 2025 | } | ||
2038 | 2026 | | |||
2039 | // adjust current X position | 2027 | lnX += m_annotationAreaWidth + m_separatorWidth; | ||
2040 | lnX += m_annotationBorderWidth + /* separator line width */1; | 2028 | if (m_updatePositionToArea) { | ||
2029 | m_positionToArea.append(AreaPosition(lnX, AnnotationBorder)); | ||||
2030 | } | ||||
2041 | } | 2031 | } | ||
2042 | 2032 | | |||
2043 | // line number | 2033 | // line number | ||
2044 | if (m_lineNumbersOn || m_dynWrapIndicatorsOn) { | 2034 | if (m_lineNumbersOn || m_dynWrapIndicatorsOn) { | ||
2045 | if (realLine > -1) { | 2035 | QColor usedLineNumberColor; | ||
2046 | int distanceToCurrent = abs(realLine - static_cast<int>(currentLine)); | 2036 | const int distanceToCurrent = abs(realLine - static_cast<int>(currentLine)); | ||
2047 | QColor color; | 2037 | if (distanceToCurrent == 0) { | ||
2048 | 2038 | usedLineNumberColor = m_view->renderer()->config()->currentLineNumberColor(); | |||
2049 | if (distanceToCurrent == 0) { | 2039 | } else { | ||
2050 | color = m_view->renderer()->config()->currentLineNumberColor(); | 2040 | usedLineNumberColor = lineNumberColor; | ||
2051 | } else { | 2041 | } | ||
2052 | color = m_view->renderer()->config()->lineNumberColor(); | 2042 | p.setPen(usedLineNumberColor); | ||
2053 | } | 2043 | p.setBrush(usedLineNumberColor); | ||
2054 | p.setPen(color); | 2044 | | ||
2055 | p.setBrush(color); | 2045 | if (lineLayout.startCol() == 0) { | ||
2056 | 2046 | if (m_relLineNumbersOn) { | |||
2057 | if (m_viewInternal->cache()->viewLine(z).startCol() == 0) { | 2047 | if (distanceToCurrent == 0) { | ||
2058 | if (m_relLineNumbersOn) { | 2048 | p.drawText(lnX + m_maxCharWidth / 2, y, m_lineNumberAreaWidth - m_maxCharWidth, h, | ||
2059 | if (distanceToCurrent == 0) { | 2049 | Qt::TextDontClip | Qt::AlignLeft | Qt::AlignVCenter, QString::number(realLine + 1)); | ||
2060 | p.drawText(lnX + m_maxCharWidth / 2, y, lnWidth - m_maxCharWidth, h, | 2050 | } else { | ||
2061 | Qt::TextDontClip|Qt::AlignLeft|Qt::AlignVCenter, QString::number(realLine + 1)); | 2051 | p.drawText(lnX + m_maxCharWidth / 2, y, m_lineNumberAreaWidth - m_maxCharWidth, h, | ||
2062 | } else { | 2052 | Qt::TextDontClip | Qt::AlignRight | Qt::AlignVCenter, QString::number(distanceToCurrent)); | ||
2063 | p.drawText(lnX + m_maxCharWidth / 2, y, lnWidth - m_maxCharWidth, h, | 2053 | } | ||
2064 | Qt::TextDontClip|Qt::AlignRight|Qt::AlignVCenter, QString::number(distanceToCurrent)); | 2054 | if (m_updateRelLineNumbers) { | ||
2065 | } | 2055 | m_updateRelLineNumbers = false; | ||
2066 | if (m_updateRelLineNumbers) { | 2056 | update(); | ||
2067 | m_updateRelLineNumbers = false; | | |||
2068 | update(); | | |||
2069 | } | | |||
2070 | } else if (m_lineNumbersOn) { | | |||
2071 | p.drawText(lnX + m_maxCharWidth / 2, y, lnWidth - m_maxCharWidth, h, | | |||
2072 | Qt::TextDontClip | Qt::AlignRight | Qt::AlignVCenter, QString::number(realLine + 1)); | | |||
2073 | } | 2057 | } | ||
2074 | } else if (m_dynWrapIndicatorsOn) { | 2058 | } else if (m_lineNumbersOn) { | ||
2075 | p.drawText(lnX + m_maxCharWidth / 2, y, lnWidth - m_maxCharWidth, h, | 2059 | p.drawText(lnX + m_maxCharWidth / 2, y, m_lineNumberAreaWidth - m_maxCharWidth, h, | ||
2076 | Qt::TextDontClip | Qt::AlignRight | Qt::AlignVCenter, m_dynWrapIndicatorChar); | 2060 | Qt::TextDontClip | Qt::AlignRight | Qt::AlignVCenter, QString::number(realLine + 1)); | ||
2077 | } | 2061 | } | ||
2062 | } else if (m_dynWrapIndicatorsOn) { | ||||
2063 | p.drawText(lnX + m_maxCharWidth / 2, y, m_lineNumberAreaWidth - m_maxCharWidth, h, | ||||
2064 | Qt::TextDontClip | Qt::AlignRight | Qt::AlignVCenter, m_dynWrapIndicatorChar); | ||||
2065 | } | ||||
2066 | | ||||
2067 | lnX += m_lineNumberAreaWidth + m_separatorWidth; | ||||
2068 | if (m_updatePositionToArea) { | ||||
2069 | m_positionToArea.append(AreaPosition(lnX, LineNumbers)); | ||||
2070 | } | ||||
2071 | } | ||||
2072 | | ||||
2073 | // modified line system | ||||
2074 | if (m_view->config()->lineModification() && !m_doc->url().isEmpty()) { | ||||
2075 | const Kate::TextLine tl = m_doc->plainKateTextLine(realLine); | ||||
2076 | if (tl->markedAsModified()) { | ||||
2077 | p.fillRect(lnX, y, m_modAreaWidth, h, m_view->renderer()->config()->modifiedLineColor()); | ||||
2078 | } else if (tl->markedAsSavedOnDisk()) { | ||||
2079 | p.fillRect(lnX, y, m_modAreaWidth, h, m_view->renderer()->config()->savedLineColor()); | ||||
2080 | } else { | ||||
2081 | p.fillRect(lnX, y, m_modAreaWidth, h, iconBarColor); | ||||
2078 | } | 2082 | } | ||
2079 | 2083 | | |||
2080 | lnX += lnWidth + 2; | 2084 | lnX += m_modAreaWidth; // No m_separatorWidth | ||
2085 | if (m_updatePositionToArea) { | ||||
2086 | m_positionToArea.append(AreaPosition(lnX, None)); | ||||
2087 | } | ||||
2081 | } | 2088 | } | ||
2082 | 2089 | | |||
2083 | // folding markers | 2090 | // folding markers | ||
2084 | if (m_foldingMarkersOn) { | 2091 | if (m_foldingMarkersOn) { | ||
2085 | // first icon border background | 2092 | const QColor foldingColor(m_view->renderer()->config()->foldingColor()); | ||
2086 | p.fillRect(lnX, y, iconPaneWidth, h, m_view->renderer()->config()->iconBarColor()); | | |||
2087 | | ||||
2088 | // possible additional folding highlighting | 2093 | // possible additional folding highlighting | ||
2089 | if ((realLine >= 0) && m_foldingRange && m_foldingRange->overlapsLine(realLine)) { | 2094 | if (m_foldingRange && m_foldingRange->overlapsLine(realLine)) { | ||
2090 | p.save(); | 2095 | p.fillRect(lnX, y, m_foldingAreaWidth, h, foldingColor); | ||
2091 | | ||||
2092 | // use linear gradient as brush | | |||
2093 | QLinearGradient g(lnX, y, lnX + iconPaneWidth, y); | | |||
2094 | const QColor foldingColor(m_view->renderer()->config()->foldingColor()); | | |||
2095 | g.setColorAt(0, foldingColor); | | |||
2096 | g.setColorAt(0.3, foldingColor.lighter(110)); | | |||
2097 | g.setColorAt(1, foldingColor); | | |||
2098 | p.setBrush(g); | | |||
2099 | p.setPen(foldingColor); | | |||
2100 | | ||||
2101 | p.setClipRect(lnX, y, iconPaneWidth, h); | | |||
2102 | p.setRenderHint(QPainter::Antialiasing); | | |||
2103 | | ||||
2104 | const qreal r = 4.0; | | |||
2105 | if (m_foldingRange->start().line() == realLine && | | |||
2106 | m_viewInternal->cache()->viewLine(z).viewLine() == 0) { | | |||
2107 | p.drawRect(lnX, y, iconPaneWidth, h + r); | | |||
2108 | } else if (m_foldingRange->end().line() == realLine && | | |||
2109 | m_viewInternal->cache()->viewLine(z).viewLine() == m_viewInternal->cache()->viewLineCount(realLine) - 1) { | | |||
2110 | p.drawRect(lnX, y - r, iconPaneWidth, h + r); | | |||
2111 | } else { | | |||
2112 | p.drawRect(lnX, y - r, iconPaneWidth, h + 2 * r); | | |||
2113 | } | | |||
2114 | p.restore(); | | |||
2115 | } | 2096 | } | ||
2116 | 2097 | | |||
2117 | if ((realLine >= 0) && (m_viewInternal->cache()->viewLine(z).startCol() == 0)) { | 2098 | if (lineLayout.startCol() == 0) { | ||
2118 | QVector<QPair<qint64, Kate::TextFolding::FoldingRangeFlags> > startingRanges = m_view->textFolding().foldingRangesStartingOnLine(realLine); | 2099 | QVector<QPair<qint64, Kate::TextFolding::FoldingRangeFlags> > startingRanges = m_view->textFolding().foldingRangesStartingOnLine(realLine); | ||
2119 | bool anyFolded = false; | 2100 | bool anyFolded = false; | ||
2120 | for (int i = 0; i < startingRanges.size(); ++i) | 2101 | for (int i = 0; i < startingRanges.size(); ++i) { | ||
2121 | if (startingRanges[i].second & Kate::TextFolding::Folded) { | 2102 | if (startingRanges[i].second & Kate::TextFolding::Folded) { | ||
2122 | anyFolded = true; | 2103 | anyFolded = true; | ||
2123 | } | 2104 | } | ||
2124 | 2105 | } | |||
2125 | Kate::TextLine tl = m_doc->kateTextLine(realLine); | 2106 | const Kate::TextLine tl = m_doc->kateTextLine(realLine); | ||
2126 | | ||||
2127 | if (!startingRanges.isEmpty() || tl->markedAsFoldingStart()) { | 2107 | if (!startingRanges.isEmpty() || tl->markedAsFoldingStart()) { | ||
2128 | if (anyFolded) { | 2108 | if (anyFolded) { | ||
2129 | paintTriangle(p, m_view->renderer()->config()->foldingColor(), lnX, y, iconPaneWidth, h, false); | 2109 | paintTriangle(p, foldingColor, lnX, y, m_foldingAreaWidth, h, false); | ||
2130 | } else { | 2110 | } else { | ||
2131 | paintTriangle(p, m_view->renderer()->config()->foldingColor(), lnX, y, iconPaneWidth, h, true); | 2111 | // Don't try to use currentLineNumberColor, the folded icon gets also not highligted | ||
2112 | paintTriangle(p, lineNumberColor, lnX, y, m_foldingAreaWidth, h, true); | ||||
2132 | } | 2113 | } | ||
2133 | } | 2114 | } | ||
2134 | } | 2115 | } | ||
2135 | 2116 | | |||
2136 | lnX += iconPaneWidth; | 2117 | lnX += m_foldingAreaWidth; | ||
2118 | if (m_updatePositionToArea) { | ||||
2119 | m_positionToArea.append(AreaPosition(lnX, FoldingMarkers)); | ||||
2120 | } | ||||
2137 | } | 2121 | } | ||
2138 | 2122 | | |||
2139 | // modified line system | 2123 | if (m_updatePositionToArea) { | ||
2140 | if (m_view->config()->lineModification() && realLine > -1 && !m_doc->url().isEmpty()) { | 2124 | m_updatePositionToArea = false; | ||
2141 | // one pixel space | 2125 | // Don't forget our "text-stuck-to-border" protector | ||
2142 | ++lnX; | 2126 | lnX += m_separatorWidth; | ||
2143 | 2127 | m_positionToArea.append(AreaPosition(lnX, None)); | |||
2144 | Kate::TextLine tl = m_doc->plainKateTextLine(realLine); | 2128 | // Now that we know our needed space, ensure we are painted properly | ||
2145 | if (tl->markedAsModified()) { | 2129 | updateGeometry(); | ||
2146 | p.fillRect(lnX, y, 3, h, m_view->renderer()->config()->modifiedLineColor()); | 2130 | update(); | ||
2147 | } | 2131 | return; | ||
2148 | if (tl->markedAsSavedOnDisk()) { | | |||
2149 | p.fillRect(lnX, y, 3, h, m_view->renderer()->config()->savedLineColor()); | | |||
2150 | } | | |||
2151 | } | 2132 | } | ||
2152 | } | 2133 | } | ||
2153 | } | 2134 | } | ||
2154 | 2135 | | |||
2155 | KateIconBorder::BorderArea KateIconBorder::positionToArea(const QPoint &p) const | 2136 | KateIconBorder::BorderArea KateIconBorder::positionToArea(const QPoint &p) const | ||
2156 | { | 2137 | { | ||
2157 | // see KateIconBorder::sizeHint() for pixel spacings | 2138 | for (int i = 0; i < m_positionToArea.size(); ++i) { | ||
2158 | int x = 0; | 2139 | if (p.x() <= m_positionToArea.at(i).first) { | ||
2159 | if (m_iconBorderOn) { | 2140 | return m_positionToArea.at(i).second; | ||
2160 | x += iconPaneWidth; | | |||
2161 | if (p.x() <= x) { | | |||
2162 | return IconBorder; | | |||
2163 | } | | |||
2164 | x += 2; | | |||
2165 | } | | |||
2166 | if (this->m_annotationBorderOn) { | | |||
2167 | x += m_annotationBorderWidth; | | |||
2168 | if (p.x() <= x) { | | |||
2169 | return AnnotationBorder; | | |||
2170 | } | | |||
2171 | x += 2; | | |||
2172 | } | | |||
2173 | if (m_lineNumbersOn || m_dynWrapIndicators) { | | |||
2174 | x += lineNumberWidth(); | | |||
2175 | if (p.x() <= x) { | | |||
2176 | return LineNumbers; | | |||
2177 | } | | |||
2178 | x += 2; | | |||
2179 | } | | |||
2180 | if (m_foldingMarkersOn) { | | |||
2181 | x += iconPaneWidth; | | |||
2182 | if (p.x() <= x) { | | |||
2183 | return FoldingMarkers; | | |||
2184 | } | | |||
2185 | } | | |||
2186 | if (m_view->config()->lineModification()) { | | |||
2187 | x += 3 + 2; | | |||
2188 | if (p.x() <= x) { | | |||
2189 | return ModificationBorder; | | |||
2190 | } | 2141 | } | ||
2191 | } | 2142 | } | ||
2143 | | ||||
2192 | return None; | 2144 | return None; | ||
2193 | } | 2145 | } | ||
2194 | 2146 | | |||
2195 | void KateIconBorder::mousePressEvent(QMouseEvent *e) | 2147 | void KateIconBorder::mousePressEvent(QMouseEvent *e) | ||
2196 | { | 2148 | { | ||
2197 | const KateTextLayout &t = m_viewInternal->yToKateTextLayout(e->y()); | 2149 | const KateTextLayout &t = m_viewInternal->yToKateTextLayout(e->y()); | ||
2198 | if (t.isValid()) { | 2150 | if (t.isValid()) { | ||
2199 | m_lastClickedLine = t.line(); | 2151 | m_lastClickedLine = t.line(); | ||
▲ Show 20 Lines • Show All 182 Lines • ▼ Show 20 Line(s) | |||||
2623 | { | 2575 | { | ||
2624 | setAnnotationItemDelegate(nullptr); | 2576 | setAnnotationItemDelegate(nullptr); | ||
2625 | } | 2577 | } | ||
2626 | 2578 | | |||
2627 | void KateIconBorder::initStyleOption(KTextEditor::StyleOptionAnnotationItem* styleOption) const | 2579 | void KateIconBorder::initStyleOption(KTextEditor::StyleOptionAnnotationItem* styleOption) const | ||
2628 | { | 2580 | { | ||
2629 | styleOption->initFrom(this); | 2581 | styleOption->initFrom(this); | ||
2630 | styleOption->view = m_view; | 2582 | styleOption->view = m_view; | ||
2631 | styleOption->decorationSize = QSize(iconPaneWidth, iconPaneWidth); | 2583 | styleOption->decorationSize = QSize(m_iconAreaWidth, m_iconAreaWidth); | ||
2632 | styleOption->contentFontMetrics = m_view->renderer()->config()->fontMetrics(); | 2584 | styleOption->contentFontMetrics = m_view->renderer()->config()->fontMetrics(); | ||
2633 | } | 2585 | } | ||
2634 | 2586 | | |||
2635 | void KateIconBorder::setStyleOptionLineData(KTextEditor::StyleOptionAnnotationItem* styleOption, | 2587 | void KateIconBorder::setStyleOptionLineData(KTextEditor::StyleOptionAnnotationItem* styleOption, | ||
2636 | int y, | 2588 | int y, | ||
2637 | int realLine, | 2589 | int realLine, | ||
2638 | const KTextEditor::AnnotationModel *model, | 2590 | const KTextEditor::AnnotationModel *model, | ||
2639 | const QString &annotationGroupIdentifier) const | 2591 | const QString &annotationGroupIdentifier) const | ||
2640 | { | 2592 | { | ||
2641 | // calculate rendered displayed line | 2593 | // calculate rendered displayed line | ||
2642 | const uint h = m_view->renderer()->lineHeight(); | 2594 | const uint h = m_view->renderer()->lineHeight(); | ||
2643 | const uint z = (y / h); | 2595 | const uint z = (y / h); | ||
2644 | 2596 | | |||
2645 | KateAnnotationGroupPositionState annotationGroupPositionState(m_viewInternal, model, | 2597 | KateAnnotationGroupPositionState annotationGroupPositionState(m_viewInternal, model, | ||
2646 | annotationGroupIdentifier, | 2598 | annotationGroupIdentifier, | ||
2647 | z, true); | 2599 | z, true); | ||
2648 | annotationGroupPositionState.nextLine(*styleOption, z, realLine); | 2600 | annotationGroupPositionState.nextLine(*styleOption, z, realLine); | ||
2649 | } | 2601 | } | ||
2650 | 2602 | | |||
2651 | 2603 | | |||
2652 | QRect KateIconBorder::annotationLineRectInView(int line) const | 2604 | QRect KateIconBorder::annotationLineRectInView(int line) const | ||
2653 | { | 2605 | { | ||
2654 | int x = 0; | 2606 | int x = 0; | ||
2655 | if (m_iconBorderOn) { | 2607 | if (m_iconBorderOn) { | ||
2656 | x += iconPaneWidth + 2; | 2608 | x += m_iconAreaWidth + 2; | ||
2657 | } | 2609 | } | ||
2658 | const int y = m_view->m_viewInternal->lineToY(line); | 2610 | const int y = m_view->m_viewInternal->lineToY(line); | ||
2659 | 2611 | | |||
2660 | return QRect(x, y, m_annotationBorderWidth, m_view->renderer()->lineHeight()); | 2612 | return QRect(x, y, m_annotationAreaWidth, m_view->renderer()->lineHeight()); | ||
2661 | } | 2613 | } | ||
2662 | 2614 | | |||
2663 | void KateIconBorder::updateAnnotationLine(int line) | 2615 | void KateIconBorder::updateAnnotationLine(int line) | ||
2664 | { | 2616 | { | ||
2665 | // TODO: why has the default value been 8, where is that magic number from? | 2617 | // TODO: why has the default value been 8, where is that magic number from? | ||
2666 | int width = 8; | 2618 | int width = 8; | ||
2667 | KTextEditor::AnnotationModel *model = m_view->annotationModel() ? | 2619 | KTextEditor::AnnotationModel *model = m_view->annotationModel() ? | ||
2668 | m_view->annotationModel() : m_doc->annotationModel(); | 2620 | m_view->annotationModel() : m_doc->annotationModel(); | ||
2669 | 2621 | | |||
2670 | if (model) { | 2622 | if (model) { | ||
2671 | KTextEditor::StyleOptionAnnotationItem styleOption; | 2623 | KTextEditor::StyleOptionAnnotationItem styleOption; | ||
2672 | initStyleOption(&styleOption); | 2624 | initStyleOption(&styleOption); | ||
2673 | width = m_annotationItemDelegate->sizeHint(styleOption, model, line).width(); | 2625 | width = m_annotationItemDelegate->sizeHint(styleOption, model, line).width(); | ||
2674 | } | 2626 | } | ||
2675 | 2627 | | |||
2676 | if (width > m_annotationBorderWidth) { | 2628 | if (width > m_annotationAreaWidth) { | ||
2677 | m_annotationBorderWidth = width; | 2629 | m_annotationAreaWidth = width; | ||
2678 | updateGeometry(); | 2630 | updateGeometry(); | ||
2679 | 2631 | | |||
2680 | QTimer::singleShot(0, this, SLOT(update())); | 2632 | QTimer::singleShot(0, this, SLOT(update())); | ||
2681 | } | 2633 | } | ||
2682 | } | 2634 | } | ||
2683 | 2635 | | |||
2684 | void KateIconBorder::showAnnotationMenu(int line, const QPoint &pos) | 2636 | void KateIconBorder::showAnnotationMenu(int line, const QPoint &pos) | ||
2685 | { | 2637 | { | ||
Show All 11 Lines | |||||
2697 | { | 2649 | { | ||
2698 | m_annotationItemDelegate->hideTooltip(m_view); | 2650 | m_annotationItemDelegate->hideTooltip(m_view); | ||
2699 | } | 2651 | } | ||
2700 | 2652 | | |||
2701 | void KateIconBorder::updateAnnotationBorderWidth() | 2653 | void KateIconBorder::updateAnnotationBorderWidth() | ||
2702 | { | 2654 | { | ||
2703 | calcAnnotationBorderWidth(); | 2655 | calcAnnotationBorderWidth(); | ||
2704 | 2656 | | |||
2705 | updateGeometry(); | 2657 | m_updatePositionToArea = true; | ||
2706 | 2658 | | |||
2707 | QTimer::singleShot(0, this, SLOT(update())); | 2659 | QTimer::singleShot(0, this, SLOT(update())); | ||
2708 | } | 2660 | } | ||
2709 | 2661 | | |||
2710 | void KateIconBorder::calcAnnotationBorderWidth() | 2662 | void KateIconBorder::calcAnnotationBorderWidth() | ||
2711 | { | 2663 | { | ||
2712 | // TODO: another magic number, not matching the one in updateAnnotationLine() | 2664 | // TODO: another magic number, not matching the one in updateAnnotationLine() | ||
2713 | m_annotationBorderWidth = 6; | 2665 | m_annotationAreaWidth = 6; | ||
2714 | KTextEditor::AnnotationModel *model = m_view->annotationModel() ? | 2666 | KTextEditor::AnnotationModel *model = m_view->annotationModel() ? | ||
2715 | m_view->annotationModel() : m_doc->annotationModel(); | 2667 | m_view->annotationModel() : m_doc->annotationModel(); | ||
2716 | 2668 | | |||
2717 | if (model) { | 2669 | if (model) { | ||
2718 | KTextEditor::StyleOptionAnnotationItem styleOption; | 2670 | KTextEditor::StyleOptionAnnotationItem styleOption; | ||
2719 | initStyleOption(&styleOption); | 2671 | initStyleOption(&styleOption); | ||
2720 | 2672 | | |||
2721 | const int lineCount = m_view->doc()->lines(); | 2673 | const int lineCount = m_view->doc()->lines(); | ||
2722 | if (lineCount > 0) { | 2674 | if (lineCount > 0) { | ||
2723 | const int checkedLineCount = m_hasUniformAnnotationItemSizes ? 1 : lineCount; | 2675 | const int checkedLineCount = m_hasUniformAnnotationItemSizes ? 1 : lineCount; | ||
2724 | for (int i = 0; i < checkedLineCount; ++i) { | 2676 | for (int i = 0; i < checkedLineCount; ++i) { | ||
2725 | const int curwidth = m_annotationItemDelegate->sizeHint(styleOption, model, i).width(); | 2677 | const int curwidth = m_annotationItemDelegate->sizeHint(styleOption, model, i).width(); | ||
2726 | if (curwidth > m_annotationBorderWidth) { | 2678 | if (curwidth > m_annotationAreaWidth) { | ||
2727 | m_annotationBorderWidth = curwidth; | 2679 | m_annotationAreaWidth = curwidth; | ||
2728 | } | 2680 | } | ||
2729 | } | 2681 | } | ||
2730 | } | 2682 | } | ||
2731 | } | 2683 | } | ||
2732 | } | 2684 | } | ||
2733 | 2685 | | |||
2734 | void KateIconBorder::annotationModelChanged(KTextEditor::AnnotationModel *oldmodel, KTextEditor::AnnotationModel *newmodel) | 2686 | void KateIconBorder::annotationModelChanged(KTextEditor::AnnotationModel *oldmodel, KTextEditor::AnnotationModel *newmodel) | ||
2735 | { | 2687 | { | ||
▲ Show 20 Lines • Show All 91 Lines • Show Last 20 Lines |