From 6fd4371b435b5846e3cb54fd7ae0c5a3c01cef54 Mon Sep 17 00:00:00 2001 From: "royqh1979@gmail.com" Date: Sun, 20 Jun 2021 22:54:16 +0800 Subject: [PATCH] * work done for color scheme --- RedPandaIDE/HighlighterManager.cpp | 39 + RedPandaIDE/HighlighterManager.h | 2 + RedPandaIDE/RedPandaIDE_zh_CN.qm | Bin 8881 -> 19427 bytes RedPandaIDE/RedPandaIDE_zh_CN.ts | 718 +++++++++++------- RedPandaIDE/colorscheme.cpp | 79 +- RedPandaIDE/colorscheme.h | 4 +- RedPandaIDE/compiler/filecompiler.cpp | 3 +- RedPandaIDE/editor.cpp | 42 +- RedPandaIDE/mainwindow.cpp | 1 + .../settingsdialog/editorclipboardwidget.cpp | 33 +- .../settingsdialog/editorclipboardwidget.h | 3 + .../editorcolorschemewidget.cpp | 122 ++- .../settingsdialog/editorcolorschemewidget.h | 5 + .../settingsdialog/editorcolorschemewidget.ui | 218 ++++-- RedPandaIDE/utils.h | 1 - RedPandaIDE/widgets/coloredit.cpp | 38 +- 16 files changed, 880 insertions(+), 428 deletions(-) diff --git a/RedPandaIDE/HighlighterManager.cpp b/RedPandaIDE/HighlighterManager.cpp index db8d003f..70e1bc61 100644 --- a/RedPandaIDE/HighlighterManager.cpp +++ b/RedPandaIDE/HighlighterManager.cpp @@ -2,6 +2,8 @@ #include #include #include "qsynedit/highlighter/cpp.h" +#include "qsynedit/Constants.h" +#include "colorscheme.h" HighlighterManager highlighterManager; @@ -26,6 +28,14 @@ PSynHighlighter HighlighterManager::getHighlighter(const QString &filename) return PSynHighlighter(); } +PSynHighlighter HighlighterManager::copyHighlighter(PSynHighlighter highlighter) +{ + if (!highlighter) + return PSynHighlighter(); + if (highlighter->getName() == SYN_HIGHLIGHTER_CPP) + return getCppHighlighter(); +} + PSynHighlighter HighlighterManager::getCppHighlighter() { SynEditCppHighlighter* highlighter = new SynEditCppHighlighter(); @@ -53,3 +63,32 @@ PSynHighlighter HighlighterManager::getCppHighlighter() highlighter->variableAttribute()->setForeground(0x400080); return pHighlighter; } + +void HighlighterManager::applyColorScheme(PSynHighlighter highlighter, const QString &schemeName) +{ + if (!highlighter) + return; + if (highlighter->getName() == SYN_HIGHLIGHTER_CPP) { + for (QString name: highlighter->attributes().keys()) { + PColorSchemeItem item = pColorManager->getItem(schemeName,name); + if (item) { + PSynHighlighterAttribute attr = highlighter->attributes()[name]; + attr->setBackground(item->background()); + attr->setForeground(item->foreground()); + SynFontStyles styles = SynFontStyle::fsNone; + if (item->bold()) { + styles.setFlag(SynFontStyle::fsBold); + } + if (item->italic()) { + styles.setFlag(SynFontStyle::fsItalic); + } + if (item->underlined()) { + styles.setFlag(SynFontStyle::fsUnderline); + } + if (item->strikeout()) { + styles.setFlag(SynFontStyle::fsStrikeOut); + } + } + } + } +} diff --git a/RedPandaIDE/HighlighterManager.h b/RedPandaIDE/HighlighterManager.h index 9213b429..669dcfd0 100644 --- a/RedPandaIDE/HighlighterManager.h +++ b/RedPandaIDE/HighlighterManager.h @@ -8,7 +8,9 @@ public: HighlighterManager(); PSynHighlighter getHighlighter(const QString& filename); + PSynHighlighter copyHighlighter(PSynHighlighter highlighter); PSynHighlighter getCppHighlighter(); + void applyColorScheme(PSynHighlighter highlighter, const QString& schemeName); }; extern HighlighterManager highlighterManager; diff --git a/RedPandaIDE/RedPandaIDE_zh_CN.qm b/RedPandaIDE/RedPandaIDE_zh_CN.qm index 835871c7e9527e9b2017b633d8d88850984ba17d..f0faa842a1dff93437fbf772d08c7ab7dfac0e62 100644 GIT binary patch literal 19427 zcmb_j3w)E+**|UHq)D2j0Qtm=QrKDVnZ9)I^9xhX`tjCpJn_a6#+YtLV2jPZf-%E(#)MlLoAEn* zxsqw(y6H&9yRCcAq?sJ5i= zbyqRg^&`e+ni$*iG-Hc*G2xbT85_5j3HJ;zHZ916#{|qj!Gz~NXUu$(3BR5We4jJn zw+9$2`4bafaf6Q}#(khaO&*O)<+19hJWe7b+ zH47Ot-p_Qs;A`UT@>q8d(+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NA-otszp^sw}!a6Fa5bPM=y_F_cW7d0gzk!dQAxv63vyhq`6@YJnLA zgXo2UuQ1VmhOb+~R!=bH(t0c`XWR=3*m9ofN|2&qKc=fC9RqYTJ&D^8Cz&2w6XHKi zPhT~FHkIl595GO2W@`V$`wr&TsguZ;&q~DGCs623HZ}*HD@WLL7LDi*vW4L|0^J~M zufT+XIjlpo0|ozPU%wcM2Hs<9SqgV%58K;X2_TJP&)Ycc%ryINiWQUoAfHKN9<0 z=dx<*P{7UYs7E7oE!Q-SsF~oJtAE6WZSkS}9OvE@f-?`{K3#MHJhYP=zJWowkGTi7 zK%DtmK5Kai18(4plki;~#lP4agT^k1{NYYa&Uq10h&Ll*i+L9!E*U?@4>jka^AP^O z#wv9DouYml?g*t)+#UV_iE{*Pz-=@fBLtOWGA=}jKVU($3Yll#!2r?1zJtgY{E^U> zio!CpFmNXmSE5E3lpr4?YL&t6NlfHbn$zy#hg(X=XaKgzt8{JAVMoT5BbSpfd8!YC zqg9S8vnWuj`g!3B&ah22GqW3s=GB7Ohl1JaglomPgw5(!;~qTU>cik^b${J2xD)>B z2fcdajlh2}{C$dOxfF7ftMbSd<5Du_w}l+jbQ2+91E~qTK_b_!lChRzd$qHYyr%CU z--hiaUx%+J@rFc_9g#%3jH}7fHIER3>0$DcX)Vc$OC;JSg2;T_anESNX*w|$j1Ubb zFj|$RYph_6$(1`MUukGRT32}}TdXK)v@Uyvl3yK@uGz8{uSCA`x3KsmlgBpdjrJ-- zg|pgFU?_4roRx;EqFp8BD=!tL_A*1M-BA+Z*}3t)oVe2RiPG#K9`jmHswJ87bZ4xm F{s-@?RD=Kk diff --git a/RedPandaIDE/RedPandaIDE_zh_CN.ts b/RedPandaIDE/RedPandaIDE_zh_CN.ts index 5bf70217..319a6bb4 100644 --- a/RedPandaIDE/RedPandaIDE_zh_CN.ts +++ b/RedPandaIDE/RedPandaIDE_zh_CN.ts @@ -1,6 +1,15 @@ + + ColorEdit + + + + NONE + 无颜色 + + Compiler @@ -21,37 +30,37 @@ - Output Filename: %1 - + - 输出文件名: %1 - Output Size: %1 - + - 输出文件大小: %1 - Compilation Time: %1 secs - + - 编译时间: %1 秒 [Error] - + [错误] [Warning] - + [警告] [Info] - + [信息] [Note] - + [说明] - Time Elasped: %1 secs @@ -164,62 +173,62 @@ C++ Compiler(g++) - + C++编译器(g++) Choose C++ Compiler - + 选择C++编译器 Choose C Compiler - + 选择C编译器 C Compiler(gcc) - + C编译器(gcc) Debugger(gdb) - + 调试器(gdb) Profiler(gprof) - + 性能分析器(gprof) make - + Choose make - + 选择make Choose Debugger - + 选择调试器 Choose Resource Compiler - + 选择资源编译器 Choose Profiler - + 选择性能分析器 Confirm - + 确认 @@ -227,28 +236,31 @@ '%1' '%2' Are you really want to continue? - + 小熊猫C++ will将会清除现有的编译器配置列表,然后在下列文件夹中搜索编译器: + '%1' +'%2' +你确定要继续吗? Compiler Set Name - + 编译器配置名称 Name - + 名称 Compiler Set Folder - + 编译器所在文件夹 New name - + 新名称 @@ -258,45 +270,50 @@ Are you really want to continue? 无标题 - + untitled%1 - + 无标题%1 - - - - - - - + + + + + + + Fail + 失败 + + + + File %1 is not writable! - + Save As - 另存为 + 另存为 - + The text to be copied exceeds count limit! - + 要复制的内容超过了行数限制! - + The text to be copied exceeds character limit! - + 要复制的内容超过了字符数限制! - + The text to be cut exceeds count limit! - + 要剪切的内容超过了行数限制! - + The text to be cut exceeds character limit! - + 要剪切的内容超过了字符数限制! @@ -304,60 +321,62 @@ Are you really want to continue? Form - + 表单 Copy Size Limit - + 复制限制 Don't copy text larger than - + 不要复制超过下列限制的内容 Lines - + 行数 Size(kilo characters): - + 千字符数 Copy with format as - + 同时带格式复制为 Copy && Export As HTML - + 复制/导出为HTML Use background color - + 使用背景色 - Use editor's color schema - + Use editor's color scheme + Use editor's color schema + 使用编辑器的配色方案 - Color schema - + Color scheme + Color schema + 配色方案 Export As RTF - + 导出为RTF @@ -365,15 +384,15 @@ Are you really want to continue? Form - + 表单 - + Scheme 配色方案 - + ... @@ -382,35 +401,123 @@ Are you really want to continue? 选项 - + Foreground: 前景色 - + Font Styles 字体样式 - + Bold 加粗 - + Italic 斜体 - + + Strikeout + 删除线 + + + Underlined 下划线 - + + Duplicate... + 复制... + + + + Rename... + 重命名... + + + + Restore to Default + 删除自定义修改 + + + + Import Scheme... + 导入配色... + + + + Export... + 导出... + + + + Delete... + 删除... + + + Background: 背景色 + + + + + + + + + + Error + 错误 + + + + Open + 打开 + + + + + Color Scheme Files (*.scheme) + 配色方案文件 (*.scheme) + + + + '%1' is not a valid name for color scheme file. + '%1'不是合法的配色方案文件名。 + + + + New scheme name + 新方案名 + + + + '%1' is not a valid scheme name! + '%1'不是合法的配色方案名! + + + + Save + 保存 + + + + Confirm Delete Scheme + 确认删除方案 + + + + Scheme '%1' will be deleted!<br />Do you really want to continue? + 配色方案'%1'将会被删除!<br />您确认要继续吗? + EditorFontWidget @@ -423,69 +530,69 @@ Are you really want to continue? Size: - + 大小: Font: - + 字体: Show only monospaced fonts - + 只显示等宽字体 Gutter - + 装订线 Gutter is visible - + 显示装订线区域 Left Offset - + 左侧留白 Right Offset - + 右侧留白 Show Line Numbers - + 显示行号 Add leading zeros to line numbers - + 在行号前补齐前导0 Line numbers starts at zero - + 第一行从0开始编号 Auto calculate the digit count of line number - + 自动计算行号位数 Digit count - + 行号位数 Use Custom Font - + 使用自定义字体 @@ -493,22 +600,22 @@ Are you really want to continue? Vertical Line - + 竖线 Horizontal Line - + 横线 Half Block - + 半个方块 Block - + 方块 @@ -516,22 +623,32 @@ Are you really want to continue? Form - + 表单 - + Theme: - + 主题: - + Font: - + 字体: - + + Language: + 语言: + + + + *Needs restart + *需要重启之后生效 + + + Font Size: - + 大小: @@ -539,43 +656,44 @@ Are you really want to continue? Compiling single file... - + 编译单个文件... - Filename: %1 - + - 文件名: %1 - Compiler Set Name: %1 - + - 编译器配置: %1 Can't delete the old executable file "%1". - + 无法删除旧的可执行文件"%1". - Can't the compiler for file %1 - + Can't find the compiler for file %1 + Can't the compiler for file %1 + 找不到适合文件%1的编译器 - + Processing %1 source file: - + 正在处理%1源程序文件: + + + + %1 Compiler: %2 + %1编译器: %2 - %1 Compiler: %2 - - - - Command: %1 %2 - + 命令: %1 %2 @@ -583,22 +701,22 @@ Are you really want to continue? Filename - + 文件名 Line - + Col - + Description - + 描述 @@ -621,12 +739,12 @@ Are you really want to continue? Issues - + 编译器 Compile Log - + 编译日志 @@ -636,19 +754,19 @@ Are you really want to continue? Tools - + 工具 Run - + 运行 Edit - + 编辑 @@ -669,7 +787,7 @@ Are you really want to continue? Ctrl+N - + Ctrl+N @@ -679,7 +797,7 @@ Are you really want to continue? Ctrl+O - + Ctrl+O @@ -689,7 +807,7 @@ Are you really want to continue? Ctrl+S - + Ctrl+S @@ -709,185 +827,203 @@ Are you really want to continue? Ctrl+Shift+S - + Ctrl+Shift+S Options - + 选项 Compile - + 编译 F9 - + F9 F10 - + F10 Undo - + 恢复 Ctrl+Z - + Ctrl+Z Redo - + 重做 Ctrl+Y - + Ctrl+Y Cut - + 剪切 Ctrl+X - + Ctrl+X Copy - + 复制 Ctrl+C - + Ctrl+C Paste - + 粘贴 Ctrl+V - + Ctrl+V Select All - + 选择全部 Ctrl+A - + Ctrl+A Indent - + 缩进 UnIndent - + 取消缩进 Toggle Comment - + 切换注释 Ctrl+/ - + Ctrl+/ Collapse All - + 全部收起 Uncollapse All - + 全部展开 Encode in ANSI - + 使用ANSI编码 Encode in UTF-8 - + 使用UTF-8编码 Auto Detect - + 自动检测 Convert to ANSI - + 转换为ANSI编码 Convert to UTF-8 - + 转换为UTF-8编码 - + File Encoding - + 文件编码 - + Line:%1 Col:%2 Selected:%3 Lines:%4 Length:%5 - + 行:%1 列:%2 已选择:%3 总行数:%4 总长度:%5 - + Read Only - + 只读 - + Insert - + 插入 - + Overwrite - + 覆写 - - Open - - - - - - Confirm Convertion - - - - + + + + + + Error + 错误 + + + + Open + 打开打开 + + + + + Confirm Convertion + 确认转换 + + + + The editing file will be saved using %1 encoding. <br />This operation can't be reverted. <br />Are you sure to continue? - + 当前编辑器中的文件将会使用%1编码保存。<br />这项操作无法被撤回。<br />你确定要继续吗? + + + + QApplication + + + Error + 错误 @@ -906,11 +1042,6 @@ Are you really want to continue? Save changes to %s? 保存修改后的内容到"%s"? - - - File %s is not writable! - - C files @@ -937,7 +1068,7 @@ Are you really want to continue? 所有文件 - + Error @@ -954,12 +1085,12 @@ Are you really want to continue? 无法写入配置文件夹"%1" - + C options C语言选项 - + Code Generation 代码生成 @@ -995,6 +1126,7 @@ Are you really want to continue? + untitled 无标题 @@ -1009,221 +1141,248 @@ Are you really want to continue? 无法打开文件"%1"进行读取 - + Can't parse json file '%1' at offset %2! Error Code: %3 JSON文件"%1"在位置"%2"处无法解析!错误码:%3 - Can't parse json file '%1' is not a color schema config file! - "%1"不是一个合法的颜色配置文件,无法解析! + "%1"不是一个合法的颜色配置文件,无法解析! - + + Can't parse json file '%1' is not a color scheme config file! + + + + Can't open file '%1' for write 无法打开文件"%1"写入内容 - + + Can't Find the color scheme file %1! + + + + + + + Can't remove the color scheme file %1! + + + + Assembler 汇编 - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + Syntax 语法 - + Character 字符 - + Comment 注释 - + Class - + Float 浮点数 - + Function 函数 - + Gloabal Variable 全局变量 - + Hexadecimal Integer 十六进制数 - + Identifier 标识符 - + Illegal Char 非法字符 - + Local Variable 局部变量 - + Integer 整数 - + Octal Integer 八进制整数 - + Preprocessor 预处理指令 - + Reserve Word 保留字(关键字) - + Space 空格字符 - + String 字符串 - + Escape Sequences 转义序列 - + Symbol 符号 - + Variable 变量 - + Brace/Bracket/Parenthesis Level 1 1级括号 - + Brace/Bracket/Parenthesis Level 2 2级括号 - + Brace/Bracket/Parenthesis Level 3 3级括号 - + Brace/Bracket/Parenthesis Level 4 4级括号 - + Gutter 装订线 - - - - - - + + + + + + Editor 编辑器 - + Active Line 当前行 - + Breakpoint 断点 - + Active Breakpoint 活动断点 - + Folding Line 代码折叠线 - + Selection 选中文字 - - + + Syntax Check 语法检查 - + Warning 警告 - + + + Rename file '%1' to '%2' failed! + + + + + Scheme '%1' already exists! + + + + default 缺省 @@ -1236,147 +1395,147 @@ Are you really want to continue? Settings::CompilerSet - + Support all ANSI standard C programs (-ansi) 支持所有ANSI标准C程序(-ansi) - + Do not recognize asm,inline or typeof as a keyword (-fno-asm) 不支持将asm、inline和typeof作为关键字(-fno-asm) - + Imitate traditional C preprocessors (-traditional-cpp) 模仿传统C预处理器行为(-traditional-cpp) - + Optimize for the following machine (-march) - + Optimize less, while maintaining full compatibility (-tune) - + Enable use of specific instructions (-mx) - + Optimization level (-Ox) - + Compile with the following pointer size (-mx) - + Language standard (-std) - + Generate debugging information (-g3) - + Generate profiling info for analysis (-pg) - + Warnings - + Inhibit all warning messages (-w) - + Show most warnings (-Wall) - + Show some more warnings (-Wextra) - + Check ISO C/C++/C++0x conformance (-pedantic) - + Only check the code for syntax errors (-fsyntax-only) - + Make all warnings into errors (-Werror) - + Abort compilation on first error (-Wfatal-errors) - + Linker - + Link an Objective C program (-lobjc) - + Do not use standard system libraries (-nostdlib) - + Do not create a console window (-mwindows) - + Strip executable (-s) - + Link libraries statically (-static) - + Output - + -fverbose-asm - + Use pipes instead of temporary files during compilation (-pipe) - + Do not assemble, compile and generate the assemble code (-S) @@ -1411,12 +1570,12 @@ Are you really want to continue? Appearence - + 外观 Environment - + 环境 @@ -1444,17 +1603,17 @@ Are you really want to continue? Font - + 字体 Copy & Export - + 复制/导出 Color - + 配色 @@ -1470,7 +1629,8 @@ Are you really want to continue? SynEdit - + + The highlighter seems to be in an infinite loop @@ -1483,7 +1643,7 @@ Are you really want to continue? - + Can't open file '%1' for save! @@ -1493,7 +1653,7 @@ Are you really want to continue? Form - + 表单 diff --git a/RedPandaIDE/colorscheme.cpp b/RedPandaIDE/colorscheme.cpp index 3a3babe5..4ea93439 100644 --- a/RedPandaIDE/colorscheme.cpp +++ b/RedPandaIDE/colorscheme.cpp @@ -302,6 +302,48 @@ QString ColorManager::copy(const QString &sourceName) return newName; } +bool ColorManager::restoreToDefault(const QString &name) +{ + PColorScheme scheme = get(name); + if (!scheme) + return false; + if (!scheme->customed()) + return false; + QString fullPath = generateFullPathname(name,scheme->bundled(),false); + PColorScheme oldScheme = ColorScheme::load(fullPath); + if (!oldScheme) + throw FileError(QObject::tr("Can't Find the color scheme file %1!").arg(fullPath)); + fullPath = generateFullPathname(name,scheme->bundled(),true); + QFile file(fullPath); + if (file.exists() && !file.remove()) + throw FileError(QObject::tr("Can't remove the color scheme file %1!").arg(fullPath)); + oldScheme->setBundled(scheme->bundled()); + oldScheme->setCustomed(false); + mSchemes[name]=oldScheme; + return true; +} + +bool ColorManager::remove(const QString &name) +{ + PColorScheme scheme = get(name); + if (!scheme) + return false; + if (scheme->bundled()) + return false; + if (scheme->customed()) { + QString fullPath = generateFullPathname(name,false,true); + QFile file(fullPath); + if (!file.remove()) + throw FileError(QObject::tr("Can't remove the color scheme file %1!").arg(fullPath)); + } + QString fullPath = generateFullPathname(name,false,false); + QFile file(fullPath); + if (!file.remove()) + throw FileError(QObject::tr("Can't remove the color scheme file %1!").arg(fullPath)); + mSchemes.remove(name); + return true; +} + QString ColorManager::generateFilename(const QString &name, bool isCustomed) { QString newName = name; @@ -328,11 +370,13 @@ void ColorManager::loadSchemesInDir(const QString &dirName, bool isBundled, bool QFileInfo fileInfo = list[i]; QString name = fileInfo.fileName(); if (name.toLower().endsWith(suffix)) { - if (!isCustomed && name.toLower().endsWith(customSuffix)) - continue; - PColorScheme scheme = ColorScheme::load(fileInfo.absoluteFilePath()); +// if (!isCustomed && name.toLower().endsWith(customSuffix)) +// continue; name.remove(name.length()-suffix.length(),suffix.length()); name.replace('_',' '); + if (!isValidName(name)) + continue; + PColorScheme scheme = ColorScheme::load(fileInfo.absoluteFilePath()); if (!isCustomed) { scheme->setBundled(isBundled); scheme->setCustomed(false); @@ -504,16 +548,33 @@ bool ColorManager::rename(const QString &oldName, const QString &newName) PColorScheme scheme = get(oldName); if (!scheme) return false; + if (scheme->bundled()) + return false; + if (scheme->customed()) { + QString oldfullPath = generateFullPathname(oldName,false,true); + QString fullpath = generateFullPathname(newName,false,true); + QFile oldFile(oldfullPath); + if (oldFile.exists() && !oldFile.rename(fullpath)) + throw FileError(QObject::tr("Rename file '%1' to '%2' failed!").arg(oldfullPath).arg(fullpath)); + } + QString oldfullPath = generateFullPathname(oldName,false,false); + QString fullpath = generateFullPathname(newName,false,false); + QFile oldFile(oldfullPath); + if (oldFile.exists() && !oldFile.rename(fullpath)) + throw FileError(QObject::tr("Rename file '%1' to '%2' failed!").arg(oldfullPath).arg(fullpath)); + mSchemes.remove(oldName); mSchemes[newName] = scheme; - + return true; } -PColorScheme ColorManager::remove(const QString &name) +bool ColorManager::add(const QString &name, PColorScheme scheme) { - PColorScheme scheme=get(name); - if (scheme) - mSchemes.remove(name); - return scheme; + if (mSchemes.contains(name)) + throw FileError(QObject::tr("Scheme '%1' already exists!").arg(name)); + scheme->setBundled(false); + scheme->setCustomed(false); + mSchemes[name] = scheme; + saveScheme(name); } PColorScheme ColorManager::get(const QString &name) diff --git a/RedPandaIDE/colorscheme.h b/RedPandaIDE/colorscheme.h index 519e0313..18143341 100644 --- a/RedPandaIDE/colorscheme.h +++ b/RedPandaIDE/colorscheme.h @@ -130,8 +130,10 @@ public: bool exists(const QString name); QString copy(const QString& source); + bool restoreToDefault(const QString& name); + bool remove(const QString& name); bool rename(const QString& oldName, const QString& newName); - PColorScheme remove(const QString& name); + bool add(const QString& name, PColorScheme scheme); PColorScheme get(const QString& name); PColorSchemeItem getItem(const QString& schemeName, const QString& itemName); bool isValidName(const QString& name); diff --git a/RedPandaIDE/compiler/filecompiler.cpp b/RedPandaIDE/compiler/filecompiler.cpp index 48111a8b..020a74a9 100644 --- a/RedPandaIDE/compiler/filecompiler.cpp +++ b/RedPandaIDE/compiler/filecompiler.cpp @@ -59,12 +59,11 @@ bool FileCompiler::prepareForCompile() mCompiler = compilerSet()->cppCompiler(); break; default: - error(tr("Can't the compiler for file %1").arg(mFileName)); + error(tr("Can't find the compiler for file %1").arg(mFileName)); return false; } mArguments += getLibraryArguments(); - log(tr("Processing %1 source file:").arg(strFileType)); log("------------------"); log(tr("%1 Compiler: %2").arg(strFileType).arg(mCompiler)); diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index f7b5caf6..1bf13c7b 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -127,7 +127,7 @@ bool Editor::save(bool force, bool reparse) { //is this file writable; if (!force && !info.isWritable()) { QMessageBox::information(pMainWindow,tr("Fail"), - QString(QObject::tr("File %s is not writable!"))); + tr("File %1 is not writable!").arg(mFilename)); return false; } if (this->modified()|| force) { @@ -295,22 +295,22 @@ void Editor::copyAsHTML() SynExporterHTML.setTitle(QFileInfo(mFilename).fileName()); SynExporterHTML.setExportAsText(false); - SynExporterHTML.setUseBackground(true); + SynExporterHTML.setUseBackground(pSettings->editor().copyHTMLUseBackground()); SynExporterHTML.setFont(font()); - SynExporterHTML.setHighlighter(highlighter()); + PSynHighlighter hl = highlighter(); + if (!pSettings->editor().copyHTMLUseEditorColor()) { + hl = highlighterManager.copyHighlighter(highlighter()); + highlighterManager.applyColorScheme(hl,pSettings->editor().copyHTMLColorScheme()); + } + SynExporterHTML.setHighlighter(hl); SynExporterHTML.setCreateHTMLFragment(true); - //SynExporterRTF.OnFormatToken := ExporterFormatToken; - SynExporterHTML.ExportRange(lines(),blockBegin(),blockEnd()); - //SynExporterHTML.CopyToClipboard(); - QMimeData * mimeData = new QMimeData; //sethtml will convert buffer to QString , which will cause encoding trouble mimeData->setData(SynExporterHTML.clipboardFormat(),SynExporterHTML.buffer()); - //mimeData->setHtml("test"); mimeData->setText(selText()); QGuiApplication::clipboard()->clear(); @@ -464,31 +464,7 @@ void Editor::applySettings() void Editor::applyColorScheme(const QString& schemeName) { - if (highlighter()) { - if (highlighter()->getName() == SYN_HIGHLIGHTER_CPP) { - for (QString name: highlighter()->attributes().keys()) { - PColorSchemeItem item = pColorManager->getItem(schemeName,name); - if (item) { - PSynHighlighterAttribute attr = highlighter()->attributes()[name]; - attr->setBackground(item->background()); - attr->setForeground(item->foreground()); - SynFontStyles styles = SynFontStyle::fsNone; - if (item->bold()) { - styles.setFlag(SynFontStyle::fsBold); - } - if (item->italic()) { - styles.setFlag(SynFontStyle::fsItalic); - } - if (item->underlined()) { - styles.setFlag(SynFontStyle::fsUnderline); - } - if (item->strikeout()) { - styles.setFlag(SynFontStyle::fsStrikeOut); - } - } - } - } - } + highlighterManager.applyColorScheme(highlighter(),schemeName); PColorSchemeItem item = pColorManager->getItem(schemeName,COLOR_SCHEME_ACTIVE_LINE); if (item) { setActiveLineColor(item->background()); diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index f7ebcfba..48238597 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -170,6 +170,7 @@ void MainWindow::applySettings() font.setStyleStrategy(QFont::PreferAntialias); QApplication * app = dynamic_cast(QApplication::instance()); app->setFont(font); + this->setFont(font); } void MainWindow::updateStatusbarForLineCol() diff --git a/RedPandaIDE/settingsdialog/editorclipboardwidget.cpp b/RedPandaIDE/settingsdialog/editorclipboardwidget.cpp index e5a6b853..4e70019a 100644 --- a/RedPandaIDE/settingsdialog/editorclipboardwidget.cpp +++ b/RedPandaIDE/settingsdialog/editorclipboardwidget.cpp @@ -2,6 +2,7 @@ #include "ui_editorclipboardwidget.h" #include "../settings.h" #include "../mainwindow.h" +#include "../colorscheme.h" EditorClipboardWidget::EditorClipboardWidget(const QString& name, const QString& group, QWidget *parent) : SettingsWidget(name,group,parent), @@ -10,6 +11,19 @@ EditorClipboardWidget::EditorClipboardWidget(const QString& name, const QString& ui->setupUi(this); ui->cbCopyWithFormatAs->addItem("None"); ui->cbCopyWithFormatAs->addItem("HTML"); + + for (QString name: pColorManager->getSchemes()) { + ui->cbHTMLColorScheme->addItem(name); + ui->cbRTFColorScheme->addItem(name); + } + connect(ui->chkCopyRTFUseEditorColor, + &QCheckBox::stateChanged, + this, + &EditorClipboardWidget::onUseSchemeChanged); + connect(ui->chkCopyHTMLUseEditorColor, + &QCheckBox::stateChanged, + this, + &EditorClipboardWidget::onUseSchemeChanged); } EditorClipboardWidget::~EditorClipboardWidget() @@ -17,6 +31,12 @@ EditorClipboardWidget::~EditorClipboardWidget() delete ui; } +void EditorClipboardWidget::onUseSchemeChanged() +{ + ui->cbRTFColorScheme->setEnabled(!ui->chkCopyRTFUseEditorColor->isChecked()); + ui->cbHTMLColorScheme->setEnabled(!ui->chkCopyHTMLUseEditorColor->isChecked()); +} + void EditorClipboardWidget::doLoad() { //pSettings->editor().load(); @@ -30,13 +50,11 @@ void EditorClipboardWidget::doLoad() pSettings->editor().copyWithFormatAs())) ); ui->chkCopyRTFUseBackground->setChecked(pSettings->editor().copyRTFUseBackground()); ui->chkCopyRTFUseEditorColor->setChecked(pSettings->editor().copyRTFUseEditorColor()); - //todo - //ui->cbCopyRTFColorScheme + ui->cbRTFColorScheme->setCurrentText(pSettings->editor().colorScheme()); ui->chkCopyHTMLUseBackground->setChecked(pSettings->editor().copyHTMLUseBackground()); ui->chkCopyHTMLUseEditorColor->setChecked(pSettings->editor().copyHTMLUseEditorColor()); - //todo - //ui->cbCopyHTMLColorScheme - + ui->cbHTMLColorScheme->setCurrentText(pSettings->editor().colorScheme()); + onUseSchemeChanged(); } void EditorClipboardWidget::doSave() @@ -49,10 +67,11 @@ void EditorClipboardWidget::doSave() pSettings->editor().setCopyRTFUseBackground(ui->chkCopyRTFUseBackground->isChecked()); pSettings->editor().setCopyRTFUseEditorColor(ui->chkCopyRTFUseEditorColor->isChecked()); - //todo - //ui->cbCopyRTFColorSchema + pSettings->editor().setCopyRTFColorScheme(ui->cbRTFColorScheme->currentText()); + pSettings->editor().setCopyHTMLUseBackground(ui->chkCopyHTMLUseBackground->isChecked()); pSettings->editor().setCopyHTMLUseEditorColor(ui->chkCopyHTMLUseEditorColor->isChecked()); + pSettings->editor().setCopyHTMLColorScheme(ui->cbHTMLColorScheme->currentText()); pSettings->editor().save(); pMainWindow->updateEditorSettings(); diff --git a/RedPandaIDE/settingsdialog/editorclipboardwidget.h b/RedPandaIDE/settingsdialog/editorclipboardwidget.h index 49cb78ce..c3b0d6fc 100644 --- a/RedPandaIDE/settingsdialog/editorclipboardwidget.h +++ b/RedPandaIDE/settingsdialog/editorclipboardwidget.h @@ -16,6 +16,9 @@ public: explicit EditorClipboardWidget(const QString& name, const QString& group, QWidget *parent = nullptr); ~EditorClipboardWidget(); +public slots: + void onUseSchemeChanged(); + private: Ui::EditorClipboardWidget *ui; diff --git a/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp b/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp index 4e164ed4..a22a0a54 100644 --- a/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp +++ b/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include EditorColorSchemeWidget::EditorColorSchemeWidget(const QString& name, const QString& group, QWidget *parent) : SettingsWidget(name,group,parent), @@ -150,7 +152,7 @@ void EditorColorSchemeWidget::setCurrentSchemeModified() ui->cbScheme->setItemData(ui->cbScheme->currentIndex(), mModifiedSchemeComboFont,Qt::FontRole); ui->cbScheme->setFont(mModifiedSchemeComboFont); - ui->cbScheme->view()->setFont(mDefaultSchemeComboFont); + //ui->cbScheme->view()->setFont(mDefaultSchemeComboFont); //we must reset the editor here, because this slot is processed after the onSettingChanged onSettingChanged(); } @@ -227,9 +229,11 @@ void EditorColorSchemeWidget::onForegroundChanged() PColorSchemeItem item = getCurrentItem(); if (!item) return; + ui->colorForeground->setVisible(ui->cbForeground->isChecked()); if (ui->cbForeground->isChecked()) { item->setForeground(ui->colorForeground->color()); } else { + ui->colorForeground->setColor(QColor()); item->setForeground(QColor()); } setCurrentSchemeModified(); @@ -240,9 +244,11 @@ void EditorColorSchemeWidget::onBackgroundChanged() PColorSchemeItem item = getCurrentItem(); if (!item) return; + ui->colorBackground->setVisible(ui->cbBackground->isChecked()); if (ui->cbBackground->isChecked()) { item->setBackground(ui->colorBackground->color()); } else { + ui->colorBackground->setColor(QColor()); item->setBackground(QColor()); } setCurrentSchemeModified(); @@ -269,7 +275,7 @@ void EditorColorSchemeWidget::changeSchemeComboFont() } else { ui->cbScheme->setFont(mDefaultSchemeComboFont); } - ui->cbScheme->view()->setFont(mDefaultSchemeComboFont); + //ui->cbScheme->view()->setFont(mDefaultSchemeComboFont); } void EditorColorSchemeWidget::doLoad() @@ -313,7 +319,9 @@ void EditorColorSchemeWidget::on_btnSchemeMenu_pressed() menu.addAction(ui->actionRename_Scheme); menu.addAction(ui->actionDelete_Scheme); } - menu.addAction(ui->actionCopy_Scheme); + QString name = ui->cbScheme->currentText(); + if (!pColorManager->exists(name+ " Copy")) + menu.addAction(ui->actionCopy_Scheme); menu.addAction(ui->actionExport_Scheme); menu.addSeparator(); } @@ -323,3 +331,111 @@ void EditorColorSchemeWidget::on_btnSchemeMenu_pressed() p.setY(ui->btnSchemeMenu->height()+2); menu.exec(ui->btnSchemeMenu->mapToGlobal(p)); } + +void EditorColorSchemeWidget::on_actionImport_Scheme_triggered() +{ + QString filename = QFileDialog::getOpenFileName(this, + tr("Open"), QString(), tr("Color Scheme Files (*.scheme)")); + if (filename.isEmpty()) + return; + QFileInfo fileInfo(filename); + QString name = fileInfo.fileName(); + QString suffix = EXT_COLOR_SCHEME; + if (!name.toLower().endsWith(suffix)) + return; + name.remove(name.length()-suffix.length(),suffix.length()); + name.replace('_',' '); + if (!pColorManager->isValidName(name)) { + QMessageBox::information(this,tr("Error"),tr("'%1' is not a valid name for color scheme file.")); + return; + } + try { + PColorScheme scheme = ColorScheme::load(filename); + pColorManager->add(name, scheme); + ui->cbScheme->addItem(name); + ui->cbScheme->setCurrentText(name); + } catch (FileError e) { + QMessageBox::information(this,tr("Error"),e.reason()); + return; + } +} + +void EditorColorSchemeWidget::on_actionRename_Scheme_triggered() +{ + QString name = ui->cbScheme->currentText(); + bool isOk; + QString newName = QInputDialog::getText(this,tr("New scheme name"),tr("New scheme name"), + QLineEdit::Normal,name,&isOk); + if (isOk) { + if (!pColorManager->isValidName(newName)) { + QMessageBox::information(this,tr("Error"),tr("'%1' is not a valid scheme name!").arg(newName)); + return; + } + try { + pColorManager->rename(name,newName); + ui->cbScheme->setItemText( + ui->cbScheme->currentIndex(), + newName + ); + if (mModifiedSchemes.contains(name)) + mModifiedSchemes.remove(name); + mModifiedSchemes.insert(newName); + } catch(FileError e) { + QMessageBox::information(this,tr("Error"),e.reason()); + } + } +} + +void EditorColorSchemeWidget::on_actionReset_Scheme_triggered() +{ + try { + if (pColorManager->restoreToDefault(ui->cbScheme->currentText())) { + ui->cbScheme->setItemData( + ui->cbScheme->currentIndex(), + QVariant(), + Qt::FontRole); + ui->cbScheme->setFont(mDefaultSchemeComboFont); + //ui->cbScheme->view()->setFont(mDefaultSchemeComboFont); + } + } catch (FileError e) { + QMessageBox::information(this,tr("Error"),e.reason()); + } + +} + +void EditorColorSchemeWidget::on_actionExport_Scheme_triggered() +{ + QString filename = QFileDialog::getSaveFileName(this, + tr("Save"), QString(), tr("Color Scheme Files (*.scheme)")); + if (filename.isEmpty()) + return; + try { + PColorScheme scheme = getCurrentScheme(); + scheme->save(filename); + } catch (FileError e) { + QMessageBox::information(this,tr("Error"),e.reason()); + return; + } +} + +void EditorColorSchemeWidget::on_actionDelete_Scheme_triggered() +{ + + QString name = ui->cbScheme->currentText(); + if (QMessageBox::information(this,tr("Confirm Delete Scheme"), + tr("Scheme '%1' will be deleted!
Do you really want to continue?") + .arg(name), + QMessageBox::Yes, QMessageBox::No)!=QMessageBox::Yes) + return; + try { + if (pColorManager->remove(name)) { + if (mModifiedSchemes.contains(name)) + mModifiedSchemes.remove(name); + ui->cbScheme->removeItem(ui->cbScheme->currentIndex()); + if (name == pSettings->editor().colorScheme()) + doSave(); + } + } catch (FileError e) { + QMessageBox::information(this,tr("Error"),e.reason()); + } +} diff --git a/RedPandaIDE/settingsdialog/editorcolorschemewidget.h b/RedPandaIDE/settingsdialog/editorcolorschemewidget.h index 43932dc5..3f27aa7f 100644 --- a/RedPandaIDE/settingsdialog/editorcolorschemewidget.h +++ b/RedPandaIDE/settingsdialog/editorcolorschemewidget.h @@ -54,6 +54,11 @@ protected: private slots: void on_actionCopy_Scheme_triggered(); void on_btnSchemeMenu_pressed(); + void on_actionImport_Scheme_triggered(); + void on_actionRename_Scheme_triggered(); + void on_actionReset_Scheme_triggered(); + void on_actionExport_Scheme_triggered(); + void on_actionDelete_Scheme_triggered(); }; #endif // EDITORCOLORSCHEMEWIDGET_H diff --git a/RedPandaIDE/settingsdialog/editorcolorschemewidget.ui b/RedPandaIDE/settingsdialog/editorcolorschemewidget.ui index 35f64f94..5b87fb3f 100644 --- a/RedPandaIDE/settingsdialog/editorcolorschemewidget.ui +++ b/RedPandaIDE/settingsdialog/editorcolorschemewidget.ui @@ -147,11 +147,11 @@ - - - true - - + + + + 7 + 0 @@ -164,102 +164,154 @@ 0 - - - - Background: + + + + true - - - - - - Foreground: - - - - - - - - 0 - 0 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - Font Styles - - - - + + + 0 + + + 0 + + + 0 + + + 0 + + + - Bold + Background: - - + + - Italic + Foreground: - - - - Strikeout + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised - - - - Underlined + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Font Styles + + + + + + Bold + + + + + + + Italic + + + + + + + Strikeout + + + + + + + Underlined + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + diff --git a/RedPandaIDE/utils.h b/RedPandaIDE/utils.h index 3ed86cf9..b4c76397 100644 --- a/RedPandaIDE/utils.h +++ b/RedPandaIDE/utils.h @@ -94,7 +94,6 @@ QString TrimLeft(const QString& s); bool StringIsBlank(const QString& s); void changeTheme(const QString& themeName); - template class final_action { diff --git a/RedPandaIDE/widgets/coloredit.cpp b/RedPandaIDE/widgets/coloredit.cpp index f2220394..520aa043 100644 --- a/RedPandaIDE/widgets/coloredit.cpp +++ b/RedPandaIDE/widgets/coloredit.cpp @@ -3,6 +3,7 @@ #include #include #include +#include ColorEdit::ColorEdit(QWidget *parent):QFrame(parent) { @@ -21,13 +22,18 @@ void ColorEdit::setColor(const QColor &value) if (mColor!=value) { mColor=value; emit colorChanged(value); - update(); + resize(sizeHint()); +// update(); } } QColor ColorEdit::contrast() { - int crBg = mColor.rgb() & 0xFFFFFF; + int crBg; + if (!mColor.isValid()) + crBg = palette().color(QPalette::Base).rgb() & 0xFFFFFF; + else + crBg = mColor.rgb() & 0xFFFFFF; int TOLERANCE = 30; int result; @@ -44,18 +50,32 @@ QColor ColorEdit::contrast() QSize ColorEdit::sizeHint() const { - QRect rect = fontMetrics().boundingRect(mColor.name()); + QRect rect; + if (mColor.isValid() ) + rect = fontMetrics().boundingRect(mColor.name()); + else + rect = fontMetrics().boundingRect(tr("NONE")); return QSize{rect.width()+ 10, rect.height()+ 6 }; } -void ColorEdit::paintEvent(QPaintEvent *event) +void ColorEdit::paintEvent(QPaintEvent *) { QPainter painter(this); QRect rect = QRect(lineWidth(),lineWidth(),width()-2*lineWidth(),height()-2*lineWidth()); - painter.fillRect(rect,mColor); - painter.setPen(contrast()); - painter.drawText(rect,Qt::AlignCenter, mColor.name()); + if (mColor.isValid()) { + //painter.fillRect(rect,mColor); + painter.setPen(contrast()); + painter.setBrush(mColor); + painter.drawRect(rect); + painter.drawText(rect,Qt::AlignCenter, mColor.name()); + } else { + //painter.fillRect(rect,palette().color(QPalette::Base)); + painter.setPen(contrast()); + painter.setBrush(palette().color(QPalette::Base)); + painter.drawRect(rect); + painter.drawText(rect,Qt::AlignCenter, tr("NONE")); + } } void ColorEdit::mouseReleaseEvent(QMouseEvent *event) @@ -78,7 +98,5 @@ void ColorEdit::leaveEvent(QEvent *event) QSize ColorEdit::minimumSizeHint() const { - QRect rect = fontMetrics().boundingRect(mColor.name()); - return QSize{rect.width(), - rect.height()}; + return sizeHint(); }