ソースを参照

Added capability to change font of python shell.

Extends ctkConsole API to provide a mechanism allowing to dynamically
change the font associated with the QTextEdit used to display the text.
This is achieved by selecting all text, updating the font and finally
re-positioning the cursor at the end of the text.
Christopher Mullins 13 年 前
コミット
d5caa56a75
共有3 個のファイルを変更した30 個の追加5 個の削除を含む
  1. 21 5
      Libs/Widgets/ctkConsole.cpp
  2. 6 0
      Libs/Widgets/ctkConsole.h
  3. 3 0
      Libs/Widgets/ctkConsole_p.h

+ 21 - 5
Libs/Widgets/ctkConsole.cpp

@@ -111,13 +111,13 @@ void ctkConsolePrivate::init()
   this->CommandTextColor = QColor(0, 0, 150); // Blue
   this->WelcomeTextColor = QColor(0, 0, 255); // Dark Blue
 
-  QFont f;
-  f.setFamily("Courier");
-  f.setStyleHint(QFont::TypeWriter);
-  f.setFixedPitch(true);
+  QFont shellFont;
+  shellFont.setFamily("Courier");
+  shellFont.setStyleHint(QFont::TypeWriter);
+  shellFont.setFixedPitch(true);
 
   QTextCharFormat format;
-  format.setFont(f);
+  format.setFont(shellFont);
   format.setForeground(this->OutputTextColor);
   this->setCurrentCharFormat(format);
 
@@ -689,6 +689,22 @@ void ctkConsole::setFormat(const QTextCharFormat& Format)
 }
 
 //-----------------------------------------------------------------------------
+QFont ctkConsole::shellFont() const
+{
+  Q_D(const ctkConsole);
+  return d->currentFont();
+}
+
+//-----------------------------------------------------------------------------
+void ctkConsole::setShellFont(const QFont& font)
+{
+  Q_D(ctkConsole);
+  d->selectAll();
+  d->setCurrentFont(font);
+  d->moveCursor(d->textCursor().End); // Reset cursor to undo highlighting
+}
+
+//-----------------------------------------------------------------------------
 CTK_GET_CPP(ctkConsole, ctkConsoleCompleter*, completer, Completer);
 
 //-----------------------------------------------------------------------------

+ 6 - 0
Libs/Widgets/ctkConsole.h

@@ -102,6 +102,12 @@ public:
   /// Sets formatting that will be used by printMessage()
   void setFormat(const QTextCharFormat& Format);
 
+  /// Returns current font of python shell
+  QFont shellFont() const;
+
+  /// Sets font of python shell
+  void setShellFont(const QFont& font);
+
   /// Return the completer of this console
   ctkConsoleCompleter* completer() const;
 

+ 3 - 0
Libs/Widgets/ctkConsole_p.h

@@ -163,6 +163,9 @@ public:
   /// Secondary prompt
   QString Ps2;
 
+  /// Font of all text in shell
+  QFont ShellFont;
+
   ctkConsole::EditorHints EditorHints;
 
   bool ScrollbarAtBottom;