Changeset View
Changeset View
Standalone View
Standalone View
src/TerminalDisplay.cpp
Show First 20 Lines • Show All 441 Lines • ▼ Show 20 Line(s) | 441 | { | |||
---|---|---|---|---|---|
442 | // terminal applications are not designed with Right-To-Left in mind, | 442 | // terminal applications are not designed with Right-To-Left in mind, | ||
443 | // so the layout is forced to Left-To-Right | 443 | // so the layout is forced to Left-To-Right | ||
444 | setLayoutDirection(Qt::LeftToRight); | 444 | setLayoutDirection(Qt::LeftToRight); | ||
445 | 445 | | |||
446 | _contentRect = QRect(_margin, _margin, 1, 1); | 446 | _contentRect = QRect(_margin, _margin, 1, 1); | ||
447 | 447 | | |||
448 | // create scroll bar for scrolling output up and down | 448 | // create scroll bar for scrolling output up and down | ||
449 | _scrollBar = new QScrollBar(this); | 449 | _scrollBar = new QScrollBar(this); | ||
450 | _scrollBar->setAutoFillBackground(false); | | |||
451 | // set the scroll bar's slider to occupy the whole area of the scroll bar initially | 450 | // set the scroll bar's slider to occupy the whole area of the scroll bar initially | ||
452 | setScroll(0, 0); | 451 | setScroll(0, 0); | ||
453 | _scrollBar->setCursor(Qt::ArrowCursor); | 452 | _scrollBar->setCursor(Qt::ArrowCursor); | ||
454 | connect(_scrollBar, &QScrollBar::valueChanged, this, &Konsole::TerminalDisplay::scrollBarPositionChanged); | 453 | connect(_scrollBar, &QScrollBar::valueChanged, this, &Konsole::TerminalDisplay::scrollBarPositionChanged); | ||
455 | connect(_scrollBar, &QScrollBar::sliderMoved, this, &Konsole::TerminalDisplay::viewScrolledByUser); | 454 | connect(_scrollBar, &QScrollBar::sliderMoved, this, &Konsole::TerminalDisplay::viewScrolledByUser); | ||
456 | 455 | | |||
457 | // setup timers for blinking text | 456 | // setup timers for blinking text | ||
458 | _blinkTextTimer = new QTimer(this); | 457 | _blinkTextTimer = new QTimer(this); | ||
▲ Show 20 Lines • Show All 640 Lines • ▼ Show 20 Line(s) | 1060 | { | |||
1099 | // | 1098 | // | ||
1100 | // The right edge must be before the left edge of the scroll bar to | 1099 | // The right edge must be before the left edge of the scroll bar to | ||
1101 | // avoid triggering a repaint of the entire widget, the distance is | 1100 | // avoid triggering a repaint of the entire widget, the distance is | ||
1102 | // given by SCROLLBAR_CONTENT_GAP | 1101 | // given by SCROLLBAR_CONTENT_GAP | ||
1103 | // | 1102 | // | ||
1104 | // Set the QT_FLUSH_PAINT environment variable to '1' before starting the | 1103 | // Set the QT_FLUSH_PAINT environment variable to '1' before starting the | ||
1105 | // application to monitor repainting. | 1104 | // application to monitor repainting. | ||
1106 | // | 1105 | // | ||
1107 | const int scrollBarWidth = _scrollBar->isHidden() ? 0 : _scrollBar->width(); | | |||
1108 | const int SCROLLBAR_CONTENT_GAP = 1; | | |||
1109 | QRect scrollRect; | 1106 | QRect scrollRect; | ||
1110 | if (_scrollbarLocation == Enum::ScrollBarLeft) { | | |||
1111 | scrollRect.setLeft(scrollBarWidth + SCROLLBAR_CONTENT_GAP); | | |||
1112 | scrollRect.setRight(width()); | | |||
1113 | } else { | | |||
1114 | scrollRect.setLeft(0); | 1107 | scrollRect.setLeft(0); | ||
1115 | scrollRect.setRight(width() - scrollBarWidth - SCROLLBAR_CONTENT_GAP); | 1108 | scrollRect.setRight(width()); | ||
1116 | } | 1109 | | ||
1117 | void* firstCharPos = &_image[ region.top() * _columns ]; | 1110 | void* firstCharPos = &_image[ region.top() * _columns ]; | ||
1118 | void* lastCharPos = &_image[(region.top() + abs(lines)) * _columns ]; | 1111 | void* lastCharPos = &_image[(region.top() + abs(lines)) * _columns ]; | ||
1119 | 1112 | | |||
1120 | const int top = _contentRect.top() + (region.top() * _fontHeight); | 1113 | const int top = _contentRect.top() + (region.top() * _fontHeight); | ||
1121 | const int linesToMove = region.height() - abs(lines); | 1114 | const int linesToMove = region.height() - abs(lines); | ||
1122 | const int bytesToMove = linesToMove * _columns * sizeof(Character); | 1115 | const int bytesToMove = linesToMove * _columns * sizeof(Character); | ||
1123 | 1116 | | |||
1124 | Q_ASSERT(linesToMove > 0); | 1117 | Q_ASSERT(linesToMove > 0); | ||
▲ Show 20 Lines • Show All 912 Lines • ▼ Show 20 Line(s) | |||||
2037 | { | 2030 | { | ||
2038 | _scrollBar->resize(_scrollBar->sizeHint().width(), contentsRect().height()); | 2031 | _scrollBar->resize(_scrollBar->sizeHint().width(), contentsRect().height()); | ||
2039 | _contentRect = contentsRect().adjusted(_margin, _margin, -_margin, -_margin); | 2032 | _contentRect = contentsRect().adjusted(_margin, _margin, -_margin, -_margin); | ||
2040 | 2033 | | |||
2041 | switch (_scrollbarLocation) { | 2034 | switch (_scrollbarLocation) { | ||
2042 | case Enum::ScrollBarHidden : | 2035 | case Enum::ScrollBarHidden : | ||
2043 | break; | 2036 | break; | ||
2044 | case Enum::ScrollBarLeft : | 2037 | case Enum::ScrollBarLeft : | ||
2045 | _contentRect.setLeft(_contentRect.left() + _scrollBar->width()); | | |||
2046 | _scrollBar->move(contentsRect().topLeft()); | 2038 | _scrollBar->move(contentsRect().topLeft()); | ||
2047 | break; | 2039 | break; | ||
2048 | case Enum::ScrollBarRight: | 2040 | case Enum::ScrollBarRight: | ||
2049 | _contentRect.setRight(_contentRect.right() - _scrollBar->width()); | | |||
2050 | _scrollBar->move(contentsRect().topRight() - QPoint(_scrollBar->width() - 1, 0)); | 2041 | _scrollBar->move(contentsRect().topRight() - QPoint(_scrollBar->width() - 1, 0)); | ||
2051 | break; | 2042 | break; | ||
2052 | } | 2043 | } | ||
2053 | 2044 | | |||
2054 | // ensure that display is always at least one column wide | 2045 | // ensure that display is always at least one column wide | ||
2055 | _columns = qMax(1, _contentRect.width() / _fontWidth); | 2046 | _columns = qMax(1, _contentRect.width() / _fontWidth); | ||
2056 | _usedColumns = qMin(_usedColumns, _columns); | 2047 | _usedColumns = qMin(_usedColumns, _columns); | ||
2057 | 2048 | | |||
2058 | // ensure that display is always at least one line high | 2049 | // ensure that display is always at least one line high | ||
2059 | _lines = qMax(1, _contentRect.height() / _fontHeight); | 2050 | _lines = qMax(1, _contentRect.height() / _fontHeight); | ||
2060 | _usedLines = qMin(_usedLines, _lines); | 2051 | _usedLines = qMin(_usedLines, _lines); | ||
2061 | 2052 | | |||
2062 | if(_centerContents) { | 2053 | if(_centerContents) { | ||
2063 | QSize unusedPixels = _contentRect.size() - QSize(_columns * _fontWidth, _lines * _fontHeight); | 2054 | QSize unusedPixels = _contentRect.size() - QSize(_columns * _fontWidth, _lines * _fontHeight); | ||
2064 | _contentRect.adjust(unusedPixels.width() / 2, unusedPixels.height() / 2, 0, 0); | 2055 | _contentRect.adjust(unusedPixels.width() / 2, unusedPixels.height() / 2, 0, 0); | ||
2065 | } | 2056 | } | ||
2066 | } | 2057 | } | ||
2067 | 2058 | | |||
2068 | // calculate the needed size, this must be synced with calcGeometry() | 2059 | // calculate the needed size, this must be synced with calcGeometry() | ||
2069 | void TerminalDisplay::setSize(int columns, int lines) | 2060 | void TerminalDisplay::setSize(int columns, int lines) | ||
2070 | { | 2061 | { | ||
2071 | const int scrollBarWidth = _scrollBar->isHidden() ? 0 : _scrollBar->sizeHint().width(); | | |||
2072 | const int horizontalMargin = _margin * 2; | 2062 | const int horizontalMargin = _margin * 2; | ||
2073 | const int verticalMargin = _margin * 2; | 2063 | const int verticalMargin = _margin * 2; | ||
2074 | 2064 | | |||
2075 | QSize newSize = QSize(horizontalMargin + scrollBarWidth + (columns * _fontWidth) , | 2065 | QSize newSize = QSize(horizontalMargin + (columns * _fontWidth) , | ||
2076 | verticalMargin + (lines * _fontHeight)); | 2066 | verticalMargin + (lines * _fontHeight)); | ||
2077 | 2067 | | |||
2078 | if (newSize != size()) { | 2068 | if (newSize != size()) { | ||
2079 | _size = newSize; | 2069 | _size = newSize; | ||
2080 | updateGeometry(); | 2070 | updateGeometry(); | ||
2081 | } | 2071 | } | ||
2082 | } | 2072 | } | ||
2083 | 2073 | | |||
Show All 39 Lines | |||||
2123 | /* ------------------------------------------------------------------------- */ | 2113 | /* ------------------------------------------------------------------------- */ | ||
2124 | 2114 | | |||
2125 | void TerminalDisplay::setScrollBarPosition(Enum::ScrollBarPositionEnum position) | 2115 | void TerminalDisplay::setScrollBarPosition(Enum::ScrollBarPositionEnum position) | ||
2126 | { | 2116 | { | ||
2127 | if (_scrollbarLocation == position) { | 2117 | if (_scrollbarLocation == position) { | ||
2128 | return; | 2118 | return; | ||
2129 | } | 2119 | } | ||
2130 | 2120 | | |||
2131 | if (position == Enum::ScrollBarHidden) { | 2121 | _scrollBar->setVisible(position != Enum::ScrollBarHidden); | ||
2132 | _scrollBar->hide(); | | |||
2133 | } else { | | |||
2134 | _scrollBar->show(); | | |||
2135 | } | | |||
2136 | | ||||
2137 | _scrollbarLocation = position; | 2122 | _scrollbarLocation = position; | ||
2138 | 2123 | | |||
2139 | propagateSize(); | 2124 | propagateSize(); | ||
2140 | update(); | 2125 | update(); | ||
2141 | } | 2126 | } | ||
2142 | 2127 | | |||
2143 | void TerminalDisplay::scrollBarPositionChanged(int) | 2128 | void TerminalDisplay::scrollBarPositionChanged(int) | ||
2144 | { | 2129 | { | ||
▲ Show 20 Lines • Show All 1793 Lines • Show Last 20 Lines |