Changeset View
Changeset View
Standalone View
Standalone View
src/TerminalDisplay.cpp
Show First 20 Lines • Show All 131 Lines • ▼ Show 20 Line(s) | 113 | { | |||
---|---|---|---|---|---|
132 | } | 132 | } | ||
133 | } | 133 | } | ||
134 | 134 | | |||
135 | const ColorEntry* TerminalDisplay::colorTable() const | 135 | const ColorEntry* TerminalDisplay::colorTable() const | ||
136 | { | 136 | { | ||
137 | return _colorTable; | 137 | return _colorTable; | ||
138 | } | 138 | } | ||
139 | 139 | | |||
140 | void TerminalDisplay::updateScrollBarPalette() | 140 | void TerminalDisplay::onColorsChanged() | ||
141 | { | 141 | { | ||
142 | // Mostly just fix the scrollbar | ||||
143 | // this is a workaround to add some readability to old themes like Fusion | ||||
144 | // changing the light value for button a bit makes themes like fusion, windows and oxygen way more readable and pleasing | ||||
145 | | ||||
146 | QPalette p = QApplication::palette(); | ||||
147 | | ||||
148 | QColor buttonTextColor = _colorTable[DEFAULT_FORE_COLOR]; | ||||
142 | QColor backgroundColor = _colorTable[DEFAULT_BACK_COLOR]; | 149 | QColor backgroundColor = _colorTable[DEFAULT_BACK_COLOR]; | ||
143 | backgroundColor.setAlphaF(_opacity); | 150 | backgroundColor.setAlphaF(_opacity); | ||
144 | QPalette p = palette(); | | |||
145 | p.setColor(QPalette::Window, backgroundColor); | | |||
146 | 151 | | |||
147 | //this is a workaround to add some readability to old themes like Fusion | 152 | QColor buttonColor = backgroundColor.toHsv(); | ||
148 | //changing the light value for button a bit makes themes like fusion, windows and oxygen way more readable and pleasing | 153 | if (buttonColor.valueF() < 0.5) { | ||
149 | QColor buttonColor; | 154 | buttonColor = buttonColor.lighter(); | ||
150 | buttonColor.setHsvF(backgroundColor.hueF(), backgroundColor.saturationF(), backgroundColor.valueF() + (backgroundColor.valueF() < 0.5 ? 0.2 : -0.2)); | 155 | } else { | ||
156 | buttonColor = buttonColor.darker(); | ||||
157 | } | ||||
151 | p.setColor(QPalette::Button, buttonColor); | 158 | p.setColor(QPalette::Button, buttonColor); | ||
159 | p.setColor(QPalette::Window, backgroundColor); | ||||
160 | p.setColor(QPalette::WindowText, buttonTextColor); | ||||
161 | p.setColor(QPalette::ButtonText, buttonTextColor); | ||||
162 | | ||||
163 | setPalette(p); | ||||
152 | 164 | | |||
153 | p.setColor(QPalette::WindowText, _colorTable[DEFAULT_FORE_COLOR]); | | |||
154 | p.setColor(QPalette::ButtonText, _colorTable[DEFAULT_FORE_COLOR]); | | |||
155 | _scrollBar->setPalette(p); | 165 | _scrollBar->setPalette(p); | ||
156 | 166 | | |||
167 | update(); | ||||
157 | } | 168 | } | ||
158 | 169 | | |||
159 | void TerminalDisplay::setBackgroundColor(const QColor& color) | 170 | void TerminalDisplay::setBackgroundColor(const QColor& color) | ||
160 | { | 171 | { | ||
161 | _colorTable[DEFAULT_BACK_COLOR] = color; | 172 | _colorTable[DEFAULT_BACK_COLOR] = color; | ||
162 | 173 | | |||
163 | QPalette p = palette(); | 174 | onColorsChanged(); | ||
164 | p.setColor(backgroundRole(), color); | | |||
165 | setPalette(p); | | |||
166 | | ||||
167 | updateScrollBarPalette(); | | |||
168 | update(); | | |||
169 | } | 175 | } | ||
176 | | ||||
170 | QColor TerminalDisplay::getBackgroundColor() const | 177 | QColor TerminalDisplay::getBackgroundColor() const | ||
171 | { | 178 | { | ||
172 | QPalette p = palette(); | 179 | return _colorTable[DEFAULT_BACK_COLOR]; | ||
173 | return p.color(backgroundRole()); | | |||
174 | } | 180 | } | ||
181 | | ||||
175 | void TerminalDisplay::setForegroundColor(const QColor& color) | 182 | void TerminalDisplay::setForegroundColor(const QColor& color) | ||
176 | { | 183 | { | ||
177 | _colorTable[DEFAULT_FORE_COLOR] = color; | 184 | _colorTable[DEFAULT_FORE_COLOR] = color; | ||
178 | 185 | | |||
179 | updateScrollBarPalette(); | 186 | onColorsChanged(); | ||
180 | update(); | | |||
181 | } | 187 | } | ||
188 | | ||||
182 | void TerminalDisplay::setColorTable(const ColorEntry table[]) | 189 | void TerminalDisplay::setColorTable(const ColorEntry table[]) | ||
183 | { | 190 | { | ||
184 | for (int i = 0; i < TABLE_COLORS; i++) { | 191 | for (int i = 0; i < TABLE_COLORS; i++) { | ||
185 | _colorTable[i] = table[i]; | 192 | _colorTable[i] = table[i]; | ||
186 | } | 193 | } | ||
187 | 194 | | |||
188 | setBackgroundColor(_colorTable[DEFAULT_BACK_COLOR]); | 195 | setBackgroundColor(_colorTable[DEFAULT_BACK_COLOR]); | ||
196 | | ||||
197 | onColorsChanged(); | ||||
189 | } | 198 | } | ||
190 | 199 | | |||
191 | /* ------------------------------------------------------------------------- */ | 200 | /* ------------------------------------------------------------------------- */ | ||
192 | /* */ | 201 | /* */ | ||
193 | /* Font */ | 202 | /* Font */ | ||
194 | /* */ | 203 | /* */ | ||
195 | /* ------------------------------------------------------------------------- */ | 204 | /* ------------------------------------------------------------------------- */ | ||
196 | 205 | | |||
▲ Show 20 Lines • Show All 265 Lines • ▼ Show 20 Line(s) | 400 | TerminalDisplay::TerminalDisplay(QWidget* parent) | |||
462 | , _trimLeadingSpaces(false) | 471 | , _trimLeadingSpaces(false) | ||
463 | , _trimTrailingSpaces(false) | 472 | , _trimTrailingSpaces(false) | ||
464 | , _mouseWheelZoom(false) | 473 | , _mouseWheelZoom(false) | ||
465 | , _margin(1) | 474 | , _margin(1) | ||
466 | , _centerContents(false) | 475 | , _centerContents(false) | ||
467 | , _readOnlyMessageWidget(nullptr) | 476 | , _readOnlyMessageWidget(nullptr) | ||
468 | , _readOnly(false) | 477 | , _readOnly(false) | ||
469 | , _opacity(1.0) | 478 | , _opacity(1.0) | ||
479 | , _dimWhenInactive(false) | ||||
470 | , _scrollWheelState(ScrollState()) | 480 | , _scrollWheelState(ScrollState()) | ||
471 | , _searchBar(new IncrementalSearchBar(this)) | 481 | , _searchBar(new IncrementalSearchBar(this)) | ||
472 | { | 482 | { | ||
473 | // terminal applications are not designed with Right-To-Left in mind, | 483 | // terminal applications are not designed with Right-To-Left in mind, | ||
474 | // so the layout is forced to Left-To-Right | 484 | // so the layout is forced to Left-To-Right | ||
475 | setLayoutDirection(Qt::LeftToRight); | 485 | setLayoutDirection(Qt::LeftToRight); | ||
476 | 486 | | |||
477 | _contentRect = QRect(_margin, _margin, 1, 1); | 487 | _contentRect = QRect(_margin, _margin, 1, 1); | ||
▲ Show 20 Lines • Show All 386 Lines • ▼ Show 20 Line(s) | 873 | { | |||
864 | setAutoFillBackground(true); | 874 | setAutoFillBackground(true); | ||
865 | } | 875 | } | ||
866 | else | 876 | else | ||
867 | { | 877 | { | ||
868 | setAutoFillBackground(false); | 878 | setAutoFillBackground(false); | ||
869 | }*/ | 879 | }*/ | ||
870 | 880 | | |||
871 | _blendColor = color.rgba(); | 881 | _blendColor = color.rgba(); | ||
872 | updateScrollBarPalette(); | 882 | onColorsChanged(); | ||
873 | } | 883 | } | ||
874 | 884 | | |||
875 | void TerminalDisplay::setWallpaper(ColorSchemeWallpaper::Ptr p) | 885 | void TerminalDisplay::setWallpaper(ColorSchemeWallpaper::Ptr p) | ||
876 | { | 886 | { | ||
877 | _wallpaper = p; | 887 | _wallpaper = p; | ||
878 | } | 888 | } | ||
879 | 889 | | |||
880 | void TerminalDisplay::drawBackground(QPainter& painter, const QRect& rect, const QColor& backgroundColor, bool useOpacitySetting) | 890 | void TerminalDisplay::drawBackground(QPainter& painter, const QRect& rect, const QColor& backgroundColor, bool useOpacitySetting) | ||
▲ Show 20 Lines • Show All 151 Lines • ▼ Show 20 Line(s) | |||||
1032 | { | 1042 | { | ||
1033 | painter.save(); | 1043 | painter.save(); | ||
1034 | 1044 | | |||
1035 | // setup painter | 1045 | // setup painter | ||
1036 | const QColor foregroundColor = style->foregroundColor.color(_colorTable); | 1046 | const QColor foregroundColor = style->foregroundColor.color(_colorTable); | ||
1037 | const QColor backgroundColor = style->backgroundColor.color(_colorTable); | 1047 | const QColor backgroundColor = style->backgroundColor.color(_colorTable); | ||
1038 | 1048 | | |||
1039 | // draw background if different from the display's background color | 1049 | // draw background if different from the display's background color | ||
1040 | if (backgroundColor != palette().background().color()) { | 1050 | if (backgroundColor != getBackgroundColor()) { | ||
1041 | drawBackground(painter, rect, backgroundColor, | 1051 | drawBackground(painter, rect, backgroundColor, | ||
1042 | false /* do not use transparency */); | 1052 | false /* do not use transparency */); | ||
1043 | } | 1053 | } | ||
1044 | 1054 | | |||
1045 | // draw cursor shape if the current character is the cursor | 1055 | // draw cursor shape if the current character is the cursor | ||
1046 | // this may alter the foreground and background colors | 1056 | // this may alter the foreground and background colors | ||
1047 | bool invertCharacterColor = false; | 1057 | bool invertCharacterColor = false; | ||
1048 | if ((style->rendition & RE_CURSOR) != 0) { | 1058 | if ((style->rendition & RE_CURSOR) != 0) { | ||
▲ Show 20 Lines • Show All 422 Lines • ▼ Show 20 Line(s) | |||||
1471 | void TerminalDisplay::paintEvent(QPaintEvent* pe) | 1481 | void TerminalDisplay::paintEvent(QPaintEvent* pe) | ||
1472 | { | 1482 | { | ||
1473 | QPainter paint(this); | 1483 | QPainter paint(this); | ||
1474 | 1484 | | |||
1475 | // Determine which characters should be repainted (1 region unit = 1 character) | 1485 | // Determine which characters should be repainted (1 region unit = 1 character) | ||
1476 | QRegion dirtyImageRegion; | 1486 | QRegion dirtyImageRegion; | ||
1477 | foreach(const QRect & rect, (pe->region() & contentsRect()).rects()) { | 1487 | foreach(const QRect & rect, (pe->region() & contentsRect()).rects()) { | ||
1478 | dirtyImageRegion += widgetToImage(rect); | 1488 | dirtyImageRegion += widgetToImage(rect); | ||
1479 | drawBackground(paint, rect, palette().background().color(), true /* use opacity setting */); | 1489 | drawBackground(paint, rect, getBackgroundColor(), true /* use opacity setting */); | ||
1480 | } | 1490 | } | ||
1491 | | ||||
1481 | foreach(const QRect & rect, dirtyImageRegion.rects()) { | 1492 | foreach(const QRect & rect, dirtyImageRegion.rects()) { | ||
1482 | drawContents(paint, rect); | 1493 | drawContents(paint, rect); | ||
1483 | } | 1494 | } | ||
1484 | drawCurrentResultRect(paint); | 1495 | drawCurrentResultRect(paint); | ||
1485 | drawInputMethodPreeditString(paint, preeditRect()); | 1496 | drawInputMethodPreeditString(paint, preeditRect()); | ||
1486 | paintFilters(paint); | 1497 | paintFilters(paint); | ||
1498 | | ||||
1499 | const bool drawDimmed = _dimWhenInactive && !hasFocus(); | ||||
1500 | const QColor dimColor(0, 0, 0, 128); | ||||
1501 | foreach(const QRect & rect, (pe->region() & contentsRect()).rects()) { | ||||
1502 | if (drawDimmed) { | ||||
1503 | paint.fillRect(rect, dimColor); | ||||
1504 | } | ||||
1505 | } | ||||
1487 | } | 1506 | } | ||
1488 | 1507 | | |||
1489 | void TerminalDisplay::printContent(QPainter& painter, bool friendly) | 1508 | void TerminalDisplay::printContent(QPainter& painter, bool friendly) | ||
1490 | { | 1509 | { | ||
1491 | // Reinitialize the font with the printers paint device so the font | 1510 | // Reinitialize the font with the printers paint device so the font | ||
1492 | // measurement calculations will be done correctly | 1511 | // measurement calculations will be done correctly | ||
1493 | QFont savedFont = getVTFont(); | 1512 | QFont savedFont = getVTFont(); | ||
1494 | QFont font(savedFont, painter.device()); | 1513 | QFont font(savedFont, painter.device()); | ||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | 1550 | { | |||
1537 | // lines for filters | 1556 | // lines for filters | ||
1538 | QPoint cursorPos = mapFromGlobal(QCursor::pos()); | 1557 | QPoint cursorPos = mapFromGlobal(QCursor::pos()); | ||
1539 | int cursorLine; | 1558 | int cursorLine; | ||
1540 | int cursorColumn; | 1559 | int cursorColumn; | ||
1541 | 1560 | | |||
1542 | getCharacterPosition(cursorPos, cursorLine, cursorColumn, false); | 1561 | getCharacterPosition(cursorPos, cursorLine, cursorColumn, false); | ||
1543 | Character cursorCharacter = _image[loc(qMin(cursorColumn, _columns - 1), cursorLine)]; | 1562 | Character cursorCharacter = _image[loc(qMin(cursorColumn, _columns - 1), cursorLine)]; | ||
1544 | 1563 | | |||
1545 | painter.setPen(QPen(cursorCharacter.foregroundColor.color(colorTable()))); | 1564 | painter.setPen(QPen(cursorCharacter.foregroundColor.color(_colorTable))); | ||
1546 | 1565 | | |||
1547 | // iterate over hotspots identified by the display's currently active filters | 1566 | // iterate over hotspots identified by the display's currently active filters | ||
1548 | // and draw appropriate visuals to indicate the presence of the hotspot | 1567 | // and draw appropriate visuals to indicate the presence of the hotspot | ||
1549 | 1568 | | |||
1550 | QList<Filter::HotSpot*> spots = _filterChain->hotSpots(); | 1569 | QList<Filter::HotSpot*> spots = _filterChain->hotSpots(); | ||
1551 | int urlNumber, urlNumInc; | 1570 | int urlNumber, urlNumInc; | ||
1552 | if (_reverseUrlHints) { | 1571 | if (_reverseUrlHints) { | ||
1553 | urlNumber = spots.size() + 1; | 1572 | urlNumber = spots.size() + 1; | ||
▲ Show 20 Lines • Show All 2094 Lines • ▼ Show 20 Line(s) | |||||
3648 | { | 3667 | { | ||
3649 | bool eventHandled = false; | 3668 | bool eventHandled = false; | ||
3650 | switch (event->type()) { | 3669 | switch (event->type()) { | ||
3651 | case QEvent::ShortcutOverride: | 3670 | case QEvent::ShortcutOverride: | ||
3652 | eventHandled = handleShortcutOverrideEvent(static_cast<QKeyEvent*>(event)); | 3671 | eventHandled = handleShortcutOverrideEvent(static_cast<QKeyEvent*>(event)); | ||
3653 | break; | 3672 | break; | ||
3654 | case QEvent::PaletteChange: | 3673 | case QEvent::PaletteChange: | ||
3655 | case QEvent::ApplicationPaletteChange: | 3674 | case QEvent::ApplicationPaletteChange: | ||
3656 | _scrollBar->setPalette(QApplication::palette()); | 3675 | onColorsChanged(); | ||
3676 | break; | ||||
3677 | case QEvent::FocusOut: | ||||
3678 | case QEvent::FocusIn: | ||||
3679 | update(); | ||||
3657 | break; | 3680 | break; | ||
3658 | default: | 3681 | default: | ||
3659 | break; | 3682 | break; | ||
3660 | } | 3683 | } | ||
3661 | return eventHandled ? true : QWidget::event(event); | 3684 | return eventHandled ? true : QWidget::event(event); | ||
3662 | } | 3685 | } | ||
3663 | 3686 | | |||
3664 | void TerminalDisplay::contextMenuEvent(QContextMenuEvent* event) | 3687 | void TerminalDisplay::contextMenuEvent(QContextMenuEvent* event) | ||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Line(s) | |||||
3727 | 3750 | | |||
3728 | void TerminalDisplay::swapFGBGColors() | 3751 | void TerminalDisplay::swapFGBGColors() | ||
3729 | { | 3752 | { | ||
3730 | // swap the default foreground & background color | 3753 | // swap the default foreground & background color | ||
3731 | ColorEntry color = _colorTable[DEFAULT_BACK_COLOR]; | 3754 | ColorEntry color = _colorTable[DEFAULT_BACK_COLOR]; | ||
3732 | _colorTable[DEFAULT_BACK_COLOR] = _colorTable[DEFAULT_FORE_COLOR]; | 3755 | _colorTable[DEFAULT_BACK_COLOR] = _colorTable[DEFAULT_FORE_COLOR]; | ||
3733 | _colorTable[DEFAULT_FORE_COLOR] = color; | 3756 | _colorTable[DEFAULT_FORE_COLOR] = color; | ||
3734 | 3757 | | |||
3735 | update(); | 3758 | onColorsChanged(); | ||
3736 | } | 3759 | } | ||
3737 | 3760 | | |||
3738 | /* --------------------------------------------------------------------- */ | 3761 | /* --------------------------------------------------------------------- */ | ||
3739 | /* */ | 3762 | /* */ | ||
3740 | /* Drag & Drop */ | 3763 | /* Drag & Drop */ | ||
3741 | /* */ | 3764 | /* */ | ||
3742 | /* --------------------------------------------------------------------- */ | 3765 | /* --------------------------------------------------------------------- */ | ||
3743 | 3766 | | |||
▲ Show 20 Lines • Show All 214 Lines • Show Last 20 Lines |