Fix out of screen issue at 150% scale setting in Windows

This commit is contained in:
DreamSourceLab 2020-03-31 10:40:31 +08:00
parent 24b475484b
commit 68ea5d8ca4
3 changed files with 28 additions and 36 deletions

View File

@ -41,6 +41,7 @@
#include <QPushButton>
#include <QMessageBox>
#include <QApplication>
#include <QScreen>
#include <algorithm>
@ -161,8 +162,8 @@ void MainFrame::resizeEvent(QResizeEvent *event)
void MainFrame::closeEvent(QCloseEvent *event)
{
_mainWindow->session_save();
writeSettings();
_mainWindow->session_save();
event->accept();
}
@ -359,25 +360,18 @@ void MainFrame::writeSettings()
settings.beginGroup("MainFrame");
settings.setValue("style", qApp->property("Style").toString());
settings.setValue("language", qApp->property("Language").toInt());
settings.setValue("geometry", saveGeometry());
settings.setValue("isMax", isMaximized());
settings.setValue("size", size());
settings.setValue("pos", pos() +
QPoint(geometry().left() - frameGeometry().left(), frameGeometry().right() - geometry().right()));
settings.endGroup();
}
void MainFrame::readSettings()
{
QSettings settings(QApplication::organizationName(), QApplication::applicationName());
QDesktopWidget* desktopWidget = QApplication::desktop();
QRect deskRect = desktopWidget->availableGeometry();
QPoint default_upleft = QPoint((deskRect.width() - defWidth)/2, (deskRect.height() - defHeight)/2);
QSize default_size = QSize(defWidth, defHeight);
settings.beginGroup("MainFrame");
bool isMax = settings.value("isMax", false).toBool();
QSize size = settings.value("size", default_size).toSize();
QPoint pos = settings.value("pos", default_upleft).toPoint();
const QByteArray geometry = settings.value("geometry", QByteArray()).toByteArray();
// defaut language
if (settings.contains("language")) {
_mainWindow->switchLanguage(settings.value("language").toInt());
@ -387,27 +381,20 @@ void MainFrame::readSettings()
}
settings.endGroup();
// check the restored position is vavlid or not
int i = 0;
for (; i < desktopWidget->screenCount(); i++) {
deskRect = desktopWidget->availableGeometry(i);
if (deskRect.contains(pos))
break;
}
if (i >= desktopWidget->screenCount())
pos = default_upleft;
if (isMax) {
resize(default_size);
move(default_upleft);
_titleBar->showMaxRestore();
if (geometry.isEmpty()) {
QScreen *screen=QGuiApplication::primaryScreen ();
const QRect availableGeometry = screen->availableGeometry();
resize(availableGeometry.width() / 2, availableGeometry.height() / 1.5);
const int origX = std::max(0, (availableGeometry.width() - width()) / 2);
const int origY = std::max(0, (availableGeometry.height() - height()) / 2);
move(origX, origY);
} else {
resize(size);
move(pos);
restoreGeometry(geometry);
}
// restore dockwidgets
_mainWindow->restore_dock();
_titleBar->setRestoreButton(isMax);
}
void MainFrame::setTaskbarProgress(int progress)

View File

@ -48,9 +48,7 @@ class MainFrame : public QFrame
Q_OBJECT
public:
static const int minWidth = 800;
static const int minHeight = 600;
static const int defWidth = 900;
static const int defHeight = 680;
static const int minHeight = 520;
public:
static const int Margin = 5;

View File

@ -685,6 +685,7 @@ void View::dev_changed(bool close)
void View::signals_changed()
{
double actualMargin = SignalMargin;
int total_rows = 0;
int label_size = 0;
uint8_t max_height = MaxHeightUnit;
@ -737,7 +738,7 @@ void View::signals_changed()
}
const double height = (_time_viewport->height()
- 2 * SignalMargin * label_size) * 1.0 / total_rows;
- 2 * actualMargin * label_size) * 1.0 / total_rows;
if (_session.get_device()->dev_inst()->mode == LOGIC) {
GVariant* gvar = _session.get_device()->get_config(NULL, NULL, SR_CONF_MAX_HEIGHT_VALUE);
@ -745,16 +746,22 @@ void View::signals_changed()
max_height = (g_variant_get_byte(gvar) + 1) * MaxHeightUnit;
g_variant_unref(gvar);
}
_signalHeight = (int)((height <= 0) ? 1 : (height >= max_height) ? max_height : height);
if (height < 2*actualMargin) {
actualMargin /= 2;
_signalHeight = max(1.0, (_time_viewport->height()
- 2 * actualMargin * label_size) * 1.0 / total_rows);
} else {
_signalHeight = (height >= max_height) ? max_height : height;
}
} else if (_session.get_device()->dev_inst()->mode == DSO) {
_signalHeight = (_header->height()
- horizontalScrollBar()->height()
- 2 * SignalMargin * label_size) * 1.0 / total_rows;
- 2 * actualMargin * label_size) * 1.0 / total_rows;
} else {
_signalHeight = (int)((height <= 0) ? 1 : height);
}
_spanY = _signalHeight + 2 * SignalMargin;
int next_v_offset = SignalMargin;
_spanY = _signalHeight + 2 * actualMargin;
int next_v_offset = actualMargin;
BOOST_FOREACH(boost::shared_ptr<Trace> t, time_traces) {
t->set_view(this);
t->set_viewport(_time_viewport);
@ -762,8 +769,8 @@ void View::signals_changed()
continue;
const double traceHeight = _signalHeight*t->rows_size();
t->set_totalHeight((int)traceHeight);
t->set_v_offset(next_v_offset + 0.5 * traceHeight + SignalMargin);
next_v_offset += traceHeight + 2 * SignalMargin;
t->set_v_offset(next_v_offset + 0.5 * traceHeight + actualMargin);
next_v_offset += traceHeight + 2 * actualMargin;
boost::shared_ptr<view::DsoSignal> dsoSig;
if ((dsoSig = dynamic_pointer_cast<view::DsoSignal>(t))) {