- enhancement: recalc layout info for code editors when dpi changed

This commit is contained in:
Roy Qu 2021-12-13 19:10:16 +08:00
parent 956b717a14
commit c3ea1e6dd4
9 changed files with 18 additions and 65 deletions

View File

@ -77,7 +77,8 @@ void ExecutableRunner::run()
process.setProcessEnvironment(env); process.setProcessEnvironment(env);
process.setCreateProcessArgumentsModifier([this](QProcess::CreateProcessArguments * args){ process.setCreateProcessArgumentsModifier([this](QProcess::CreateProcessArguments * args){
if (mStartConsole) { if (mStartConsole) {
args->flags |= CREATE_NEW_CONSOLE; args->flags |= CREATE_NEW_CONSOLE;
args->flags &= ~CREATE_NO_WINDOW;
} }
if (!mRedirectInput) { if (!mRedirectInput) {
args->startupInfo -> dwFlags &= ~STARTF_USESTDHANDLES; args->startupInfo -> dwFlags &= ~STARTF_USESTDHANDLES;

View File

@ -264,18 +264,6 @@ void EditorList::selectPreviousPage()
} }
} }
void EditorList::notifyDPIChanged(int dpi)
{
for (int i=0;i<mLeftPageWidget->count();i++) {
Editor* e = static_cast<Editor*>(mLeftPageWidget->widget(i));
e->changeDPI(dpi);
}
for (int i=0;i<mRightPageWidget->count();i++) {
Editor* e = static_cast<Editor*>(mRightPageWidget->widget(i));
e->changeDPI(dpi);
}
}
Editor *EditorList::operator[](int index) Editor *EditorList::operator[](int index)
{ {
if (index>=0 && index<mLeftPageWidget->count()) { if (index>=0 && index<mLeftPageWidget->count()) {

View File

@ -53,7 +53,6 @@ public:
int pageCount(); int pageCount();
void selectNextPage(); void selectNextPage();
void selectPreviousPage(); void selectPreviousPage();
void notifyDPIChanged(int dpi);
Editor* operator[](int index); Editor* operator[](int index);

View File

@ -41,11 +41,8 @@ bool WindowLogoutEventFilter::nativeEventFilter(const QByteArray & /*eventType*/
} }
break; break;
case WM_DPICHANGED: case WM_DPICHANGED:
if (pMainWindow) { //todo
int dpi = HIWORD(pMsg->wParam); break;
pMainWindow->notifyDPIChanged(dpi);
}
break;
} }
return false; return false;
} }

View File

@ -175,8 +175,6 @@ MainWindow::MainWindow(QWidget *parent)
this, &MainWindow::onDebugEvaluateInput); this, &MainWindow::onDebugEvaluateInput);
connect(ui->cbMemoryAddress->lineEdit(), &QLineEdit::returnPressed, connect(ui->cbMemoryAddress->lineEdit(), &QLineEdit::returnPressed,
this, &MainWindow::onDebugMemoryAddressInput); this, &MainWindow::onDebugMemoryAddressInput);
connect(this,&MainWindow::dpiChanged,
this,&MainWindow::onDPIChanged);
mTodoParser = std::make_shared<TodoParser>(); mTodoParser = std::make_shared<TodoParser>();
mSymbolUsageManager = std::make_shared<SymbolUsageManager>(); mSymbolUsageManager = std::make_shared<SymbolUsageManager>();
@ -643,11 +641,6 @@ void MainWindow::setActiveBreakpoint(QString FileName, int Line, bool setFocus)
} }
} }
void MainWindow::dpiChanged(int dpi)
{
mEditorList->notifyDPIChanged(dpi);
}
void MainWindow::updateAppTitle() void MainWindow::updateAppTitle()
{ {
QString appName=tr("Red Panda Dev-C++"); QString appName=tr("Red Panda Dev-C++");
@ -5633,12 +5626,6 @@ bool MainWindow::openningFiles() const
return mOpenningFiles; return mOpenningFiles;
} }
void MainWindow::notifyDPIChanged(int dpi)
{
emit dpiChanged(dpi);
}
void MainWindow::on_actionTool_Window_Bars_triggered() void MainWindow::on_actionTool_Window_Bars_triggered()
{ {
bool state = ui->tabInfos->isVisible(); bool state = ui->tabInfos->isVisible();

View File

@ -163,10 +163,6 @@ public:
bool openningFiles() const; bool openningFiles() const;
void notifyDPIChanged(int dpi);
signals:
void dpiChanged(int dpi);
public slots: public slots:
void onCompileLog(const QString& msg); void onCompileLog(const QString& msg);
void onCompileIssue(PCompileIssue issue); void onCompileIssue(PCompileIssue issue);
@ -198,7 +194,6 @@ public slots:
void onTodoParsing(const QString& filename, int lineNo, int ch, const QString& line); void onTodoParsing(const QString& filename, int lineNo, int ch, const QString& line);
void onTodoParseFinished(); void onTodoParseFinished();
void setActiveBreakpoint(QString FileName, int Line, bool setFocus); void setActiveBreakpoint(QString FileName, int Line, bool setFocus);
void onDPIChanged();
private: private:
void prepareProjectForCompile(); void prepareProjectForCompile();
@ -658,7 +653,6 @@ protected:
void closeEvent(QCloseEvent *event) override; void closeEvent(QCloseEvent *event) override;
void showEvent(QShowEvent* event) override; void showEvent(QShowEvent* event) override;
void hideEvent(QHideEvent *event) override; void hideEvent(QHideEvent *event) override;
}; };
extern MainWindow* pMainWindow; extern MainWindow* pMainWindow;

View File

@ -85,7 +85,7 @@
<enum>QTabWidget::West</enum> <enum>QTabWidget::West</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>2</number>
</property> </property>
<property name="usesScrollButtons"> <property name="usesScrollButtons">
<bool>true</bool> <bool>true</bool>
@ -1398,7 +1398,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1114</width> <width>1114</width>
<height>30</height> <height>23</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuFile"> <widget class="QMenu" name="menuFile">

View File

@ -24,7 +24,6 @@
SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent) SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent)
{ {
mDPI = -1;
mLastKey = 0; mLastKey = 0;
mLastKeyModifiers = Qt::NoModifier; mLastKeyModifiers = Qt::NoModifier;
mModified = false; mModified = false;
@ -149,8 +148,6 @@ SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent)
//setMouseTracking(true); //setMouseTracking(true);
setAcceptDrops(true); setAcceptDrops(true);
mDPI = fontMetrics().fontDpi();
} }
int SynEdit::displayLineCount() const int SynEdit::displayLineCount() const
@ -5809,26 +5806,8 @@ void SynEdit::updateMouseCursor(){
} }
} }
void SynEdit::changeDPI(int dpi)
{
if (dpi!=mDPI) {
mDPI=dpi;
}
}
void SynEdit::paintEvent(QPaintEvent *event) void SynEdit::paintEvent(QPaintEvent *event)
{ {
if (fontMetrics().fontDpi()!=mDPI) {
QFont f;
f.setFamily(font().family());
f.setPointSize(font().pointSize());
f.setBold(font().bold());
f.setItalic(font().bold());
f.setUnderline(font().underline());
f.setStrikeOut(font().strikeOut());
setFont(f);
return;
}
if (mPainterLock>0) if (mPainterLock>0)
return; return;
if (mPainting) if (mPainting)
@ -5840,6 +5819,17 @@ void SynEdit::paintEvent(QPaintEvent *event)
// Now paint everything while the caret is hidden. // Now paint everything while the caret is hidden.
QPainter painter(viewport()); QPainter painter(viewport());
if (fontMetrics().fontDpi()!=painter.device()->logicalDpiX()) {
QFont f;
f.setFamily(font().family());
f.setPointSize(font().pointSize());
f.setBold(font().bold());
f.setItalic(font().bold());
f.setUnderline(font().underline());
f.setStrikeOut(font().strikeOut());
setFont(f);
return;
}
//Get the invalidated rect. //Get the invalidated rect.
QRect rcClip = event->rect(); QRect rcClip = event->rect();
QRect rcCaret = calculateCaretRect(); QRect rcCaret = calculateCaretRect();

View File

@ -275,8 +275,7 @@ public:
void updateMouseCursor(); void updateMouseCursor();
void changeDPI(int dpi); // setter && getters
// setter && getters
int topLine() const; int topLine() const;
void setTopLine(int value); void setTopLine(int value);
@ -706,8 +705,6 @@ private:
BufferCoord mDragSelEndSave; BufferCoord mDragSelEndSave;
bool mDragging; bool mDragging;
int mDPI;
friend class SynEditTextPainter; friend class SynEditTextPainter;
// QWidget interface // QWidget interface