Changeset View
Changeset View
Standalone View
Standalone View
src/TerminalDisplay.cpp
Show First 20 Lines • Show All 477 Lines • ▼ Show 20 Line(s) | 404 | TerminalDisplay::TerminalDisplay(QWidget* parent) | |||
---|---|---|---|---|---|
478 | , _margin(1) | 478 | , _margin(1) | ||
479 | , _centerContents(false) | 479 | , _centerContents(false) | ||
480 | , _readOnlyMessageWidget(nullptr) | 480 | , _readOnlyMessageWidget(nullptr) | ||
481 | , _readOnly(false) | 481 | , _readOnly(false) | ||
482 | , _opacity(1.0) | 482 | , _opacity(1.0) | ||
483 | , _dimWhenInactive(false) | 483 | , _dimWhenInactive(false) | ||
484 | , _scrollWheelState(ScrollState()) | 484 | , _scrollWheelState(ScrollState()) | ||
485 | , _searchBar(new IncrementalSearchBar(this)) | 485 | , _searchBar(new IncrementalSearchBar(this)) | ||
486 | , _headerBar(new TerminalHeaderBar(this)) | ||||
486 | , _searchResultRect(QRect()) | 487 | , _searchResultRect(QRect()) | ||
487 | { | 488 | { | ||
488 | // terminal applications are not designed with Right-To-Left in mind, | 489 | // terminal applications are not designed with Right-To-Left in mind, | ||
489 | // so the layout is forced to Left-To-Right | 490 | // so the layout is forced to Left-To-Right | ||
490 | setLayoutDirection(Qt::LeftToRight); | 491 | setLayoutDirection(Qt::LeftToRight); | ||
491 | 492 | | |||
492 | _contentRect = QRect(_margin, _margin, 1, 1); | 493 | _contentRect = QRect(_margin, _margin, 1, 1); | ||
493 | 494 | | |||
494 | // create scroll bar for scrolling output up and down | 495 | // create scroll bar for scrolling output up and down | ||
495 | _scrollBar = new QScrollBar(this); | 496 | _scrollBar = new QScrollBar(this); | ||
496 | _scrollBar->setAutoFillBackground(false); | 497 | _scrollBar->setAutoFillBackground(false); | ||
497 | // set the scroll bar's slider to occupy the whole area of the scroll bar initially | 498 | // set the scroll bar's slider to occupy the whole area of the scroll bar initially | ||
498 | setScroll(0, 0); | 499 | setScroll(0, 0); | ||
499 | _scrollBar->setCursor(Qt::ArrowCursor); | 500 | _scrollBar->setCursor(Qt::ArrowCursor); | ||
501 | _headerBar->setCursor(Qt::ArrowCursor); | ||||
500 | connect(_scrollBar, &QScrollBar::valueChanged, this, &Konsole::TerminalDisplay::scrollBarPositionChanged); | 502 | connect(_scrollBar, &QScrollBar::valueChanged, this, &Konsole::TerminalDisplay::scrollBarPositionChanged); | ||
501 | connect(_scrollBar, &QScrollBar::sliderMoved, this, &Konsole::TerminalDisplay::viewScrolledByUser); | 503 | connect(_scrollBar, &QScrollBar::sliderMoved, this, &Konsole::TerminalDisplay::viewScrolledByUser); | ||
502 | 504 | | |||
503 | // setup timers for blinking text | 505 | // setup timers for blinking text | ||
504 | _blinkTextTimer = new QTimer(this); | 506 | _blinkTextTimer = new QTimer(this); | ||
505 | _blinkTextTimer->setInterval(TEXT_BLINK_DELAY); | 507 | _blinkTextTimer->setInterval(TEXT_BLINK_DELAY); | ||
506 | connect(_blinkTextTimer, &QTimer::timeout, this, &Konsole::TerminalDisplay::blinkTextEvent); | 508 | connect(_blinkTextTimer, &QTimer::timeout, this, &Konsole::TerminalDisplay::blinkTextEvent); | ||
507 | 509 | | |||
Show All 20 Lines | |||||
528 | // enable input method support | 530 | // enable input method support | ||
529 | setAttribute(Qt::WA_InputMethodEnabled, true); | 531 | setAttribute(Qt::WA_InputMethodEnabled, true); | ||
530 | 532 | | |||
531 | // this is an important optimization, it tells Qt | 533 | // this is an important optimization, it tells Qt | ||
532 | // that TerminalDisplay will handle repainting its entire area. | 534 | // that TerminalDisplay will handle repainting its entire area. | ||
533 | setAttribute(Qt::WA_OpaquePaintEvent); | 535 | setAttribute(Qt::WA_OpaquePaintEvent); | ||
534 | 536 | | |||
535 | // Add the stretch item once, the KMessageWidgets are inserted at index 0. | 537 | // Add the stretch item once, the KMessageWidgets are inserted at index 0. | ||
538 | _verticalLayout->addWidget(_headerBar); | ||||
536 | _verticalLayout->addStretch(); | 539 | _verticalLayout->addStretch(); | ||
537 | _verticalLayout->setSpacing(0); | 540 | _verticalLayout->setSpacing(0); | ||
538 | 541 | _verticalLayout->setMargin(0); | |||
539 | setLayout(_verticalLayout); | 542 | setLayout(_verticalLayout); | ||
540 | 543 | | |||
541 | // Take the scrollbar into account and add a margin to the layout. Without the timer the scrollbar width | | |||
542 | // is garbage. | | |||
543 | QTimer::singleShot(0, this, [this]() { | | |||
544 | const int scrollBarWidth = _scrollBar->isVisible() ? geometry().intersected(_scrollBar->geometry()).width() : 0; | | |||
545 | _verticalLayout->setContentsMargins(0, 0, scrollBarWidth, 0); | | |||
546 | }); | | |||
547 | | ||||
548 | new AutoScrollHandler(this); | 544 | new AutoScrollHandler(this); | ||
549 | | ||||
550 | | ||||
551 | #ifndef QT_NO_ACCESSIBILITY | 545 | #ifndef QT_NO_ACCESSIBILITY | ||
552 | QAccessible::installFactory(Konsole::accessibleInterfaceFactory); | 546 | QAccessible::installFactory(Konsole::accessibleInterfaceFactory); | ||
553 | #endif | 547 | #endif | ||
554 | } | 548 | } | ||
555 | 549 | | |||
556 | TerminalDisplay::~TerminalDisplay() | 550 | TerminalDisplay::~TerminalDisplay() | ||
557 | { | 551 | { | ||
558 | disconnect(_blinkTextTimer); | 552 | disconnect(_blinkTextTimer); | ||
▲ Show 20 Lines • Show All 1202 Lines • ▼ Show 20 Line(s) | 1754 | if (_textBlinking) { | |||
1761 | blinkTextEvent(); | 1755 | blinkTextEvent(); | ||
1762 | } | 1756 | } | ||
1763 | 1757 | | |||
1764 | // suppress further text blinking | 1758 | // suppress further text blinking | ||
1765 | _blinkTextTimer->stop(); | 1759 | _blinkTextTimer->stop(); | ||
1766 | Q_ASSERT(!_textBlinking); | 1760 | Q_ASSERT(!_textBlinking); | ||
1767 | 1761 | | |||
1768 | _showUrlHint = false; | 1762 | _showUrlHint = false; | ||
1769 | 1763 | _headerBar->terminalFocusOut(); | |||
1770 | emit focusLost(); | 1764 | emit focusLost(); | ||
1771 | } | 1765 | } | ||
1772 | 1766 | | |||
1773 | void TerminalDisplay::focusInEvent(QFocusEvent*) | 1767 | void TerminalDisplay::focusInEvent(QFocusEvent*) | ||
1774 | { | 1768 | { | ||
1775 | if (_allowBlinkingCursor) { | 1769 | if (_allowBlinkingCursor) { | ||
1776 | _blinkCursorTimer->start(); | 1770 | _blinkCursorTimer->start(); | ||
1777 | } | 1771 | } | ||
1778 | 1772 | | |||
1779 | updateCursor(); | 1773 | updateCursor(); | ||
1780 | 1774 | | |||
1781 | if (_allowBlinkingText && _hasTextBlinker) { | 1775 | if (_allowBlinkingText && _hasTextBlinker) { | ||
1782 | _blinkTextTimer->start(); | 1776 | _blinkTextTimer->start(); | ||
1783 | } | 1777 | } | ||
1784 | 1778 | _headerBar->terminalFocusIn(); | |||
1785 | emit focusGained(); | 1779 | emit focusGained(); | ||
1786 | } | 1780 | } | ||
1787 | 1781 | | |||
1788 | void TerminalDisplay::blinkTextEvent() | 1782 | void TerminalDisplay::blinkTextEvent() | ||
1789 | { | 1783 | { | ||
1790 | Q_ASSERT(_allowBlinkingText); | 1784 | Q_ASSERT(_allowBlinkingText); | ||
1791 | 1785 | | |||
1792 | _textBlinking = !_textBlinking; | 1786 | _textBlinking = !_textBlinking; | ||
1793 | 1787 | | |||
1794 | // TODO: Optimize to only repaint the areas of the widget where there is | 1788 | // TODO: Optimize to only repaint the areas of the widget where there is | ||
1795 | // blinking text rather than repainting the whole widget. | 1789 | // blinking text rather than repainting the whole widget. | ||
1790 | _headerBar->terminalFocusOut(); | ||||
1796 | update(); | 1791 | update(); | ||
1797 | } | 1792 | } | ||
1798 | 1793 | | |||
1799 | void TerminalDisplay::blinkCursorEvent() | 1794 | void TerminalDisplay::blinkCursorEvent() | ||
1800 | { | 1795 | { | ||
1801 | Q_ASSERT(_allowBlinkingCursor); | 1796 | Q_ASSERT(_allowBlinkingCursor); | ||
1802 | 1797 | | |||
1803 | _cursorBlinking = !_cursorBlinking; | 1798 | _cursorBlinking = !_cursorBlinking; | ||
Show All 18 Lines | |||||
1822 | /* */ | 1817 | /* */ | ||
1823 | /* Geometry & Resizing */ | 1818 | /* Geometry & Resizing */ | ||
1824 | /* */ | 1819 | /* */ | ||
1825 | /* ------------------------------------------------------------------------- */ | 1820 | /* ------------------------------------------------------------------------- */ | ||
1826 | 1821 | | |||
1827 | void TerminalDisplay::resizeEvent(QResizeEvent *event) | 1822 | void TerminalDisplay::resizeEvent(QResizeEvent *event) | ||
1828 | { | 1823 | { | ||
1829 | const auto width = event->size().width() - _scrollBar->geometry().width(); | 1824 | const auto width = event->size().width() - _scrollBar->geometry().width(); | ||
1830 | _searchBar->correctPosition(QSize(width, event->size().height())); | 1825 | const auto headerHeight = _headerBar->isVisible() ? _headerBar->height() : 0; | ||
1826 | | ||||
1827 | _searchBar->correctPosition(QSize(width, headerHeight)); | ||||
1831 | if (contentsRect().isValid()) { | 1828 | if (contentsRect().isValid()) { | ||
1832 | updateImageSize(); | 1829 | updateImageSize(); | ||
1833 | } | 1830 | } | ||
1834 | } | 1831 | } | ||
1835 | 1832 | | |||
1836 | void TerminalDisplay::propagateSize() | 1833 | void TerminalDisplay::propagateSize() | ||
1837 | { | 1834 | { | ||
1838 | if (_image != nullptr) { | 1835 | if (_image != nullptr) { | ||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Line(s) | |||||
1896 | { | 1893 | { | ||
1897 | for (int i = 0; i < _imageSize; ++i) { | 1894 | for (int i = 0; i < _imageSize; ++i) { | ||
1898 | _image[i] = Screen::DefaultChar; | 1895 | _image[i] = Screen::DefaultChar; | ||
1899 | } | 1896 | } | ||
1900 | } | 1897 | } | ||
1901 | 1898 | | |||
1902 | void TerminalDisplay::calcGeometry() | 1899 | void TerminalDisplay::calcGeometry() | ||
1903 | { | 1900 | { | ||
1904 | _scrollBar->resize(_scrollBar->sizeHint().width(), contentsRect().height()); | 1901 | const auto headerHeight = _headerBar->isVisible() ? _headerBar->height() : 0; | ||
1902 | | ||||
1903 | _scrollBar->resize( | ||||
1904 | _scrollBar->sizeHint().width(), // width | ||||
1905 | contentsRect().height() - headerHeight // height | ||||
1906 | ); | ||||
1907 | | ||||
1905 | _contentRect = contentsRect().adjusted(_margin, _margin, -_margin, -_margin); | 1908 | _contentRect = contentsRect().adjusted(_margin, _margin, -_margin, -_margin); | ||
1906 | 1909 | | |||
1907 | switch (_scrollbarLocation) { | 1910 | switch (_scrollbarLocation) { | ||
1908 | case Enum::ScrollBarHidden : | 1911 | case Enum::ScrollBarHidden : | ||
1909 | break; | 1912 | break; | ||
1910 | case Enum::ScrollBarLeft : | 1913 | case Enum::ScrollBarLeft : | ||
1911 | _contentRect.setLeft(_contentRect.left() + _scrollBar->width()); | 1914 | _contentRect.setLeft(_contentRect.left() + _scrollBar->width()); | ||
1912 | _scrollBar->move(contentsRect().topLeft()); | 1915 | _scrollBar->move(contentsRect().left(), | ||
1916 | contentsRect().top() + headerHeight); | ||||
1913 | break; | 1917 | break; | ||
1914 | case Enum::ScrollBarRight: | 1918 | case Enum::ScrollBarRight: | ||
1915 | _contentRect.setRight(_contentRect.right() - _scrollBar->width()); | 1919 | _contentRect.setRight(_contentRect.right() - _scrollBar->width()); | ||
1916 | _scrollBar->move(contentsRect().topRight() - QPoint(_scrollBar->width() - 1, 0)); | 1920 | _scrollBar->move(contentsRect().right() - _scrollBar->width() - 1, | ||
1921 | contentsRect().top() + headerHeight); | ||||
1917 | break; | 1922 | break; | ||
1918 | } | 1923 | } | ||
1919 | 1924 | | |||
1925 | _contentRect.setTop(_contentRect.top() + headerHeight); | ||||
1926 | | ||||
1920 | // ensure that display is always at least one column wide | 1927 | // ensure that display is always at least one column wide | ||
1921 | _columns = qMax(1, _contentRect.width() / _fontWidth); | 1928 | _columns = qMax(1, _contentRect.width() / _fontWidth); | ||
1922 | _usedColumns = qMin(_usedColumns, _columns); | 1929 | _usedColumns = qMin(_usedColumns, _columns); | ||
1923 | 1930 | | |||
1924 | // ensure that display is always at least one line high | 1931 | // ensure that display is always at least one line high | ||
1925 | _lines = qMax(1, _contentRect.height() / _fontHeight); | 1932 | _lines = qMax(1, _contentRect.height() / _fontHeight); | ||
1926 | _usedLines = qMin(_usedLines, _lines); | 1933 | _usedLines = qMin(_usedLines, _lines); | ||
1927 | 1934 | | |||
▲ Show 20 Lines • Show All 1455 Lines • ▼ Show 20 Line(s) | |||||
3383 | } | 3390 | } | ||
3384 | 3391 | | |||
3385 | KMessageWidget* TerminalDisplay::createMessageWidget(const QString &text) { | 3392 | KMessageWidget* TerminalDisplay::createMessageWidget(const QString &text) { | ||
3386 | auto widget = new KMessageWidget(text); | 3393 | auto widget = new KMessageWidget(text); | ||
3387 | widget->setWordWrap(true); | 3394 | widget->setWordWrap(true); | ||
3388 | widget->setFocusProxy(this); | 3395 | widget->setFocusProxy(this); | ||
3389 | widget->setCursor(Qt::ArrowCursor); | 3396 | widget->setCursor(Qt::ArrowCursor); | ||
3390 | 3397 | | |||
3391 | _verticalLayout->insertWidget(0, widget); | 3398 | _verticalLayout->insertWidget(1, widget); | ||
3392 | return widget; | 3399 | return widget; | ||
3393 | } | 3400 | } | ||
3394 | 3401 | | |||
3395 | void TerminalDisplay::updateReadOnlyState(bool readonly) { | 3402 | void TerminalDisplay::updateReadOnlyState(bool readonly) { | ||
3396 | if (_readOnly == readonly) { | 3403 | if (_readOnly == readonly) { | ||
3397 | return; | 3404 | return; | ||
3398 | } | 3405 | } | ||
3399 | 3406 | | |||
▲ Show 20 Lines • Show All 368 Lines • ▼ Show 20 Line(s) | 3766 | { | |||
3768 | mimeData->setHtml(clipboardMimeData->html()); | 3775 | mimeData->setHtml(clipboardMimeData->html()); | ||
3769 | _dragInfo.dragObject->setMimeData(mimeData); | 3776 | _dragInfo.dragObject->setMimeData(mimeData); | ||
3770 | _dragInfo.dragObject->exec(Qt::CopyAction); | 3777 | _dragInfo.dragObject->exec(Qt::CopyAction); | ||
3771 | } | 3778 | } | ||
3772 | 3779 | | |||
3773 | void TerminalDisplay::setSessionController(SessionController* controller) | 3780 | void TerminalDisplay::setSessionController(SessionController* controller) | ||
3774 | { | 3781 | { | ||
3775 | _sessionController = controller; | 3782 | _sessionController = controller; | ||
3783 | _headerBar->finishHeaderSetup(controller); | ||||
3776 | } | 3784 | } | ||
3777 | 3785 | | |||
3778 | SessionController* TerminalDisplay::sessionController() | 3786 | SessionController* TerminalDisplay::sessionController() | ||
3779 | { | 3787 | { | ||
3780 | return _sessionController; | 3788 | return _sessionController; | ||
3781 | } | 3789 | } | ||
3782 | 3790 | | |||
3783 | IncrementalSearchBar *TerminalDisplay::searchBar() const | 3791 | IncrementalSearchBar *TerminalDisplay::searchBar() const | ||
▲ Show 20 Lines • Show All 125 Lines • Show Last 20 Lines |