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 835871c7..f0faa842 100644 Binary files a/RedPandaIDE/RedPandaIDE_zh_CN.qm and b/RedPandaIDE/RedPandaIDE_zh_CN.qm differ 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(); }