diff --git a/NEWS.md b/NEWS.md index 2ba26843..866f19fd 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ Version 0.11.1 For Dev-C++ 7 Beta - enhancement: Problem's test case shouldn't accept rich text inputs + - enhancement: recalc layout info for code editors when dpi changed Version 0.11.0 For Dev-C++ 7 Beta - enhancement: redesign the expression parser for code completion diff --git a/RedPandaIDE/editor.h b/RedPandaIDE/editor.h index 83a55c72..9eb41da5 100644 --- a/RedPandaIDE/editor.h +++ b/RedPandaIDE/editor.h @@ -351,13 +351,7 @@ public: protected: void mouseReleaseEvent(QMouseEvent *event) override; - - // QWidget interface -protected: void inputMethodEvent(QInputMethodEvent *) override; - - // QWidget interface -protected: void closeEvent(QCloseEvent *event) override; }; diff --git a/RedPandaIDE/editorlist.cpp b/RedPandaIDE/editorlist.cpp index 66ed92d0..d631aca1 100644 --- a/RedPandaIDE/editorlist.cpp +++ b/RedPandaIDE/editorlist.cpp @@ -7,6 +7,7 @@ #include "settings.h" #include "project.h" #include "systemconsts.h" +#include EditorList::EditorList(QTabWidget* leftPageWidget, QTabWidget* rightPageWidget, @@ -263,6 +264,18 @@ void EditorList::selectPreviousPage() } } +void EditorList::notifyDPIChanged(int dpi) +{ + for (int i=0;icount();i++) { + Editor* e = static_cast(mLeftPageWidget->widget(i)); + e->changeDPI(dpi); + } + for (int i=0;icount();i++) { + Editor* e = static_cast(mRightPageWidget->widget(i)); + e->changeDPI(dpi); + } +} + Editor *EditorList::operator[](int index) { if (index>=0 && indexcount()) { diff --git a/RedPandaIDE/editorlist.h b/RedPandaIDE/editorlist.h index e4820783..37ee2eb5 100644 --- a/RedPandaIDE/editorlist.h +++ b/RedPandaIDE/editorlist.h @@ -53,6 +53,7 @@ public: int pageCount(); void selectNextPage(); void selectPreviousPage(); + void notifyDPIChanged(int dpi); Editor* operator[](int index); diff --git a/RedPandaIDE/main.cpp b/RedPandaIDE/main.cpp index 6a2abee6..2c47e0f9 100644 --- a/RedPandaIDE/main.cpp +++ b/RedPandaIDE/main.cpp @@ -28,7 +28,8 @@ public: bool WindowLogoutEventFilter::nativeEventFilter(const QByteArray & /*eventType*/, void *message, long *result){ MSG * pMsg = static_cast(message); - if (pMsg->message == WM_QUERYENDSESSION) { + switch(pMsg->message) { + case WM_QUERYENDSESSION: if (pMsg->lParam == 0 || (pMsg->lParam & ENDSESSION_LOGOFF)) { if (!pMainWindow->close()) { @@ -38,8 +39,13 @@ bool WindowLogoutEventFilter::nativeEventFilter(const QByteArray & /*eventType*/ } return true; } - } else if (pMsg->message == WM_DPICHANGED) { - qDebug()<<"app dpi changed!"; + break; + case WM_DPICHANGED: + if (pMainWindow) { + int dpi = HIWORD(pMsg->wParam); + pMainWindow->notifyDPIChanged(dpi); + } + break; } return false; } diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index ce663847..747df46a 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -175,6 +175,8 @@ MainWindow::MainWindow(QWidget *parent) this, &MainWindow::onDebugEvaluateInput); connect(ui->cbMemoryAddress->lineEdit(), &QLineEdit::returnPressed, this, &MainWindow::onDebugMemoryAddressInput); + connect(this,&MainWindow::dpiChanged, + this,&MainWindow::onDPIChanged); mTodoParser = std::make_shared(); mSymbolUsageManager = std::make_shared(); @@ -641,6 +643,11 @@ void MainWindow::setActiveBreakpoint(QString FileName, int Line, bool setFocus) } } +void MainWindow::dpiChanged(int dpi) +{ + mEditorList->notifyDPIChanged(dpi); +} + void MainWindow::updateAppTitle() { QString appName=tr("Red Panda Dev-C++"); @@ -5626,6 +5633,11 @@ bool MainWindow::openningFiles() const return mOpenningFiles; } +void MainWindow::notifyDPIChanged(int dpi) +{ + emit dpiChanged(dpi); +} + void MainWindow::on_actionTool_Window_Bars_triggered() { diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index f1b706b2..84eedb7d 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -163,6 +163,10 @@ public: bool openningFiles() const; + void notifyDPIChanged(int dpi); + +signals: + void dpiChanged(int dpi); public slots: void onCompileLog(const QString& msg); void onCompileIssue(PCompileIssue issue); @@ -194,6 +198,7 @@ public slots: void onTodoParsing(const QString& filename, int lineNo, int ch, const QString& line); void onTodoParseFinished(); void setActiveBreakpoint(QString FileName, int Line, bool setFocus); + void onDPIChanged(); private: void prepareProjectForCompile(); diff --git a/RedPandaIDE/qsynedit/SynEdit.cpp b/RedPandaIDE/qsynedit/SynEdit.cpp index 94a22705..0b57233f 100644 --- a/RedPandaIDE/qsynedit/SynEdit.cpp +++ b/RedPandaIDE/qsynedit/SynEdit.cpp @@ -24,6 +24,7 @@ SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent) { + mDPI = -1; mLastKey = 0; mLastKeyModifiers = Qt::NoModifier; mModified = false; @@ -148,6 +149,8 @@ SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent) //setMouseTracking(true); setAcceptDrops(true); + + mDPI = fontMetrics().fontDpi(); } int SynEdit::displayLineCount() const @@ -3138,8 +3141,9 @@ void SynEdit::recalcCharExtent() mTextHeight = 0; mCharWidth = 0; - mTextHeight = fontMetrics().lineSpacing(); - mCharWidth = fontMetrics().horizontalAdvance("M"); + QFontMetrics fm(font()); + mTextHeight = fm.lineSpacing(); + mCharWidth = fm.horizontalAdvance("M"); if (hasStyles[0]) { // has bold font QFont f = font(); f.setBold(true); @@ -3177,8 +3181,6 @@ void SynEdit::recalcCharExtent() mCharWidth = fm.horizontalAdvance("M"); } mTextHeight += mExtraLineSpacing; - //mCharWidth = mCharWidth * dpiFactor(); - //mTextHeight = mTextHeight * dpiFactor(); } QString SynEdit::expandAtWideGlyphs(const QString &S) @@ -5807,8 +5809,26 @@ void SynEdit::updateMouseCursor(){ } } +void SynEdit::changeDPI(int dpi) +{ + if (dpi!=mDPI) { + mDPI=dpi; + } +} + 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) return; if (mPainting) @@ -6264,18 +6284,6 @@ void SynEdit::dragLeaveEvent(QDragLeaveEvent *) // showCaret(); } -bool SynEdit::nativeEvent(const QByteArray &eventType, void *message, long *result) -{ -#ifdef Q_OS_WIN - MSG* msg = (MSG*)message; - if (msg && msg->message == WM_DPICHANGED) { - qDebug()<<"dpi changed!"; - synFontChanged(); - } -#endif - return QAbstractScrollArea::nativeEvent(eventType,message,result); -} - int SynEdit::maxScrollHeight() const { if (mOptions.testFlag(eoScrollPastEof)) diff --git a/RedPandaIDE/qsynedit/SynEdit.h b/RedPandaIDE/qsynedit/SynEdit.h index 7dcf8a74..6dd06be0 100644 --- a/RedPandaIDE/qsynedit/SynEdit.h +++ b/RedPandaIDE/qsynedit/SynEdit.h @@ -274,6 +274,8 @@ public: const PSynHighlighterAttribute &attr3); void updateMouseCursor(); + + void changeDPI(int dpi); // setter && getters int topLine() const; void setTopLine(int value); @@ -704,6 +706,8 @@ private: BufferCoord mDragSelEndSave; bool mDragging; + int mDPI; + friend class SynEditTextPainter; // QWidget interface @@ -737,10 +741,6 @@ void dragEnterEvent(QDragEnterEvent *event) override; void dropEvent(QDropEvent *event) override; void dragMoveEvent(QDragMoveEvent *event) override; void dragLeaveEvent(QDragLeaveEvent *event) override; - -// QWidget interface -protected: -bool nativeEvent(const QByteArray &eventType, void *message, long *result) override; }; #endif // SYNEDIT_H