2019-06-23 19:04:53 +02:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2023-06-21 16:41:22 +02:00
|
|
|
* Copyright (C) 2007-2023 Cppcheck team.
|
2019-06-23 19:04:53 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "codeeditstyledialog.h"
|
2021-04-03 21:30:50 +02:00
|
|
|
|
|
|
|
#include "codeeditor.h"
|
2020-04-13 13:44:48 +02:00
|
|
|
#include "codeeditstylecontrols.h"
|
2022-02-02 16:17:28 +01:00
|
|
|
|
2019-06-23 19:04:53 +02:00
|
|
|
#include <QDialogButtonBox>
|
2023-04-08 16:08:47 +02:00
|
|
|
#include <QFlags>
|
|
|
|
#include <QFontMetrics>
|
2022-02-02 16:17:28 +01:00
|
|
|
#include <QFormLayout>
|
2023-04-08 16:08:47 +02:00
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QtGlobal>
|
2019-06-23 19:04:53 +02:00
|
|
|
|
2022-04-13 12:24:00 +02:00
|
|
|
class QWidget;
|
|
|
|
|
2019-06-23 19:04:53 +02:00
|
|
|
const QString StyleEditDialog::mSampleDocument(
|
2019-06-25 15:29:15 +02:00
|
|
|
"/*****\n"
|
|
|
|
"* Multiline Comment\n"
|
|
|
|
"*****/\n"
|
|
|
|
"#include <QApplication>\n"
|
|
|
|
"#include <iostream>\n"
|
|
|
|
"\n"
|
|
|
|
"class fwdClass;\n"
|
|
|
|
"\n"
|
|
|
|
"int main(int argc, char *argv[])\n"
|
|
|
|
"{\n"
|
|
|
|
" QApplication a(argc, argv);\n"
|
|
|
|
" int nLife = 42;\n"
|
|
|
|
" w.show();\n"
|
|
|
|
" // single line comment\n"
|
|
|
|
" // line below is highlighted\n"
|
|
|
|
" fwdClass( nLife );\n"
|
|
|
|
" return a.exec();\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
"void class fwdClass( double dValue ) {\n"
|
|
|
|
" std::cout << \"Ipsum Lorem: \"\n"
|
|
|
|
" << nValue\n"
|
|
|
|
" << std::endl;\n"
|
|
|
|
"}\n");
|
2019-06-23 19:04:53 +02:00
|
|
|
|
|
|
|
const QStringList StyleEditDialog::mErrSymbolsList = (
|
2021-08-07 20:51:18 +02:00
|
|
|
QStringList(QStringList()
|
|
|
|
<< "nLife"
|
|
|
|
<< "dValue"
|
|
|
|
<< "nValue"));
|
2019-06-23 19:04:53 +02:00
|
|
|
const int StyleEditDialog::mErrLineNum = 16;
|
|
|
|
|
2019-06-25 15:29:15 +02:00
|
|
|
StyleEditDialog::StyleEditDialog(const CodeEditorStyle& newStyle,
|
|
|
|
QWidget *parent /*= nullptr*/) :
|
|
|
|
QDialog(parent),
|
|
|
|
mStyleIncoming(newStyle),
|
|
|
|
mStyleOutgoing(newStyle)
|
2019-06-23 19:04:53 +02:00
|
|
|
{
|
|
|
|
QVBoxLayout *vboxMain = new QVBoxLayout(this);
|
|
|
|
QHBoxLayout *hboxEdit = new QHBoxLayout();
|
|
|
|
// Color/Weight controls
|
|
|
|
QFormLayout *flEditControls = new QFormLayout();
|
2019-06-25 15:29:15 +02:00
|
|
|
mBtnWidgetColorFG = new SelectColorButton(this);
|
|
|
|
flEditControls->addRow(QObject::tr("Editor Foreground Color"),
|
|
|
|
mBtnWidgetColorFG);
|
|
|
|
mBtnWidgetColorBG = new SelectColorButton(this);
|
|
|
|
flEditControls->addRow(QObject::tr("Editor Background Color"),
|
|
|
|
mBtnWidgetColorBG);
|
|
|
|
mBtnHighlightBG = new SelectColorButton(this);
|
|
|
|
flEditControls->addRow(QObject::tr("Highlight Background Color"),
|
|
|
|
mBtnHighlightBG);
|
|
|
|
mBtnLineNumFG = new SelectColorButton(this);
|
|
|
|
flEditControls->addRow(QObject::tr("Line Number Foreground Color"),
|
|
|
|
mBtnLineNumFG);
|
|
|
|
mBtnLineNumBG = new SelectColorButton(this);
|
|
|
|
flEditControls->addRow(QObject::tr("Line Number Background Color"),
|
|
|
|
mBtnLineNumBG);
|
|
|
|
mBtnKeywordFG = new SelectColorButton(this);
|
|
|
|
flEditControls->addRow(QObject::tr("Keyword Foreground Color"),
|
|
|
|
mBtnKeywordFG);
|
|
|
|
mCBKeywordWeight = new SelectFontWeightCombo(this);
|
|
|
|
flEditControls->addRow(QObject::tr("Keyword Font Weight"),
|
|
|
|
mCBKeywordWeight);
|
|
|
|
mBtnClassFG = new SelectColorButton(this);
|
2019-07-12 17:55:44 +02:00
|
|
|
flEditControls->addRow(QObject::tr("Class Foreground Color"),
|
2019-06-25 15:29:15 +02:00
|
|
|
mBtnClassFG);
|
|
|
|
mCBClassWeight = new SelectFontWeightCombo(this);
|
|
|
|
flEditControls->addRow(QObject::tr("Class Font Weight"),
|
|
|
|
mCBClassWeight);
|
|
|
|
mBtnQuoteFG = new SelectColorButton(this);
|
|
|
|
flEditControls->addRow(QObject::tr("Quote Foreground Color"),
|
|
|
|
mBtnQuoteFG);
|
|
|
|
mCBQuoteWeight = new SelectFontWeightCombo(this);
|
|
|
|
flEditControls->addRow(QObject::tr("Quote Font Weight"),
|
|
|
|
mCBQuoteWeight);
|
|
|
|
mBtnCommentFG = new SelectColorButton(this);
|
|
|
|
flEditControls->addRow(QObject::tr("Comment Foreground Color"),
|
|
|
|
mBtnCommentFG);
|
|
|
|
mCBCommentWeight = new SelectFontWeightCombo(this);
|
|
|
|
flEditControls->addRow(QObject::tr("Comment Font Weight"),
|
|
|
|
mCBCommentWeight);
|
|
|
|
mBtnSymbolFG = new SelectColorButton(this);
|
|
|
|
flEditControls->addRow(QObject::tr("Symbol Foreground Color"),
|
|
|
|
mBtnSymbolFG);
|
|
|
|
mBtnSymbolBG = new SelectColorButton(this);
|
|
|
|
flEditControls->addRow(QObject::tr("Symbol Background Color"),
|
|
|
|
mBtnSymbolBG);
|
|
|
|
mCBSymbolWeight = new SelectFontWeightCombo(this);
|
|
|
|
flEditControls->addRow(QObject::tr("Symbol Font Weight"),
|
|
|
|
mCBSymbolWeight);
|
|
|
|
hboxEdit->addLayout(flEditControls);
|
2019-06-23 19:04:53 +02:00
|
|
|
// CodeEditor to display Style
|
2019-06-25 15:29:15 +02:00
|
|
|
mSampleEditor = new CodeEditor(this);
|
|
|
|
QFont sampleFont("Monospace");
|
2019-06-23 19:04:53 +02:00
|
|
|
QFontMetrics fm(sampleFont);
|
2022-02-01 17:26:16 +01:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
|
|
|
|
mSampleEditor->setMinimumWidth(fm.horizontalAdvance(QString(40, 'W')));
|
|
|
|
#else
|
2019-07-23 10:28:45 +02:00
|
|
|
mSampleEditor->setMinimumWidth(fm.width(QString(40, 'W')));
|
2022-02-01 17:26:16 +01:00
|
|
|
#endif
|
2019-06-23 19:04:53 +02:00
|
|
|
// designate highlight, errors, and symbols
|
2019-06-25 15:29:15 +02:00
|
|
|
mSampleEditor->setError(mSampleDocument, mErrLineNum, mErrSymbolsList);
|
2019-06-23 19:04:53 +02:00
|
|
|
// End Controls
|
2019-06-25 15:29:15 +02:00
|
|
|
hboxEdit->addWidget(mSampleEditor);
|
|
|
|
vboxMain->addLayout(hboxEdit);
|
2019-06-23 19:04:53 +02:00
|
|
|
|
|
|
|
// Default Controls
|
|
|
|
QHBoxLayout *hboxDefaultControls = new QHBoxLayout();
|
2019-06-25 15:29:15 +02:00
|
|
|
mBtnDefaultLight = new QPushButton(QObject::tr("Set to Default Light"),
|
|
|
|
this);
|
|
|
|
mBtnDefaultDark = new QPushButton(QObject::tr("Set to Default Dark"),
|
|
|
|
this);
|
|
|
|
hboxDefaultControls->addStretch(1);
|
|
|
|
hboxDefaultControls->addWidget(mBtnDefaultLight);
|
|
|
|
hboxDefaultControls->addWidget(mBtnDefaultDark);
|
|
|
|
hboxDefaultControls->addStretch(1);
|
|
|
|
vboxMain->addLayout(hboxDefaultControls);
|
|
|
|
vboxMain->addStretch(2);
|
2019-06-23 19:04:53 +02:00
|
|
|
// dialog controls
|
|
|
|
QDialogButtonBox *dBtnBox = new QDialogButtonBox(
|
|
|
|
QDialogButtonBox::Cancel |
|
|
|
|
QDialogButtonBox::Ok |
|
2019-06-25 15:29:15 +02:00
|
|
|
QDialogButtonBox::Reset);
|
|
|
|
vboxMain->addStretch(1);
|
|
|
|
vboxMain->addWidget(dBtnBox);
|
2019-06-23 19:04:53 +02:00
|
|
|
|
|
|
|
// setup values for style controls
|
|
|
|
updateControls();
|
|
|
|
updateStyle();
|
|
|
|
|
2019-06-25 15:29:15 +02:00
|
|
|
connect(dBtnBox, SIGNAL(accepted()), this, SLOT(accept()));
|
|
|
|
connect(dBtnBox, SIGNAL(rejected()), this, SLOT(reject()));
|
|
|
|
connect(dBtnBox->button(QDialogButtonBox::Reset), SIGNAL(clicked()),
|
|
|
|
this, SLOT(resetStyle()));
|
|
|
|
connect(mBtnDefaultLight, SIGNAL(clicked()),
|
|
|
|
this, SLOT(setStyleDefaultLight()));
|
|
|
|
connect(mBtnDefaultDark, SIGNAL(clicked()),
|
|
|
|
this, SLOT(setStyleDefaultDark()));
|
2019-07-25 08:29:42 +02:00
|
|
|
connect(mBtnWidgetColorFG, SIGNAL(colorChanged(const QColor&)),
|
|
|
|
this, SLOT(colorChangedWidgetFG(const QColor&)));
|
|
|
|
connect(mBtnWidgetColorBG, SIGNAL(colorChanged(const QColor&)),
|
|
|
|
this, SLOT(colorChangedWidgetBG(const QColor&)));
|
|
|
|
connect(mBtnHighlightBG, SIGNAL(colorChanged(const QColor&)),
|
|
|
|
this, SLOT(colorChangedHighlightBG(const QColor&)));
|
|
|
|
connect(mBtnLineNumFG, SIGNAL(colorChanged(const QColor&)),
|
|
|
|
this, SLOT(colorChangedLineNumFG(const QColor&)));
|
|
|
|
connect(mBtnLineNumBG, SIGNAL(colorChanged(const QColor&)),
|
|
|
|
this, SLOT(colorChangedLineNumBG(const QColor&)));
|
|
|
|
connect(mBtnKeywordFG, SIGNAL(colorChanged(const QColor&)),
|
|
|
|
this, SLOT(colorChangedKeywordFG(const QColor&)));
|
|
|
|
connect(mCBKeywordWeight, SIGNAL(weightChanged(const QFont::Weight&)),
|
|
|
|
this, SLOT(weightChangedKeyword(const QFont::Weight&)));
|
|
|
|
connect(mBtnClassFG, SIGNAL(colorChanged(const QColor&)),
|
|
|
|
this, SLOT(colorChangedClassFG(const QColor&)));
|
|
|
|
connect(mCBClassWeight, SIGNAL(weightChanged(const QFont::Weight&)),
|
|
|
|
this, SLOT(weightChangedClass(const QFont::Weight&)));
|
|
|
|
connect(mBtnQuoteFG, SIGNAL(colorChanged(const QColor&)),
|
|
|
|
this, SLOT(colorChangedQuoteFG(const QColor&)));
|
|
|
|
connect(mCBQuoteWeight, SIGNAL(weightChanged(const QFont::Weight&)),
|
|
|
|
this, SLOT(weightChangedQuote(const QFont::Weight&)));
|
|
|
|
connect(mBtnCommentFG, SIGNAL(colorChanged(const QColor&)),
|
|
|
|
this, SLOT(colorChangedCommentFG(const QColor&)));
|
|
|
|
connect(mCBCommentWeight, SIGNAL(weightChanged(const QFont::Weight&)),
|
|
|
|
this, SLOT(weightChangedComment(const QFont::Weight&)));
|
|
|
|
connect(mBtnSymbolFG, SIGNAL(colorChanged(const QColor&)),
|
|
|
|
this, SLOT(colorChangedSymbolFG(const QColor&)));
|
|
|
|
connect(mBtnSymbolBG, SIGNAL(colorChanged(const QColor&)),
|
|
|
|
this, SLOT(colorChangedSymbolBG(const QColor&)));
|
|
|
|
connect(mCBSymbolWeight, SIGNAL(weightChanged(const QFont::Weight&)),
|
|
|
|
this, SLOT(weightChangedSymbol(const QFont::Weight&)));
|
2019-06-23 19:04:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void StyleEditDialog::updateControls()
|
|
|
|
{
|
2019-06-25 15:29:15 +02:00
|
|
|
mBtnWidgetColorFG->setColor(mStyleOutgoing.widgetFGColor);
|
|
|
|
mBtnWidgetColorBG->setColor(mStyleOutgoing.widgetBGColor);
|
|
|
|
mBtnHighlightBG->setColor(mStyleOutgoing.highlightBGColor);
|
|
|
|
mBtnLineNumFG->setColor(mStyleOutgoing.lineNumFGColor);
|
|
|
|
mBtnLineNumBG->setColor(mStyleOutgoing.lineNumBGColor);
|
|
|
|
mBtnKeywordFG->setColor(mStyleOutgoing.keywordColor);
|
|
|
|
mCBKeywordWeight->setWeight(mStyleOutgoing.keywordWeight);
|
|
|
|
mBtnClassFG->setColor(mStyleOutgoing.classColor);
|
|
|
|
mCBClassWeight->setWeight(mStyleOutgoing.classWeight);
|
|
|
|
mBtnQuoteFG->setColor(mStyleOutgoing.quoteColor);
|
|
|
|
mCBQuoteWeight->setWeight(mStyleOutgoing.quoteWeight);
|
|
|
|
mBtnCommentFG->setColor(mStyleOutgoing.commentColor);
|
|
|
|
mCBCommentWeight->setWeight(mStyleOutgoing.commentWeight);
|
|
|
|
mBtnSymbolFG->setColor(mStyleOutgoing.symbolFGColor);
|
|
|
|
mBtnSymbolBG->setColor(mStyleOutgoing.symbolBGColor);
|
|
|
|
mCBSymbolWeight->setWeight(mStyleOutgoing.symbolWeight);
|
2019-06-23 19:04:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void StyleEditDialog::updateStyle()
|
|
|
|
{
|
2019-06-25 15:29:15 +02:00
|
|
|
mBtnDefaultLight->setEnabled(mStyleOutgoing != defaultStyleLight);
|
|
|
|
mBtnDefaultDark->setEnabled(mStyleOutgoing != defaultStyleDark);
|
2019-06-23 19:04:53 +02:00
|
|
|
// set Editor Styling
|
2019-06-25 15:29:15 +02:00
|
|
|
mSampleEditor->setStyle(mStyleOutgoing);
|
2019-06-23 19:04:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CodeEditorStyle StyleEditDialog::getStyle()
|
|
|
|
{
|
|
|
|
return mStyleOutgoing;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StyleEditDialog::resetStyle()
|
|
|
|
{
|
|
|
|
mStyleOutgoing = mStyleIncoming;
|
|
|
|
updateControls();
|
|
|
|
updateStyle();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StyleEditDialog::setStyleDefaultLight()
|
|
|
|
{
|
|
|
|
mStyleOutgoing = defaultStyleLight;
|
|
|
|
updateControls();
|
|
|
|
updateStyle();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StyleEditDialog::setStyleDefaultDark()
|
|
|
|
{
|
|
|
|
mStyleOutgoing = defaultStyleDark;
|
|
|
|
updateControls();
|
|
|
|
updateStyle();
|
|
|
|
}
|
|
|
|
|
2019-07-24 08:30:36 +02:00
|
|
|
void StyleEditDialog::colorChangedWidgetFG(const QColor& newColor)
|
2019-06-23 19:04:53 +02:00
|
|
|
{
|
|
|
|
mStyleOutgoing.widgetFGColor = newColor;
|
|
|
|
updateStyle();
|
|
|
|
}
|
|
|
|
|
2019-07-24 08:30:36 +02:00
|
|
|
void StyleEditDialog::colorChangedWidgetBG(const QColor& newColor)
|
2019-06-23 19:04:53 +02:00
|
|
|
{
|
|
|
|
mStyleOutgoing.widgetBGColor = newColor;
|
|
|
|
updateStyle();
|
|
|
|
}
|
|
|
|
|
2019-07-24 08:30:36 +02:00
|
|
|
void StyleEditDialog::colorChangedHighlightBG(const QColor& newColor)
|
2019-06-23 19:04:53 +02:00
|
|
|
{
|
|
|
|
mStyleOutgoing.highlightBGColor = newColor;
|
|
|
|
updateStyle();
|
|
|
|
}
|
|
|
|
|
2019-07-24 08:30:36 +02:00
|
|
|
void StyleEditDialog::colorChangedLineNumFG(const QColor& newColor)
|
2019-06-23 19:04:53 +02:00
|
|
|
{
|
|
|
|
mStyleOutgoing.lineNumFGColor = newColor;
|
|
|
|
updateStyle();
|
|
|
|
}
|
|
|
|
|
2019-07-24 08:30:36 +02:00
|
|
|
void StyleEditDialog::colorChangedLineNumBG(const QColor& newColor)
|
2019-06-23 19:04:53 +02:00
|
|
|
{
|
|
|
|
mStyleOutgoing.lineNumBGColor = newColor;
|
|
|
|
updateStyle();
|
|
|
|
}
|
|
|
|
|
2019-07-24 08:30:36 +02:00
|
|
|
void StyleEditDialog::colorChangedKeywordFG(const QColor& newColor)
|
2019-06-23 19:04:53 +02:00
|
|
|
{
|
|
|
|
mStyleOutgoing.keywordColor = newColor;
|
|
|
|
updateStyle();
|
|
|
|
}
|
|
|
|
|
2019-07-24 08:30:36 +02:00
|
|
|
void StyleEditDialog::weightChangedKeyword(const QFont::Weight& newWeight)
|
2019-06-23 19:04:53 +02:00
|
|
|
{
|
|
|
|
mStyleOutgoing.keywordWeight = newWeight;
|
|
|
|
updateStyle();
|
|
|
|
}
|
|
|
|
|
2019-07-24 08:30:36 +02:00
|
|
|
void StyleEditDialog::colorChangedClassFG(const QColor& newColor)
|
2019-06-23 19:04:53 +02:00
|
|
|
{
|
|
|
|
mStyleOutgoing.classColor = newColor;
|
|
|
|
updateStyle();
|
|
|
|
}
|
|
|
|
|
2019-07-24 08:30:36 +02:00
|
|
|
void StyleEditDialog::weightChangedClass(const QFont::Weight& newWeight)
|
2019-06-23 19:04:53 +02:00
|
|
|
{
|
|
|
|
mStyleOutgoing.classWeight = newWeight;
|
|
|
|
updateStyle();
|
|
|
|
}
|
|
|
|
|
2019-07-24 08:30:36 +02:00
|
|
|
void StyleEditDialog::colorChangedQuoteFG(const QColor& newColor)
|
2019-06-23 19:04:53 +02:00
|
|
|
{
|
|
|
|
mStyleOutgoing.quoteColor = newColor;
|
|
|
|
updateStyle();
|
|
|
|
}
|
|
|
|
|
2019-07-24 08:30:36 +02:00
|
|
|
void StyleEditDialog::weightChangedQuote(const QFont::Weight& newWeight)
|
2019-06-23 19:04:53 +02:00
|
|
|
{
|
|
|
|
mStyleOutgoing.quoteWeight = newWeight;
|
|
|
|
updateStyle();
|
|
|
|
}
|
|
|
|
|
2019-07-24 08:30:36 +02:00
|
|
|
void StyleEditDialog::colorChangedCommentFG(const QColor& newColor)
|
2019-06-23 19:04:53 +02:00
|
|
|
{
|
|
|
|
mStyleOutgoing.commentColor = newColor;
|
|
|
|
updateStyle();
|
|
|
|
}
|
|
|
|
|
2019-07-24 08:30:36 +02:00
|
|
|
void StyleEditDialog::weightChangedComment(const QFont::Weight& newWeight)
|
2019-06-23 19:04:53 +02:00
|
|
|
{
|
|
|
|
mStyleOutgoing.commentWeight = newWeight;
|
|
|
|
updateStyle();
|
|
|
|
}
|
|
|
|
|
2019-07-24 08:30:36 +02:00
|
|
|
void StyleEditDialog::colorChangedSymbolFG(const QColor& newColor)
|
2019-06-23 19:04:53 +02:00
|
|
|
{
|
|
|
|
mStyleOutgoing.symbolFGColor = newColor;
|
|
|
|
updateStyle();
|
|
|
|
}
|
|
|
|
|
2019-07-24 08:30:36 +02:00
|
|
|
void StyleEditDialog::colorChangedSymbolBG(const QColor& newColor)
|
2019-06-23 19:04:53 +02:00
|
|
|
{
|
|
|
|
mStyleOutgoing.symbolBGColor = newColor;
|
|
|
|
updateStyle();
|
|
|
|
}
|
|
|
|
|
2019-07-24 08:30:36 +02:00
|
|
|
void StyleEditDialog::weightChangedSymbol(const QFont::Weight& newWeight)
|
2019-06-23 19:04:53 +02:00
|
|
|
{
|
|
|
|
mStyleOutgoing.symbolWeight = newWeight;
|
|
|
|
updateStyle();
|
|
|
|
}
|