- fix: left and bottom panel size not correct when DPI changed

This commit is contained in:
Roy Qu 2022-02-20 22:36:12 +08:00
parent 7cc5cf4f45
commit 63b277d843
4 changed files with 42 additions and 7 deletions

View File

@ -19,6 +19,7 @@ Red Panda C++ Version 0.14.3
- enhancement: when add files to project, auto add it to git (if the project has a git repository) - enhancement: when add files to project, auto add it to git (if the project has a git repository)
- enhancement: when save a file, and it's under files view's current folder, auto add it to git (if it has a git repository) - enhancement: when save a file, and it's under files view's current folder, auto add it to git (if it has a git repository)
- enhancement: new file icons for high contrast icon set - enhancement: new file icons for high contrast icon set
- fix: left and bottom panel size not correct when DPI changed
Red Panda C++ Version 0.14.2 Red Panda C++ Version 0.14.2

View File

@ -61,11 +61,16 @@ bool WindowLogoutEventFilter::nativeEventFilter(const QByteArray & /*eventType*/
return true; return true;
} }
break; break;
case WM_DPICHANGED: case WM_DPICHANGED:{
int oldDPI = screenDPI();
QEvent * dpiEvent = new QEvent(DPI_CHANGED_EVENT);
qApp->postEvent(pMainWindow,dpiEvent);
setScreenDPI(HIWORD(pMsg->wParam)); setScreenDPI(HIWORD(pMsg->wParam));
pMainWindow->updateDPI(); int newDPI = screenDPI();
pMainWindow->updateDPI(oldDPI,newDPI);
break; break;
} }
}
return false; return false;
} }
#endif #endif

View File

@ -742,9 +742,13 @@ void MainWindow::setActiveBreakpoint(QString FileName, int Line, bool setFocus)
} }
} }
void MainWindow::updateDPI() void MainWindow::updateDPI(int oldDPI, int newDPI)
{ {
applySettings(); applySettings();
if (oldDPI<1)
oldDPI = 1;
mBottomPanelHeight = mBottomPanelHeight * newDPI / oldDPI ;
mLeftPanelWidth = mLeftPanelWidth * newDPI / oldDPI ;
} }
void MainWindow::onFileSaved(const QString &path, bool inProject) void MainWindow::onFileSaved(const QString &path, bool inProject)
@ -1837,6 +1841,8 @@ void MainWindow::openCloseBottomPanel(bool open)
QList<int> sizes = ui->splitterMessages->sizes(); QList<int> sizes = ui->splitterMessages->sizes();
int tabHeight = ui->tabMessages->tabBar()->height(); int tabHeight = ui->tabMessages->tabBar()->height();
ui->tabMessages->setMinimumHeight(tabHeight+5); ui->tabMessages->setMinimumHeight(tabHeight+5);
if ( mBottomPanelHeight < ui->tabMessages->tabBar()->height() + 5)
mBottomPanelHeight = ui->tabMessages->tabBar()->height() + 5;
int totalSize = sizes[0] + sizes[1]; int totalSize = sizes[0] + sizes[1];
sizes[1] = mBottomPanelHeight; sizes[1] = mBottomPanelHeight;
sizes[0] = std::max(1,totalSize - sizes[1]); sizes[0] = std::max(1,totalSize - sizes[1]);
@ -1853,7 +1859,7 @@ void MainWindow::openCloseBottomPanel(bool open)
} }
mBottomPanelOpenned = open; mBottomPanelOpenned = open;
QSplitterHandle* handle = ui->splitterMessages->handle(1); QSplitterHandle* handle = ui->splitterMessages->handle(1);
handle->setEnabled(open); handle->setEnabled(mBottomPanelOpenned);
} }
void MainWindow::openCloseLeftPanel(bool open) void MainWindow::openCloseLeftPanel(bool open)
@ -1865,10 +1871,12 @@ void MainWindow::openCloseLeftPanel(bool open)
mOpenClosingLeftPanel = false; mOpenClosingLeftPanel = false;
}); });
// Switch between open and close // Switch between open and close
if (open) { if (open ) {
QList<int> sizes = ui->splitterInfos->sizes(); QList<int> sizes = ui->splitterInfos->sizes();
int tabWidth = ui->tabInfos->tabBar()->width(); int tabWidth = ui->tabInfos->tabBar()->width();
ui->tabInfos->setMinimumWidth(tabWidth+5); ui->tabInfos->setMinimumWidth(tabWidth+5);
if (mLeftPanelWidth < ui->tabInfos->tabBar()->width() + 5)
mLeftPanelWidth = ui->tabInfos->tabBar()->width() + 5;
int totalSize = sizes[0] + sizes[1]; int totalSize = sizes[0] + sizes[1];
sizes[0] = mLeftPanelWidth; sizes[0] = mLeftPanelWidth;
sizes[1] = std::max(1,totalSize - sizes[0]); sizes[1] = std::max(1,totalSize - sizes[0]);
@ -1885,7 +1893,7 @@ void MainWindow::openCloseLeftPanel(bool open)
} }
mLeftPanelOpenned = open; mLeftPanelOpenned = open;
QSplitterHandle* handle = ui->splitterInfos->handle(1); QSplitterHandle* handle = ui->splitterInfos->handle(1);
handle->setEnabled(open); handle->setEnabled(mLeftPanelOpenned);
} }
void MainWindow::prepareDebugger() void MainWindow::prepareDebugger()
@ -4080,6 +4088,21 @@ void MainWindow::hideEvent(QHideEvent *)
settings.setLeftPanelWidth(mLeftPanelWidth); settings.setLeftPanelWidth(mLeftPanelWidth);
} }
bool MainWindow::event(QEvent *event)
{
if (event->type()==DPI_CHANGED_EVENT) {
int saveHeight = mBottomPanelHeight ;
int saveWidth = mLeftPanelWidth;
openCloseBottomPanel(mBottomPanelOpenned);
openCloseLeftPanel(mLeftPanelOpenned);
mBottomPanelHeight = saveHeight;
mLeftPanelWidth = saveWidth;
event->accept();
return true;
}
return QMainWindow::event(event);
}
//void MainWindow::dragEnterEvent(QDragEnterEvent *event) //void MainWindow::dragEnterEvent(QDragEnterEvent *event)
//{ //{
// if (event->mimeData()->hasUrls()){ // if (event->mimeData()->hasUrls()){

View File

@ -68,6 +68,8 @@ class SearchDialog;
class Project; class Project;
class ColorSchemeItem; class ColorSchemeItem;
#define DPI_CHANGED_EVENT ((QEvent::Type)(QEvent::User+1))
class MainWindow : public QMainWindow class MainWindow : public QMainWindow
{ {
Q_OBJECT Q_OBJECT
@ -217,7 +219,7 @@ 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 updateDPI(); void updateDPI(int oldDPI, int newDPI);
void onFileSaved(const QString& path, bool inProject); void onFileSaved(const QString& path, bool inProject);
private: private:
@ -727,6 +729,10 @@ protected:
void showEvent(QShowEvent* event) override; void showEvent(QShowEvent* event) override;
void hideEvent(QHideEvent *event) override; void hideEvent(QHideEvent *event) override;
// QObject interface
public:
bool event(QEvent *event) override;
}; };
extern MainWindow* pMainWindow; extern MainWindow* pMainWindow;