- enhancement: correctly handle auto indents for statement span many lines;
- enhancment: only use colors have good contrasts with the background in the class browser and code completion suggestion window
This commit is contained in:
parent
2db0d95593
commit
4eec185ac4
2
NEWS.md
2
NEWS.md
|
@ -4,6 +4,8 @@ Version 0.7.6
|
||||||
- enhancement: the line containing 'public:' / 'private:' / 'protected:' / 'case *:' will use of indents of the surrounding '{' line, instead of just unindent one level
|
- enhancement: the line containing 'public:' / 'private:' / 'protected:' / 'case *:' will use of indents of the surrounding '{' line, instead of just unindent one level
|
||||||
- enhancement: correctly handle auto indents for multi-level embedding complex statements like 'for(...) if (...) printf();
|
- enhancement: correctly handle auto indents for multi-level embedding complex statements like 'for(...) if (...) printf();
|
||||||
- change: Don't use 'pause' in the console pauser, in case of privilege problems.
|
- change: Don't use 'pause' in the console pauser, in case of privilege problems.
|
||||||
|
- enhancement: correctly handle auto indents for statement span many lines;
|
||||||
|
- enhancment: only use colors have good contrasts with the background in the class browser and code completion suggestion window
|
||||||
|
|
||||||
Version 0.7.5
|
Version 0.7.5
|
||||||
- enhancement: more accurate auto indent calculation
|
- enhancement: more accurate auto indent calculation
|
||||||
|
|
|
@ -425,56 +425,67 @@ void MainWindow::updateCompileActions()
|
||||||
|| mEditorList->pageCount()>0);
|
|| mEditorList->pageCount()>0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
static bool haveGoodContrast(const QColor& c1, const QColor &c2) {
|
||||||
|
int lightness1 = c1.lightness();
|
||||||
|
int lightness2 = c2.lightness();
|
||||||
|
return std::abs(lightness1 - lightness2)>=150;
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::updateEditorColorSchemes()
|
void MainWindow::updateEditorColorSchemes()
|
||||||
{
|
{
|
||||||
|
if (!mStatementColors)
|
||||||
|
return;
|
||||||
|
mStatementColors->clear();
|
||||||
|
|
||||||
mEditorList->applyColorSchemes(pSettings->editor().colorScheme());
|
mEditorList->applyColorSchemes(pSettings->editor().colorScheme());
|
||||||
QString schemeName = pSettings->editor().colorScheme();
|
QString schemeName = pSettings->editor().colorScheme();
|
||||||
//color for code completion popup
|
//color for code completion popup
|
||||||
PColorSchemeItem item;
|
PColorSchemeItem item;
|
||||||
|
|
||||||
item = pColorManager->getItem(schemeName, SYNS_AttrFunction);
|
item = pColorManager->getItem(schemeName, SYNS_AttrFunction);
|
||||||
if (item) {
|
QColor baseColor = palette().color(QPalette::Base);
|
||||||
|
if (item && haveGoodContrast(item->foreground(), baseColor)) {
|
||||||
mStatementColors->insert(StatementKind::skFunction,item);
|
mStatementColors->insert(StatementKind::skFunction,item);
|
||||||
mStatementColors->insert(StatementKind::skConstructor,item);
|
mStatementColors->insert(StatementKind::skConstructor,item);
|
||||||
mStatementColors->insert(StatementKind::skDestructor,item);
|
mStatementColors->insert(StatementKind::skDestructor,item);
|
||||||
}
|
}
|
||||||
item = pColorManager->getItem(schemeName, SYNS_AttrClass);
|
item = pColorManager->getItem(schemeName, SYNS_AttrClass);
|
||||||
if (item) {
|
if (item && haveGoodContrast(item->foreground(), baseColor)) {
|
||||||
mStatementColors->insert(StatementKind::skClass,item);
|
mStatementColors->insert(StatementKind::skClass,item);
|
||||||
mStatementColors->insert(StatementKind::skTypedef,item);
|
mStatementColors->insert(StatementKind::skTypedef,item);
|
||||||
mStatementColors->insert(StatementKind::skAlias,item);
|
mStatementColors->insert(StatementKind::skAlias,item);
|
||||||
}
|
}
|
||||||
item = pColorManager->getItem(schemeName, SYNS_AttrIdentifier);
|
item = pColorManager->getItem(schemeName, SYNS_AttrIdentifier);
|
||||||
if (item) {
|
if (item && haveGoodContrast(item->foreground(), baseColor)) {
|
||||||
mStatementColors->insert(StatementKind::skEnumType,item);
|
mStatementColors->insert(StatementKind::skEnumType,item);
|
||||||
mStatementColors->insert(StatementKind::skEnumClassType,item);
|
mStatementColors->insert(StatementKind::skEnumClassType,item);
|
||||||
}
|
}
|
||||||
item = pColorManager->getItem(schemeName, SYNS_AttrVariable);
|
item = pColorManager->getItem(schemeName, SYNS_AttrVariable);
|
||||||
if (item) {
|
if (item && haveGoodContrast(item->foreground(), baseColor)) {
|
||||||
mStatementColors->insert(StatementKind::skVariable,item);
|
mStatementColors->insert(StatementKind::skVariable,item);
|
||||||
}
|
}
|
||||||
item = pColorManager->getItem(schemeName, SYNS_AttrLocalVariable);
|
item = pColorManager->getItem(schemeName, SYNS_AttrLocalVariable);
|
||||||
if (item) {
|
if (item && haveGoodContrast(item->foreground(), baseColor)) {
|
||||||
mStatementColors->insert(StatementKind::skLocalVariable,item);
|
mStatementColors->insert(StatementKind::skLocalVariable,item);
|
||||||
mStatementColors->insert(StatementKind::skParameter,item);
|
mStatementColors->insert(StatementKind::skParameter,item);
|
||||||
}
|
}
|
||||||
item = pColorManager->getItem(schemeName, SYNS_AttrGlobalVariable);
|
item = pColorManager->getItem(schemeName, SYNS_AttrGlobalVariable);
|
||||||
if (item) {
|
if (item && haveGoodContrast(item->foreground(), baseColor)) {
|
||||||
mStatementColors->insert(StatementKind::skGlobalVariable,item);
|
mStatementColors->insert(StatementKind::skGlobalVariable,item);
|
||||||
}
|
}
|
||||||
item = pColorManager->getItem(schemeName, SYNS_AttrPreprocessor);
|
item = pColorManager->getItem(schemeName, SYNS_AttrPreprocessor);
|
||||||
if (item) {
|
if (item && haveGoodContrast(item->foreground(), baseColor)) {
|
||||||
mStatementColors->insert(StatementKind::skPreprocessor,item);
|
mStatementColors->insert(StatementKind::skPreprocessor,item);
|
||||||
mStatementColors->insert(StatementKind::skEnum,item);
|
mStatementColors->insert(StatementKind::skEnum,item);
|
||||||
mHeaderCompletionPopup->setSuggestionColor(item->foreground());
|
mHeaderCompletionPopup->setSuggestionColor(item->foreground());
|
||||||
}
|
}
|
||||||
item = pColorManager->getItem(schemeName, SYNS_AttrReservedWord);
|
item = pColorManager->getItem(schemeName, SYNS_AttrReservedWord);
|
||||||
if (item) {
|
if (item && haveGoodContrast(item->foreground(), baseColor)) {
|
||||||
mStatementColors->insert(StatementKind::skKeyword,item);
|
mStatementColors->insert(StatementKind::skKeyword,item);
|
||||||
mStatementColors->insert(StatementKind::skUserCodeSnippet,item);
|
mStatementColors->insert(StatementKind::skUserCodeSnippet,item);
|
||||||
}
|
}
|
||||||
item = pColorManager->getItem(schemeName, SYNS_AttrString);
|
item = pColorManager->getItem(schemeName, SYNS_AttrString);
|
||||||
if (item) {
|
if (item && haveGoodContrast(item->foreground(), baseColor)) {
|
||||||
mStatementColors->insert(StatementKind::skNamespace,item);
|
mStatementColors->insert(StatementKind::skNamespace,item);
|
||||||
mStatementColors->insert(StatementKind::skNamespaceAlias,item);
|
mStatementColors->insert(StatementKind::skNamespaceAlias,item);
|
||||||
}
|
}
|
||||||
|
@ -490,6 +501,7 @@ void MainWindow::applySettings()
|
||||||
else
|
else
|
||||||
QApplication::setStyle("fusion");
|
QApplication::setStyle("fusion");
|
||||||
qApp->setPalette(appTheme->palette());
|
qApp->setPalette(appTheme->palette());
|
||||||
|
updateEditorColorSchemes();
|
||||||
|
|
||||||
QFont font(pSettings->environment().interfaceFont(),
|
QFont font(pSettings->environment().interfaceFont(),
|
||||||
pSettings->environment().interfaceFontSize());
|
pSettings->environment().interfaceFontSize());
|
||||||
|
|
|
@ -1455,13 +1455,6 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
|
||||||
int len = matchingIndents.length();
|
int len = matchingIndents.length();
|
||||||
while (i<len && !newIndents.isEmpty()) {
|
while (i<len && !newIndents.isEmpty()) {
|
||||||
int indent = matchingIndents[i];
|
int indent = matchingIndents[i];
|
||||||
if (indent >= sitStatemntBrace) {
|
|
||||||
int counts = indent - sitStatemntBrace;
|
|
||||||
for (int j=0;j<counts;j++) {
|
|
||||||
matchingIndents.insert(i+1,sitStatement);
|
|
||||||
}
|
|
||||||
len = matchingIndents.length();
|
|
||||||
}
|
|
||||||
int idx = newIndents.lastIndexOf(indent);
|
int idx = newIndents.lastIndexOf(indent);
|
||||||
if (idx >=0) {
|
if (idx >=0) {
|
||||||
newIndents.remove(idx,newIndents.length()-idx);
|
newIndents.remove(idx,newIndents.length()-idx);
|
||||||
|
@ -1471,10 +1464,20 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if (i>=len) {
|
if (i>=len) {
|
||||||
indentSpaces = leftSpaces(mLines->getString(l-1));
|
// we found the where the indent started
|
||||||
// if (newIndents.length()>0)
|
if (len>0 && !range.matchingIndents.isEmpty()
|
||||||
// indentSpaces+=mTabWidth;
|
&&
|
||||||
break;
|
( matchingIndents.back()== sitBrace
|
||||||
|
|| matchingIndents.back() == sitStatement
|
||||||
|
) ) {
|
||||||
|
// but it's not a complete statement
|
||||||
|
matchingIndents = range.matchingIndents;
|
||||||
|
} else {
|
||||||
|
indentSpaces = leftSpaces(mLines->getString(l-1));
|
||||||
|
if (newIndents.length()>0)
|
||||||
|
indentSpaces+=mTabWidth;
|
||||||
|
break;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
matchingIndents = range.matchingIndents + matchingIndents.mid(i);
|
matchingIndents = range.matchingIndents + matchingIndents.mid(i);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,6 @@ enum SynIndentType {
|
||||||
sitParenthesis = 1,
|
sitParenthesis = 1,
|
||||||
sitBracket = 2,
|
sitBracket = 2,
|
||||||
sitStatement = 3,
|
sitStatement = 3,
|
||||||
sitStatemntBrace = 100
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SynRangeState {
|
struct SynRangeState {
|
||||||
|
|
|
@ -393,8 +393,9 @@ void SynEditCppHighlighter::braceOpenProc()
|
||||||
if (mRange.getLastIndent() == sitStatement) {
|
if (mRange.getLastIndent() == sitStatement) {
|
||||||
// if last indent is started by 'if' 'for' etc
|
// if last indent is started by 'if' 'for' etc
|
||||||
// just replace it
|
// just replace it
|
||||||
int counts = popStatementIndents();
|
while (mRange.getLastIndent() == sitStatement)
|
||||||
pushIndents(sitStatemntBrace+counts);
|
popIndents(sitStatement);
|
||||||
|
pushIndents(sitBrace);
|
||||||
// int idx = mRange.indents.length()-1;
|
// int idx = mRange.indents.length()-1;
|
||||||
// if (idx < mRange.firstIndentThisLine) {
|
// if (idx < mRange.firstIndentThisLine) {
|
||||||
// mRange.firstIndentThisLine = idx;
|
// mRange.firstIndentThisLine = idx;
|
||||||
|
@ -1358,8 +1359,6 @@ void SynEditCppHighlighter::processChar()
|
||||||
void SynEditCppHighlighter::popIndents(int indentType)
|
void SynEditCppHighlighter::popIndents(int indentType)
|
||||||
{
|
{
|
||||||
while (!mRange.indents.isEmpty() && mRange.indents.back()!=indentType) {
|
while (!mRange.indents.isEmpty() && mRange.indents.back()!=indentType) {
|
||||||
if (indentType == sitBrace && mRange.indents.back() >= sitStatemntBrace)
|
|
||||||
break;
|
|
||||||
mRange.indents.pop_back();
|
mRange.indents.pop_back();
|
||||||
}
|
}
|
||||||
if (!mRange.indents.isEmpty()) {
|
if (!mRange.indents.isEmpty()) {
|
||||||
|
@ -1371,20 +1370,6 @@ void SynEditCppHighlighter::popIndents(int indentType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int SynEditCppHighlighter::popStatementIndents()
|
|
||||||
{
|
|
||||||
int counts = 0;
|
|
||||||
while (!mRange.indents.isEmpty() && mRange.indents.back() == sitStatement) {
|
|
||||||
int idx = mRange.indents.length()-1;
|
|
||||||
if (idx < mRange.firstIndentThisLine) {
|
|
||||||
// mRange.matchingIndents.append(mRange.indents[idx]);
|
|
||||||
counts++;
|
|
||||||
}
|
|
||||||
mRange.indents.pop_back();
|
|
||||||
}
|
|
||||||
return counts;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SynEditCppHighlighter::pushIndents(int indentType)
|
void SynEditCppHighlighter::pushIndents(int indentType)
|
||||||
{
|
{
|
||||||
int idx = mRange.indents.length();
|
int idx = mRange.indents.length();
|
||||||
|
|
|
@ -126,7 +126,6 @@ private:
|
||||||
void xorSymbolProc();
|
void xorSymbolProc();
|
||||||
void processChar();
|
void processChar();
|
||||||
void popIndents(int indentType);
|
void popIndents(int indentType);
|
||||||
int popStatementIndents();
|
|
||||||
void pushIndents(int indentType);
|
void pushIndents(int indentType);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -127,7 +127,7 @@ QVariant ClassBrowserModel::data(const QModelIndex &index, int role) const
|
||||||
return node->statement->command + node->statement->args;
|
return node->statement->command + node->statement->args;
|
||||||
}
|
}
|
||||||
} else if (role == Qt::ForegroundRole) {
|
} else if (role == Qt::ForegroundRole) {
|
||||||
if (node->statement) {
|
if (mColors && node->statement) {
|
||||||
PStatement statement = (node->statement);
|
PStatement statement = (node->statement);
|
||||||
StatementKind kind;
|
StatementKind kind;
|
||||||
if (mParser) {
|
if (mParser) {
|
||||||
|
@ -143,8 +143,8 @@ QVariant ClassBrowserModel::data(const QModelIndex &index, int role) const
|
||||||
if (item) {
|
if (item) {
|
||||||
return item->foreground();
|
return item->foreground();
|
||||||
}
|
}
|
||||||
return pMainWindow->palette().color(QPalette::Text);
|
|
||||||
}
|
}
|
||||||
|
return pMainWindow->palette().color(QPalette::Text);
|
||||||
} else if (role == Qt::DecorationRole) {
|
} else if (role == Qt::DecorationRole) {
|
||||||
if (node->statement) {
|
if (node->statement) {
|
||||||
PStatement statement = (node->statement);
|
PStatement statement = (node->statement);
|
||||||
|
|
Loading…
Reference in New Issue