00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <QComboBox>
00027 # include <QFontDatabase>
00028 # include <QHeaderView>
00029 #endif
00030
00031 #include "DlgEditorImp.h"
00032 #include "PrefWidgets.h"
00033 #include "PythonEditor.h"
00034
00035 using namespace Gui;
00036 using namespace Gui::Dialog;
00037
00038 namespace Gui {
00039 namespace Dialog {
00040 struct DlgSettingsEditorP
00041 {
00042 QVector<QPair<QString, unsigned long> > colormap;
00043 };
00044 }
00045 }
00046
00047
00048
00056 DlgSettingsEditorImp::DlgSettingsEditorImp( QWidget* parent )
00057 : PreferencePage( parent )
00058 {
00059 this->setupUi(this);
00060 d = new DlgSettingsEditorP();
00061 QColor col;
00062 col = Qt::black;
00063 unsigned long lText = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
00064 d->colormap.push_back(QPair<QString, unsigned long>
00065 (QString::fromAscii(QT_TR_NOOP("Text")), lText));
00066 col = Qt::cyan;
00067 unsigned long lBookmarks = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
00068 d->colormap.push_back(QPair<QString, unsigned long>
00069 (QString::fromAscii(QT_TR_NOOP("Bookmark")), lBookmarks));
00070 col = Qt::red;
00071 unsigned long lBreakpnts = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
00072 d->colormap.push_back(QPair<QString, unsigned long>
00073 (QString::fromAscii(QT_TR_NOOP("Breakpoint")), lBreakpnts));
00074 col = Qt::blue;
00075 unsigned long lKeywords = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
00076 d->colormap.push_back(QPair<QString, unsigned long>
00077 (QString::fromAscii(QT_TR_NOOP("Keyword")), lKeywords));
00078 col.setRgb(0, 170, 0);
00079 unsigned long lComments = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
00080 d->colormap.push_back(QPair<QString, unsigned long>
00081 (QString::fromAscii(QT_TR_NOOP("Comment")), lComments));
00082 col.setRgb(160, 160, 164);
00083 unsigned long lBlockCom = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
00084 d->colormap.push_back(QPair<QString, unsigned long>
00085 (QString::fromAscii(QT_TR_NOOP("Block comment")), lBlockCom));
00086 col = Qt::blue;
00087 unsigned long lNumbers = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
00088 d->colormap.push_back(QPair<QString, unsigned long>
00089 (QString::fromAscii(QT_TR_NOOP("Number")), lNumbers));
00090 col = Qt::red;
00091 unsigned long lStrings = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
00092 d->colormap.push_back(QPair<QString, unsigned long>
00093 (QString::fromAscii(QT_TR_NOOP("String")), lStrings));
00094 col = Qt::red;
00095 unsigned long lCharacter = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
00096 d->colormap.push_back(QPair<QString, unsigned long>
00097 (QString::fromAscii(QT_TR_NOOP("Character")), lCharacter));
00098 col.setRgb(255, 170, 0);
00099 unsigned long lClass = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
00100 d->colormap.push_back(QPair<QString, unsigned long>
00101 (QString::fromAscii(QT_TR_NOOP("Class name")), lClass));
00102 col.setRgb(255, 170, 0);
00103 unsigned long lDefine = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
00104 d->colormap.push_back(QPair<QString, unsigned long>
00105 (QString::fromAscii(QT_TR_NOOP("Define name")), lDefine));
00106 col.setRgb(160, 160, 164);
00107 unsigned long lOperat = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
00108 d->colormap.push_back(QPair<QString, unsigned long>
00109 (QString::fromAscii(QT_TR_NOOP("Operator")), lOperat));
00110 col.setRgb(170, 170, 127);
00111 unsigned long lPyOutput = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
00112 d->colormap.push_back(QPair<QString, unsigned long>
00113 (QString::fromAscii(QT_TR_NOOP("Python output")), lPyOutput));
00114 col = Qt::red;
00115 unsigned long lPyError = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
00116 d->colormap.push_back(QPair<QString, unsigned long>
00117 (QString::fromAscii(QT_TR_NOOP("Python error")), lPyError));
00118
00119 QStringList labels; labels << tr("Items");
00120 this->displayItems->setHeaderLabels(labels);
00121 this->displayItems->header()->hide();
00122 for (QVector<QPair<QString, unsigned long> >::ConstIterator it = d->colormap.begin(); it != d->colormap.end(); ++it) {
00123 QTreeWidgetItem* item = new QTreeWidgetItem(this->displayItems);
00124 item->setText(0, tr((*it).first.toAscii()));
00125 }
00126 pythonSyntax = new PythonSyntaxHighlighter(textEdit1);
00127 pythonSyntax->setDocument(textEdit1->document());
00128 }
00129
00131 DlgSettingsEditorImp::~DlgSettingsEditorImp()
00132 {
00133
00134 delete pythonSyntax;
00135 delete d;
00136 }
00137
00142 void DlgSettingsEditorImp::on_displayItems_currentItemChanged(QTreeWidgetItem *item)
00143 {
00144 int index = displayItems->indexOfTopLevelItem(item);
00145 unsigned long col = d->colormap[index].second;
00146 colorButton->setColor(QColor((col >> 24) & 0xff, (col >> 16) & 0xff, (col >> 8) & 0xff));
00147 }
00148
00150 void DlgSettingsEditorImp::on_colorButton_changed()
00151 {
00152 QColor col = colorButton->color();
00153 unsigned long lcol = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
00154
00155 int index = displayItems->indexOfTopLevelItem(displayItems->currentItem());
00156 d->colormap[index].second = lcol;
00157 pythonSyntax->setColor( d->colormap[index].first, col );
00158 }
00159
00160 void DlgSettingsEditorImp::saveSettings()
00161 {
00162 EnableLineNumber->onSave();
00163 EnableFolding->onSave();
00164 tabSize->onSave();
00165 indentSize->onSave();
00166 radioTabs->onSave();
00167 radioSpaces->onSave();
00168
00169
00170 ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("Editor");
00171 for (QVector<QPair<QString, unsigned long> >::ConstIterator it = d->colormap.begin(); it != d->colormap.end(); ++it)
00172 hGrp->SetUnsigned((*it).first.toAscii(), (*it).second);
00173
00174 hGrp->SetInt( "FontSize", fontSize->value() );
00175 hGrp->SetASCII( "Font", fontFamily->currentText().toAscii() );
00176 }
00177
00178 void DlgSettingsEditorImp::loadSettings()
00179 {
00180 EnableLineNumber->onRestore();
00181 EnableFolding->onRestore();
00182 tabSize->onRestore();
00183 indentSize->onRestore();
00184 radioTabs->onRestore();
00185 radioSpaces->onRestore();
00186
00187 textEdit1->setPlainText(QString::fromAscii(
00188 "# Short Python sample\n"
00189 "import sys\n"
00190 "def foo(begin, end):\n"
00191 " i=begin\n"
00192 " while (i<end):\n"
00193 " print i\n"
00194 " i=i+1\n"
00195 " print \"Text\"\n"
00196 "\n"
00197 "foo(0, 20))\n"));
00198
00199
00200 ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("Editor");
00201 for (QVector<QPair<QString, unsigned long> >::Iterator it = d->colormap.begin(); it != d->colormap.end(); ++it){
00202 unsigned long col = hGrp->GetUnsigned((*it).first.toAscii(), (*it).second);
00203 (*it).second = col;
00204 QColor color;
00205 color.setRgb((col >> 24) & 0xff, (col >> 16) & 0xff, (col >> 8) & 0xff);
00206 pythonSyntax->setColor( (*it).first, color );
00207 }
00208
00209
00210
00211 fontSize->setValue(10);
00212 fontSize->setValue( hGrp->GetInt("FontSize", fontSize->value()) );
00213
00214 QFontDatabase fdb;
00215 QStringList familyNames = fdb.families( QFontDatabase::Any );
00216 fontFamily->addItems(familyNames);
00217 int index = familyNames.indexOf(QString::fromAscii(hGrp->GetASCII("Font", "Courier").c_str()));
00218 if (index < 0) index = 0;
00219 fontFamily->setCurrentIndex(index);
00220 on_fontFamily_activated();
00221
00222 displayItems->setCurrentItem(displayItems->topLevelItem(0));
00223 }
00224
00228 void DlgSettingsEditorImp::changeEvent(QEvent *e)
00229 {
00230 if (e->type() == QEvent::LanguageChange) {
00231 int index = 0;
00232 for (QVector<QPair<QString, unsigned long> >::ConstIterator it = d->colormap.begin(); it != d->colormap.end(); ++it)
00233 this->displayItems->topLevelItem(index++)->setText(0, tr((*it).first.toAscii()));
00234 this->retranslateUi(this);
00235 } else {
00236 QWidget::changeEvent(e);
00237 }
00238 }
00239
00240 void DlgSettingsEditorImp::on_fontFamily_activated()
00241 {
00242 const QString& fontFamily = this->fontFamily->currentText();
00243 int fontSize = this->fontSize->value();
00244 QFont ft(fontFamily, fontSize);
00245 textEdit1->setFont(ft);
00246 }
00247
00248 void DlgSettingsEditorImp::on_fontSize_valueChanged()
00249 {
00250 on_fontFamily_activated();
00251 }
00252
00253 #include "moc_DlgEditorImp.cpp"