changeset 16622:818eef7b2618

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.
author John W. Eaton <jwe@octave.org>
date Mon, 06 May 2013 06:00:44 -0400
parents db31d1e77d7b
children 2df11dd7a589
files libgui/qterminal/libqterminal/QTerminal.cc libgui/qterminal/libqterminal/QTerminalInterface.h libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.cpp libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.h libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp libgui/qterminal/libqterminal/win32/QWinTerminalImpl.h libgui/src/resource-manager.cc libgui/src/resource-manager.h libgui/src/settings-dialog.cc libgui/src/settings-dialog.h libgui/src/settings-dialog.ui
diffstat 11 files changed, 363 insertions(+), 133 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/qterminal/libqterminal/QTerminal.cc
+++ b/libgui/qterminal/libqterminal/QTerminal.cc
@@ -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<QColor> 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<QColor> ());
+
+  setBackgroundColor
+    (settings->value ("terminal/color_b",
+                      QVariant (default_colors.at (1))).value<QColor> ());
+
+  setSelectionColor
+    (settings->value ("terminal/color_s",
+                      QVariant (default_colors.at (2))).value<QColor> ());
+
+  setCursorColor
+    (cursorUseForegroundColor,
+     settings->value ("terminal/color_c",
+                      QVariant (default_colors.at (3))).value<QColor> ());
 }
--- a/libgui/qterminal/libqterminal/QTerminalInterface.h
+++ b/libgui/qterminal/libqterminal/QTerminalInterface.h
@@ -24,6 +24,7 @@
 #define QTERMINALINTERFACE_H
 
 #include <QWidget>
+#include <QColor>
 #include <QMenu>
 
 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;
 
--- a/libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.cpp
+++ b/libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.cpp
@@ -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();
--- a/libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.h
+++ b/libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.h
@@ -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();
--- a/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp
+++ b/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp
@@ -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)
--- a/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.h
+++ b/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.h
@@ -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);
--- a/libgui/src/resource-manager.cc
+++ b/libgui/src/resource-manager.cc
@@ -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<QColor>
+resource_manager::terminal_default_colors (void)
+{
+  return QList<QColor> () << QColor(0,0,0)
+                          << QColor(255,255,255)
+                          << QColor(192,192,192)
+                          << QColor(128,128,128);
+}
+
 const char*
 resource_manager::octave_keywords (void)
 {
--- a/libgui/src/resource-manager.h
+++ b/libgui/src/resource-manager.h
@@ -87,6 +87,10 @@
   static QStringList storage_class_names (void);
   static QList<QColor> storage_class_default_colors (void);
 
+  static QString terminal_color_chars (void) { return "fbsc"; }
+  static QStringList terminal_color_names (void);
+  static QList<QColor> terminal_default_colors (void);
+
 private:
 
   static resource_manager *instance;
--- a/libgui/src/settings-dialog.cc
+++ b/libgui/src/settings-dialog.cc
@@ -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<QColor> 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<QColor> ();
+      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 <color_picker *>(
+                            "terminal_color_"+class_chars.mid (i,1));
+      if (color)
+        settings->setValue ("terminal/color_"+class_chars.mid (i,1),
+                            color->color ());
+    }
+  settings->sync ();
+}
--- a/libgui/src/settings-dialog.h
+++ b/libgui/src/settings-dialog.h
@@ -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
--- a/libgui/src/settings-dialog.ui
+++ b/libgui/src/settings-dialog.ui
@@ -32,7 +32,7 @@
    <item>
     <widget class="QTabWidget" name="tabWidget">
      <property name="currentIndex">
-      <number>0</number>
+      <number>3</number>
      </property>
      <widget class="QWidget" name="tab_4">
       <property name="enabled">
@@ -317,126 +317,167 @@
       <attribute name="title">
        <string>Terminal</string>
       </attribute>
-      <layout class="QVBoxLayout" name="verticalLayout">
-       <item>
-        <layout class="QHBoxLayout" name="horizontalLayout_5">
-         <item>
-          <widget class="QLabel" name="label_11">
-           <property name="text">
-            <string>Font</string>
-           </property>
-          </widget>
-         </item>
-         <item>
-          <widget class="QFontComboBox" name="terminal_fontName">
-           <property name="editable">
-            <bool>false</bool>
-           </property>
-           <property name="fontFilters">
-            <set>QFontComboBox::MonospacedFonts</set>
-           </property>
-          </widget>
-         </item>
-         <item>
-          <widget class="QLabel" name="label_12">
-           <property name="text">
-            <string>Font Size</string>
-           </property>
-          </widget>
-         </item>
-         <item>
-          <widget class="QSpinBox" name="terminal_fontSize">
-           <property name="minimum">
-            <number>2</number>
-           </property>
-           <property name="maximum">
-            <number>96</number>
-           </property>
-           <property name="value">
-            <number>10</number>
-           </property>
-          </widget>
-         </item>
-         <item>
-          <spacer name="horizontalSpacer_5">
-           <property name="orientation">
-            <enum>Qt::Horizontal</enum>
-           </property>
-           <property name="sizeHint" stdset="0">
-            <size>
-             <width>40</width>
-             <height>20</height>
-            </size>
-           </property>
-          </spacer>
-         </item>
-        </layout>
-       </item>
-       <item>
-        <layout class="QHBoxLayout" name="horizontalLayout_3">
-         <item>
-          <widget class="QLabel" name="label">
-           <property name="text">
-            <string>Cursor type:</string>
-           </property>
-          </widget>
-         </item>
-         <item>
-          <widget class="QComboBox" name="terminal_cursorType"/>
-         </item>
-         <item>
-          <spacer name="horizontalSpacer">
-           <property name="orientation">
-            <enum>Qt::Horizontal</enum>
-           </property>
-           <property name="sizeHint" stdset="0">
-            <size>
-             <width>40</width>
-             <height>20</height>
-            </size>
-           </property>
-          </spacer>
-         </item>
-        </layout>
-       </item>
-       <item>
-        <layout class="QHBoxLayout" name="horizontalLayout_2">
-         <item>
-          <widget class="QCheckBox" name="terminal_cursorBlinking">
-           <property name="text">
-            <string>Cursor blinking</string>
-           </property>
-          </widget>
-         </item>
-         <item>
-          <spacer name="horizontalSpacer_2">
-           <property name="orientation">
-            <enum>Qt::Horizontal</enum>
-           </property>
-           <property name="sizeHint" stdset="0">
-            <size>
-             <width>40</width>
-             <height>20</height>
-            </size>
-           </property>
-          </spacer>
-         </item>
-        </layout>
-       </item>
-       <item>
-        <spacer name="verticalSpacer_3">
-         <property name="orientation">
-          <enum>Qt::Vertical</enum>
-         </property>
-         <property name="sizeHint" stdset="0">
-          <size>
-           <width>20</width>
-           <height>321</height>
-          </size>
-         </property>
-        </spacer>
-       </item>
-      </layout>
+      <widget class="QWidget" name="horizontalLayoutWidget">
+       <property name="geometry">
+        <rect>
+         <x>10</x>
+         <y>50</y>
+         <width>631</width>
+         <height>31</height>
+        </rect>
+       </property>
+       <layout class="QHBoxLayout" name="horizontalLayout_3">
+        <item>
+         <widget class="QLabel" name="label">
+          <property name="text">
+           <string>Cursor type:</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QComboBox" name="terminal_cursorType"/>
+        </item>
+        <item>
+         <spacer name="horizontalSpacer">
+          <property name="orientation">
+           <enum>Qt::Horizontal</enum>
+          </property>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>40</width>
+            <height>20</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
+        <item>
+         <widget class="QCheckBox" name="terminal_cursorBlinking">
+          <property name="text">
+           <string>Cursor blinking</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QCheckBox" name="terminal_cursorUseForegroundColor">
+          <property name="text">
+           <string>Use Foreground Color</string>
+          </property>
+         </widget>
+        </item>
+       </layout>
+      </widget>
+      <widget class="QWidget" name="verticalLayoutWidget_2">
+       <property name="geometry">
+        <rect>
+         <x>10</x>
+         <y>90</y>
+         <width>631</width>
+         <height>164</height>
+        </rect>
+       </property>
+       <layout class="QVBoxLayout" name="verticalLayout">
+        <item>
+         <widget class="QGroupBox" name="terminal_colors_box">
+          <property name="minimumSize">
+           <size>
+            <width>0</width>
+            <height>162</height>
+           </size>
+          </property>
+          <property name="title">
+           <string>Terminal Colors</string>
+          </property>
+         </widget>
+        </item>
+       </layout>
+      </widget>
+      <widget class="QWidget" name="verticalLayoutWidget_3">
+       <property name="geometry">
+        <rect>
+         <x>10</x>
+         <y>260</y>
+         <width>631</width>
+         <height>121</height>
+        </rect>
+       </property>
+       <layout class="QVBoxLayout" name="verticalLayout_8">
+        <item>
+         <spacer name="verticalSpacer_3">
+          <property name="orientation">
+           <enum>Qt::Vertical</enum>
+          </property>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>20</width>
+            <height>40</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
+       </layout>
+      </widget>
+      <widget class="QWidget" name="layoutWidget">
+       <property name="geometry">
+        <rect>
+         <x>10</x>
+         <y>10</y>
+         <width>631</width>
+         <height>30</height>
+        </rect>
+       </property>
+       <layout class="QHBoxLayout" name="horizontalLayout_5">
+        <item>
+         <widget class="QLabel" name="label_11">
+          <property name="text">
+           <string>Font</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QFontComboBox" name="terminal_fontName">
+          <property name="editable">
+           <bool>false</bool>
+          </property>
+          <property name="fontFilters">
+           <set>QFontComboBox::MonospacedFonts</set>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QLabel" name="label_12">
+          <property name="text">
+           <string>Font Size</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QSpinBox" name="terminal_fontSize">
+          <property name="minimum">
+           <number>2</number>
+          </property>
+          <property name="maximum">
+           <number>96</number>
+          </property>
+          <property name="value">
+           <number>10</number>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <spacer name="horizontalSpacer_5">
+          <property name="orientation">
+           <enum>Qt::Horizontal</enum>
+          </property>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>40</width>
+            <height>20</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
+       </layout>
+      </widget>
      </widget>
      <widget class="QWidget" name="tab_2">
       <attribute name="title">
@@ -513,6 +554,12 @@
          <height>81</height>
         </rect>
        </property>
+       <property name="minimumSize">
+        <size>
+         <width>0</width>
+         <height>81</height>
+        </size>
+       </property>
        <property name="title">
         <string>Storage Class Colors</string>
        </property>