# HG changeset patch # User John W. Eaton # Date 1367834444 14400 # Node ID 818eef7b2618c99826f32944083ce988afba6137 # Parent db31d1e77d7bd352ed3fc8a4ef3b94b852f6c325 allow terminal colors to be set from preferences dialog * QTerminalInterface.h (QTerminalInterface::setBackgroundColor, QTerminalInterface::setForeroundColor, QTerminalInterface::setSelectionColor, QTerminalInterface::setCursorColor): New functions. * QUnixTerminalImpl.h, QUnixTerminalImpl.cpp QUnixTerminalImpl::setBackgroundColor, QUnixTerminalImpl::setForeroundColor, QUnixTerminalImpl::setSelectionColor, QUnixTerminalImpl::setCursorColor): New functions. * QWinTerminalImpl.h, QWinTerminalImpl.cpp (QConsolePrivate::setCursorColor): New argument, useForegroundColor. (QConsolePrivate::m_selectionColor, QConsolePrivate::m_cursorColor): New member variablebs. (QConsolePrivate::selectionColor, QConsolePrivate::cursorColor, QConsolePrivate::setSelectionColor, QConsolePrivate::setCursorColor): Use member variables instead of Windows console color map. (QConsolePrivate::cursorColor): Return foreground color if stored color is invalid. (QConsolePrivate::setCursorColor): Store invalid color if useForegroundcolor. (QConsolePrivate::QConsolePrivate): Set default selection and cursor colors. * QTerminal.cc (QTerminal::notice_settings): Handle terminal color settings. * resource-manager.h, resource-manager.cc (resource_manager::terminal_color_names, resource_manager::terminal_default_colors, resource_manager::terminal_color_chars): New functions. * settings-dialog.h, settings-dialog.cc (settings_dialog::read_terminal_colors): New function. (settings_dialog::settings_dialog): Call read_terminal_colors. Read valud for using foreground color for cursor color. (settings_dialog::write_terminal_colors): New function. (settings_dialog::write_changed_settings): Call write_terminal_colors. Handle setting for using foreground color for cursor color. * settings-dialog.ui: Add color selection to terminal settings dialog. diff -r db31d1e77d7b -r 818eef7b2618 libgui/qterminal/libqterminal/QTerminal.cc --- a/libgui/qterminal/libqterminal/QTerminal.cc Mon May 06 02:20:06 2013 -0400 +++ b/libgui/qterminal/libqterminal/QTerminal.cc Mon May 06 06:00:44 2013 -0400 @@ -41,4 +41,33 @@ setCursorType(QTerminalInterface::BlockCursor, cursorBlinking); else if (cursorType == "underline") setCursorType(QTerminalInterface::UnderlineCursor, cursorBlinking); + + bool cursorUseForegroundColor + = settings->value ("terminal/cursorUseForegroundColor",true).toBool (); + + // FIXME -- we shouldn't duplicate this information here and in the + // resource manager. + QList default_colors; + + default_colors << QColor(0,0,0) + << QColor(255,255,255) + << QColor(192,192,192) + << QColor(128,128,128); + + setForegroundColor + (settings->value ("terminal/color_f", + QVariant (default_colors.at (0))).value ()); + + setBackgroundColor + (settings->value ("terminal/color_b", + QVariant (default_colors.at (1))).value ()); + + setSelectionColor + (settings->value ("terminal/color_s", + QVariant (default_colors.at (2))).value ()); + + setCursorColor + (cursorUseForegroundColor, + settings->value ("terminal/color_c", + QVariant (default_colors.at (3))).value ()); } diff -r db31d1e77d7b -r 818eef7b2618 libgui/qterminal/libqterminal/QTerminalInterface.h --- a/libgui/qterminal/libqterminal/QTerminalInterface.h Mon May 06 02:20:06 2013 -0400 +++ b/libgui/qterminal/libqterminal/QTerminalInterface.h Mon May 06 06:00:44 2013 -0400 @@ -24,6 +24,7 @@ #define QTERMINALINTERFACE_H #include +#include #include class QTerminalInterface : public QWidget @@ -61,7 +62,13 @@ Q_UNUSED(blinking); } -public slots: + virtual void setBackgroundColor (const QColor& color) = 0; + virtual void setForegroundColor (const QColor& color) = 0; + virtual void setSelectionColor (const QColor& color) = 0; + virtual void setCursorColor (bool useForegroundColor, + const QColor& color) = 0; + + public slots: virtual void copyClipboard() = 0; virtual void pasteClipboard() = 0; diff -r db31d1e77d7b -r 818eef7b2618 libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.cpp --- a/libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.cpp Mon May 06 02:20:06 2013 -0400 +++ b/libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.cpp Mon May 06 06:00:44 2013 -0400 @@ -135,6 +135,18 @@ m_terminalView->setBlinkingCursor(blinking); } +// FIXME -- not sure how to make these work properly given the way the +// Unix terminal handles colors. +void QUnixTerminalImpl::setBackgroundColor (const QColor& color) { } +void QUnixTerminalImpl::setForegroundColor (const QColor& color) { } +void QUnixTerminalImpl::setSelectionColor (const QColor& color) { } + +void QUnixTerminalImpl::setCursorColor (bool useForegroundColor, + const QColor& color) +{ + m_terminalView->setKeyboardCursorColor (useForegroundColor, color); +} + void QUnixTerminalImpl::showEvent(QShowEvent *) { m_terminalView->updateImage(); diff -r db31d1e77d7b -r 818eef7b2618 libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.h --- a/libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.h Mon May 06 02:20:06 2013 -0400 +++ b/libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.h Mon May 06 06:00:44 2013 -0400 @@ -43,6 +43,11 @@ void setCursorType(CursorType type, bool blinking); + void setBackgroundColor (const QColor& color); + void setForegroundColor (const QColor& color); + void setSelectionColor (const QColor& color); + void setCursorColor (bool useForegroundColor, const QColor& color); + public slots: void copyClipboard(); void pasteClipboard(); diff -r db31d1e77d7b -r 818eef7b2618 libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp --- a/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp Mon May 06 02:20:06 2013 -0400 +++ b/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp Mon May 06 06:00:44 2013 -0400 @@ -137,7 +137,7 @@ void setBackgroundColor (const QColor& color); void setForegroundColor (const QColor& color); void setSelectionColor (const QColor& color); - void setCursorColor (const QColor& color); + void setCursorColor (bool useForegroundColor, const QColor& color); void drawTextBackground (QPainter& p, int cx1, int cy1, int cx2, int cy2, int cw, int ch); @@ -172,6 +172,9 @@ QPoint m_beginSelection; QPoint m_endSelection; + QColor m_selectionColor; + QColor m_cursorColor; + HANDLE m_stdOut; HWND m_consoleWindow; CHAR_INFO* m_buffer; @@ -305,8 +308,11 @@ SetConsoleTextAttribute (m_stdOut, 0xF0); + // Defaults. setBackgroundColor (Qt::white); setForegroundColor (Qt::black); + setSelectionColor (Qt::lightGray); + setCursorColor (false, Qt::darkGray); // FIXME -- should we set the palette? QPalette palette (backgroundColor ()); @@ -476,14 +482,25 @@ m_consoleView->update (); } -// FIXME -- maybe we should not be messing with the Windows console -// colors for things like the selection and cursor which are entirely up -// to us to draw. +QColor QConsolePrivate::backgroundColor (void) const +{ + return m_colors[15]; +} + +QColor QConsolePrivate::foregroundColor (void) const +{ + return m_colors[0]; +} -QColor QConsolePrivate::backgroundColor (void) const { return m_colors[15]; } -QColor QConsolePrivate::foregroundColor (void) const { return m_colors[0]; } -QColor QConsolePrivate::selectionColor (void) const { return m_colors[7]; } -QColor QConsolePrivate::cursorColor (void) const { return m_colors[8]; } +QColor QConsolePrivate::selectionColor (void) const +{ + return m_selectionColor; +} + +QColor QConsolePrivate::cursorColor (void) const +{ + return m_cursorColor.isValid () ? m_cursorColor : foregroundColor (); +} void QConsolePrivate::setBackgroundColor (const QColor& color) { @@ -497,12 +514,13 @@ void QConsolePrivate::setSelectionColor (const QColor& color) { - m_colors[7] = color; + m_selectionColor = color; } -void QConsolePrivate::setCursorColor (const QColor& color) +void QConsolePrivate::setCursorColor (bool useForegroundColor, + const QColor& color) { - m_colors[8] = color; + m_cursorColor = useForegroundColor ? QColor () : color; } void QConsolePrivate::drawTextBackground (QPainter& p, int cx1, int cy1, @@ -1364,6 +1382,27 @@ setBlinkingCursor (blinking); } +void QWinTerminalImpl::setBackgroundColor (const QColor& color) +{ + d->setBackgroundColor (color); +} + +void QWinTerminalImpl::setForegroundColor (const QColor& color) +{ + d->setForegroundColor (color); +} + +void QWinTerminalImpl::setSelectionColor (const QColor& color) +{ + d->setSelectionColor (color); +} + +void QWinTerminalImpl::setCursorColor (bool useForegroundColor, + const QColor& color) +{ + d->setCursorColor (useForegroundColor, color); +} + ////////////////////////////////////////////////////////////////////////////// void QWinTerminalImpl::setTerminalFont (const QFont& f) diff -r db31d1e77d7b -r 818eef7b2618 libgui/qterminal/libqterminal/win32/QWinTerminalImpl.h --- a/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.h Mon May 06 02:20:06 2013 -0400 +++ b/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.h Mon May 06 06:00:44 2013 -0400 @@ -55,6 +55,11 @@ void sendText (const QString& s); void setCursorType (CursorType type, bool blinking); + void setBackgroundColor (const QColor& color); + void setForegroundColor (const QColor& color); + void setSelectionColor (const QColor& color); + void setCursorColor (bool useForegoundColor, const QColor& color); + public slots: void copyClipboard (void); void pasteClipboard (void); diff -r db31d1e77d7b -r 818eef7b2618 libgui/src/resource-manager.cc --- a/libgui/src/resource-manager.cc Mon May 06 02:20:06 2013 -0400 +++ b/libgui/src/resource-manager.cc Mon May 06 06:00:44 2013 -0400 @@ -217,6 +217,24 @@ << QColor(255,190,255); } +QStringList +resource_manager::terminal_color_names (void) +{ + return QStringList () << QObject::tr ("foreground") + << QObject::tr ("background") + << QObject::tr ("selection") + << QObject::tr ("cursor"); +} + +QList +resource_manager::terminal_default_colors (void) +{ + return QList () << QColor(0,0,0) + << QColor(255,255,255) + << QColor(192,192,192) + << QColor(128,128,128); +} + const char* resource_manager::octave_keywords (void) { diff -r db31d1e77d7b -r 818eef7b2618 libgui/src/resource-manager.h --- a/libgui/src/resource-manager.h Mon May 06 02:20:06 2013 -0400 +++ b/libgui/src/resource-manager.h Mon May 06 06:00:44 2013 -0400 @@ -87,6 +87,10 @@ static QStringList storage_class_names (void); static QList storage_class_default_colors (void); + static QString terminal_color_chars (void) { return "fbsc"; } + static QStringList terminal_color_names (void); + static QList terminal_default_colors (void); + private: static resource_manager *instance; diff -r db31d1e77d7b -r 818eef7b2618 libgui/src/settings-dialog.cc --- a/libgui/src/settings-dialog.cc Mon May 06 02:20:06 2013 -0400 +++ b/libgui/src/settings-dialog.cc Mon May 06 06:00:44 2013 -0400 @@ -97,6 +97,7 @@ ui->useProxyServer->setChecked (settings->value ("useProxyServer",false).toBool ()); ui->proxyHostName->setText (settings->value ("proxyHostName").toString ()); ui->terminal_cursorBlinking->setChecked (settings->value ("terminal/cursorBlinking",true).toBool ()); + ui->terminal_cursorUseForegroundColor->setChecked (settings->value ("terminal/cursorUseForegroundColor",true).toBool ()); QString cursorType = settings->value ("terminal/cursorType","ibeam").toString (); @@ -129,6 +130,9 @@ // qorkspace colors read_workspace_colors (settings); + // terminal colors + read_terminal_colors (settings); + #ifdef HAVE_QSCINTILLA // editor styles: create lexer, read settings, and create dialog elements QsciLexer *lexer; @@ -285,6 +289,43 @@ ui->workspace_colors_box->setLayout (style_grid); } +void +settings_dialog::read_terminal_colors (QSettings *settings) +{ + + QList default_colors = resource_manager::terminal_default_colors (); + QStringList class_names = resource_manager::terminal_color_names (); + QString class_chars = resource_manager::terminal_color_chars (); + int nr_of_classes = class_chars.length (); + + QGridLayout *style_grid = new QGridLayout (); + QLabel *description[nr_of_classes]; + color_picker *color[nr_of_classes]; + + int column = 0; + int row = 0; + for (int i = 0; i < nr_of_classes; i++) + { + description[i] = new QLabel (class_names.at (i)); + description[i]->setAlignment (Qt::AlignRight); + QVariant default_var = default_colors.at (i); + QColor setting_color = settings->value ("terminal/color_"+class_chars.mid (i,1), + default_var).value (); + color[i] = new color_picker (setting_color); + color[i]->setObjectName ("terminal_color_"+class_chars.mid (i,1)); + color[i]->setMinimumSize (30,10); + style_grid->addWidget (description[i], row,2*column); + style_grid->addWidget (color[i], row,2*column+1); + if (++column == 2) + { + row++; + column = 0; + } + } + + // place grid with elements into the tab + ui->terminal_colors_box->setLayout (style_grid); +} void settings_dialog::write_changed_settings () @@ -330,6 +371,7 @@ settings->setValue ("proxyUserName", ui->proxyUserName->text ()); settings->setValue ("proxyPassword", ui->proxyPassword->text ()); settings->setValue ("terminal/cursorBlinking", ui->terminal_cursorBlinking->isChecked ()); + settings->setValue ("terminal/cursorUseForegroundColor", ui->terminal_cursorUseForegroundColor->isChecked ()); // the cursor QString cursorType; @@ -366,6 +408,8 @@ #endif write_workspace_colors (settings); + + write_terminal_colors (settings); } #ifdef HAVE_QSCINTILLA @@ -444,3 +488,20 @@ } settings->sync (); } + +void +settings_dialog::write_terminal_colors (QSettings *settings) +{ + QString class_chars = resource_manager::terminal_color_chars (); + color_picker *color; + + for (int i = 0; i < class_chars.length (); i++) + { + color = ui->terminal_colors_box->findChild ( + "terminal_color_"+class_chars.mid (i,1)); + if (color) + settings->setValue ("terminal/color_"+class_chars.mid (i,1), + color->color ()); + } + settings->sync (); +} diff -r db31d1e77d7b -r 818eef7b2618 libgui/src/settings-dialog.h --- a/libgui/src/settings-dialog.h Mon May 06 02:20:06 2013 -0400 +++ b/libgui/src/settings-dialog.h Mon May 06 06:00:44 2013 -0400 @@ -52,6 +52,9 @@ void read_workspace_colors (QSettings *settings); void write_workspace_colors (QSettings *settings); + + void read_terminal_colors (QSettings *settings); + void write_terminal_colors (QSettings *settings); }; #endif // SETTINGSDIALOG_H diff -r db31d1e77d7b -r 818eef7b2618 libgui/src/settings-dialog.ui --- a/libgui/src/settings-dialog.ui Mon May 06 02:20:06 2013 -0400 +++ b/libgui/src/settings-dialog.ui Mon May 06 06:00:44 2013 -0400 @@ -32,7 +32,7 @@ - 0 + 3 @@ -317,126 +317,167 @@ Terminal - - - - - - - Font - - - - - - - false - - - QFontComboBox::MonospacedFonts - - - - - - - Font Size - - - - - - - 2 - - - 96 - - - 10 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - Cursor type: - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - Cursor blinking - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Qt::Vertical - - - - 20 - 321 - - - - - + + + + 10 + 50 + 631 + 31 + + + + + + + Cursor type: + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Cursor blinking + + + + + + + Use Foreground Color + + + + + + + + + 10 + 90 + 631 + 164 + + + + + + + + 0 + 162 + + + + Terminal Colors + + + + + + + + + 10 + 260 + 631 + 121 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + 10 + 10 + 631 + 30 + + + + + + + Font + + + + + + + false + + + QFontComboBox::MonospacedFonts + + + + + + + Font Size + + + + + + + 2 + + + 96 + + + 10 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + @@ -513,6 +554,12 @@ 81 + + + 0 + 81 + + Storage Class Colors