From bf25853da131b25c7df66d232a2ece62726b8e5f Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Fri, 11 Feb 2022 20:19:48 +0800 Subject: [PATCH] - fix: wrong code completion font size, when screen dpi changed - enhancement: replace Files View Panel's path lineedit control with combo box --- NEWS.md | 4 +++ RedPandaIDE/mainwindow.cpp | 35 +++++++++++++++------ RedPandaIDE/mainwindow.h | 2 +- RedPandaIDE/mainwindow.ui | 35 ++++++++++++++++----- RedPandaIDE/parser/parserutils.h | 1 + RedPandaIDE/widgets/codecompletionpopup.cpp | 33 ++++++++++++++++--- RedPandaIDE/widgets/codecompletionpopup.h | 4 +++ 7 files changed, 91 insertions(+), 23 deletions(-) diff --git a/NEWS.md b/NEWS.md index 917cdbef..8cfc2b78 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +Red Panda C++ Version 0.14.3 + - fix: wrong code completion font size, when screen dpi changed + - enhancement: replace Files View Panel's path lineedit control with combo box + Red Panda C++ Version 0.14.2 - enhancement: file system view mode for project - enhancement: remove / rename / create new folder in the files view diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index eba87d58..9668f42c 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -58,6 +58,7 @@ #include #include #include +#include #include "settingsdialog/settingsdialog.h" #include "compiler/compilermanager.h" @@ -290,6 +291,8 @@ MainWindow::MainWindow(QWidget *parent) for (int i=1;itreeFiles->hideColumn(i); } + connect(ui->cbFilesPath->lineEdit(),&QLineEdit::returnPressed, + this,&MainWindow::onFilesViewPathChanged); //class browser ui->classBrowser->setUniformRowHeights(true); @@ -1184,7 +1187,7 @@ void MainWindow::updateActionIcons() for (QToolButton* btn: mClassBrowserToolbar->findChildren()) { btn->setIconSize(iconSize); } - for (QToolButton* btn: mFilesViewToolbar->findChildren()) { + for (QToolButton* btn: ui->panelFiles->findChildren()) { btn->setIconSize(iconSize); } @@ -2721,13 +2724,8 @@ void MainWindow::buildContextMenus() }); //toolbar for files view - mFilesViewToolbar = new QWidget(); { - QVBoxLayout* layout = dynamic_cast( ui->tabFiles->layout()); - layout->insertWidget(0,mFilesViewToolbar); - QHBoxLayout* hlayout = new QHBoxLayout(); - hlayout->setContentsMargins(2,2,2,2); - mFilesViewToolbar->setLayout(hlayout); + QHBoxLayout* hlayout = dynamic_cast( ui->panelFiles->layout()); QToolButton * toolButton; int size = pointToPixel(pSettings->environment().interfaceFontSize()); QSize iconSize(size,size); @@ -2739,7 +2737,6 @@ void MainWindow::buildContextMenus() toolButton->setIconSize(iconSize); toolButton->setDefaultAction(ui->actionLocate_in_Files_View); hlayout->addWidget(toolButton); - hlayout->addStretch(); } } @@ -3660,6 +3657,17 @@ void MainWindow::onFileChanged(const QString &path) } } +void MainWindow::onFilesViewPathChanged() +{ + QString filesPath = ui->cbFilesPath->currentText(); + QFileInfo fileInfo(filesPath); + if (fileInfo.exists() && fileInfo.isDir()) { + setFilesViewRoot(filesPath); + } else { + ui->cbFilesPath->setCurrentText(pSettings->environment().currentFolder()); + } +} + const std::shared_ptr &MainWindow::headerCompletionPopup() const { return mHeaderCompletionPopup; @@ -5596,8 +5604,15 @@ void MainWindow::setFilesViewRoot(const QString &path) mFileSystemModel.setRootPath(path); ui->treeFiles->setRootIndex(mFileSystemModel.index(path)); pSettings->environment().setCurrentFolder(path); - ui->txtFilesPath->setText(path); - ui->txtFilesPath->setCursorPosition(1); + int pos = ui->cbFilesPath->findText(path); + if (pos<0) { + ui->cbFilesPath->addItem(mFileSystemModel.iconProvider()->icon(QFileIconProvider::Folder),path); + pos = ui->cbFilesPath->findText(path); + } else if (ui->cbFilesPath->itemIcon(pos).isNull()) { + ui->cbFilesPath->setItemIcon(pos,mFileSystemModel.iconProvider()->icon(QFileIconProvider::Folder)); + } + ui->cbFilesPath->setCurrentIndex(pos); + ui->cbFilesPath->lineEdit()->setCursorPosition(1); } void MainWindow::clearIssues() diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index 9473a659..7b65dbdd 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -255,6 +255,7 @@ private slots: void onEditorRenamed(const QString& oldFilename, const QString& newFilename, bool firstSave); void onAutoSaveTimeout(); void onFileChanged(const QString& path); + void onFilesViewPathChanged(); void onWatchViewContextMenu(const QPoint& pos); void onBookmarkContextMenu(const QPoint& pos); @@ -671,7 +672,6 @@ private: QAction * mFilesView_OpenWithExternal; QAction * mFilesView_OpenInTerminal; QAction * mFilesView_OpenInExplorer; - QWidget * mFilesViewToolbar; QAction * mFilesView_CreateFolder; QAction * mFilesView_RemoveFile; diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index d904fb8f..8eccde9c 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -244,13 +244,34 @@ 0 - - - true - - - true - + + + + 2 + + + 0 + + + 0 + + + 2 + + + 0 + + + + + true + + + QComboBox::InsertAtTop + + + + diff --git a/RedPandaIDE/parser/parserutils.h b/RedPandaIDE/parser/parserutils.h index e0eddae0..2d3b0c79 100644 --- a/RedPandaIDE/parser/parserutils.h +++ b/RedPandaIDE/parser/parserutils.h @@ -169,6 +169,7 @@ struct Statement { // fields for code completion int usageCount; //Usage Count int matchPosTotal; // total of matched positions + int matchPosSpan; // distance between the first match pos and the last match pos; int firstMatchLength; // length of first match; int caseMatched; // if match with case QList matchPositions; diff --git a/RedPandaIDE/widgets/codecompletionpopup.cpp b/RedPandaIDE/widgets/codecompletionpopup.cpp index 3b1f5970..1e679cee 100644 --- a/RedPandaIDE/widgets/codecompletionpopup.cpp +++ b/RedPandaIDE/widgets/codecompletionpopup.cpp @@ -217,6 +217,8 @@ static bool nameComparator(PStatement statement1,PStatement statement2) { } static bool defaultComparator(PStatement statement1,PStatement statement2) { + if (statement1->matchPosSpan!=statement2->matchPosSpan) + return statement1->matchPosSpan < statement2->matchPosSpan; if (statement1->firstMatchLength != statement2->firstMatchLength) return statement1->firstMatchLength > statement2->firstMatchLength; if (statement1->matchPosTotal != statement2->matchPosTotal) @@ -243,6 +245,8 @@ static bool defaultComparator(PStatement statement1,PStatement statement2) { } static bool sortByScopeComparator(PStatement statement1,PStatement statement2){ + if (statement1->matchPosSpan!=statement2->matchPosSpan) + return statement1->matchPosSpan < statement2->matchPosSpan; if (statement1->firstMatchLength != statement2->firstMatchLength) return statement1->firstMatchLength > statement2->firstMatchLength; if (statement1->matchPosTotal != statement2->matchPosTotal) @@ -281,6 +285,8 @@ static bool sortByScopeComparator(PStatement statement1,PStatement statement2){ } static bool sortWithUsageComparator(PStatement statement1,PStatement statement2) { + if (statement1->matchPosSpan!=statement2->matchPosSpan) + return statement1->matchPosSpan < statement2->matchPosSpan; if (statement1->firstMatchLength != statement2->firstMatchLength) return statement1->firstMatchLength > statement2->firstMatchLength; if (statement1->matchPosTotal != statement2->matchPosTotal) @@ -311,6 +317,8 @@ static bool sortWithUsageComparator(PStatement statement1,PStatement statement2) } static bool sortByScopeWithUsageComparator(PStatement statement1,PStatement statement2){ + if (statement1->matchPosSpan!=statement2->matchPosSpan) + return statement1->matchPosSpan < statement2->matchPosSpan; if (statement1->firstMatchLength != statement2->firstMatchLength) return statement1->firstMatchLength > statement2->firstMatchLength; if (statement1->matchPosTotal != statement2->matchPosTotal) @@ -410,17 +418,19 @@ void CodeCompletionPopup::filterList(const QString &member) if (mIgnoreCase && matched==member.length()) { statement->caseMatched = caseMatched; statement->matchPosTotal = totalPos; - if (member.length()>0) + if (member.length()>0) { statement->firstMatchLength = statement->matchPositions.front()->end - statement->matchPositions.front()->start; - else + statement->matchPosSpan = statement->matchPositions.last()->end - statement->matchPositions.front()->start; + } else statement->firstMatchLength = 0; mCompletionStatementList.append(statement); } else if (caseMatched == member.length()) { statement->caseMatched = caseMatched; statement->matchPosTotal = totalPos; - if (member.length()>0) + if (member.length()>0) { statement->firstMatchLength = statement->matchPositions.front()->end - statement->matchPositions.front()->start; - else + statement->matchPosSpan = statement->matchPositions.last()->end - statement->matchPositions.front()->start; + } else statement->firstMatchLength = 0; mCompletionStatementList.append(statement); } else { @@ -428,6 +438,7 @@ void CodeCompletionPopup::filterList(const QString &member) statement->caseMatched = 0; statement->matchPosTotal = 0; statement->firstMatchLength = 0; + statement->matchPosSpan = 0; } } if (mRecordUsage) { @@ -943,7 +954,8 @@ bool CodeCompletionPopup::event(QEvent *event) { bool result = QWidget::event(event); if (event->type() == QEvent::FontChange) { - mListView->setFont(font()); + mListView->setFont(font()); + mDelegate->setFont(font()); } return result; } @@ -1009,6 +1021,7 @@ void CodeCompletionListItemDelegate::paint(QPainter *painter, const QStyleOption PStatement statement; if (mModel && (statement = mModel->statement(index)) ) { painter->save(); + painter->setFont(font()); QColor normalColor = mNormalColor; if (option.state & QStyle::State_Selected) { painter->fillRect(option.rect, option.palette.highlight()); @@ -1078,6 +1091,16 @@ void CodeCompletionListItemDelegate::setMatchedColor(const QColor &newMatchedCol mMatchedColor = newMatchedColor; } +const QFont &CodeCompletionListItemDelegate::font() const +{ + return mFont; +} + +void CodeCompletionListItemDelegate::setFont(const QFont &newFont) +{ + mFont = newFont; +} + CodeCompletionListItemDelegate::CodeCompletionListItemDelegate(CodeCompletionListModel *model, QWidget *parent) : QStyledItemDelegate(parent), mModel(model) { diff --git a/RedPandaIDE/widgets/codecompletionpopup.h b/RedPandaIDE/widgets/codecompletionpopup.h index 5d7604b5..6212159b 100644 --- a/RedPandaIDE/widgets/codecompletionpopup.h +++ b/RedPandaIDE/widgets/codecompletionpopup.h @@ -55,10 +55,14 @@ public: const QColor &matchedColor() const; void setMatchedColor(const QColor &newMatchedColor); + const QFont &font() const; + void setFont(const QFont &newFont); + private: CodeCompletionListModel *mModel; QColor mNormalColor; QColor mMatchedColor; + QFont mFont; }; class CodeCompletionPopup : public QWidget