Skip to content

Commit

Permalink
Fix scrollbar position when show window
Browse files Browse the repository at this point in the history
  • Loading branch information
mhtvsSFrpHdE committed Sep 1, 2022
1 parent edff543 commit 308049e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
23 changes: 16 additions & 7 deletions qpp/prefetch/Source/Interface/MainWindow/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,17 @@ MainWindow::~MainWindow()

void MainWindow::scrollBarToBottom_slot()
{
// Background update is not necessary
if (isVisible() == false)
{
return;
}

auto scrollBar = ui->stdOut_plainTextEdit->verticalScrollBar();
auto scrollBarMaxSize = scrollBar->maximum();

// Fix scroll bar position
// Default maximum will left two empty line in text view
//
// On DPI zoom 200%, size - 2 seems too much for text
scrollBarMaxSize = scrollBarMaxSize - printOffset;
scrollBar->setValue(scrollBarMaxSize);
}
Expand Down Expand Up @@ -150,9 +154,6 @@ void MainWindow::print_slot(QString textToPrint)
ui->stdOut_plainTextEdit->setTextCursor(cursor);

ui->stdOut_plainTextEdit->insertPlainText(textToPrint);

// Print may happen at background
ui->stdOut_plainTextEdit->update();
}

void MainWindow::sendCommand_slot()
Expand Down Expand Up @@ -182,13 +183,21 @@ void MainWindow::closeEvent(QCloseEvent *closeEventAddress)
Global::inputLoopThreadAddress->receiveText("exit");
}

void MainWindow::changeEvent(QEvent *eventAddress)
void MainWindow::changeEvent(QEvent *changeEventAddress)
{
if (eventAddress->type() == QEvent::WindowStateChange)
if (changeEventAddress->type() == QEvent::WindowStateChange)
{
// Minimize to tray
if (isMinimized())
{
minimized_slot();
}
}
}

void MainWindow::showEvent(QShowEvent *showEventAddress)
{
// Fix scroll bar position on restore
ui->stdOut_plainTextEdit->insertPlainText("");
scrollBarToBottom_slot();
};
5 changes: 4 additions & 1 deletion qpp/prefetch/Source/Interface/MainWindow/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ public slots:
void closeEvent(QCloseEvent *closeEventAddress) override;

// Handle application minimize event
void changeEvent(QEvent *event) override;
void changeEvent(QEvent *changeEventAddress) override;

// Handle application show event
void showEvent(QShowEvent *showEventAddress) override;
};

#endif // MAINWINDOW_H
1 change: 1 addition & 0 deletions qpp/prefetch/Source/Interface/TrayIcon/tray_icon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "..\..\Input\stdin.h"
#include "..\..\Setting\setting.h"
#include "..\Dpi\dpi.h"
#include "..\..\Define\define.h"

QSystemTrayIcon *TrayIcon::systemTrayIcon = NULL;

Expand Down

0 comments on commit 308049e

Please sign in to comment.