Changeset View
Changeset View
Standalone View
Standalone View
src/TerminalDisplay.cpp
Context not available. | |||||
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++) { | ||
Context not available. | |||||
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 | /* ------------------------------------------------------------------------- */ | ||
Context not available. | |||||
470 | , _readOnlyMessageWidget(nullptr) | 479 | , _readOnlyMessageWidget(nullptr) | ||
471 | , _readOnly(false) | 480 | , _readOnly(false) | ||
472 | , _opacity(1.0) | 481 | , _opacity(1.0) | ||
482 | , _dimWhenInactive(false) | ||||
473 | , _scrollWheelState(ScrollState()) | 483 | , _scrollWheelState(ScrollState()) | ||
474 | , _searchBar(new IncrementalSearchBar(this)) | 484 | , _searchBar(new IncrementalSearchBar(this)) | ||
475 | { | 485 | { | ||
Context not available. | |||||
872 | }*/ | 882 | }*/ | ||
873 | 883 | | |||
874 | _blendColor = color.rgba(); | 884 | _blendColor = color.rgba(); | ||
875 | updateScrollBarPalette(); | 885 | onColorsChanged(); | ||
876 | } | 886 | } | ||
877 | 887 | | |||
878 | void TerminalDisplay::setWallpaper(ColorSchemeWallpaper::Ptr p) | 888 | void TerminalDisplay::setWallpaper(ColorSchemeWallpaper::Ptr p) | ||
Context not available. | |||||
1040 | const QColor backgroundColor = style->backgroundColor.color(_colorTable); | 1050 | const QColor backgroundColor = style->backgroundColor.color(_colorTable); | ||
1041 | 1051 | | |||
1042 | // draw background if different from the display's background color | 1052 | // draw background if different from the display's background color | ||
1043 | if (backgroundColor != palette().background().color()) { | 1053 | if (backgroundColor != getBackgroundColor()) { | ||
1044 | drawBackground(painter, rect, backgroundColor, | 1054 | drawBackground(painter, rect, backgroundColor, | ||
1045 | false /* do not use transparency */); | 1055 | false /* do not use transparency */); | ||
1046 | } | 1056 | } | ||
Context not available. | |||||
1475 | { | 1485 | { | ||
1476 | QPainter paint(this); | 1486 | QPainter paint(this); | ||
1477 | 1487 | | |||
1488 | const bool drawDimmed = _dimWhenInactive && !hasFocus(); | ||||
1489 | const QColor dimColor(0, 0, 0, 128); | ||||
1490 | | ||||
1478 | foreach(const QRect & rect, (pe->region() & contentsRect()).rects()) { | 1491 | foreach(const QRect & rect, (pe->region() & contentsRect()).rects()) { | ||
1479 | drawBackground(paint, rect, palette().background().color(), | 1492 | drawBackground(paint, rect, getBackgroundColor(), | ||
1480 | true /* use opacity setting */); | 1493 | true /* use opacity setting */); | ||
1481 | drawContents(paint, rect); | 1494 | drawContents(paint, rect); | ||
1495 | if (drawDimmed) { | ||||
1496 | paint.fillRect(rect, dimColor); | ||||
1497 | } | ||||
1482 | } | 1498 | } | ||
1483 | drawCurrentResultRect(paint); | 1499 | drawCurrentResultRect(paint); | ||
1484 | drawInputMethodPreeditString(paint, preeditRect()); | 1500 | drawInputMethodPreeditString(paint, preeditRect()); | ||
Context not available. | |||||
1541 | getCharacterPosition(cursorPos, cursorLine, cursorColumn, false); | 1557 | getCharacterPosition(cursorPos, cursorLine, cursorColumn, false); | ||
1542 | Character cursorCharacter = _image[loc(qMin(cursorColumn, _columns - 1), cursorLine)]; | 1558 | Character cursorCharacter = _image[loc(qMin(cursorColumn, _columns - 1), cursorLine)]; | ||
1543 | 1559 | | |||
1544 | painter.setPen(QPen(cursorCharacter.foregroundColor.color(colorTable()))); | 1560 | painter.setPen(QPen(cursorCharacter.foregroundColor.color(_colorTable))); | ||
1545 | 1561 | | |||
1546 | // iterate over hotspots identified by the display's currently active filters | 1562 | // iterate over hotspots identified by the display's currently active filters | ||
1547 | // and draw appropriate visuals to indicate the presence of the hotspot | 1563 | // and draw appropriate visuals to indicate the presence of the hotspot | ||
Context not available. | |||||
3695 | break; | 3711 | break; | ||
3696 | case QEvent::PaletteChange: | 3712 | case QEvent::PaletteChange: | ||
3697 | case QEvent::ApplicationPaletteChange: | 3713 | case QEvent::ApplicationPaletteChange: | ||
3698 | _scrollBar->setPalette(QApplication::palette()); | 3714 | onColorsChanged(); | ||
3715 | break; | ||||
3716 | case QEvent::FocusOut: | ||||
3717 | case QEvent::FocusIn: | ||||
3718 | update(); | ||||
3699 | break; | 3719 | break; | ||
3700 | default: | 3720 | default: | ||
3701 | break; | 3721 | break; | ||
Context not available. | |||||
3774 | _colorTable[DEFAULT_BACK_COLOR] = _colorTable[DEFAULT_FORE_COLOR]; | 3794 | _colorTable[DEFAULT_BACK_COLOR] = _colorTable[DEFAULT_FORE_COLOR]; | ||
3775 | _colorTable[DEFAULT_FORE_COLOR] = color; | 3795 | _colorTable[DEFAULT_FORE_COLOR] = color; | ||
3776 | 3796 | | |||
3777 | update(); | 3797 | onColorsChanged(); | ||
3778 | } | 3798 | } | ||
3779 | 3799 | | |||
3780 | /* --------------------------------------------------------------------- */ | 3800 | /* --------------------------------------------------------------------- */ | ||
Context not available. |