r16727 by jghali - #10141: Console syntax highlighting options do not work
scribus-commit
scribus-commit at lists.scribus.net
Thu Jul 21 22:03:55 UTC 2011
Author: jghali
Date: Thu Jul 21 22:03:54 2011
New Revision: 16727
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=16727
Log:
#10141: Console syntax highlighting options do not work
Modified:
branches/Version135/Scribus/scribus/plugins/scriptplugin/pconsole.cpp
branches/Version135/Scribus/scribus/plugins/scriptplugin/pconsole.h
branches/Version135/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp
branches/Version135/Scribus/scribus/plugins/scriptplugin/scriptercore.h
branches/Version135/Scribus/scribus/plugins/scriptplugin/scripterprefsgui.cpp
branches/Version135/Scribus/scribus/plugins/scriptplugin/scripterprefsgui.h
branches/Version135/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
Modified: branches/Version135/Scribus/scribus/plugins/scriptplugin/pconsole.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16727&path=/branches/Version135/Scribus/scribus/plugins/scriptplugin/pconsole.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/plugins/scriptplugin/pconsole.cpp (original)
+++ branches/Version135/Scribus/scribus/plugins/scriptplugin/pconsole.cpp Thu Jul 21 22:03:54 2011
@@ -49,7 +49,6 @@
commandEdit->setTabStopWidth(qRound(commandEdit->fontPointSize() * 4));
// install syntax highlighter.
- //SyntaxHighlighter *sxHigh =
new SyntaxHighlighter(commandEdit);
languageChange();
@@ -83,6 +82,11 @@
{
}
+void PythonConsole::updateSyntaxHighlighter()
+{
+ new SyntaxHighlighter(commandEdit);
+}
+
void PythonConsole::setFonts()
{
QFont font = QFont("Fixed");
@@ -313,6 +317,9 @@
void SyntaxHighlighter::highlightBlock(const QString &text)
{
+ // Apply default text color
+ setFormat(0, text.length(), colors.textColor);
+
foreach (HighlightingRule rule, highlightingRules)
{
QRegExp expression(rule.pattern);
@@ -362,16 +369,19 @@
textColor.setNamedColor(prefs->get("syntaxtext", "#000000"));
}
-SyntaxColors::~SyntaxColors()
+void SyntaxColors::saveToPrefs()
{
PrefsContext* prefs = PrefsManager::instance()->prefsFile->getPluginContext("scriptplugin");
- prefs->set("syntaxerror", qcolor2named(errorColor));
- prefs->set("syntaxcomment", qcolor2named(commentColor));
- prefs->set("syntaxkeyword", qcolor2named(keywordColor));
- prefs->set("syntaxsign", qcolor2named(signColor));
- prefs->set("syntaxnumber", qcolor2named(numberColor));
- prefs->set("syntaxstring", qcolor2named(stringColor));
- prefs->set("syntaxtext", qcolor2named(textColor));
+ if (prefs)
+ {
+ prefs->set("syntaxerror", qcolor2named(errorColor));
+ prefs->set("syntaxcomment", qcolor2named(commentColor));
+ prefs->set("syntaxkeyword", qcolor2named(keywordColor));
+ prefs->set("syntaxsign", qcolor2named(signColor));
+ prefs->set("syntaxnumber", qcolor2named(numberColor));
+ prefs->set("syntaxstring", qcolor2named(stringColor));
+ prefs->set("syntaxtext", qcolor2named(textColor));
+ }
}
QString SyntaxColors::qcolor2named(QColor color)
Modified: branches/Version135/Scribus/scribus/plugins/scriptplugin/pconsole.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16727&path=/branches/Version135/Scribus/scribus/plugins/scriptplugin/pconsole.h
==============================================================================
--- branches/Version135/Scribus/scribus/plugins/scriptplugin/pconsole.h (original)
+++ branches/Version135/Scribus/scribus/plugins/scriptplugin/pconsole.h Thu Jul 21 22:03:54 2011
@@ -43,6 +43,8 @@
//! \brief Close event for turning the action off
void closeEvent(QCloseEvent *);
+ void updateSyntaxHighlighter();
+
public slots:
//! menu operations
virtual void slot_runScript();
@@ -86,7 +88,7 @@
{
public:
SyntaxColors();
- ~SyntaxColors();
+
QColor errorColor;
QColor commentColor;
QColor keywordColor;
@@ -94,6 +96,9 @@
QColor numberColor;
QColor stringColor;
QColor textColor;
+
+ void saveToPrefs();
+
private:
/*! \brief Converts QColor into #rrggbb string.
\param color a QColor to convert. */
@@ -113,7 +118,7 @@
SyntaxHighlighter(QTextEdit *textEdit);
protected:
- void highlightBlock(const QString &text);
+ virtual void highlightBlock(const QString &text);
struct HighlightingRule
{
Modified: branches/Version135/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16727&path=/branches/Version135/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp (original)
+++ branches/Version135/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp Thu Jul 21 22:03:54 2011
@@ -610,6 +610,11 @@
m_enableExtPython = enable;
}
+void ScripterCore::updateSyntaxHighlighter()
+{
+ pcon->updateSyntaxHighlighter();
+}
+
const QString & ScripterCore::startupScript() const
{
return m_startupScript;
Modified: branches/Version135/Scribus/scribus/plugins/scriptplugin/scriptercore.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16727&path=/branches/Version135/Scribus/scribus/plugins/scriptplugin/scriptercore.h
==============================================================================
--- branches/Version135/Scribus/scribus/plugins/scriptplugin/scriptercore.h (original)
+++ branches/Version135/Scribus/scribus/plugins/scriptplugin/scriptercore.h Thu Jul 21 22:03:54 2011
@@ -56,6 +56,7 @@
bool extensionsEnabled() const;
void setStartupScript(const QString& newScript);
void setExtensionsEnabled(bool enable);
+ void updateSyntaxHighlighter();
protected:
// Private helper functions
Modified: branches/Version135/Scribus/scribus/plugins/scriptplugin/scripterprefsgui.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16727&path=/branches/Version135/Scribus/scribus/plugins/scriptplugin/scripterprefsgui.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/plugins/scriptplugin/scripterprefsgui.cpp (original)
+++ branches/Version135/Scribus/scribus/plugins/scriptplugin/scripterprefsgui.cpp Thu Jul 21 22:03:54 2011
@@ -20,6 +20,10 @@
: PrefsPanel(parent)
{
setupUi(this);
+
+ // Create SyntaxColors with save to prefs
+ // disabled by defaults, only save when apply()
+ syntaxColors = new SyntaxColors();
languageChange();
setupSyntaxColors();
@@ -34,13 +38,13 @@
// signals and slots connections
connect(extensionScriptsChk, SIGNAL(toggled(bool)), startupScriptEdit, SLOT(setEnabled(bool)));
// colors
- connect(textButton, SIGNAL(clicked()), this, SLOT(setColor()));
+ connect(textButton , SIGNAL(clicked()), this, SLOT(setColor()));
connect(commentButton, SIGNAL(clicked()), this, SLOT(setColor()));
connect(keywordButton, SIGNAL(clicked()), this, SLOT(setColor()));
- connect(errorButton, SIGNAL(clicked()), this, SLOT(setColor()));
- connect(signButton, SIGNAL(clicked()), this, SLOT(setColor()));
- connect(stringButton, SIGNAL(clicked()), this, SLOT(setColor()));
- connect(numberButton, SIGNAL(clicked()), this, SLOT(setColor()));
+ connect(errorButton , SIGNAL(clicked()), this, SLOT(setColor()));
+ connect(signButton , SIGNAL(clicked()), this, SLOT(setColor()));
+ connect(stringButton , SIGNAL(clicked()), this, SLOT(setColor()));
+ connect(numberButton , SIGNAL(clicked()), this, SLOT(setColor()));
connect(startupScriptChangeButton, SIGNAL(clicked()), this, SLOT(changeStartupScript()));
}
@@ -49,6 +53,7 @@
*/
ScripterPrefsGui::~ScripterPrefsGui()
{
+ delete syntaxColors;
}
/*
@@ -74,49 +79,63 @@
{
scripterCore->setExtensionsEnabled(extensionScriptsChk->isChecked());
scripterCore->setStartupScript(startupScriptEdit->text());
- // colors
- SyntaxColors *syntax = new SyntaxColors();
- syntax->textColor = textButton->palette().color(QPalette::Window);
- syntax->commentColor = commentButton->palette().color(QPalette::Window);
- syntax->keywordColor = keywordButton->palette().color(QPalette::Window);
- syntax->errorColor = errorButton->palette().color(QPalette::Window);
- syntax->signColor = signButton->palette().color(QPalette::Window);
- syntax->stringColor = stringButton->palette().color(QPalette::Window);
- syntax->numberColor = numberButton->palette().color(QPalette::Window);
- delete(syntax);
+ syntaxColors->saveToPrefs();
+
+ // Necessary to update console syntax highlighter
+ emit prefsChanged();
}
void ScripterPrefsGui::setColor()
{
- QPalette palette;
- QPushButton* button = (QPushButton*)sender();
- QColor color = QColorDialog::getColor(button->palette().color(QPalette::Window), this);
+ QPushButton* button = (QPushButton*) sender();
+
+ QColor oldColor;
+ if (button == textButton) oldColor = syntaxColors->textColor;
+ if (button == commentButton) oldColor = syntaxColors->commentColor;
+ if (button == keywordButton) oldColor = syntaxColors->keywordColor;
+ if (button == errorButton) oldColor = syntaxColors->errorColor;
+ if (button == signButton) oldColor = syntaxColors->signColor;
+ if (button == stringButton) oldColor = syntaxColors->stringColor;
+ if (button == numberButton) oldColor = syntaxColors->numberColor;
+
+ QColor color = QColorDialog::getColor(oldColor, this);
if (color.isValid())
{
- palette.setColor(button->backgroundRole(), color);
- button->setPalette(palette);
+ setButtonIcon(button, color);
+
+ if (button == textButton) syntaxColors->textColor = color;
+ if (button == commentButton) syntaxColors->commentColor = color;
+ if (button == keywordButton) syntaxColors->keywordColor = color;
+ if (button == errorButton) syntaxColors->errorColor = color;
+ if (button == signButton) syntaxColors->signColor = color;
+ if (button == stringButton) syntaxColors->stringColor = color;
+ if (button == numberButton) syntaxColors->numberColor = color;
}
+}
+
+void ScripterPrefsGui::setButtonIcon(QPushButton* button, QColor color)
+{
+ QSize iconSize = button->iconSize();
+ double iconWidth = qMax(iconSize.width() , button->width() / 3);
+ double iconHeight = qMin(iconSize.height(), button->height() / 3);
+ QSize newIconSize(iconWidth, iconHeight);
+ if (iconSize != newIconSize)
+ button->setIconSize(newIconSize);
+ QPixmap icon(button->iconSize());
+ icon.fill(color);
+ button->setIcon(icon);
}
void ScripterPrefsGui::setupSyntaxColors()
{
- QPalette palette;
- SyntaxColors *syntax = new SyntaxColors();
- palette.setColor(textButton->backgroundRole(), syntax->textColor);
- textButton->setPalette(palette);
- palette.setColor(commentButton->backgroundRole(), syntax->commentColor);
- commentButton->setPalette(palette);
- palette.setColor(keywordButton->backgroundRole(), syntax->keywordColor);
- keywordButton->setPalette(palette);
- palette.setColor(errorButton->backgroundRole(), syntax->errorColor);
- errorButton->setPalette(palette);
- palette.setColor(signButton->backgroundRole(), syntax->signColor);
- signButton->setPalette(palette);
- palette.setColor(stringButton->backgroundRole(), syntax->stringColor);
- stringButton->setPalette(palette);
- palette.setColor(numberButton->backgroundRole(), syntax->numberColor);
- numberButton->setPalette(palette);
- delete(syntax);
+ SyntaxColors syntax;
+ setButtonIcon(textButton , syntax.textColor);
+ setButtonIcon(commentButton, syntax.commentColor);
+ setButtonIcon(keywordButton, syntax.keywordColor);
+ setButtonIcon(errorButton , syntax.errorColor);
+ setButtonIcon(signButton , syntax.signColor);
+ setButtonIcon(stringButton , syntax.stringColor);
+ setButtonIcon(numberButton , syntax.numberColor);
}
void ScripterPrefsGui::changeStartupScript()
Modified: branches/Version135/Scribus/scribus/plugins/scriptplugin/scripterprefsgui.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16727&path=/branches/Version135/Scribus/scribus/plugins/scriptplugin/scripterprefsgui.h
==============================================================================
--- branches/Version135/Scribus/scribus/plugins/scriptplugin/scripterprefsgui.h (original)
+++ branches/Version135/Scribus/scribus/plugins/scriptplugin/scripterprefsgui.h Thu Jul 21 22:03:54 2011
@@ -10,6 +10,7 @@
#include "ui_scripterprefsgui.h"
#include "prefspanel.h"
+class SyntaxColors;
/*! \brief Subclass of PrefsPanel that's supplied to the prefs
dialog for use when showing plugin preferences. */
@@ -26,6 +27,9 @@
protected:
void setupSyntaxColors();
+ void setButtonIcon(QPushButton* button, QColor color);
+
+ SyntaxColors* syntaxColors;
protected slots:
void languageChange();
@@ -33,7 +37,11 @@
\author Petr Vanek
\warning I'm trying to handle multiple signals via single slot here. sender() Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise the return value is undefined. This function will return something apparently correct in other cases as well. However, its value may change during any function call, depending on what signal-slot connections are activated during that call. In Qt 3.0 the value will change more often than in 2.x. This function violates the object-oriented principle of modularity. However, getting access to the sender might be useful when many signals are connected to a single slot. The sender is undefined if the slot is called as a normal C++ function. */
void setColor();
+
void changeStartupScript();
+
+ signals:
+ void prefsChanged();
};
#endif
Modified: branches/Version135/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16727&path=/branches/Version135/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp (original)
+++ branches/Version135/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp Thu Jul 21 22:03:54 2011
@@ -196,6 +196,7 @@
{
panel = new ScripterPrefsGui(parent);
Q_CHECK_PTR(panel);
+ connect(panel, SIGNAL(prefsChanged()), scripterCore, SLOT(updateSyntaxHighlighter()));
caption = tr("Scripter");
icon = loadIcon("python.png");
return true;
More information about the scribus-commit
mailing list