Skip to content

Commit

Permalink
WIP fixing dialog position
Browse files Browse the repository at this point in the history
  • Loading branch information
martinburchell committed May 17, 2024
1 parent f5c24ac commit 1ec570c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
25 changes: 17 additions & 8 deletions tablet_qt/dialogs/passwordchangedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ PasswordChangeDialog::PasswordChangeDialog(const QString& text,
connect(buttonbox, &QDialogButtonBox::rejected,
this, &PasswordChangeDialog::reject);
mainlayout->addWidget(buttonbox);
mainlayout->addStretch(1);

QScreen *screen = uifunc::screen();

Expand Down Expand Up @@ -161,27 +162,31 @@ void PasswordChangeDialog::centre()
{
sizeToScreen();

const int screen_width = uifunc::screenWidth();
const int screen_height = uifunc::screenHeight();
const int screen_width = uifunc::screenAvailableWidth();
const int screen_height = uifunc::screenAvailableHeight();
const int old_height = height();
const int old_width = width();
const int x = (screen_width - old_height) / 2;
const int y = (screen_height - old_width) / 2;
const int x = (screen_width - old_width) / 2;
const int y = (screen_height - old_height) / 2;
reportSize();
qInfo() << QString("Moving to: %1, %2").arg(x).arg(y);
move(x, y);
reportSize();
}


void PasswordChangeDialog::sizeToScreen()
{
const int screen_width = uifunc::screenWidth();
const int screen_height = uifunc::screenHeight();
const int screen_width = uifunc::screenAvailableWidth();
const int screen_height = uifunc::screenAvailableHeight();

bool changed = false;

int new_width = width();
int new_height = height();

reportSize();

if (new_width > screen_width)
{
new_width = screen_width;
Expand All @@ -193,15 +198,19 @@ void PasswordChangeDialog::sizeToScreen()
changed = true;
}
if (changed) {
qInfo() << QString("Resizing to: %1, %2").arg(new_width).arg(new_height);
resize(new_width, new_height);
}

reportSize();

}


void PasswordChangeDialog::reportSize()
{
const int screen_width = uifunc::screenWidth();
const int screen_height = uifunc::screenHeight();
const int screen_width = uifunc::screenAvailableWidth();
const int screen_height = uifunc::screenAvailableHeight();
const int old_height = height();
const int old_width = width();
QPoint old_pos = pos();
Expand Down
17 changes: 17 additions & 0 deletions tablet_qt/lib/uifunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,22 @@ QScreen* screen()
}


QRect screenAvailableGeometry()
{
// https://stackoverflow.com/questions/18975734/how-can-i-find-the-screen-desktop-size-in-qt-so-i-can-display-a-desktop-notific
return screen()->availableGeometry();
}

int screenAvailableWidth()
{
return screenAvailableGeometry().width();
}

int screenAvailableHeight()
{
return screenAvailableGeometry().height();
}

QRect screenGeometry()
{
// https://stackoverflow.com/questions/18975734/how-can-i-find-the-screen-desktop-size-in-qt-so-i-can-display-a-desktop-notific
Expand All @@ -729,6 +745,7 @@ int screenHeight()
return screenGeometry().height();
}


qreal screenDpi()
{
return screen()->logicalDotsPerInch();
Expand Down
3 changes: 3 additions & 0 deletions tablet_qt/lib/uifunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ QSize minimumSizeForTitle(const QDialog* dialog,
bool include_app_name = false);

QScreen* screen();
QRect screenAvailableGeometry();
int screenAvailableWidth();
int screenAvailableHeight();
QRect screenGeometry();
int screenWidth();
int screenHeight();
Expand Down

0 comments on commit 1ec570c

Please sign in to comment.