diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro index cad3582a..15612ce7 100644 --- a/RedPandaIDE/RedPandaIDE.pro +++ b/RedPandaIDE/RedPandaIDE.pro @@ -46,7 +46,8 @@ SOURCES += \ systemconsts.cpp \ utils.cpp \ widgets/coloredit.cpp \ - widgets/issuestable.cpp + widgets/issuestable.cpp \ + widgets/qpatchedcombobox.cpp HEADERS += \ HighlighterManager.h \ @@ -87,7 +88,8 @@ HEADERS += \ utils.h \ common.h \ widgets/coloredit.h \ - widgets/issuestable.h + widgets/issuestable.h \ + widgets/qpatchedcombobox.h FORMS += \ mainwindow.ui \ diff --git a/RedPandaIDE/RedPandaIDE_zh_CN.qm b/RedPandaIDE/RedPandaIDE_zh_CN.qm index 5af430e5..835871c7 100644 Binary files a/RedPandaIDE/RedPandaIDE_zh_CN.qm and b/RedPandaIDE/RedPandaIDE_zh_CN.qm differ diff --git a/RedPandaIDE/colorscheme.cpp b/RedPandaIDE/colorscheme.cpp index 9654e656..392c2a9c 100644 --- a/RedPandaIDE/colorscheme.cpp +++ b/RedPandaIDE/colorscheme.cpp @@ -54,7 +54,7 @@ PColorScheme ColorScheme::load(const QString &filename) .arg(file.fileName()).arg(error.offset).arg(error.error); } if (!doc.isObject()) { - qDebug()< ColorScheme::items() void ColorScheme::save(const QString &filename) { QFile file(filename); + QFileInfo info(filename); + info.dir().mkpath(info.dir().absolutePath()); if (!file.open(QFile::WriteOnly)) { - throw new FileError(QObject::tr("Can't open file '%1' for write").arg(file.fileName())); + throw FileError(QObject::tr("Can't open file '%1' for write").arg(file.fileName())); } QJsonObject json; toJson(json); @@ -249,11 +251,11 @@ void ColorManager::reload() { mSchemes.clear(); //bundled schemes ( the lowest priority) - loadSchemesInDir(pSettings->dirs().data(Settings::Dirs::DataType::ColorSheme),false); + loadSchemesInDir(pSettings->dirs().data(Settings::Dirs::DataType::ColorSheme),true,false); //config schemes ( higher priority) - loadSchemesInDir(pSettings->dirs().config(Settings::Dirs::DataType::ColorSheme),false); + loadSchemesInDir(pSettings->dirs().config(Settings::Dirs::DataType::ColorSheme),false,false); //customed schemes ( highest priority) - loadSchemesInDir(pSettings->dirs().config(Settings::Dirs::DataType::ColorSheme),true); + loadSchemesInDir(pSettings->dirs().config(Settings::Dirs::DataType::ColorSheme),false,true); } QStringList ColorManager::getSchemes(const QString &themeType) @@ -309,15 +311,16 @@ QString ColorManager::generateFilename(const QString &name, bool isCustomed) return newName += EXT_COLOR_SCHEME; } -void ColorManager::loadSchemesInDir(const QString &dirName, bool isCustomed) +void ColorManager::loadSchemesInDir(const QString &dirName, bool isBundled, bool isCustomed) { QDir dir(dirName); dir.setFilter(QDir::Files); QFileInfoList list = dir.entryInfoList(); QString suffix; + QString customSuffix = EXT_PREFIX_CUSTOM; + customSuffix += EXT_COLOR_SCHEME; if (isCustomed) { - suffix = EXT_PREFIX_CUSTOM; - suffix = suffix + EXT_COLOR_SCHEME; + suffix = customSuffix; } else { suffix = EXT_COLOR_SCHEME; } @@ -325,9 +328,25 @@ void ColorManager::loadSchemesInDir(const QString &dirName, bool isCustomed) 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()); name.remove(name.length()-suffix.length(),suffix.length()); name.replace('_',' '); + if (!isCustomed) { + scheme->setBundled(isBundled); + scheme->setCustomed(false); + } else { + scheme->setBundled(false); + if (mSchemes.contains(name)) { + PColorScheme oldScheme = mSchemes[name]; + if (oldScheme) { + scheme->setBundled(oldScheme->bundled()); + } + mSchemes.remove(name); + } + scheme->setCustomed(true); + } mSchemes[name]=scheme; } } @@ -547,10 +566,19 @@ PColorSchemeItemDefine ColorManager::getDefine(const QString &name) return PColorSchemeItemDefine(); } +bool ColorManager::saveScheme(const QString &name) +{ + PColorScheme scheme = get(name); + if (!scheme) + return false; + QString newFilepath = generateFullPathname(name,scheme->bundled(),scheme->customed()); + scheme->save(newFilepath); +} + QString ColorManager::generateFullPathname(const QString &name, bool isBundled, bool isCustomed) { QString filename = generateFilename(name,isCustomed); - if (isBundled) { + if (isBundled && !isCustomed) { return includeTrailingPathDelimiter(pSettings->dirs().data(Settings::Dirs::DataType::ColorSheme))+filename; } else { return includeTrailingPathDelimiter(pSettings->dirs().config(Settings::Dirs::DataType::ColorSheme))+filename; diff --git a/RedPandaIDE/colorscheme.h b/RedPandaIDE/colorscheme.h index b76849c1..e1ebf355 100644 --- a/RedPandaIDE/colorscheme.h +++ b/RedPandaIDE/colorscheme.h @@ -138,10 +138,11 @@ public: void addDefine(const QString& name, const QString& displayName, const QString& group, bool hasForeground, bool hasBackground, bool hasFontStyle); bool removeDefine(const QString &name); PColorSchemeItemDefine getDefine(const QString& name); + bool saveScheme(const QString &name); private: QString generateFullPathname(const QString& name, bool isBundled, bool isCustomed); QString generateFilename(const QString& name, bool isCustomed); - void loadSchemesInDir(const QString& dirName, bool isCustomed); + void loadSchemesInDir(const QString& dirName, bool isBundled, bool isCustomed); void initItemDefines(); private: QMap mSchemeItemDefines; diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 33e65110..f7b5caf6 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -49,11 +49,11 @@ Editor::Editor(QWidget *parent, const QString& filename, bool inProject, bool isNew, QTabWidget* parentPageControl): SynEdit(parent), - mFilename(filename), mEncodingOption(encoding), + mFilename(filename), + mParentPageControl(parentPageControl), mInProject(inProject), - mIsNew(isNew), - mParentPageControl(parentPageControl) + mIsNew(isNew) { if (mFilename.isEmpty()) { newfileCount++; @@ -84,6 +84,7 @@ Editor::Editor(QWidget *parent, const QString& filename, } applySettings(); + applyColorScheme(pSettings->editor().colorScheme()); connect(this,&SynEdit::statusChanged,this,&Editor::onStatusChanged); } diff --git a/RedPandaIDE/editorlist.cpp b/RedPandaIDE/editorlist.cpp index 2351664c..98a1ff14 100644 --- a/RedPandaIDE/editorlist.cpp +++ b/RedPandaIDE/editorlist.cpp @@ -116,6 +116,18 @@ void EditorList::applySettings() } } +void EditorList::applyColorSchemes(const QString& name) +{ + for (int i=0;icount();i++) { + Editor* e = static_cast(mLeftPageWidget->widget(i)); + e->applyColorScheme(name); + } + for (int i=0;icount();i++) { + Editor* e = static_cast(mRightPageWidget->widget(i)); + e->applyColorScheme(name); + } +} + bool EditorList::closeAll(bool force) { beginUpdate(); auto end = finally([this] { diff --git a/RedPandaIDE/editorlist.h b/RedPandaIDE/editorlist.h index b458795e..a7fc0102 100644 --- a/RedPandaIDE/editorlist.h +++ b/RedPandaIDE/editorlist.h @@ -39,6 +39,7 @@ public: void beginUpdate(); void endUpdate(); void applySettings(); + void applyColorSchemes(const QString& name); private: QTabWidget* getNewEditorPageControl() const; diff --git a/RedPandaIDE/main.cpp b/RedPandaIDE/main.cpp index b0b0dba2..7826b7c6 100644 --- a/RedPandaIDE/main.cpp +++ b/RedPandaIDE/main.cpp @@ -63,17 +63,18 @@ int main(int argc, char *argv[]) return -1; } auto settings = std::unique_ptr(pSettings); + settings->environment().load(); settings->compilerSets().loadSets(); settings->editor().load(); - settings->environment().load(); - pColorManager = new ColorManager(); - - //load translations + //Translation must be loaded after language setting is loaded QTranslator trans; trans.load("RedPandaIDE_"+pSettings->environment().language(),":/translations"); app.installTranslator(&trans); + //Color scheme settings must be loaded after translation + pColorManager = new ColorManager(); + MainWindow mainWindow; pMainWindow = &mainWindow; mainWindow.show(); diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 6e33f591..f7ebcfba 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -157,6 +157,11 @@ void MainWindow::updateEditorActions() } +void MainWindow::updateEditorColorSchemes() +{ + mEditorList->applyColorSchemes(pSettings->editor().colorScheme()); +} + void MainWindow::applySettings() { changeTheme(pSettings->environment().theme()); diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index 21b1693d..bf1d4769 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -27,6 +27,7 @@ public: void updateForStatusbarModeInfo(); void updateEditorSettings(); void updateEditorActions(); + void updateEditorColorSchemes(); void applySettings(); diff --git a/RedPandaIDE/qsynedit/KeyStrokes.cpp b/RedPandaIDE/qsynedit/KeyStrokes.cpp index 29530593..e83595a5 100644 --- a/RedPandaIDE/qsynedit/KeyStrokes.cpp +++ b/RedPandaIDE/qsynedit/KeyStrokes.cpp @@ -159,31 +159,18 @@ void SynEditKeyStrokes::clear() void SynEditKeyStrokes::resetDefaults() { - qDebug()<<"SynEditKeyStrokes: resetDefaults "; - qDebug()<<"SynEditKeyStrokes: resetDefaults: clear "; clear(); - qDebug()<<"SynEditKeyStrokes: resetDefaults: add start "; add(SynEditorCommand::ecUp, Qt::Key_Up, Qt::NoModifier); - qDebug()<<"SynEditKeyStrokes: resetDefaults: add start 0"; add(SynEditorCommand::ecSelUp, Qt::Key_Up, Qt::ShiftModifier); - qDebug()<<"SynEditKeyStrokes: resetDefaults: add start 01"; add(SynEditorCommand::ecScrollUp, Qt::Key_Up, Qt::ControlModifier); - qDebug()<<"SynEditKeyStrokes: resetDefaults: add start 02"; add(SynEditorCommand::ecDown, Qt::Key_Down, Qt::NoModifier); - qDebug()<<"SynEditKeyStrokes: resetDefaults: add start 03"; add(SynEditorCommand::ecSelDown, Qt::Key_Down, Qt::ShiftModifier); - qDebug()<<"SynEditKeyStrokes: resetDefaults: add start 04"; add(SynEditorCommand::ecScrollDown, Qt::Key_Down, Qt::ControlModifier); - qDebug()<<"SynEditKeyStrokes: resetDefaults: add start 05"; add(SynEditorCommand::ecLeft, Qt::Key_Left, Qt::NoModifier); - qDebug()<<"SynEditKeyStrokes: resetDefaults: add start 06"; add(SynEditorCommand::ecSelLeft, Qt::Key_Left, Qt::ShiftModifier); add(SynEditorCommand::ecWordLeft, Qt::Key_Left, Qt::ControlModifier); - qDebug()<<"SynEditKeyStrokes: resetDefaults: add start 1"; add(SynEditorCommand::ecSelWordLeft, Qt::Key_Left, Qt::ShiftModifier|Qt::ControlModifier); - qDebug()<<"SynEditKeyStrokes: resetDefaults: add start 2 "; add(SynEditorCommand::ecRight, Qt::Key_Right, Qt::NoModifier); - qDebug()<<"SynEditKeyStrokes: resetDefaults: add start 3"; add(SynEditorCommand::ecSelRight, Qt::Key_Right, Qt::ShiftModifier); add(SynEditorCommand::ecWordRight, Qt::Key_Right, Qt::ControlModifier); @@ -257,5 +244,4 @@ void SynEditKeyStrokes::resetDefaults() add(SynEditorCommand::ecColumnSelect, Qt::Key_C, Qt::ControlModifier | Qt::ShiftModifier); add(SynEditorCommand::ecLineSelect, Qt::Key_L, Qt::ControlModifier | Qt::ShiftModifier); add(SynEditorCommand::ecMatchBracket, Qt::Key_B, Qt::ControlModifier | Qt::ShiftModifier); - qDebug()<<"SynEditKeyStrokes: resetDefaults: add end "; } diff --git a/RedPandaIDE/qsynedit/MiscClasses.cpp b/RedPandaIDE/qsynedit/MiscClasses.cpp index 19abf811..7c48f0e8 100644 --- a/RedPandaIDE/qsynedit/MiscClasses.cpp +++ b/RedPandaIDE/qsynedit/MiscClasses.cpp @@ -287,7 +287,6 @@ QColor SynGutter::color() const void SynGutter::setColor(const QColor &value) { if (mColor!=value) { - qDebug()<<"mColor"<(this); - qDebug()<<"init SynEdit: 1"; mOrigLines = mLines; //fPlugins := TList.Create; mMouseMoved = false; @@ -35,7 +33,6 @@ SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent) mLines->connect(mLines.get(), &SynEditStringList::deleted, this, &SynEdit::linesDeleted); mLines->connect(mLines.get(), &SynEditStringList::inserted, this, &SynEdit::linesInserted); mLines->connect(mLines.get(), &SynEditStringList::putted, this, &SynEdit::linesPutted); - qDebug()<<"init SynEdit: 2"; #ifdef Q_OS_WIN mFontDummy = QFont("Consolas",12); @@ -46,7 +43,6 @@ SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent) #endif mFontDummy.setStyleStrategy(QFont::PreferAntialias); setFont(mFontDummy); - qDebug()<<"init SynEdit:3"; mUndoList = std::make_shared(); mUndoList->connect(mUndoList.get(), &SynEditUndoList::addedUndo, this, &SynEdit::undoAdded); @@ -54,7 +50,6 @@ SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent) mRedoList = std::make_shared(); mRedoList->connect(mRedoList.get(), &SynEditUndoList::addedUndo, this, &SynEdit::redoAdded); mOrigRedoList = mRedoList; - qDebug()<<"init SynEdit: 4"; mCaretColor = QColorConstants::Red; mActiveLineColor = QColorConstants::Svg::lightblue; @@ -64,7 +59,6 @@ SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent) mBookMarkOpt.connect(&mBookMarkOpt, &SynBookMarkOpt::changed, this, &SynEdit::bookMarkOptionsChanged); // fRightEdge has to be set before FontChanged is called for the first time mRightEdge = 80; - qDebug()<<"init SynEdit: 5"; mGutter.setRightOffset(21); mGutter.connect(&mGutter, &SynGutter::changed, this, &SynEdit::gutterChanged); @@ -77,7 +71,6 @@ SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent) mInserting = true; mScrollBars = SynScrollStyle::ssBoth; mExtraLineSpacing = 0; - qDebug()<<"init SynEdit: 6"; this->setFrameShape(QFrame::Panel); this->setFrameShadow(QFrame::Sunken); @@ -87,18 +80,14 @@ SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent) mSelectionMode = SynSelectionMode::smNormal; mActiveSelectionMode = SynSelectionMode::smNormal; mReadOnly = false; - qDebug()<<"init SynEdit: 7"; //stop qt to auto fill background setAutoFillBackground(false); //fFocusList := TList.Create; //fKbdHandler := TSynEditKbdHandler.Create; //fMarkList.OnChange := MarkListChange; - qDebug()<<"init SynEdit: 7-1"; setDefaultKeystrokes(); - qDebug()<<"init SynEdit: 7-2"; mRightEdgeColor = QColorConstants::Svg::silver; - qDebug()<<"init SynEdit: 8"; /* IME input */ mImeCount = 0; @@ -118,7 +107,6 @@ SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent) mOptions = eoAutoIndent | eoAddIndent | eoDragDropEditing | eoEnhanceEndKey | eoTabIndent | eoGroupUndo | eoKeepCaretX | eoSelectWordByDblClick; - qDebug()<<"init SynEdit: 9"; mScrollTimer = new QTimer(this); mScrollTimer->setInterval(100); @@ -132,10 +120,8 @@ SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent) mUseCodeFolding = true; m_blinkTimerId = 0; m_blinkStatus = 0; - qDebug()<<"init SynEdit: 10"; synFontChanged(); - qDebug()<<"init SynEdit: done"; showCaret(); diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index 226bacf3..28bbc0e2 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -14,6 +14,7 @@ const char ValueToChar[28] = {'0', '1', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', Settings* pSettings; Settings::Settings(const QString &filename): + mFilename(filename), mSettings(filename,QSettings::IniFormat), mDirs(this), mEditor(this), @@ -282,14 +283,24 @@ void Settings::Editor::setCopyWithFormatAs(int copyWithFormatAs) mCopyWithFormatAs = copyWithFormatAs; } -QString Settings::Editor::copyHTMLColorSchema() const +QString Settings::Editor::colorScheme() const { - return mCopyHTMLColorSchema; + return mColorScheme; } -void Settings::Editor::setCopyHTMLColorSchema(const QString ©HTMLColorSchema) +void Settings::Editor::setColorScheme(const QString &colorScheme) { - mCopyHTMLColorSchema = copyHTMLColorSchema; + mColorScheme = colorScheme; +} + +QString Settings::Editor::copyHTMLColorScheme() const +{ + return mCopyHTMLColorScheme; +} + +void Settings::Editor::setCopyHTMLColorScheme(const QString ©HTMLColorScheme) +{ + mCopyHTMLColorScheme = copyHTMLColorScheme; } bool Settings::Editor::copyHTMLUseEditorColor() const @@ -312,14 +323,14 @@ void Settings::Editor::setCopyHTMLUseBackground(bool copyHTMLUseBackground) mCopyHTMLUseBackground = copyHTMLUseBackground; } -QString Settings::Editor::copyRTFColorSchema() const +QString Settings::Editor::copyRTFColorScheme() const { - return mCopyRTFColorSchema; + return mCopyRTFColorScheme; } -void Settings::Editor::setCopyRTFColorSchema(const QString ©RTFColorSchema) +void Settings::Editor::setCopyRTFColorScheme(const QString ©RTFColorScheme) { - mCopyRTFColorSchema = copyRTFColorSchema; + mCopyRTFColorScheme = copyRTFColorScheme; } bool Settings::Editor::copyRTFUseEditorColor() const @@ -591,11 +602,14 @@ void Settings::Editor::doSave() saveValue("copy_line_limits",mCopyLineLimits); saveValue("copy_with_format_as",mCopyWithFormatAs); saveValue("copy_rtf_use_background",mCopyRTFUseBackground); - saveValue("copy_rtf_use_editor_color_schema",mCopyRTFUseEditorColor); - saveValue("copy_rtf_color_schema",mCopyRTFColorSchema); + saveValue("copy_rtf_use_editor_color_scheme",mCopyRTFUseEditorColor); + saveValue("copy_rtf_color_scheme",mCopyRTFColorScheme); saveValue("copy_html_use_background",mCopyHTMLUseBackground); - saveValue("copy_html_use_editor_color_schema",mCopyHTMLUseEditorColor); - saveValue("copy_html_color_schema", mCopyHTMLColorSchema); + saveValue("copy_html_use_editor_color_scheme",mCopyHTMLUseEditorColor); + saveValue("copy_html_color_scheme", mCopyHTMLColorScheme); + + //color scheme + saveValue("color_scheme", mColorScheme); } void Settings::Editor::doLoad() @@ -649,12 +663,14 @@ void Settings::Editor::doLoad() mCopyLineLimits = intValue("copy_line_limits",100000); mCopyWithFormatAs = intValue("copy_with_format_as",0); mCopyRTFUseBackground = boolValue("copy_rtf_use_background",false); - mCopyRTFUseEditorColor = boolValue("copy_rtf_use_editor_color_schema",true); - mCopyRTFColorSchema = stringValue("copy_rtf_color_schema",""); + mCopyRTFUseEditorColor = boolValue("copy_rtf_use_editor_color_scheme",true); + mCopyRTFColorScheme = stringValue("copy_rtf_color_scheme",""); mCopyHTMLUseBackground = boolValue("copy_html_use_background",false); - mCopyHTMLUseEditorColor = boolValue("copy_html_use_editor_color_schema",true); - mCopyHTMLColorSchema = stringValue("copy_html_color_schema",""); + mCopyHTMLUseEditorColor = boolValue("copy_html_use_editor_color_scheme",true); + mCopyHTMLColorScheme = stringValue("copy_html_color_scheme",""); + //color + mColorScheme = stringValue("color_scheme", "VS Code"); } SynEditCaretType Settings::Editor::caretForOverwrite() const diff --git a/RedPandaIDE/settings.h b/RedPandaIDE/settings.h index b7e115d9..58893c1d 100644 --- a/RedPandaIDE/settings.h +++ b/RedPandaIDE/settings.h @@ -200,8 +200,8 @@ public: bool copyRTFUseEditorColor() const; void setCopyRTFUseEditorColor(bool copyRTFUseEditorColor); - QString copyRTFColorSchema() const; - void setCopyRTFColorSchema(const QString ©RTFColorSchema); + QString copyRTFColorScheme() const; + void setCopyRTFColorScheme(const QString ©RTFColorScheme); bool copyHTMLUseBackground() const; void setCopyHTMLUseBackground(bool copyHTMLUseBackground); @@ -209,12 +209,15 @@ public: bool copyHTMLUseEditorColor() const; void setCopyHTMLUseEditorColor(bool copyHTMLUseEditorColor); - QString copyHTMLColorSchema() const; - void setCopyHTMLColorSchema(const QString ©HTMLColorSchema); + QString copyHTMLColorScheme() const; + void setCopyHTMLColorScheme(const QString ©HTMLColorScheme); int copyWithFormatAs() const; void setCopyWithFormatAs(int copyWithFormatAs); + QString colorScheme() const; + void setColorScheme(const QString &colorScheme); + private: QByteArray mDefaultEncoding; //General @@ -266,10 +269,13 @@ public: int mCopyWithFormatAs; bool mCopyRTFUseBackground; bool mCopyRTFUseEditorColor; - QString mCopyRTFColorSchema; + QString mCopyRTFColorScheme; bool mCopyHTMLUseBackground; bool mCopyHTMLUseEditorColor; - QString mCopyHTMLColorSchema; + QString mCopyHTMLColorScheme; + + //Color + QString mColorScheme; // _Base interface protected: diff --git a/RedPandaIDE/settingsdialog/editorclipboardwidget.cpp b/RedPandaIDE/settingsdialog/editorclipboardwidget.cpp index 5b989673..e5a6b853 100644 --- a/RedPandaIDE/settingsdialog/editorclipboardwidget.cpp +++ b/RedPandaIDE/settingsdialog/editorclipboardwidget.cpp @@ -21,7 +21,7 @@ void EditorClipboardWidget::doLoad() { //pSettings->editor().load(); //copy - QString mCopyHTMLColorSchema; + QString mCopyHTMLColorScheme; ui->grpCopySizeLimit->setChecked(pSettings->editor().copySizeLimit()); ui->spinCopyCharLimits->setValue(pSettings->editor().copyCharLimits()); @@ -31,11 +31,11 @@ void EditorClipboardWidget::doLoad() ui->chkCopyRTFUseBackground->setChecked(pSettings->editor().copyRTFUseBackground()); ui->chkCopyRTFUseEditorColor->setChecked(pSettings->editor().copyRTFUseEditorColor()); //todo - //ui->cbCopyRTFColorSchema + //ui->cbCopyRTFColorScheme ui->chkCopyHTMLUseBackground->setChecked(pSettings->editor().copyHTMLUseBackground()); ui->chkCopyHTMLUseEditorColor->setChecked(pSettings->editor().copyHTMLUseEditorColor()); //todo - //ui->cbCopyHTMLColorSchema + //ui->cbCopyHTMLColorScheme } diff --git a/RedPandaIDE/settingsdialog/editorclipboardwidget.ui b/RedPandaIDE/settingsdialog/editorclipboardwidget.ui index 54c8dd25..400856b5 100644 --- a/RedPandaIDE/settingsdialog/editorclipboardwidget.ui +++ b/RedPandaIDE/settingsdialog/editorclipboardwidget.ui @@ -7,7 +7,7 @@ 0 0 400 - 429 + 470 @@ -150,7 +150,7 @@ - Use editor's color schema + Use editor's color scheme @@ -172,12 +172,12 @@ - Color schema + Color scheme - + @@ -217,7 +217,7 @@ - Use editor's color schema + Use editor's color scheme @@ -239,12 +239,12 @@ - Color schema + Color scheme - + diff --git a/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp b/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp index 10760cc0..dd95dbaf 100644 --- a/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp +++ b/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp @@ -2,6 +2,10 @@ #include "ui_editorcolorschemewidget.h" #include "../settings.h" #include "../colorscheme.h" +#include "../mainwindow.h" + +#include +#include EditorColorSchemeWidget::EditorColorSchemeWidget(const QString& name, const QString& group, QWidget *parent) : SettingsWidget(name,group,parent), @@ -9,8 +13,18 @@ EditorColorSchemeWidget::EditorColorSchemeWidget(const QString& name, const QStr { ui->setupUi(this); + mDefaultSchemeComboFont = ui->cbScheme->font(); + mModifiedSchemeComboFont = mDefaultSchemeComboFont; + mModifiedSchemeComboFont.setBold(true); + int schemeCount=0; for (QString schemeName: pColorManager->getSchemes()) { + PColorScheme scheme = pColorManager->get(schemeName); + if (!scheme) + return; ui->cbScheme->addItem(schemeName); + if (scheme->customed()) + ui->cbScheme->setItemData(schemeCount,mModifiedSchemeComboFont,Qt::FontRole); + schemeCount++; } ui->treeItems->setModel(&mDefinesModel); mDefinesModel.setHorizontalHeaderLabels(QStringList()); @@ -18,29 +32,17 @@ EditorColorSchemeWidget::EditorColorSchemeWidget(const QString& name, const QStr addDefine(defineName, pColorManager->getDefine(defineName)); } ui->treeItems->expandAll(); - connect(ui->treeItems->selectionModel(), &QItemSelectionModel::selectionChanged, - this, &EditorColorSchemeWidget::onItemSelectionChanged); - connect(this, &SettingsWidget::settingsChanged,this, - &EditorColorSchemeWidget::onSettingChanged); - connect(ui->cbBackground,&QCheckBox::stateChanged, - this, &EditorColorSchemeWidget::onBackgroundChanged); - connect(ui->colorBackground,&ColorEdit::colorChanged, - this, &EditorColorSchemeWidget::onBackgroundChanged); - connect(ui->cbForeground,&QCheckBox::stateChanged, - this, &EditorColorSchemeWidget::onForegroundChanged); - connect(ui->colorForeground,&ColorEdit::colorChanged, - this, &EditorColorSchemeWidget::onForegroundChanged); - connect(ui->cbBold,&QCheckBox::stateChanged, - this, &EditorColorSchemeWidget::onFontStyleChanged); - connect(ui->cbItalic,&QCheckBox::stateChanged, - this, &EditorColorSchemeWidget::onFontStyleChanged); - connect(ui->cbStrikeout,&QCheckBox::stateChanged, - this, &EditorColorSchemeWidget::onFontStyleChanged); - connect(ui->cbUnderlined,&QCheckBox::stateChanged, - this, &EditorColorSchemeWidget::onFontStyleChanged); QModelIndex groupIndex = mDefinesModel.index(0,0); QModelIndex index = mDefinesModel.index(0,0,groupIndex); ui->treeItems->setCurrentIndex(index); + connect(ui->treeItems->selectionModel(), &QItemSelectionModel::selectionChanged, + this, &EditorColorSchemeWidget::onItemSelectionChanged); + connect(ui->cbScheme, QOverload::of(&QComboBox::currentIndexChanged), + this, &EditorColorSchemeWidget::changeSchemeComboFont); + connect(ui->cbScheme, QOverload::of(&QComboBox::currentIndexChanged), + this, &EditorColorSchemeWidget::onItemSelectionChanged); + connect(this, &SettingsWidget::settingsChanged,this, + &EditorColorSchemeWidget::onSettingChanged); ui->editDemo->lines()->setText( "#include \n" "#include \n" @@ -62,6 +64,7 @@ EditorColorSchemeWidget::EditorColorSchemeWidget(const QString& name, const QStr "}\n" ); ui->editDemo->setReadOnly(true); + onItemSelectionChanged(); } void EditorColorSchemeWidget::addDefine(const QString& name, PColorSchemeItemDefine define) @@ -94,6 +97,63 @@ PColorScheme EditorColorSchemeWidget::getCurrentScheme() return pColorManager->get(ui->cbScheme->currentText()); } +void EditorColorSchemeWidget::connectModificationSlots() +{ + connect(ui->cbBackground,&QCheckBox::stateChanged, + this, &EditorColorSchemeWidget::onBackgroundChanged); + connect(ui->colorBackground,&ColorEdit::colorChanged, + this, &EditorColorSchemeWidget::onBackgroundChanged); + connect(ui->cbForeground,&QCheckBox::stateChanged, + this, &EditorColorSchemeWidget::onForegroundChanged); + connect(ui->colorForeground,&ColorEdit::colorChanged, + this, &EditorColorSchemeWidget::onForegroundChanged); + connect(ui->cbBold,&QCheckBox::stateChanged, + this, &EditorColorSchemeWidget::onFontStyleChanged); + connect(ui->cbItalic,&QCheckBox::stateChanged, + this, &EditorColorSchemeWidget::onFontStyleChanged); + connect(ui->cbStrikeout,&QCheckBox::stateChanged, + this, &EditorColorSchemeWidget::onFontStyleChanged); + connect(ui->cbUnderlined,&QCheckBox::stateChanged, + this, &EditorColorSchemeWidget::onFontStyleChanged); +} + +void EditorColorSchemeWidget::disconnectModificationSlots() +{ + disconnect(ui->cbBackground,&QCheckBox::stateChanged, + this, &EditorColorSchemeWidget::onBackgroundChanged); + disconnect(ui->colorBackground,&ColorEdit::colorChanged, + this, &EditorColorSchemeWidget::onBackgroundChanged); + disconnect(ui->cbForeground,&QCheckBox::stateChanged, + this, &EditorColorSchemeWidget::onForegroundChanged); + disconnect(ui->colorForeground,&ColorEdit::colorChanged, + this, &EditorColorSchemeWidget::onForegroundChanged); + disconnect(ui->cbBold,&QCheckBox::stateChanged, + this, &EditorColorSchemeWidget::onFontStyleChanged); + disconnect(ui->cbItalic,&QCheckBox::stateChanged, + this, &EditorColorSchemeWidget::onFontStyleChanged); + disconnect(ui->cbStrikeout,&QCheckBox::stateChanged, + this, &EditorColorSchemeWidget::onFontStyleChanged); + disconnect(ui->cbUnderlined,&QCheckBox::stateChanged, + this, &EditorColorSchemeWidget::onFontStyleChanged); +} + +void EditorColorSchemeWidget::setCurrentSchemeModified() +{ + PColorScheme scheme = getCurrentScheme(); + if (scheme) { + scheme->setCustomed(true); + } + if (mModifiedSchemes.contains(ui->cbScheme->currentText())) + return; + mModifiedSchemes.insert(ui->cbScheme->currentText()); + ui->cbScheme->setItemData(ui->cbScheme->currentIndex(), + mModifiedSchemeComboFont,Qt::FontRole); + ui->cbScheme->setFont(mModifiedSchemeComboFont); + ui->cbScheme->view()->setFont(mDefaultSchemeComboFont); + //we must reset the editor here, because this slot is processed after the onSettingChanged + onSettingChanged(); +} + EditorColorSchemeWidget::~EditorColorSchemeWidget() { delete ui; @@ -112,6 +172,7 @@ static void setColorProp(ColorEdit* ce, QCheckBox* cb, const QColor& color) { void EditorColorSchemeWidget::onItemSelectionChanged() { + disconnectModificationSlots(); QItemSelectionModel * selectionModel = ui->treeItems->selectionModel(); QString name =mDefinesModel.data(selectionModel->currentIndex(),NameRole).toString(); bool found = false; @@ -150,8 +211,9 @@ void EditorColorSchemeWidget::onItemSelectionChanged() } } } - // not found + ui->widgetSchemeItem->setEnabled(found); + connectModificationSlots(); } void EditorColorSchemeWidget::onSettingChanged() @@ -169,10 +231,7 @@ void EditorColorSchemeWidget::onForegroundChanged() } else { item->setForeground(QColor()); } - PColorScheme scheme = getCurrentScheme(); - if (scheme) { - scheme->setCustomed(true); - } + setCurrentSchemeModified(); } void EditorColorSchemeWidget::onBackgroundChanged() @@ -185,10 +244,7 @@ void EditorColorSchemeWidget::onBackgroundChanged() } else { item->setBackground(QColor()); } - PColorScheme scheme = getCurrentScheme(); - if (scheme) { - scheme->setCustomed(true); - } + setCurrentSchemeModified(); } void EditorColorSchemeWidget::onFontStyleChanged() @@ -200,18 +256,67 @@ void EditorColorSchemeWidget::onFontStyleChanged() item->setItalic(ui->cbItalic->isChecked()); item->setStrikeout(ui->cbStrikeout->isChecked()); item->setUnderlined(ui->cbUnderlined->isChecked()); - PColorScheme scheme = getCurrentScheme(); - if (scheme) { - scheme->setCustomed(true); + setCurrentSchemeModified(); +} + +void EditorColorSchemeWidget::changeSchemeComboFont() +{ + QString name = ui->cbScheme->currentText(); + PColorScheme scheme = pColorManager->get(name); + if (scheme && scheme->customed()) { + ui->cbScheme->setFont(mModifiedSchemeComboFont); + } else { + ui->cbScheme->setFont(mDefaultSchemeComboFont); } + ui->cbScheme->view()->setFont(mDefaultSchemeComboFont); } void EditorColorSchemeWidget::doLoad() { - + ui->cbScheme->setCurrentText(pSettings->editor().colorScheme()); } void EditorColorSchemeWidget::doSave() +{ + try { + for (QString name:mModifiedSchemes) { + pColorManager->saveScheme(name); + } + pSettings->editor().setColorScheme(ui->cbScheme->currentText()); + pSettings->editor().save(); + pMainWindow->updateEditorColorSchemes(); + } catch (FileError e) { + QMessageBox::information(this,tr("Error"),e.reason()); + } +} + +void EditorColorSchemeWidget::on_actionCopy_Scheme_triggered() { } + +void EditorColorSchemeWidget::on_btnSchemeMenu_pressed() +{ + QMenu menu; + + PColorScheme scheme = pColorManager->get(ui->cbScheme->currentText()); + if (scheme) { + if (scheme->customed()) { + menu.addAction(ui->actionReset_Scheme); + } + if (!scheme->bundled()) { + menu.addAction(ui->actionRename_Scheme); + menu.addAction(ui->actionDelete_Scheme); + } + menu.addAction(ui->actionCopy_Scheme); + menu.addAction(ui->actionExport_Scheme); + menu.addSeparator(); + } + menu.addAction(ui->actionImport_Scheme); + QPoint p; + p.setX(0); + p.setY(ui->btnSchemeMenu->height()+2); + QAction* action = menu.exec(ui->btnSchemeMenu->mapToGlobal(p)); + if (action) + action->trigger(); +} diff --git a/RedPandaIDE/settingsdialog/editorcolorschemewidget.h b/RedPandaIDE/settingsdialog/editorcolorschemewidget.h index 209df5be..43932dc5 100644 --- a/RedPandaIDE/settingsdialog/editorcolorschemewidget.h +++ b/RedPandaIDE/settingsdialog/editorcolorschemewidget.h @@ -4,6 +4,7 @@ #include "settingswidget.h" #include "../colorscheme.h" +#include #include namespace Ui { @@ -27,21 +28,32 @@ public slots: void onForegroundChanged(); void onBackgroundChanged(); void onFontStyleChanged(); + void changeSchemeComboFont(); private: void addDefine(const QString& name, PColorSchemeItemDefine define); PColorSchemeItem getCurrentItem(); PColorScheme getCurrentScheme(); + void connectModificationSlots(); + void disconnectModificationSlots(); + void setCurrentSchemeModified(); private: Ui::EditorColorSchemeWidget *ui; QStandardItemModel mDefinesModel; + QFont mDefaultSchemeComboFont; + QFont mModifiedSchemeComboFont; + QSet mModifiedSchemes; + QMenu mMenu; // SettingsWidget interface protected: void doLoad() override; void doSave() override; +private slots: + void on_actionCopy_Scheme_triggered(); + void on_btnSchemeMenu_pressed(); }; #endif // EDITORCOLORSCHEMEWIDGET_H diff --git a/RedPandaIDE/settingsdialog/editorcolorschemewidget.ui b/RedPandaIDE/settingsdialog/editorcolorschemewidget.ui index 7616d935..35f64f94 100644 --- a/RedPandaIDE/settingsdialog/editorcolorschemewidget.ui +++ b/RedPandaIDE/settingsdialog/editorcolorschemewidget.ui @@ -46,10 +46,10 @@ - + - + ... @@ -108,7 +108,16 @@ true + + + 1 + 0 + + + + 7 + 0 @@ -124,7 +133,7 @@ - + 0 0 @@ -171,6 +180,12 @@ + + + 0 + 0 + + QFrame::StyledPanel @@ -179,8 +194,27 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + 0 + 0 + + QFrame::StyledPanel @@ -189,7 +223,7 @@ - + Font Styles @@ -223,35 +257,9 @@ - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - @@ -260,7 +268,7 @@ - 0 + 2 0 @@ -277,6 +285,36 @@ + + + Duplicate... + + + + + Rename... + + + + + Restore to Default + + + + + Import Scheme... + + + + + Export... + + + + + Delete... + + @@ -291,6 +329,11 @@
editor.h
1
+ + QPatchedComboBox + QComboBox +
widgets/qpatchedcombobox.h
+
diff --git a/RedPandaIDE/widgets/coloredit.cpp b/RedPandaIDE/widgets/coloredit.cpp index c91ef2c1..f2220394 100644 --- a/RedPandaIDE/widgets/coloredit.cpp +++ b/RedPandaIDE/widgets/coloredit.cpp @@ -46,7 +46,7 @@ QSize ColorEdit::sizeHint() const { QRect rect = fontMetrics().boundingRect(mColor.name()); return QSize{rect.width()+ 10, - rect.width()+ 6 }; + rect.height()+ 6 }; } void ColorEdit::paintEvent(QPaintEvent *event) @@ -56,7 +56,6 @@ void ColorEdit::paintEvent(QPaintEvent *event) painter.fillRect(rect,mColor); painter.setPen(contrast()); painter.drawText(rect,Qt::AlignCenter, mColor.name()); - qDebug()< +#include +#include +#include + +class QPatchedComboBoxListView : public QListView +{ + Q_OBJECT +public: + QPatchedComboBoxListView(QComboBox *cmb = nullptr) : combo(cmb) {} + +protected: + void resizeEvent(QResizeEvent *event) override + { + resizeContents(viewport()->width(), contentsSize().height()); + QListView::resizeEvent(event); + } + + QStyleOptionViewItem viewOptions() const override + { + QStyleOptionViewItem option = QListView::viewOptions(); + option.showDecorationSelected = true; +// if (combo) +// option.font = combo->font(); + return option; + } + + void paintEvent(QPaintEvent *e) override + { + if (combo) { + QStyleOptionComboBox opt; + opt.initFrom(combo); + opt.editable = combo->isEditable(); + if (combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo)) { + //we paint the empty menu area to avoid having blank space that can happen when scrolling + QStyleOptionMenuItem menuOpt; + menuOpt.initFrom(this); + menuOpt.palette = palette(); + menuOpt.state = QStyle::State_None; + menuOpt.checkType = QStyleOptionMenuItem::NotCheckable; + menuOpt.menuRect = e->rect(); + menuOpt.maxIconWidth = 0; + menuOpt.tabWidth = 0; + QPainter p(viewport()); + combo->style()->drawControl(QStyle::CE_MenuEmptyArea, &menuOpt, &p, this); + } + } + QListView::paintEvent(e); + } + +private: + QComboBox *combo; +}; + +class QPatchedComboBox : public QComboBox +{ + Q_OBJECT +public: + explicit QPatchedComboBox(QWidget *parent = nullptr); +}; + +#endif // QPATCHEDCOMBOBOX_H