Mercurial > hg > octave-avbm
comparison libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp @ 16620:13728d41fb6a
use functions to handle colors in Windows GUI terminal
* QWinTerminalImpl.cpp (QConsolePrivate::backgroundColor,
QConsolePrivate::foregroundColor, QConsolePrivate::selectionColor,
QConsolePrivate::cursorColor, QConsolePrivate::setBackgroundColor,
QConsolePrivate::setForegroundColor,
QConsolePrivate::setSelectionColor, QConsolePrivate::setCursorColor):
New functions.
(QConsolePrivate::m_backgroundColor,
QConsolePrivate::m_foregroundColor): Delete member variables.
(QConsolePrivate::QConsolePrivate): Call setBackgroundColor and
setForegroundColor to set default colors.
(QWinTerminalImpl::viewPaintEvent): Use functions to access colors.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 06 May 2013 02:20:01 -0400 |
parents | 3a17dd5964e3 |
children | db31d1e77d7b |
comparison
equal
deleted
inserted
replaced
16619:3a17dd5964e3 | 16620:13728d41fb6a |
---|---|
127 QPoint posToCell (const QPoint& pt); | 127 QPoint posToCell (const QPoint& pt); |
128 QString getSelection (void); | 128 QString getSelection (void); |
129 void updateSelection (void); | 129 void updateSelection (void); |
130 void clearSelection (void); | 130 void clearSelection (void); |
131 | 131 |
132 QColor backgroundColor (void) const; | |
133 QColor foregroundColor (void) const; | |
134 QColor selectionColor (void) const; | |
135 QColor cursorColor (void) const; | |
136 | |
137 void setBackgroundColor (const QColor& color); | |
138 void setForegroundColor (const QColor& color); | |
139 void setSelectionColor (const QColor& color); | |
140 void setCursorColor (const QColor& color); | |
141 | |
132 private: | 142 private: |
133 QWinTerminalImpl* q; | 143 QWinTerminalImpl* q; |
134 | 144 |
135 private: | 145 private: |
136 QFont m_font; | 146 QFont m_font; |
137 QColor m_backgroundColor; | |
138 QColor m_foregroundColor; | |
139 QString m_command; | 147 QString m_command; |
140 QConsoleColors m_colors; | 148 QConsoleColors m_colors; |
141 bool m_inWheelEvent; | 149 bool m_inWheelEvent; |
142 QString m_title; | 150 QString m_title; |
143 | 151 |
261 | 269 |
262 wchar_t titleBuf[260]; | 270 wchar_t titleBuf[260]; |
263 GetConsoleTitleW (titleBuf, sizeof (titleBuf)); | 271 GetConsoleTitleW (titleBuf, sizeof (titleBuf)); |
264 q->setWindowTitle (QString::fromWCharArray (titleBuf)); | 272 q->setWindowTitle (QString::fromWCharArray (titleBuf)); |
265 | 273 |
266 m_backgroundColor = Qt::white; | |
267 m_foregroundColor = Qt::black; | |
268 SetConsoleTextAttribute (m_stdOut, 0xF0); | |
269 | |
270 m_font.setFamily ("Lucida Console"); | 274 m_font.setFamily ("Lucida Console"); |
271 m_font.setPointSize (9); | 275 m_font.setPointSize (9); |
272 m_font.setStyleHint (QFont::TypeWriter); | 276 m_font.setStyleHint (QFont::TypeWriter); |
273 | 277 |
274 m_buffer = m_tmpBuffer = 0; | 278 m_buffer = m_tmpBuffer = 0; |
280 l->setContentsMargins (0, 0, 0, 0); | 284 l->setContentsMargins (0, 0, 0, 0); |
281 l->setSpacing (0); | 285 l->setSpacing (0); |
282 l->addWidget (m_consoleView, 1); | 286 l->addWidget (m_consoleView, 1); |
283 l->addWidget (m_scrollBar, 0); | 287 l->addWidget (m_scrollBar, 0); |
284 | 288 |
285 m_consoleView->setPalette (QPalette (m_backgroundColor)); | 289 SetConsoleTextAttribute (m_stdOut, 0xF0); |
290 | |
291 setBackgroundColor (Qt::white); | |
292 setForegroundColor (Qt::black); | |
293 | |
294 QPalette palette (backgroundColor ()); | |
295 | |
296 m_consoleView->setPalette (palette); | |
286 m_consoleView->setAutoFillBackground (true); | 297 m_consoleView->setAutoFillBackground (true); |
298 | |
287 m_consoleView->setFont (m_font); | 299 m_consoleView->setFont (m_font); |
288 parent->setFocusPolicy (Qt::StrongFocus); | 300 parent->setFocusPolicy (Qt::StrongFocus); |
289 parent->winId (); | 301 parent->winId (); |
290 | 302 |
291 updateScrollBar (); | 303 updateScrollBar (); |
444 m_beginSelection = m_endSelection = QPoint (); | 456 m_beginSelection = m_endSelection = QPoint (); |
445 | 457 |
446 m_consoleView->update (); | 458 m_consoleView->update (); |
447 } | 459 } |
448 | 460 |
449 ////////////////////////////////////////////////////////////////////////////// | 461 QColor QConsolePrivate::backgroundColor (void) const { return m_colors[15]; } |
462 QColor QConsolePrivate::foregroundColor (void) const { return m_colors[0]; } | |
463 QColor QConsolePrivate::selectionColor (void) const { return m_colors[7]; } | |
464 QColor QConsolePrivate::cursorColor (void) const { return m_colors[8]; } | |
465 | |
466 void QConsolePrivate::setBackgroundColor (const QColor& color) | |
467 { | |
468 m_colors[15] = color; | |
469 } | |
470 | |
471 void QConsolePrivate::setForegroundColor (const QColor& color) | |
472 { | |
473 m_colors[0] = color; | |
474 } | |
475 | |
476 void QConsolePrivate::setSelectionColor (const QColor& color) | |
477 { | |
478 m_colors[7] = color; | |
479 } | |
480 | |
481 void QConsolePrivate::setCursorColor (const QColor& color) | |
482 { | |
483 m_colors[8] = color; | |
484 } | |
485 | |
486 ///////////////////////////////////////////////////////////////////////////// | |
450 | 487 |
451 void QConsolePrivate::closeStandardIO (int fd, DWORD stdHandleId, | 488 void QConsolePrivate::closeStandardIO (int fd, DWORD stdHandleId, |
452 const char* name) | 489 const char* name) |
453 { | 490 { |
454 if (close (fd) == -1) | 491 if (close (fd) == -1) |
911 if (cx1 > d->m_consoleRect.width () - 1 | 948 if (cx1 > d->m_consoleRect.width () - 1 |
912 || cy1 > d->m_consoleRect.height () - 1) | 949 || cy1 > d->m_consoleRect.height () - 1) |
913 return; | 950 return; |
914 | 951 |
915 p.setFont (d->m_font); | 952 p.setFont (d->m_font); |
916 p.setPen (d->m_foregroundColor); | 953 p.setPen (d->foregroundColor ()); |
917 | 954 |
918 ascent = p.fontMetrics ().ascent (); | 955 ascent = p.fontMetrics ().ascent (); |
919 stride = d->m_consoleRect.width (); | 956 stride = d->m_consoleRect.width (); |
920 | 957 |
921 s.reserve (cx2 - cx1 + 1); | 958 s.reserve (cx2 - cx1 + 1); |
1004 | 1041 |
1005 int len = ((j == end.y () && end.x () < charsThisLine) | 1042 int len = ((j == end.y () && end.x () < charsThisLine) |
1006 ? end.x () - selectionBegin + 1 | 1043 ? end.x () - selectionBegin + 1 |
1007 : stride - selectionBegin); | 1044 : stride - selectionBegin); |
1008 | 1045 |
1009 QColor selectionColor = d->m_colors[7]; | 1046 QColor color = d->selectionColor (); |
1010 | 1047 |
1011 p.save (); | 1048 p.save (); |
1012 | 1049 |
1013 p.setCompositionMode (QPainter::RasterOp_SourceXorDestination); | 1050 p.setCompositionMode (QPainter::RasterOp_SourceXorDestination); |
1014 | 1051 |
1015 p.fillRect (selectionBegin * cw, y-ascent, len * cw, ch, | 1052 p.fillRect (selectionBegin * cw, y-ascent, len * cw, ch, color); |
1016 selectionColor); | |
1017 | 1053 |
1018 p.restore (); | 1054 p.restore (); |
1019 } | 1055 } |
1020 } | 1056 } |
1021 | 1057 |
1022 if (! d->m_cursorBlinking) | 1058 if (! d->m_cursorBlinking) |
1023 { | 1059 { |
1024 QColor cursorColor = d->m_colors[7]; | 1060 QColor color = d->cursorColor (); |
1025 QRect cursorRect = d->cursorRect (); | 1061 QRect cursorRect = d->cursorRect (); |
1026 | 1062 |
1027 p.setPen (d->m_foregroundColor); | 1063 p.setPen (d->foregroundColor ()); |
1028 | 1064 |
1029 if (d->m_cursorType == QConsolePrivate::BlockCursor) | 1065 if (d->m_cursorType == QConsolePrivate::BlockCursor) |
1030 { | 1066 { |
1031 if (hasFocus ()) | 1067 if (hasFocus ()) |
1032 { | 1068 { |
1033 p.setCompositionMode (QPainter::RasterOp_SourceXorDestination); | 1069 p.setCompositionMode (QPainter::RasterOp_SourceXorDestination); |
1034 | 1070 |
1035 p.fillRect (cursorRect, cursorColor); | 1071 p.fillRect (cursorRect, color); |
1036 } | 1072 } |
1037 else | 1073 else |
1038 { | 1074 { |
1039 // draw the cursor outline, adjusting the area so that | 1075 // draw the cursor outline, adjusting the area so that |
1040 // it is draw entirely inside 'rect' | 1076 // it is draw entirely inside 'rect' |