Subversion Repositories Scribus

Compare Revisions

Ignore whitespace Rev 16727 → Rev 16728

/trunk/Scribus/scribus/plugins/scriptplugin/prefs_scripter.h
44,6 → 44,9
\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 // PREFS_SCRIPTER_H
/trunk/Scribus/scribus/plugins/scriptplugin/scripterprefsgui.h
10,6 → 10,7
#include "ui_scripterprefsgui.h"
#include "ui/prefspanel.h"
 
class SyntaxColors;
 
/*! \brief Subclass of PrefsPanel that's supplied to the prefs
dialog for use when showing plugin preferences. */
26,7 → 27,10
 
protected:
void setupSyntaxColors();
void setButtonIcon(QPushButton* button, QColor color);
 
SyntaxColors* syntaxColors;
 
protected slots:
void languageChange();
/*! \brief All requests for color change are handled here.
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
/trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.h
56,6 → 56,7
bool extensionsEnabled() const;
void setStartupScript(const QString& newScript);
void setExtensionsEnabled(bool enable);
void updateSyntaxHighlighter();
 
protected:
// Private helper functions
/trunk/Scribus/scribus/plugins/scriptplugin/pconsole.cpp
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);
375,8 → 382,19
}
}
 
SyntaxColors::~SyntaxColors()
void SyntaxColors::saveToPrefs()
{
PrefsContext* prefs = PrefsManager::instance()->prefsFile->getPluginContext("scriptplugin");
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)
/trunk/Scribus/scribus/plugins/scriptplugin/prefs_scripter.cpp
78,13 → 78,25
prefs->set("syntaxnumber", numberColor.name());
prefs->set("syntaxstring", stringColor.name());
prefs->set("syntaxtext", textColor.name());
 
emit prefsChanged();
}
}
 
void Prefs_Scripter::setColor()
{
QPushButton* button = (QPushButton*)sender();
QColor color = QColorDialog::getColor(button->palette().color(QPalette::Window), this);
QPushButton* button = (QPushButton*) sender();
 
QColor oldColor;
if (button == textButton) oldColor = textColor;
if (button == commentButton) oldColor = commentColor;
if (button == keywordButton) oldColor = keywordColor;
if (button == errorButton) oldColor = errorColor;
if (button == signButton) oldColor = signColor;
if (button == stringButton) oldColor = stringColor;
if (button == numberButton) oldColor = numberColor;
 
QColor color = QColorDialog::getColor(oldColor, this);
if (color.isValid() && button)
{
QPixmap pm(54, 14);
/trunk/Scribus/scribus/plugins/scriptplugin/scripterprefsgui.cpp
20,6 → 20,8
: PrefsPanel(parent)
{
setupUi(this);
 
syntaxColors = new SyntaxColors();
languageChange();
setupSyntaxColors();
34,13 → 36,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 → 51,7
*/
ScripterPrefsGui::~ScripterPrefsGui()
{
delete syntaxColors;
}
 
/*
74,49 → 77,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(color, 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()
/trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp
576,6 → 576,11
m_enableExtPython = enable;
}
 
void ScripterCore::updateSyntaxHighlighter()
{
pcon->updateSyntaxHighlighter();
}
 
const QString & ScripterCore::startupScript() const
{
return m_startupScript;
/trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
202,6 → 202,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;
212,6 → 213,7
{
panel = new Prefs_Scripter(parent);
Q_CHECK_PTR(panel);
connect(panel, SIGNAL(prefsChanged()), scripterCore, SLOT(updateSyntaxHighlighter()));
caption = tr("Scripter");
icon = loadIcon("python_16.png");
return true;
/trunk/Scribus/scribus/plugins/scriptplugin/pconsole.h
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
{