From 8fb756da776601ae718f5f9c1bdb3e084a484d8b Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Sat, 6 Apr 2024 21:45:00 +0800 Subject: [PATCH] - enhancement: Size of icons in the completion popup changes with the editor font size. --- RedPandaIDE/editor.cpp | 26 +- RedPandaIDE/editor.h | 2 + RedPandaIDE/iconsmanager.cpp | 225 ++++++++++-------- RedPandaIDE/iconsmanager.h | 14 +- RedPandaIDE/mainwindow.cpp | 2 +- RedPandaIDE/settings.cpp | 24 +- RedPandaIDE/settings.h | 12 +- .../editorcodecompletionwidget.cpp | 8 +- .../editorcodecompletionwidget.ui | 8 +- RedPandaIDE/widgets/codecompletionpopup.cpp | 12 +- RedPandaIDE/widgets/codecompletionpopup.h | 2 +- RedPandaIDE/widgets/headercompletionpopup.cpp | 2 +- 12 files changed, 198 insertions(+), 139 deletions(-) diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 17191194..22a3a3a4 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -3576,8 +3576,8 @@ void Editor::showCompletion(const QString& preWord,bool autoComplete, CodeComple mCompletionPopup->setHideSymbolsStartWithUnderline(pSettings->codeCompletion().hideSymbolsStartsWithUnderLine()); mCompletionPopup->setHideSymbolsStartWithTwoUnderline(pSettings->codeCompletion().hideSymbolsStartsWithTwoUnderLine()); mCompletionPopup->setIgnoreCase(pSettings->codeCompletion().ignoreCase()); - mCompletionPopup->resize(pSettings->codeCompletion().width(), - pSettings->codeCompletion().height()); + QSize popSize = calcCompletionPopupSize(); + mCompletionPopup->resize(popSize); // Position it at the top of the next line QPoint popupPos = mapToGlobal(displayCoordToPixels(displayXY())); @@ -3674,10 +3674,10 @@ void Editor::showHeaderCompletion(bool autoComplete, bool forceShow) p.setY(p.y() + textHeight() + 2); mHeaderCompletionPopup->move(mapToGlobal(p)); - mHeaderCompletionPopup->setIgnoreCase(pSettings->codeCompletion().ignoreCase()); - mHeaderCompletionPopup->resize(pSettings->codeCompletion().width(), - pSettings->codeCompletion().height()); + + QSize popSize = calcCompletionPopupSize(); + mHeaderCompletionPopup->resize(popSize); //Set Font size; mHeaderCompletionPopup->setFont(font()); mHeaderCompletionPopup->setLineHeightFactor(pSettings->editor().lineSpacing()); @@ -4575,6 +4575,22 @@ void Editor::cancelHoverLink() } } +QSize Editor::calcCompletionPopupSize() +{ +#if QT_VERSION_MAJOR==5 && QT_VERSION_MINOR < 15 + int screenHeight = qApp->primaryScreen()->size().height(); + int screenWidht = qApp->primaryScreen()->size().width; +#else + int screenHeight = screen()->size().height(); + int screenWidth = screen()->size().width(); +#endif + int popWidth = std::min(pSettings->codeCompletion().widthInColumns() * charWidth(), + screenWidth / 2) + 4; + int popHeight = std::min(pSettings->codeCompletion().heightInLines() * textHeight(), + (screenHeight / 2 - textHeight() * 2)) + 4; + return QSize{popWidth, popHeight}; +} + quint64 Editor::lastFocusOutTime() const { return mLastFocusOutTime; diff --git a/RedPandaIDE/editor.h b/RedPandaIDE/editor.h index a222ee2f..ffa82023 100644 --- a/RedPandaIDE/editor.h +++ b/RedPandaIDE/editor.h @@ -303,6 +303,8 @@ private: void updateHoverLink(int line); void cancelHoverLink(); + QSize calcCompletionPopupSize(); + private: bool mInited; QDateTime mBackupTime; diff --git a/RedPandaIDE/iconsmanager.cpp b/RedPandaIDE/iconsmanager.cpp index 380054c0..2c31a197 100644 --- a/RedPandaIDE/iconsmanager.cpp +++ b/RedPandaIDE/iconsmanager.cpp @@ -41,7 +41,7 @@ IconsManager::IconsManager(QObject *parent) : QObject(parent) mMakeDisabledIconDarker = false; } -void IconsManager::updateEditorGuttorIcons(const QString& iconSet,int size) +void IconsManager::updateEditorGutterIcons(const QString& iconSet,int size) { QString iconFolder = mIconSetTemplate.arg( iconSetsFolder(),iconSet,"editor"); updateMakeDisabledIconDarker(iconSet); @@ -54,29 +54,12 @@ void IconsManager::updateEditorGuttorIcons(const QString& iconSet,int size) void IconsManager::updateParserIcons(const QString &iconSet, int size) { - QString iconFolder = mIconSetTemplate.arg( iconSetsFolder(),iconSet,"classparser"); - updateMakeDisabledIconDarker(iconSet); - mIconPixmaps.insert(PARSER_TYPE, createSVGIcon(iconFolder+"type.svg",size,size)); - mIconPixmaps.insert(PARSER_CLASS, createSVGIcon(iconFolder+"class.svg",size,size)); - mIconPixmaps.insert(PARSER_NAMESPACE, createSVGIcon(iconFolder+"namespace.svg",size,size)); - mIconPixmaps.insert(PARSER_DEFINE, createSVGIcon(iconFolder+"define.svg",size,size)); - mIconPixmaps.insert(PARSER_ENUM, createSVGIcon(iconFolder+"enum.svg",size,size));; - mIconPixmaps.insert(PARSER_GLOBAL_METHOD, createSVGIcon(iconFolder+"global_method.svg",size,size)); - mIconPixmaps.insert(PARSER_INHERITED_PROTECTED_METHOD, createSVGIcon(iconFolder+"method_inherited_protected.svg",size,size)); - mIconPixmaps.insert(PARSER_INHERITED_METHOD, createSVGIcon(iconFolder+"method_inherited.svg",size,size)); - mIconPixmaps.insert(PARSER_PROTECTED_METHOD, createSVGIcon(iconFolder+"method_protected.svg",size,size)); - mIconPixmaps.insert(PARSER_PUBLIC_METHOD, createSVGIcon(iconFolder+"method_public.svg",size,size)); - mIconPixmaps.insert(PARSER_PRIVATE_METHOD, createSVGIcon(iconFolder+"method_private.svg",size,size)); - mIconPixmaps.insert(PARSER_GLOBAL_VAR, createSVGIcon(iconFolder+"global.svg",size,size)); - mIconPixmaps.insert(PARSER_INHERITED_PROTECTD_VAR, createSVGIcon(iconFolder+"var_inherited_protected.svg",size,size)); - mIconPixmaps.insert(PARSER_INHERITED_VAR, createSVGIcon(iconFolder+"var_inherited.svg",size,size)); - mIconPixmaps.insert(PARSER_PROTECTED_VAR, createSVGIcon(iconFolder+"var_protected.svg",size,size)); - mIconPixmaps.insert(PARSER_PUBLIC_VAR, createSVGIcon(iconFolder+"var_public.svg",size,size)); - mIconPixmaps.insert(PARSER_PRIVATE_VAR, createSVGIcon(iconFolder+"var_private.svg",size,size)); - mIconPixmaps.insert(PARSER_KEYWORD, createSVGIcon(iconFolder+"keyword.svg",size,size)); - mIconPixmaps.insert(PARSER_CODE_SNIPPET, createSVGIcon(iconFolder+"code_snippet.svg",size,size)); - mIconPixmaps.insert(PARSER_LOCAL_VAR, createSVGIcon(iconFolder+"var.svg",size,size)); - + mParserIconSize = size; + mParserIconSet = iconSet; + mCachedParserIconSet = ""; + mCachedParserIconSize = -1; + mCachedParserIconPixmaps.clear(); + updateParserIcons(mIconPixmaps,iconSet,size); } void IconsManager::updateActionIcons(const QString& iconSet, int size) @@ -281,79 +264,26 @@ void IconsManager::prepareCustomIconSet(const QString &customIconSet) QPixmap IconsManager::getPixmapForStatement(PStatement statement) { - if (!statement) - return QPixmap(); - StatementKind kind = getKindOfStatement(statement); - switch (kind) { - case StatementKind::Typedef: - return *(pIconsManager->getPixmap(IconsManager::PARSER_TYPE)); - case StatementKind::Class: - return *(pIconsManager->getPixmap(IconsManager::PARSER_CLASS)); - case StatementKind::Namespace: - case StatementKind::NamespaceAlias: - return *(pIconsManager->getPixmap(IconsManager::PARSER_NAMESPACE)); - case StatementKind::Preprocessor: - return *(pIconsManager->getPixmap(IconsManager::PARSER_DEFINE)); - case StatementKind::EnumClassType: - case StatementKind::EnumType: - case StatementKind::Enum: - return *(pIconsManager->getPixmap(IconsManager::PARSER_ENUM)); - case StatementKind::Function: - case StatementKind::Constructor: - case StatementKind::Destructor: - if (statement->scope == StatementScope::Global) - return *(pIconsManager->getPixmap(IconsManager::PARSER_GLOBAL_METHOD)); - if (statement->isInherited()) { - if (statement->accessibility == StatementAccessibility::Protected) { - return *(pIconsManager->getPixmap(IconsManager::PARSER_INHERITED_PROTECTED_METHOD)); - } else if (statement->accessibility == StatementAccessibility::Public) { - return *(pIconsManager->getPixmap(IconsManager::PARSER_INHERITED_METHOD)); - } else { - return *(pIconsManager->getPixmap(IconsManager::PARSER_PRIVATE_METHOD)); - } - } else { - if (statement->accessibility == StatementAccessibility::Protected) { - return *(pIconsManager->getPixmap(IconsManager::PARSER_PROTECTED_METHOD)); - } else if (statement->accessibility == StatementAccessibility::Public) { - return *(pIconsManager->getPixmap(IconsManager::PARSER_PUBLIC_METHOD)); - } else { - return *(pIconsManager->getPixmap(IconsManager::PARSER_PRIVATE_METHOD)); - } - } - break; - case StatementKind::GlobalVariable: - return *(pIconsManager->getPixmap(IconsManager::PARSER_GLOBAL_VAR)); - case StatementKind::LocalVariable: - return *(pIconsManager->getPixmap(IconsManager::PARSER_LOCAL_VAR)); - case StatementKind::Variable: - if (statement->isInherited()) { - if (statement->accessibility == StatementAccessibility::Protected) { - return *(pIconsManager->getPixmap(IconsManager::PARSER_INHERITED_PROTECTD_VAR)); - } else if (statement->accessibility == StatementAccessibility::Public) { - return *(pIconsManager->getPixmap(IconsManager::PARSER_INHERITED_VAR)); - } else { - return *(pIconsManager->getPixmap(IconsManager::PARSER_PRIVATE_VAR)); - } - } else { - if (statement->accessibility == StatementAccessibility::Protected) { - return *(pIconsManager->getPixmap(IconsManager::PARSER_PROTECTED_VAR)); - } else if (statement->accessibility == StatementAccessibility::Public) { - return *(pIconsManager->getPixmap(IconsManager::PARSER_PUBLIC_VAR)); - } else { - return *(pIconsManager->getPixmap(IconsManager::PARSER_PRIVATE_VAR)); - } - } - break; - case StatementKind::Keyword: - return *(pIconsManager->getPixmap(IconsManager::PARSER_KEYWORD)); - case StatementKind::UserCodeSnippet: - return *(pIconsManager->getPixmap(IconsManager::PARSER_CODE_SNIPPET)); - case StatementKind::Alias: - return *(pIconsManager->getPixmap(IconsManager::PARSER_TYPE)); - default: - break; + return getPixmapForStatement(mIconPixmaps, statement); +} + +QPixmap IconsManager::getPixmapForStatement(PStatement statement, int size) +{ + if (size == mParserIconSize) + return getPixmapForStatement(statement); + if (mParserIconSet != mCachedParserIconSet + || size != mCachedParserIconSize) { + mCachedParserIconSet.clear(); + mCachedParserIconSet = mParserIconSet; + mCachedParserIconSize = size; + updateParserIcons(mCachedParserIconPixmaps,mParserIconSet,size); } - return QPixmap(); + return getPixmapForStatement(mCachedParserIconPixmaps, statement); +} + +IconsManager::PPixmap IconsManager::getPixmap(const QMap &iconPixmaps, IconName iconName) const +{ + return iconPixmaps.value(iconName, mDefaultIconPixmap); } const QString IconsManager::iconSetsFolder() const @@ -404,3 +334,106 @@ void IconsManager::updateMakeDisabledIconDarker(const QString& iconset ) { mMakeDisabledIconDarker = (iconset == "contrast"); } + +void IconsManager::updateParserIcons(QMap &iconPixmaps, const QString &iconSet, int size) +{ + QString iconFolder = mIconSetTemplate.arg( iconSetsFolder(),iconSet,"classparser"); + updateMakeDisabledIconDarker(iconSet); + iconPixmaps.insert(PARSER_TYPE, createSVGIcon(iconFolder+"type.svg",size,size)); + iconPixmaps.insert(PARSER_CLASS, createSVGIcon(iconFolder+"class.svg",size,size)); + iconPixmaps.insert(PARSER_NAMESPACE, createSVGIcon(iconFolder+"namespace.svg",size,size)); + iconPixmaps.insert(PARSER_DEFINE, createSVGIcon(iconFolder+"define.svg",size,size)); + iconPixmaps.insert(PARSER_ENUM, createSVGIcon(iconFolder+"enum.svg",size,size));; + iconPixmaps.insert(PARSER_GLOBAL_METHOD, createSVGIcon(iconFolder+"global_method.svg",size,size)); + iconPixmaps.insert(PARSER_INHERITED_PROTECTED_METHOD, createSVGIcon(iconFolder+"method_inherited_protected.svg",size,size)); + iconPixmaps.insert(PARSER_INHERITED_METHOD, createSVGIcon(iconFolder+"method_inherited.svg",size,size)); + iconPixmaps.insert(PARSER_PROTECTED_METHOD, createSVGIcon(iconFolder+"method_protected.svg",size,size)); + iconPixmaps.insert(PARSER_PUBLIC_METHOD, createSVGIcon(iconFolder+"method_public.svg",size,size)); + iconPixmaps.insert(PARSER_PRIVATE_METHOD, createSVGIcon(iconFolder+"method_private.svg",size,size)); + iconPixmaps.insert(PARSER_GLOBAL_VAR, createSVGIcon(iconFolder+"global.svg",size,size)); + iconPixmaps.insert(PARSER_INHERITED_PROTECTD_VAR, createSVGIcon(iconFolder+"var_inherited_protected.svg",size,size)); + iconPixmaps.insert(PARSER_INHERITED_VAR, createSVGIcon(iconFolder+"var_inherited.svg",size,size)); + iconPixmaps.insert(PARSER_PROTECTED_VAR, createSVGIcon(iconFolder+"var_protected.svg",size,size)); + iconPixmaps.insert(PARSER_PUBLIC_VAR, createSVGIcon(iconFolder+"var_public.svg",size,size)); + iconPixmaps.insert(PARSER_PRIVATE_VAR, createSVGIcon(iconFolder+"var_private.svg",size,size)); + iconPixmaps.insert(PARSER_KEYWORD, createSVGIcon(iconFolder+"keyword.svg",size,size)); + iconPixmaps.insert(PARSER_CODE_SNIPPET, createSVGIcon(iconFolder+"code_snippet.svg",size,size)); + iconPixmaps.insert(PARSER_LOCAL_VAR, createSVGIcon(iconFolder+"var.svg",size,size)); +} + +QPixmap IconsManager::getPixmapForStatement(const QMap &iconPixmaps, PStatement statement) +{ + if (!statement) + return QPixmap(); + StatementKind kind = getKindOfStatement(statement); + switch (kind) { + case StatementKind::Typedef: + return *(getPixmap(iconPixmaps, IconsManager::PARSER_TYPE)); + case StatementKind::Class: + return *(getPixmap(iconPixmaps, IconsManager::PARSER_CLASS)); + case StatementKind::Namespace: + case StatementKind::NamespaceAlias: + return *(getPixmap(iconPixmaps, IconsManager::PARSER_NAMESPACE)); + case StatementKind::Preprocessor: + return *(getPixmap(iconPixmaps, IconsManager::PARSER_DEFINE)); + case StatementKind::EnumClassType: + case StatementKind::EnumType: + case StatementKind::Enum: + return *(getPixmap(iconPixmaps, IconsManager::PARSER_ENUM)); + case StatementKind::Function: + case StatementKind::Constructor: + case StatementKind::Destructor: + if (statement->scope == StatementScope::Global) + return *(getPixmap(iconPixmaps, IconsManager::PARSER_GLOBAL_METHOD)); + if (statement->isInherited()) { + if (statement->accessibility == StatementAccessibility::Protected) { + return *(getPixmap(iconPixmaps, IconsManager::PARSER_INHERITED_PROTECTED_METHOD)); + } else if (statement->accessibility == StatementAccessibility::Public) { + return *(getPixmap(iconPixmaps, IconsManager::PARSER_INHERITED_METHOD)); + } else { + return *(getPixmap(iconPixmaps, IconsManager::PARSER_PRIVATE_METHOD)); + } + } else { + if (statement->accessibility == StatementAccessibility::Protected) { + return *(getPixmap(iconPixmaps, IconsManager::PARSER_PROTECTED_METHOD)); + } else if (statement->accessibility == StatementAccessibility::Public) { + return *(getPixmap(iconPixmaps, IconsManager::PARSER_PUBLIC_METHOD)); + } else { + return *(getPixmap(iconPixmaps, IconsManager::PARSER_PRIVATE_METHOD)); + } + } + break; + case StatementKind::GlobalVariable: + return *(getPixmap(iconPixmaps, IconsManager::PARSER_GLOBAL_VAR)); + case StatementKind::LocalVariable: + return *(getPixmap(iconPixmaps, IconsManager::PARSER_LOCAL_VAR)); + case StatementKind::Variable: + if (statement->isInherited()) { + if (statement->accessibility == StatementAccessibility::Protected) { + return *(getPixmap(iconPixmaps, IconsManager::PARSER_INHERITED_PROTECTD_VAR)); + } else if (statement->accessibility == StatementAccessibility::Public) { + return *(getPixmap(iconPixmaps, IconsManager::PARSER_INHERITED_VAR)); + } else { + return *(getPixmap(iconPixmaps, IconsManager::PARSER_PRIVATE_VAR)); + } + } else { + if (statement->accessibility == StatementAccessibility::Protected) { + return *(getPixmap(iconPixmaps, IconsManager::PARSER_PROTECTED_VAR)); + } else if (statement->accessibility == StatementAccessibility::Public) { + return *(getPixmap(iconPixmaps, IconsManager::PARSER_PUBLIC_VAR)); + } else { + return *(getPixmap(iconPixmaps, IconsManager::PARSER_PRIVATE_VAR)); + } + } + break; + case StatementKind::Keyword: + return *(getPixmap(iconPixmaps, IconsManager::PARSER_KEYWORD)); + case StatementKind::UserCodeSnippet: + return *(getPixmap(iconPixmaps, IconsManager::PARSER_CODE_SNIPPET)); + case StatementKind::Alias: + return *(getPixmap(iconPixmaps, IconsManager::PARSER_TYPE)); + default: + break; + } + return QPixmap(); +} diff --git a/RedPandaIDE/iconsmanager.h b/RedPandaIDE/iconsmanager.h index 23abab54..c9ba2d32 100644 --- a/RedPandaIDE/iconsmanager.h +++ b/RedPandaIDE/iconsmanager.h @@ -198,7 +198,7 @@ public: }; explicit IconsManager(QObject *parent = nullptr); - void updateEditorGuttorIcons(const QString& iconSet, int size); + void updateEditorGutterIcons(const QString& iconSet, int size); void updateParserIcons(const QString& iconSet, int size); void updateActionIcons(const QString& iconSet, int size); void updateFileSystemIcons(const QString& iconSet, int size); @@ -216,13 +216,20 @@ public: void prepareCustomIconSet(const QString &customIconSet); QPixmap getPixmapForStatement(PStatement statement); + QPixmap getPixmapForStatement(PStatement statement, int size); const QString iconSetsFolder() const; void setIconSetsFolder(const QString &newIconSetsFolder); QList listIconSets(); + QString iconSet() const; + void setIconSet(const QString &newIconSet); + private: void updateMakeDisabledIconDarker(const QString& iconset); + void updateParserIcons(QMap &iconPixmaps, const QString& iconSet, int size); + QPixmap getPixmapForStatement(const QMap &iconPixmaps, PStatement statement); + PPixmap getPixmap(const QMap &iconPixmaps, IconName iconName) const; signals: void actionIconsUpdated(); private: @@ -231,6 +238,11 @@ private: QSize mActionIconSize; QString mIconSetTemplate; QString mIconSetsFolder; + QString mParserIconSet; + int mParserIconSize; + QString mCachedParserIconSet; + int mCachedParserIconSize; + QMap mCachedParserIconPixmaps; bool mMakeDisabledIconDarker; }; diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 2f079a8d..b875b9b4 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -547,7 +547,7 @@ void MainWindow::updateStatusbarForLineCol(bool clear) void MainWindow::updateEditorSettings() { - pIconsManager->updateEditorGuttorIcons( + pIconsManager->updateEditorGutterIcons( pSettings->environment().iconSet(), calIconSize(pSettings->editor().fontName(),pSettings->editor().fontSize()) ); diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index 0d72e206..8bcf45c2 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -4843,30 +4843,30 @@ void Settings::CodeCompletion::setEnabled(bool newEnabled) mEnabled = newEnabled; } -int Settings::CodeCompletion::height() const +int Settings::CodeCompletion::heightInLines() const { - return mHeight; + return mHeightInLines; } -void Settings::CodeCompletion::setHeight(int newHeight) +void Settings::CodeCompletion::setHeightInLines(int newHeight) { - mHeight = newHeight; + mHeightInLines = newHeight; } -int Settings::CodeCompletion::width() const +int Settings::CodeCompletion::widthInColumns() const { - return mWidth; + return mWidthInColumns; } -void Settings::CodeCompletion::setWidth(int newWidth) +void Settings::CodeCompletion::setWidthInColumns(int newWidth) { - mWidth = newWidth; + mWidthInColumns = newWidth; } void Settings::CodeCompletion::doSave() { - saveValue("width",mWidth); - saveValue("height",mHeight); + saveValue("widthInColumns",mWidthInColumns); + saveValue("heightInLines",mHeightInLines); saveValue("enabled",mEnabled); saveValue("parse_local_headers",mParseLocalHeaders); saveValue("parse_global_headers",mParseGlobalHeaders); @@ -4888,8 +4888,8 @@ void Settings::CodeCompletion::doSave() void Settings::CodeCompletion::doLoad() { //Appearance - mWidth = intValue("width",700); - mHeight = intValue("height",400); + mWidthInColumns = intValue("widthInColumns",30); + mHeightInLines = intValue("heightInLines",8); mEnabled = boolValue("enabled",true); mParseLocalHeaders = boolValue("parse_local_headers",true); mParseGlobalHeaders = boolValue("parse_global_headers",true); diff --git a/RedPandaIDE/settings.h b/RedPandaIDE/settings.h index b2a8fab1..d880a5b4 100644 --- a/RedPandaIDE/settings.h +++ b/RedPandaIDE/settings.h @@ -643,11 +643,11 @@ public: class CodeCompletion: public _Base { public: explicit CodeCompletion(Settings *settings); - int width() const; - void setWidth(int newWidth); + int widthInColumns() const; + void setWidthInColumns(int newWidth); - int height() const; - void setHeight(int newHeight); + int heightInLines() const; + void setHeightInLines(int newHeight); bool enabled() const; void setEnabled(bool newEnabled); @@ -695,8 +695,8 @@ public: void setShareParser(bool newShareParser); private: - int mWidth; - int mHeight; + int mWidthInColumns; + int mHeightInLines; bool mEnabled; bool mParseLocalHeaders; bool mParseGlobalHeaders; diff --git a/RedPandaIDE/settingsdialog/editorcodecompletionwidget.cpp b/RedPandaIDE/settingsdialog/editorcodecompletionwidget.cpp index a8eeb6b9..f488cda8 100644 --- a/RedPandaIDE/settingsdialog/editorcodecompletionwidget.cpp +++ b/RedPandaIDE/settingsdialog/editorcodecompletionwidget.cpp @@ -41,8 +41,8 @@ void EditorCodeCompletionWidget::doLoad() ui->chkParseLocalFiles->setChecked(pSettings->codeCompletion().parseLocalHeaders()); ui->chkParseSystemFiles->setChecked(pSettings->codeCompletion().parseGlobalHeaders()); - ui->spinWidth->setValue(pSettings->codeCompletion().width()); - ui->spinHeight->setValue(pSettings->codeCompletion().height()); + ui->spinWidth->setValue(pSettings->codeCompletion().widthInColumns()); + ui->spinHeight->setValue(pSettings->codeCompletion().heightInLines()); ui->chkShowSuggestionWhileTyping->setChecked(pSettings->codeCompletion().showCompletionWhileInput()); ui->chkRecordUsage->setChecked(pSettings->codeCompletion().recordUsage()); @@ -67,8 +67,8 @@ void EditorCodeCompletionWidget::doSave() pSettings->codeCompletion().setParseLocalHeaders(ui->chkParseLocalFiles->isChecked()); pSettings->codeCompletion().setParseGlobalHeaders(ui->chkParseSystemFiles->isChecked()); - pSettings->codeCompletion().setWidth(ui->spinWidth->value()); - pSettings->codeCompletion().setHeight(ui->spinHeight->value()); + pSettings->codeCompletion().setWidthInColumns(ui->spinWidth->value()); + pSettings->codeCompletion().setHeightInLines(ui->spinHeight->value()); pSettings->codeCompletion().setShowCompletionWhileInput(ui->chkShowSuggestionWhileTyping->isChecked()); pSettings->codeCompletion().setRecordUsage(ui->chkRecordUsage->isChecked()); diff --git a/RedPandaIDE/settingsdialog/editorcodecompletionwidget.ui b/RedPandaIDE/settingsdialog/editorcodecompletionwidget.ui index 57748328..421562d0 100644 --- a/RedPandaIDE/settingsdialog/editorcodecompletionwidget.ui +++ b/RedPandaIDE/settingsdialog/editorcodecompletionwidget.ui @@ -250,10 +250,10 @@ - 100 + 5 - 10000 + 999 @@ -267,10 +267,10 @@ - 100 + 1 - 10000 + 999 diff --git a/RedPandaIDE/widgets/codecompletionpopup.cpp b/RedPandaIDE/widgets/codecompletionpopup.cpp index 19b70a5b..aa945181 100644 --- a/RedPandaIDE/widgets/codecompletionpopup.cpp +++ b/RedPandaIDE/widgets/codecompletionpopup.cpp @@ -1300,10 +1300,6 @@ QVariant CodeCompletionListModel::data(const QModelIndex &index, int role) const PStatement statement = mStatements->at(index.row()); return statement->command; } - case Qt::DecorationRole:{ - PStatement statement = mStatements->at(index.row()); - return pIconsManager->getPixmapForStatement(statement); - } } return QVariant(); } @@ -1317,14 +1313,14 @@ PStatement CodeCompletionListModel::statement(const QModelIndex &index) const return mStatements->at(index.row()); } -QPixmap CodeCompletionListModel::statementIcon(const QModelIndex &index) const +QPixmap CodeCompletionListModel::statementIcon(const QModelIndex &index, int size) const { if (!index.isValid()) return QPixmap(); if (index.row()>=mStatements->count()) return QPixmap(); PStatement statement = mStatements->at(index.row()); - return pIconsManager->getPixmapForStatement(statement); + return pIconsManager->getPixmapForStatement(statement, size); } void CodeCompletionListModel::notifyUpdated() @@ -1348,7 +1344,7 @@ void CodeCompletionListItemDelegate::paint(QPainter *painter, const QStyleOption if (option.state & QStyle::State_Selected) { painter->fillRect(option.rect, mCurrentSelectionColor); } - QPixmap icon = mModel->statementIcon(index); + QPixmap icon = mModel->statementIcon(index, QFontMetrics(font()).height()); int x=option.rect.left(); if (!icon.isNull()) { qreal dpr=icon.devicePixelRatioF(); @@ -1422,7 +1418,7 @@ void CodeCompletionListItemDelegate::setFont(const QFont &newFont) QSize CodeCompletionListItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { QSize size = QStyledItemDelegate::sizeHint(option, index); - size.setHeight(size.height()*mLineHeightFactor); + size.setHeight(QFontMetrics(mFont).height()*mLineHeightFactor); return size; } diff --git a/RedPandaIDE/widgets/codecompletionpopup.h b/RedPandaIDE/widgets/codecompletionpopup.h index 5b3615ae..3593e5ef 100644 --- a/RedPandaIDE/widgets/codecompletionpopup.h +++ b/RedPandaIDE/widgets/codecompletionpopup.h @@ -30,7 +30,7 @@ public: int rowCount(const QModelIndex &parent) const override; QVariant data(const QModelIndex &index, int role) const override; PStatement statement(const QModelIndex &index) const; - QPixmap statementIcon(const QModelIndex &index) const; + QPixmap statementIcon(const QModelIndex &index, int size) const; void notifyUpdated(); private: diff --git a/RedPandaIDE/widgets/headercompletionpopup.cpp b/RedPandaIDE/widgets/headercompletionpopup.cpp index 736e4d91..b5fcf81b 100644 --- a/RedPandaIDE/widgets/headercompletionpopup.cpp +++ b/RedPandaIDE/widgets/headercompletionpopup.cpp @@ -454,7 +454,7 @@ void HeaderCompletionListItemDelegate::paint(QPainter *painter, const QStyleOpti QSize HeaderCompletionListItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { QSize size = QStyledItemDelegate::sizeHint(option, index); - size.setHeight(size.height()*mLineHeightFactor); + size.setHeight(QFontMetrics(mFont).height()*mLineHeightFactor); return size; }