Back to index

scribus-ng  1.3.4.dfsg+svn20071115
scripterprefsgui.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 #include "scripterprefsgui.h"
00008 #include "scriptercore.h"
00009 #include "pconsole.h"
00010 
00011 #include <qvariant.h>
00012 #include <qcheckbox.h>
00013 #include <qlabel.h>
00014 #include <qlineedit.h>
00015 #include <qlayout.h>
00016 #include <qtooltip.h>
00017 #include <qwhatsthis.h>
00018 #include <prefspanel.h>
00019 #include <qtabwidget.h>
00020 #include <qpushbutton.h>
00021 #include <qtoolbutton.h>
00022 #include <qcolordialog.h>
00023 #include <qfiledialog.h>
00024 
00025 
00026 ScripterPrefsGui::ScripterPrefsGui(QWidget* parent )
00027        : PrefsPanel(parent, "ScripterPrefsGui")
00028 {
00029        ScripterPrefsGuiBaseLayout = new QGridLayout(this, 1, 1, 10, 5, "ScripterPrefsGuiBaseLayout");
00030 
00031        tabWidget = new QTabWidget(this, "tabWidget");
00032        //tabWidget->setGeometry(QRect(70, 50, 380, 230));
00033 
00034        startupTab = new QWidget(tabWidget, "startupTab");
00035        tabWidget->insertTab(startupTab, tr("Extensions"));
00036        consoleTab = new QWidget(tabWidget, "consoleTab");
00037        tabWidget->insertTab(consoleTab, tr("Console"));
00038 
00039        extLayout = new QVBoxLayout(startupTab, 10, 5, "extLayout");
00040        extLayout->setAlignment(Qt::AlignTop);
00041        extensionScriptsChk = new QCheckBox(startupTab, "extensionScriptsChk");
00042        extLayout->addWidget(extensionScriptsChk);
00043 
00044        startupScriptLayout = new QHBoxLayout(0, 10, 5, "startupScriptLayout");
00045 
00046        startupScriptEditLabel = new QLabel(startupTab, "startupScriptEditLabel");
00047        startupScriptEdit = new QLineEdit(startupTab, "startupScriptEdit");
00048        startupScriptChangeButton = new QToolButton( startupTab, "startupScriptChangeButton" );
00049        startupScriptChangeButton->setMinimumSize( QSize( 88, 24 ) );
00050        startupScriptChangeButton->setText( tr( "Change..." ) );
00051        
00052        startupScriptLayout->addWidget(startupScriptEditLabel);
00053        startupScriptLayout->addWidget(startupScriptEdit);
00054        startupScriptLayout->addWidget(startupScriptChangeButton);
00055        extLayout->addLayout(startupScriptLayout);
00056        extScriptSpacer = new QSpacerItem(10, 10, QSizePolicy::Minimum, QSizePolicy::Expanding);
00057        extLayout->addItem(extScriptSpacer);
00058 
00059        // colors
00060        colorLayout = new QGridLayout(consoleTab, 1, 1, 10, 5);
00061 
00062        errorLabel = new QLabel(consoleTab);
00063        commentLabel = new QLabel(consoleTab);
00064        keywordLabel = new QLabel(consoleTab);
00065        signLabel = new QLabel(consoleTab);
00066        numberLabel = new QLabel(consoleTab);
00067        stringLabel = new QLabel(consoleTab);
00068        textLabel = new QLabel(consoleTab);
00069        errorButton = new QPushButton(consoleTab);
00070        commentButton = new QPushButton(consoleTab);
00071        keywordButton = new QPushButton(consoleTab);
00072        signButton = new QPushButton(consoleTab);
00073        numberButton = new QPushButton(consoleTab);
00074        stringButton = new QPushButton(consoleTab);
00075        textButton = new QPushButton(consoleTab);
00076 
00077        colorLayout->addWidget(textLabel, 0, 0);
00078        colorLayout->addWidget(textButton, 0, 1);
00079        colorLayout->addWidget(commentLabel, 1, 0);
00080        colorLayout->addWidget(commentButton, 1, 1);
00081        colorLayout->addWidget(keywordLabel, 2, 0);
00082        colorLayout->addWidget(keywordButton, 2, 1);
00083        colorLayout->addWidget(signLabel, 3, 0);
00084        colorLayout->addWidget(signButton, 3, 1);
00085        colorLayout->addWidget(errorLabel, 4, 0);
00086        colorLayout->addWidget(errorButton, 4, 1);
00087        colorLayout->addWidget(stringLabel, 5, 0);
00088        colorLayout->addWidget(stringButton, 5, 1);
00089        colorLayout->addWidget(numberLabel, 6, 0);
00090        colorLayout->addWidget(numberButton, 6, 1);
00091 
00092        ScripterPrefsGuiBaseLayout->addWidget(tabWidget, 0, 0);
00093        languageChange();
00094        setupSyntaxColors();
00095        resize(minimumSizeHint());
00096        clearWState(WState_Polished);
00097 
00098        // Set the state of the ext script enable checkbox
00099        extensionScriptsChk->setChecked(scripterCore->extensionsEnabled());
00100        // The startup script box should be disabled  if ext scripts are off
00101        startupScriptEdit->setEnabled(extensionScriptsChk->isChecked());
00102        connect(extensionScriptsChk, SIGNAL(toggled(bool)),
00103                      startupScriptEdit, SLOT(setEnabled(bool)));
00104 
00105        // signals and slots connections
00106        connect(extensionScriptsChk, SIGNAL(toggled(bool)), startupScriptEdit, SLOT(setEnabled(bool)));
00107        // colors
00108        connect(textButton, SIGNAL(clicked()), this, SLOT(setColor()));
00109        connect(commentButton, SIGNAL(clicked()), this, SLOT(setColor()));
00110        connect(keywordButton, SIGNAL(clicked()), this, SLOT(setColor()));
00111        connect(errorButton, SIGNAL(clicked()), this, SLOT(setColor()));
00112        connect(signButton, SIGNAL(clicked()), this, SLOT(setColor()));
00113        connect(stringButton, SIGNAL(clicked()), this, SLOT(setColor()));
00114        connect(numberButton, SIGNAL(clicked()), this, SLOT(setColor()));
00115        connect(startupScriptChangeButton, SIGNAL(clicked()), this, SLOT(changeStartupScript()));
00116 }
00117 
00118 /*
00119  *  Destroys the object and frees any allocated resources
00120  */
00121 ScripterPrefsGui::~ScripterPrefsGui()
00122 {
00123        // no need to delete child widgets, Qt does it all for us
00124 }
00125 
00126 /*
00127  *  Sets the strings of the subwidgets using the current
00128  *  language.
00129  */
00130 void ScripterPrefsGui::languageChange()
00131 {
00132        setCaption( tr("Scripter Preferences"));
00133        extensionScriptsChk->setText( tr("Enable Extension Scripts"));
00134        startupScriptEditLabel->setText( tr("Startup Script:"));
00135        errorLabel->setText( tr("Errors:", "syntax highlighting"));
00136        commentLabel->setText( tr("Comments:", "syntax highlighting"));
00137        keywordLabel->setText( tr("Keywords:", "syntax highlighting"));
00138        signLabel->setText( tr("Signs:", "syntax highlighting"));
00139        numberLabel->setText( tr("Numbers:", "syntax highlighting"));
00140        stringLabel->setText( tr("Strings:", "syntax highlighting"));
00141        textLabel->setText( tr("Base Texts:", "syntax highlighting"));
00142 }
00143 
00144 // Apply changes to prefs. Auto connected.
00145 void ScripterPrefsGui::apply()
00146 {
00147        scripterCore->setExtensionsEnabled(extensionScriptsChk->isChecked());
00148        scripterCore->setStartupScript(startupScriptEdit->text());
00149        // colors
00150        SyntaxColors *syntax = new SyntaxColors();
00151        syntax->textColor = textButton->paletteBackgroundColor();
00152        syntax->commentColor = commentButton->paletteBackgroundColor();
00153        syntax->keywordColor = keywordButton->paletteBackgroundColor();
00154        syntax->errorColor = errorButton->paletteBackgroundColor();
00155        syntax->signColor = signButton->paletteBackgroundColor();
00156        syntax->stringColor = stringButton->paletteBackgroundColor();
00157        syntax->numberColor = numberButton->paletteBackgroundColor();
00158        delete(syntax);
00159 }
00160 
00161 void ScripterPrefsGui::setColor()
00162 {
00163        QPushButton* button = (QPushButton*)sender();
00164        QColor color = QColorDialog::getColor(button->paletteBackgroundColor(), this, tr("Select Color"));
00165        if (color.isValid())
00166               button->setPaletteBackgroundColor(color);
00167 }
00168 
00169 void ScripterPrefsGui::setupSyntaxColors()
00170 {
00171        SyntaxColors *syntax = new SyntaxColors();
00172        textButton->setPaletteBackgroundColor(syntax->textColor);
00173        commentButton->setPaletteBackgroundColor(syntax->commentColor);
00174        keywordButton->setPaletteBackgroundColor(syntax->keywordColor);
00175        errorButton->setPaletteBackgroundColor(syntax->errorColor);
00176        signButton->setPaletteBackgroundColor(syntax->signColor);
00177        stringButton->setPaletteBackgroundColor(syntax->stringColor);
00178        numberButton->setPaletteBackgroundColor(syntax->numberColor);
00179        delete(syntax);
00180 }
00181 
00182 void ScripterPrefsGui::changeStartupScript()
00183 {
00184        QString currentScript=startupScriptEdit->text();
00185        QFileInfo fi(startupScriptEdit->text());
00186        if (!fi.exists())
00187               currentScript = QDir::homeDirPath();
00188 
00189        QString s = QFileDialog::getOpenFileName(currentScript, "Python Scripts (*.py *.PY)", this, "d", tr("Locate Startup Script"));
00190        if (!s.isEmpty())
00191               startupScriptEdit->setText(s);
00192 }
00193 
00194 #include "scripterprefsgui.moc"