- fix: wrong code completion font size, when screen dpi changed

- enhancement: replace Files View Panel's path lineedit control with combo box
This commit is contained in:
Roy Qu 2022-02-11 20:19:48 +08:00
parent edf456b554
commit bf25853da1
7 changed files with 91 additions and 23 deletions

View File

@ -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 Red Panda C++ Version 0.14.2
- enhancement: file system view mode for project - enhancement: file system view mode for project
- enhancement: remove / rename / create new folder in the files view - enhancement: remove / rename / create new folder in the files view

View File

@ -58,6 +58,7 @@
#include <QTemporaryFile> #include <QTemporaryFile>
#include <QTextBlock> #include <QTextBlock>
#include <QTranslator> #include <QTranslator>
#include <QFileIconProvider>
#include "settingsdialog/settingsdialog.h" #include "settingsdialog/settingsdialog.h"
#include "compiler/compilermanager.h" #include "compiler/compilermanager.h"
@ -290,6 +291,8 @@ MainWindow::MainWindow(QWidget *parent)
for (int i=1;i<mFileSystemModel.columnCount();i++) { for (int i=1;i<mFileSystemModel.columnCount();i++) {
ui->treeFiles->hideColumn(i); ui->treeFiles->hideColumn(i);
} }
connect(ui->cbFilesPath->lineEdit(),&QLineEdit::returnPressed,
this,&MainWindow::onFilesViewPathChanged);
//class browser //class browser
ui->classBrowser->setUniformRowHeights(true); ui->classBrowser->setUniformRowHeights(true);
@ -1184,7 +1187,7 @@ void MainWindow::updateActionIcons()
for (QToolButton* btn: mClassBrowserToolbar->findChildren<QToolButton *>()) { for (QToolButton* btn: mClassBrowserToolbar->findChildren<QToolButton *>()) {
btn->setIconSize(iconSize); btn->setIconSize(iconSize);
} }
for (QToolButton* btn: mFilesViewToolbar->findChildren<QToolButton *>()) { for (QToolButton* btn: ui->panelFiles->findChildren<QToolButton *>()) {
btn->setIconSize(iconSize); btn->setIconSize(iconSize);
} }
@ -2721,13 +2724,8 @@ void MainWindow::buildContextMenus()
}); });
//toolbar for files view //toolbar for files view
mFilesViewToolbar = new QWidget();
{ {
QVBoxLayout* layout = dynamic_cast<QVBoxLayout*>( ui->tabFiles->layout()); QHBoxLayout* hlayout = dynamic_cast<QHBoxLayout*>( ui->panelFiles->layout());
layout->insertWidget(0,mFilesViewToolbar);
QHBoxLayout* hlayout = new QHBoxLayout();
hlayout->setContentsMargins(2,2,2,2);
mFilesViewToolbar->setLayout(hlayout);
QToolButton * toolButton; QToolButton * toolButton;
int size = pointToPixel(pSettings->environment().interfaceFontSize()); int size = pointToPixel(pSettings->environment().interfaceFontSize());
QSize iconSize(size,size); QSize iconSize(size,size);
@ -2739,7 +2737,6 @@ void MainWindow::buildContextMenus()
toolButton->setIconSize(iconSize); toolButton->setIconSize(iconSize);
toolButton->setDefaultAction(ui->actionLocate_in_Files_View); toolButton->setDefaultAction(ui->actionLocate_in_Files_View);
hlayout->addWidget(toolButton); 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<HeaderCompletionPopup> &MainWindow::headerCompletionPopup() const const std::shared_ptr<HeaderCompletionPopup> &MainWindow::headerCompletionPopup() const
{ {
return mHeaderCompletionPopup; return mHeaderCompletionPopup;
@ -5596,8 +5604,15 @@ void MainWindow::setFilesViewRoot(const QString &path)
mFileSystemModel.setRootPath(path); mFileSystemModel.setRootPath(path);
ui->treeFiles->setRootIndex(mFileSystemModel.index(path)); ui->treeFiles->setRootIndex(mFileSystemModel.index(path));
pSettings->environment().setCurrentFolder(path); pSettings->environment().setCurrentFolder(path);
ui->txtFilesPath->setText(path); int pos = ui->cbFilesPath->findText(path);
ui->txtFilesPath->setCursorPosition(1); 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() void MainWindow::clearIssues()

View File

@ -255,6 +255,7 @@ private slots:
void onEditorRenamed(const QString& oldFilename, const QString& newFilename, bool firstSave); void onEditorRenamed(const QString& oldFilename, const QString& newFilename, bool firstSave);
void onAutoSaveTimeout(); void onAutoSaveTimeout();
void onFileChanged(const QString& path); void onFileChanged(const QString& path);
void onFilesViewPathChanged();
void onWatchViewContextMenu(const QPoint& pos); void onWatchViewContextMenu(const QPoint& pos);
void onBookmarkContextMenu(const QPoint& pos); void onBookmarkContextMenu(const QPoint& pos);
@ -671,7 +672,6 @@ private:
QAction * mFilesView_OpenWithExternal; QAction * mFilesView_OpenWithExternal;
QAction * mFilesView_OpenInTerminal; QAction * mFilesView_OpenInTerminal;
QAction * mFilesView_OpenInExplorer; QAction * mFilesView_OpenInExplorer;
QWidget * mFilesViewToolbar;
QAction * mFilesView_CreateFolder; QAction * mFilesView_CreateFolder;
QAction * mFilesView_RemoveFile; QAction * mFilesView_RemoveFile;

View File

@ -244,15 +244,36 @@
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="QLineEdit" name="txtFilesPath"> <widget class="QWidget" name="panelFiles" native="true">
<property name="frame"> <layout class="QHBoxLayout" name="horizontalLayout_13">
<property name="spacing">
<number>2</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QComboBox" name="cbFilesPath">
<property name="editable">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="readOnly"> <property name="insertPolicy">
<bool>true</bool> <enum>QComboBox::InsertAtTop</enum>
</property> </property>
</widget> </widget>
</item> </item>
</layout>
</widget>
</item>
<item> <item>
<widget class="QTreeView" name="treeFiles"> <widget class="QTreeView" name="treeFiles">
<property name="editTriggers"> <property name="editTriggers">

View File

@ -169,6 +169,7 @@ struct Statement {
// fields for code completion // fields for code completion
int usageCount; //Usage Count int usageCount; //Usage Count
int matchPosTotal; // total of matched positions 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 firstMatchLength; // length of first match;
int caseMatched; // if match with case int caseMatched; // if match with case
QList<PStatementMathPosition> matchPositions; QList<PStatementMathPosition> matchPositions;

View File

@ -217,6 +217,8 @@ static bool nameComparator(PStatement statement1,PStatement statement2) {
} }
static bool defaultComparator(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) if (statement1->firstMatchLength != statement2->firstMatchLength)
return statement1->firstMatchLength > statement2->firstMatchLength; return statement1->firstMatchLength > statement2->firstMatchLength;
if (statement1->matchPosTotal != statement2->matchPosTotal) if (statement1->matchPosTotal != statement2->matchPosTotal)
@ -243,6 +245,8 @@ static bool defaultComparator(PStatement statement1,PStatement statement2) {
} }
static bool sortByScopeComparator(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) if (statement1->firstMatchLength != statement2->firstMatchLength)
return statement1->firstMatchLength > statement2->firstMatchLength; return statement1->firstMatchLength > statement2->firstMatchLength;
if (statement1->matchPosTotal != statement2->matchPosTotal) if (statement1->matchPosTotal != statement2->matchPosTotal)
@ -281,6 +285,8 @@ static bool sortByScopeComparator(PStatement statement1,PStatement statement2){
} }
static bool sortWithUsageComparator(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) if (statement1->firstMatchLength != statement2->firstMatchLength)
return statement1->firstMatchLength > statement2->firstMatchLength; return statement1->firstMatchLength > statement2->firstMatchLength;
if (statement1->matchPosTotal != statement2->matchPosTotal) if (statement1->matchPosTotal != statement2->matchPosTotal)
@ -311,6 +317,8 @@ static bool sortWithUsageComparator(PStatement statement1,PStatement statement2)
} }
static bool sortByScopeWithUsageComparator(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) if (statement1->firstMatchLength != statement2->firstMatchLength)
return statement1->firstMatchLength > statement2->firstMatchLength; return statement1->firstMatchLength > statement2->firstMatchLength;
if (statement1->matchPosTotal != statement2->matchPosTotal) if (statement1->matchPosTotal != statement2->matchPosTotal)
@ -410,17 +418,19 @@ void CodeCompletionPopup::filterList(const QString &member)
if (mIgnoreCase && matched==member.length()) { if (mIgnoreCase && matched==member.length()) {
statement->caseMatched = caseMatched; statement->caseMatched = caseMatched;
statement->matchPosTotal = totalPos; statement->matchPosTotal = totalPos;
if (member.length()>0) if (member.length()>0) {
statement->firstMatchLength = statement->matchPositions.front()->end - statement->matchPositions.front()->start; 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; statement->firstMatchLength = 0;
mCompletionStatementList.append(statement); mCompletionStatementList.append(statement);
} else if (caseMatched == member.length()) { } else if (caseMatched == member.length()) {
statement->caseMatched = caseMatched; statement->caseMatched = caseMatched;
statement->matchPosTotal = totalPos; statement->matchPosTotal = totalPos;
if (member.length()>0) if (member.length()>0) {
statement->firstMatchLength = statement->matchPositions.front()->end - statement->matchPositions.front()->start; 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; statement->firstMatchLength = 0;
mCompletionStatementList.append(statement); mCompletionStatementList.append(statement);
} else { } else {
@ -428,6 +438,7 @@ void CodeCompletionPopup::filterList(const QString &member)
statement->caseMatched = 0; statement->caseMatched = 0;
statement->matchPosTotal = 0; statement->matchPosTotal = 0;
statement->firstMatchLength = 0; statement->firstMatchLength = 0;
statement->matchPosSpan = 0;
} }
} }
if (mRecordUsage) { if (mRecordUsage) {
@ -944,6 +955,7 @@ bool CodeCompletionPopup::event(QEvent *event)
bool result = QWidget::event(event); bool result = QWidget::event(event);
if (event->type() == QEvent::FontChange) { if (event->type() == QEvent::FontChange) {
mListView->setFont(font()); mListView->setFont(font());
mDelegate->setFont(font());
} }
return result; return result;
} }
@ -1009,6 +1021,7 @@ void CodeCompletionListItemDelegate::paint(QPainter *painter, const QStyleOption
PStatement statement; PStatement statement;
if (mModel && (statement = mModel->statement(index)) ) { if (mModel && (statement = mModel->statement(index)) ) {
painter->save(); painter->save();
painter->setFont(font());
QColor normalColor = mNormalColor; QColor normalColor = mNormalColor;
if (option.state & QStyle::State_Selected) { if (option.state & QStyle::State_Selected) {
painter->fillRect(option.rect, option.palette.highlight()); painter->fillRect(option.rect, option.palette.highlight());
@ -1078,6 +1091,16 @@ void CodeCompletionListItemDelegate::setMatchedColor(const QColor &newMatchedCol
mMatchedColor = newMatchedColor; 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), CodeCompletionListItemDelegate::CodeCompletionListItemDelegate(CodeCompletionListModel *model, QWidget *parent) : QStyledItemDelegate(parent),
mModel(model) mModel(model)
{ {

View File

@ -55,10 +55,14 @@ public:
const QColor &matchedColor() const; const QColor &matchedColor() const;
void setMatchedColor(const QColor &newMatchedColor); void setMatchedColor(const QColor &newMatchedColor);
const QFont &font() const;
void setFont(const QFont &newFont);
private: private:
CodeCompletionListModel *mModel; CodeCompletionListModel *mModel;
QColor mNormalColor; QColor mNormalColor;
QColor mMatchedColor; QColor mMatchedColor;
QFont mFont;
}; };
class CodeCompletionPopup : public QWidget class CodeCompletionPopup : public QWidget