Skip to content

Commit

Permalink
WIP on fixing iOS dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
martinburchell committed May 16, 2024
1 parent 2e7a318 commit d755c38
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 70 deletions.
6 changes: 0 additions & 6 deletions tablet_qt/common/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,6 @@ namespace platform {
const bool PLATFORM_TABLET = false;
#endif

#if defined(Q_OS_IOS)
const bool PLATFORM_FULL_SCREEN_DIALOGS = true;
#else
const bool PLATFORM_FULL_SCREEN_DIALOGS = false;
#endif

// https://stackoverflow.com/questions/36649393/qt-check-if-current-process-is-32-or-64-bit/41863992

bool isHost64Bit()
Expand Down
5 changes: 0 additions & 5 deletions tablet_qt/common/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ extern const bool PLATFORM_MACOS;
// Is it a tablet OS?
extern const bool PLATFORM_TABLET;

// Dialogs are full screen on iOS and on Android
// they don't position correctly when rotated.
// https://bugreports.qt.io/browse/QTBUG-91363
extern const bool PLATFORM_FULL_SCREEN_DIALOGS;

// What OS type (e.g. "Android", "Linux", "Windows", "iOS", "MacOS")?
extern const QString OS_CLASS;

Expand Down
10 changes: 1 addition & 9 deletions tablet_qt/dialogs/dangerousconfirmationdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <QLabel>
#include <QLineEdit>
#include <QVBoxLayout>
#include "common/platform.h"
#include "common/textconst.h"
#include "lib/uifunc.h"

Expand Down Expand Up @@ -53,20 +52,13 @@ DangerousConfirmationDialog::DangerousConfirmationDialog(
this, &DangerousConfirmationDialog::reject);

auto mainlayout = new QVBoxLayout();
if (platform::PLATFORM_FULL_SCREEN_DIALOGS) {
setWindowState(Qt::WindowFullScreen);
mainlayout->addStretch(1);
}

mainlayout->addWidget(prompt);
mainlayout->addWidget(prompt2);
mainlayout->addWidget(m_editor);
mainlayout->addWidget(buttonbox);

if (platform::PLATFORM_FULL_SCREEN_DIALOGS) {
prompt->setWordWrap(true);
mainlayout->addStretch(1);
}
prompt->setWordWrap(true);

setLayout(mainlayout);
}
Expand Down
16 changes: 4 additions & 12 deletions tablet_qt/dialogs/modedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <QDialogButtonBox>
#include <QLabel>
#include <QVBoxLayout>
#include "common/platform.h"
#include "common/varconst.h"
#include "lib/stringfunc.h"
#include "lib/uifunc.h"
Expand Down Expand Up @@ -71,24 +70,17 @@ ModeDialog::ModeDialog(const int previous_choice,
connect(buttonbox, &QDialogButtonBox::rejected, this, &ModeDialog::reject);

auto mainlayout = new QVBoxLayout();
if (platform::PLATFORM_FULL_SCREEN_DIALOGS) {
setWindowState(Qt::WindowFullScreen);
mainlayout->addStretch(1);
}

mainlayout->addWidget(prompt);
mainlayout->addWidget(single_user_button);
mainlayout->addWidget(clinician_button);
mainlayout->addWidget(prompt2);
mainlayout->addWidget(buttonbox);

if (platform::PLATFORM_FULL_SCREEN_DIALOGS) {
prompt->setWordWrap(true);
prompt2->setWordWrap(true);
single_user_button->setWordWrap(true);
clinician_button->setWordWrap(true);
mainlayout->addStretch(1);
}
prompt->setWordWrap(true);
prompt2->setWordWrap(true);
single_user_button->setWordWrap(true);
clinician_button->setWordWrap(true);

setLayout(mainlayout);
}
Expand Down
78 changes: 65 additions & 13 deletions tablet_qt/dialogs/passwordchangedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
#include <QDialogButtonBox>
#include <QLabel>
#include <QLineEdit>
#include <QScreen>

#include <QVBoxLayout>
#include "common/platform.h"
#include "lib/filefunc.h"
#include "lib/uifunc.h"

Expand Down Expand Up @@ -52,26 +53,22 @@ PasswordChangeDialog::PasswordChangeDialog(const QString& text,
setMinimumSize(uifunc::minimumSizeForTitle(this));

auto mainlayout = new QVBoxLayout();
if (platform::PLATFORM_FULL_SCREEN_DIALOGS) {
setWindowState(Qt::WindowFullScreen);
mainlayout->addStretch(1);
}

auto prompt = new QLabel(text);
prompt->setWordWrap(true);
mainlayout->addWidget(prompt);

if (require_old_password) {
auto prompt_old = new QLabel(tr("Enter old password:"));
if (platform::PLATFORM_FULL_SCREEN_DIALOGS) {
prompt_old->setWordWrap(true);
}
prompt_old->setWordWrap(true);
mainlayout->addWidget(prompt_old);
m_editor_old = new QLineEdit();
m_editor_old->setEchoMode(QLineEdit::Password);
mainlayout->addWidget(m_editor_old);
}

auto prompt_new1 = new QLabel(tr("Enter new password:"));
prompt_new1->setWordWrap(true);
mainlayout->addWidget(prompt_new1);
m_editor_new1 = new QLineEdit();
m_editor_new1->setEchoMode(QLineEdit::Password);
Expand All @@ -81,6 +78,7 @@ PasswordChangeDialog::PasswordChangeDialog(const QString& text,
mainlayout->addWidget(m_editor_new1);

auto prompt_new2 = new QLabel(tr("Enter new password again for confirmation:"));
prompt_new2->setWordWrap(true);

mainlayout->addWidget(prompt_new2);
m_editor_new2 = new QLineEdit();
Expand All @@ -95,15 +93,69 @@ PasswordChangeDialog::PasswordChangeDialog(const QString& text,
this, &PasswordChangeDialog::reject);
mainlayout->addWidget(buttonbox);

if (platform::PLATFORM_FULL_SCREEN_DIALOGS) {
prompt->setWordWrap(true);
prompt_new1->setWordWrap(true);
mainlayout->addStretch(1);
}
QScreen *screen = uifunc::screen();

connect(screen, &QScreen::orientationChanged,
this, &PasswordChangeDialog::orientationChanged);

setLayout(mainlayout);
}

void PasswordChangeDialog::orientationChanged(Qt::ScreenOrientation orientation)
{
QString description;

switch (orientation) {

case Qt::LandscapeOrientation:
description = "landscape";
break;

case Qt::PortraitOrientation:
description = "portrait";
break;

case Qt::InvertedLandscapeOrientation:
description = "inverted landscape";
break;

case Qt::InvertedPortraitOrientation:
description = "inverted portrait";
break;

default:
description = "unknown";
break;
}

QScreen *screen = uifunc::screen();
QRect screen_rect = screen->geometry();

QString label = QString("Orientation:%1 Screen:%2x%3 Dialog:%4x%5 Pos:%6,%7").
arg(description).arg(screen_rect.width()).arg(screen_rect.height()).arg(width()).arg(height()).arg(pos().x()).arg(pos().y());
qInfo() << Q_FUNC_INFO;
qInfo() << label;

qInfo() << "Hide";
hide();
qInfo() << "Resize";
//resize(height(), width());
qInfo() << "Show";
show();
}

void PasswordChangeDialog::resizeEvent(QResizeEvent* event)
{
Q_UNUSED(event)

qInfo()<< Q_FUNC_INFO;

qInfo()
<< "dialog geometry = " << geometry()
<< "screen geometry = " << uifunc::screenGeometry();

}


QString PasswordChangeDialog::oldPassword() const
{
Expand Down
3 changes: 3 additions & 0 deletions tablet_qt/dialogs/passwordchangedialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class PasswordChangeDialog : public QDialog
QWidget* parent = nullptr);
QString oldPassword() const;
QString newPassword() const;
void resizeEvent(QResizeEvent* event);
public slots:
void orientationChanged(Qt::ScreenOrientation orientation);
protected:
void okClicked();
protected:
Expand Down
11 changes: 2 additions & 9 deletions tablet_qt/dialogs/passwordentrydialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <QLabel>
#include <QLineEdit>
#include <QVBoxLayout>
#include "common/platform.h"
#include "lib/uifunc.h"


Expand All @@ -36,6 +35,7 @@ PasswordEntryDialog::PasswordEntryDialog(const QString& text,
setMinimumSize(uifunc::minimumSizeForTitle(this));

auto prompt = new QLabel(text);
prompt->setWordWrap(true);

m_editor = new QLineEdit();
m_editor->setEchoMode(QLineEdit::Password);
Expand All @@ -48,19 +48,12 @@ PasswordEntryDialog::PasswordEntryDialog(const QString& text,
this, &PasswordEntryDialog::reject);

auto mainlayout = new QVBoxLayout();
if (platform::PLATFORM_FULL_SCREEN_DIALOGS) {
setWindowState(Qt::WindowFullScreen);
mainlayout->addStretch(1);
}

mainlayout->addWidget(prompt);
mainlayout->addWidget(m_editor);
mainlayout->addWidget(buttonbox);

if (platform::PLATFORM_FULL_SCREEN_DIALOGS) {
prompt->setWordWrap(true);
mainlayout->addStretch(1);
}
prompt->setWordWrap(true);

setLayout(mainlayout);
}
Expand Down
13 changes: 2 additions & 11 deletions tablet_qt/dialogs/patientregistrationdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <QPushButton>
#include <QFormLayout>
#include <QUrl>
#include "common/platform.h"
#include "lib/uifunc.h"
#include "qobjects/urlvalidator.h"
#include "widgets/proquintlineedit.h"
Expand Down Expand Up @@ -67,11 +66,6 @@ PatientRegistrationDialog::PatientRegistrationDialog(

// So we do this instead
auto mainlayout = new QVBoxLayout();
if (platform::PLATFORM_FULL_SCREEN_DIALOGS) {
setWindowState(Qt::WindowFullScreen);
mainlayout->addStretch(1);
}

auto server_url_label = new QLabel(
tr("<b>CamCOPS server location</b> (e.g. https://server.example.com/camcops/api):")
);
Expand All @@ -92,11 +86,8 @@ PatientRegistrationDialog::PatientRegistrationDialog(

mainlayout->addWidget(m_buttonbox);

if (platform::PLATFORM_FULL_SCREEN_DIALOGS) {
server_url_label->setWordWrap(true);
patient_proquint_label->setWordWrap(true);
mainlayout->addStretch(1);
}
server_url_label->setWordWrap(true);
patient_proquint_label->setWordWrap(true);

setLayout(mainlayout);
}
Expand Down
5 changes: 0 additions & 5 deletions tablet_qt/dialogs/scrollmessagebox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include <QScrollArea>
#include <QSize>
#include <QStyle>
#include "common/platform.h"
#include "common/preprocessor_aid.h" // IWYU pragma: keep
#include "common/textconst.h"
#include "layouts/gridlayouthfw.h"
Expand Down Expand Up @@ -105,10 +104,6 @@ ScrollMessageBox::ScrollMessageBox(const QMessageBox::Icon& icon,
auto grid = new QGridLayout();
#endif

if (platform::PLATFORM_FULL_SCREEN_DIALOGS) {
setWindowState(Qt::WindowFullScreen);
}

/*
ICON { LABEL LABEL LABEL }
ICON { LABEL LABEL LABEL } in scroller
Expand Down
1 change: 1 addition & 0 deletions tablet_qt/lib/uifunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ QSize minimumSizeForTitle(const QDialog* dialog,
const QSize dialog_min_size = dialog->minimumSize();
QSize size(dialog_min_size);
size.setWidth(qMax(size.width(), final_w));
size.setWidth(qMin(size.width(), dialog->maximumWidth()));
#ifdef DEBUG_MIN_SIZE_FOR_TITLE
qDebug().nospace()
<< Q_FUNC_INFO
Expand Down

0 comments on commit d755c38

Please sign in to comment.