- 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
- enhancement: file system view mode for project
- enhancement: remove / rename / create new folder in the files view

View File

@ -58,6 +58,7 @@
#include <QTemporaryFile>
#include <QTextBlock>
#include <QTranslator>
#include <QFileIconProvider>
#include "settingsdialog/settingsdialog.h"
#include "compiler/compilermanager.h"
@ -290,6 +291,8 @@ MainWindow::MainWindow(QWidget *parent)
for (int i=1;i<mFileSystemModel.columnCount();i++) {
ui->treeFiles->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<QToolButton *>()) {
btn->setIconSize(iconSize);
}
for (QToolButton* btn: mFilesViewToolbar->findChildren<QToolButton *>()) {
for (QToolButton* btn: ui->panelFiles->findChildren<QToolButton *>()) {
btn->setIconSize(iconSize);
}
@ -2721,13 +2724,8 @@ void MainWindow::buildContextMenus()
});
//toolbar for files view
mFilesViewToolbar = new QWidget();
{
QVBoxLayout* layout = dynamic_cast<QVBoxLayout*>( ui->tabFiles->layout());
layout->insertWidget(0,mFilesViewToolbar);
QHBoxLayout* hlayout = new QHBoxLayout();
hlayout->setContentsMargins(2,2,2,2);
mFilesViewToolbar->setLayout(hlayout);
QHBoxLayout* hlayout = dynamic_cast<QHBoxLayout*>( 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<HeaderCompletionPopup> &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()

View File

@ -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;

View File

@ -244,13 +244,34 @@
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="txtFilesPath">
<property name="frame">
<bool>true</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<widget class="QWidget" name="panelFiles" native="true">
<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>
</property>
<property name="insertPolicy">
<enum>QComboBox::InsertAtTop</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>

View File

@ -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<PStatementMathPosition> matchPositions;

View File

@ -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)
{

View File

@ -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