From 111e4504acb5f1575b00d60cba8552c70db45c08 Mon Sep 17 00:00:00 2001 From: Adasauce Date: Tue, 18 Feb 2020 11:08:19 -0400 Subject: [PATCH 1/8] Replace QHBoxLayout with QFormLayout in UserSettings This allows form fields to wrap dynamically when they are too long for the view. This should help mobile and small screen users to configure the app without having to force it into portrait mode, or not be able to reach the settings fields at all. --- src/UserSettingsPage.cpp | 210 ++++++++++++++------------------------- src/UserSettingsPage.h | 2 + 2 files changed, 74 insertions(+), 138 deletions(-) diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index 87d802b8..495e5aea 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -173,81 +174,43 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge topBarLayout_->addWidget(backBtn_, 1, Qt::AlignLeft | Qt::AlignVCenter); topBarLayout_->addStretch(1); - auto addSetting = [this, &font](QString labelText) { - auto layout = new QHBoxLayout; - layout->setContentsMargins(0, OptionMargin, 0, OptionMargin); + formLayout_ = new QFormLayout; - auto label = new QLabel(labelText, this); - label->setFont(font); + formLayout_->setLabelAlignment(Qt::AlignLeft); + formLayout_->setFormAlignment(Qt::AlignRight); + formLayout_->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow); + formLayout_->setRowWrapPolicy(QFormLayout::WrapLongRows); + formLayout_->setHorizontalSpacing(0); - auto toggle = new Toggle(this); + auto general_ = new QLabel(tr("GENERAL"), this); + general_->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); + general_->setFont(font); - layout->addWidget(label); - layout->addWidget(toggle, 0, Qt::AlignRight); + trayToggle_ = new Toggle(this); + startInTrayToggle_ = new Toggle(this); - return std::pair{layout, toggle}; - }; - - QHBoxLayout *trayOptionLayout_ = nullptr; - std::tie(trayOptionLayout_, trayToggle_) = addSetting(tr("Minimize to tray")); - - QHBoxLayout *startInTrayOptionLayout_ = nullptr; - std::tie(startInTrayOptionLayout_, startInTrayToggle_) = addSetting(tr("Start in tray")); if (!settings_->isTrayEnabled()) startInTrayToggle_->setDisabled(true); - QHBoxLayout *groupViewLayout = nullptr; - std::tie(groupViewLayout, groupViewToggle_) = addSetting(tr("Group's sidebar")); - - QHBoxLayout *avatarViewLayout = nullptr; - std::tie(avatarViewLayout, avatarCircles_) = addSetting(tr("Circular Avatars")); - - QHBoxLayout *typingLayout = nullptr; - std::tie(typingLayout, typingNotifications_) = addSetting(tr("Typing notifications")); - - QHBoxLayout *receiptsLayout = nullptr; - std::tie(receiptsLayout, readReceipts_) = addSetting(tr("Read receipts")); - - QHBoxLayout *markdownLayout = nullptr; - std::tie(markdownLayout, markdownEnabled_) = addSetting(tr("Send messages as Markdown")); - - QHBoxLayout *desktopLayout = nullptr; - std::tie(desktopLayout, desktopNotifications_) = addSetting(tr("Desktop notifications")); - - auto scaleFactorOptionLayout = new QHBoxLayout; - scaleFactorOptionLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin); - auto scaleFactorLabel = new QLabel(tr("Scale factor"), this); - scaleFactorLabel->setFont(font); - scaleFactorCombo_ = new QComboBox(this); + avatarCircles_ = new Toggle(this); + groupViewToggle_ = new Toggle(this); + typingNotifications_ = new Toggle(this); + readReceipts_ = new Toggle(this); + markdownEnabled_ = new Toggle(this); + desktopNotifications_ = new Toggle(this); + scaleFactorCombo_ = new QComboBox(this); for (double option = 1; option <= 3; option += 0.25) scaleFactorCombo_->addItem(QString::number(option)); - - scaleFactorOptionLayout->addWidget(scaleFactorLabel); - scaleFactorOptionLayout->addWidget(scaleFactorCombo_, 0, Qt::AlignRight); - - auto fontSizeOptionLayout = new QHBoxLayout; - fontSizeOptionLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin); - auto fontSizeLabel = new QLabel(tr("Font size"), this); - fontSizeLabel->setFont(font); fontSizeCombo_ = new QComboBox(this); for (double option = 10; option < 17; option += 0.5) fontSizeCombo_->addItem(QString("%1 ").arg(QString::number(option))); - fontSizeOptionLayout->addWidget(fontSizeLabel); - fontSizeOptionLayout->addWidget(fontSizeCombo_, 0, Qt::AlignRight); - - auto fontFamilyOptionLayout = new QHBoxLayout; - auto emojiFontFamilyOptionLayout = new QHBoxLayout; - fontFamilyOptionLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin); - emojiFontFamilyOptionLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin); - auto fontFamilyLabel = new QLabel(tr("Font Family"), this); - auto emojiFamilyLabel = new QLabel(tr("Emoji Font Famly"), this); - fontFamilyLabel->setFont(font); - emojiFamilyLabel->setFont(font); fontSelectionCombo_ = new QComboBox(this); emojiFontSelectionCombo_ = new QComboBox(this); + QFontDatabase fontDb; auto fontFamilies = fontDb.families(); + // TODO: Is there a way to limit to just emojis, rather than // all emoji fonts? auto emojiFamilies = fontDb.families(QFontDatabase::Symbol); @@ -266,16 +229,6 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge fontIndex = emojiFontSelectionCombo_->findText(settings_->emojiFont()); emojiFontSelectionCombo_->setCurrentIndex(fontIndex); - fontFamilyOptionLayout->addWidget(fontFamilyLabel); - fontFamilyOptionLayout->addWidget(fontSelectionCombo_, 0, Qt::AlignRight); - - emojiFontFamilyOptionLayout->addWidget(emojiFamilyLabel); - emojiFontFamilyOptionLayout->addWidget(emojiFontSelectionCombo_, 0, Qt::AlignRight); - - auto themeOptionLayout_ = new QHBoxLayout; - themeOptionLayout_->setContentsMargins(0, OptionMargin, 0, OptionMargin); - auto themeLabel_ = new QLabel(tr("Theme"), this); - themeLabel_->setFont(font); themeCombo_ = new QComboBox(this); themeCombo_->addItem("Light"); themeCombo_->addItem("Dark"); @@ -286,112 +239,87 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge int themeIndex = themeCombo_->findText(themeStr); themeCombo_->setCurrentIndex(themeIndex); - themeOptionLayout_->addWidget(themeLabel_); - themeOptionLayout_->addWidget(themeCombo_, 0, Qt::AlignRight); - - auto encryptionLayout_ = new QVBoxLayout; - encryptionLayout_->setContentsMargins(0, OptionMargin, 0, OptionMargin); - encryptionLayout_->setAlignment(Qt::AlignVCenter); + auto encryptionLabel_ = new QLabel(tr("ENCRYPTION"), this); + encryptionLabel_->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); + encryptionLabel_->setFont(font); QFont monospaceFont; monospaceFont.setFamily("Monospace"); monospaceFont.setStyleHint(QFont::Monospace); monospaceFont.setPointSizeF(monospaceFont.pointSizeF() * 0.9); - auto deviceIdLayout = new QHBoxLayout; - deviceIdLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin); - - auto deviceIdLabel = new QLabel(tr("Device ID"), this); - deviceIdLabel->setFont(font); - deviceIdLabel->setMargin(0); deviceIdValue_ = new QLabel{this}; deviceIdValue_->setTextInteractionFlags(Qt::TextSelectableByMouse); deviceIdValue_->setFont(monospaceFont); - deviceIdLayout->addWidget(deviceIdLabel, 1); - deviceIdLayout->addWidget(deviceIdValue_); - auto deviceFingerprintLayout = new QHBoxLayout; - deviceFingerprintLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin); - - auto deviceFingerprintLabel = new QLabel(tr("Device Fingerprint"), this); - deviceFingerprintLabel->setFont(font); - deviceFingerprintLabel->setMargin(0); deviceFingerprintValue_ = new QLabel{this}; deviceFingerprintValue_->setTextInteractionFlags(Qt::TextSelectableByMouse); deviceFingerprintValue_->setFont(monospaceFont); - deviceFingerprintLayout->addWidget(deviceFingerprintLabel, 1); - deviceFingerprintLayout->addWidget(deviceFingerprintValue_); - auto sessionKeysLayout = new QHBoxLayout; - sessionKeysLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin); auto sessionKeysLabel = new QLabel(tr("Session Keys"), this); sessionKeysLabel->setFont(font); - sessionKeysLayout->addWidget(sessionKeysLabel, 1); + sessionKeysLabel->setMargin(OptionMargin); auto sessionKeysImportBtn = new QPushButton{tr("IMPORT"), this}; - connect( - sessionKeysImportBtn, &QPushButton::clicked, this, &UserSettingsPage::importSessionKeys); auto sessionKeysExportBtn = new QPushButton{tr("EXPORT"), this}; - connect( - sessionKeysExportBtn, &QPushButton::clicked, this, &UserSettingsPage::exportSessionKeys); + + auto sessionKeysLayout = new QHBoxLayout(this); + sessionKeysLayout->addWidget(new QLabel("", this), 1, Qt::AlignRight); sessionKeysLayout->addWidget(sessionKeysExportBtn, 0, Qt::AlignRight); sessionKeysLayout->addWidget(sessionKeysImportBtn, 0, Qt::AlignRight); - encryptionLayout_->addLayout(deviceIdLayout); - encryptionLayout_->addLayout(deviceFingerprintLayout); - encryptionLayout_->addWidget(new HorizontalLine{this}); - encryptionLayout_->addLayout(sessionKeysLayout); + auto boxWrap = [this, &font](QString labelText, QWidget *field) { + auto label = new QLabel(labelText, this); + label->setFont(font); + label->setMargin(OptionMargin); - font.setWeight(QFont::Medium); + auto layout = new QHBoxLayout(this); + layout->addWidget(field, 0, Qt::AlignRight); - auto encryptionLabel_ = new QLabel(tr("ENCRYPTION"), this); - encryptionLabel_->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); - encryptionLabel_->setFont(font); + formLayout_->addRow(label, layout); + }; - auto general_ = new QLabel(tr("GENERAL"), this); - general_->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); - general_->setFont(font); + formLayout_->addRow(general_); + formLayout_->addRow(new HorizontalLine(this)); + boxWrap(tr("Minimize to tray"), trayToggle_); + boxWrap(tr("Start in tray"), startInTrayToggle_); + formLayout_->addRow(new HorizontalLine{this}); + boxWrap(tr("Circular Avatars"), avatarCircles_); + boxWrap(tr("Group's sidebar"), groupViewToggle_); + boxWrap(tr("Typing notifications"), typingNotifications_); + formLayout_->addRow(new HorizontalLine{this}); + boxWrap(tr("Read receipts"), readReceipts_); + boxWrap(tr("Send messages as Markdown"), markdownEnabled_); + boxWrap(tr("Desktop notifications"), desktopNotifications_); + formLayout_->addRow(new QLabel("", this)); + formLayout_->addRow(new HorizontalLine{this}); + boxWrap(tr("Scale factor"), scaleFactorCombo_); + boxWrap(tr("Font size"), fontSizeCombo_); + formLayout_->addRow(new HorizontalLine(this)); + boxWrap(tr("Font Family"), fontSelectionCombo_); + boxWrap(tr("Emoji Font Family"), emojiFontSelectionCombo_); + boxWrap(tr("Theme"), themeCombo_); + formLayout_->addRow(new QLabel("", this)); + formLayout_->addRow(encryptionLabel_); + formLayout_->addRow(new HorizontalLine(this)); + boxWrap(tr("Device ID"), deviceIdValue_); + boxWrap(tr("Device Fingerprint"), deviceFingerprintValue_); + formLayout_->addRow(new HorizontalLine(this)); + formLayout_->addRow(sessionKeysLabel, sessionKeysLayout); mainLayout_ = new QVBoxLayout; mainLayout_->setAlignment(Qt::AlignTop); mainLayout_->setSpacing(7); mainLayout_->setContentsMargins( sideMargin_, LayoutTopMargin, sideMargin_, LayoutBottomMargin); - mainLayout_->addWidget(general_, 1, Qt::AlignLeft | Qt::AlignBottom); - mainLayout_->addWidget(new HorizontalLine(this)); - mainLayout_->addLayout(trayOptionLayout_); - mainLayout_->addLayout(startInTrayOptionLayout_); - mainLayout_->addWidget(new HorizontalLine(this)); - mainLayout_->addLayout(groupViewLayout); - mainLayout_->addLayout(avatarViewLayout); - mainLayout_->addWidget(new HorizontalLine(this)); - mainLayout_->addLayout(typingLayout); - mainLayout_->addLayout(receiptsLayout); - mainLayout_->addLayout(markdownLayout); - mainLayout_->addLayout(desktopLayout); - mainLayout_->addWidget(new HorizontalLine(this)); + mainLayout_->addLayout(formLayout_); #if defined(Q_OS_MAC) - scaleFactorLabel->hide(); + // TODO: hide these with formlayout scaleFactorCombo_->hide(); - emojiFamilyLabel->hide(); emojiFontSelectionCombo_->hide(); #endif - mainLayout_->addLayout(scaleFactorOptionLayout); - mainLayout_->addLayout(fontSizeOptionLayout); - mainLayout_->addLayout(fontFamilyOptionLayout); - mainLayout_->addLayout(emojiFontFamilyOptionLayout); - mainLayout_->addWidget(new HorizontalLine(this)); - mainLayout_->addLayout(themeOptionLayout_); - mainLayout_->addWidget(new HorizontalLine(this)); - - mainLayout_->addSpacing(50); - - mainLayout_->addWidget(encryptionLabel_, 1, Qt::AlignLeft | Qt::AlignBottom); - mainLayout_->addWidget(new HorizontalLine(this)); - mainLayout_->addLayout(encryptionLayout_); - auto scrollArea_ = new QScrollArea(this); scrollArea_->setFrameShape(QFrame::NoFrame); scrollArea_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); @@ -467,6 +395,12 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge settings_->setDesktopNotifications(!isDisabled); }); + connect( + sessionKeysImportBtn, &QPushButton::clicked, this, &UserSettingsPage::importSessionKeys); + + connect( + sessionKeysExportBtn, &QPushButton::clicked, this, &UserSettingsPage::exportSessionKeys); + connect(backBtn_, &QPushButton::clicked, this, [this]() { settings_->save(); emit moveBack(); @@ -507,7 +441,7 @@ UserSettingsPage::resizeEvent(QResizeEvent *event) else sideMargin_ = static_cast(event->size().width() - contentMinWidth) / 2.; - if (sideMargin_ < 40) + if (sideMargin_ < 70) sideMargin_ = 0; mainLayout_->setContentsMargins( diff --git a/src/UserSettingsPage.h b/src/UserSettingsPage.h index 299905ab..7b290073 100644 --- a/src/UserSettingsPage.h +++ b/src/UserSettingsPage.h @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -166,6 +167,7 @@ private slots: private: // Layouts QVBoxLayout *topLayout_; + QFormLayout *formLayout_; QVBoxLayout *mainLayout_; QHBoxLayout *topBarLayout_; From 21b207d1f0df5260442838384a84ba66111a7b48 Mon Sep 17 00:00:00 2001 From: Adasauce Date: Tue, 18 Feb 2020 17:16:07 -0400 Subject: [PATCH 2/8] Review changes to UserSettingsPage - Switch to {} widget initialization - set fixed size on the Toggles so they don't scale down vertically - add another setting section for INTERFACE - add a placeholder value for deviceFingerprintValue_ so it can calculate the right size. - fix warnings about `QLayout: Attempting to add QLayout "" to UserSettingsPage "",` in boxWrap - hide widgets properly in Q_OS_MAC - remove mainLayout_ completely - clean up resizeEvent --- src/UserSettingsPage.cpp | 137 ++++++++++++++++++++------------------- src/UserSettingsPage.h | 3 +- 2 files changed, 72 insertions(+), 68 deletions(-) diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index 495e5aea..5ab73fdf 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -152,12 +152,12 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge : QWidget{parent} , settings_{settings} { - topLayout_ = new QVBoxLayout(this); + topLayout_ = new QVBoxLayout{this}; QIcon icon; icon.addFile(":/icons/icons/ui/angle-pointing-to-left.png"); - auto backBtn_ = new FlatButton(this); + auto backBtn_ = new FlatButton{this}; backBtn_->setMinimumSize(QSize(24, 24)); backBtn_->setIcon(icon); backBtn_->setIconSize(QSize(24, 24)); @@ -182,54 +182,56 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge formLayout_->setRowWrapPolicy(QFormLayout::WrapLongRows); formLayout_->setHorizontalSpacing(0); - auto general_ = new QLabel(tr("GENERAL"), this); + auto general_ = new QLabel{tr("GENERAL"), this}; general_->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); general_->setFont(font); - trayToggle_ = new Toggle(this); - startInTrayToggle_ = new Toggle(this); + trayToggle_ = new Toggle{this}; + startInTrayToggle_ = new Toggle{this}; + avatarCircles_ = new Toggle{this}; + groupViewToggle_ = new Toggle{this}; + typingNotifications_ = new Toggle{this}; + readReceipts_ = new Toggle{this}; + markdownEnabled_ = new Toggle{this}; + desktopNotifications_ = new Toggle{this}; + scaleFactorCombo_ = new QComboBox{this}; + fontSizeCombo_ = new QComboBox{this}; + fontSelectionCombo_ = new QComboBox{this}; + emojiFontSelectionCombo_ = new QComboBox{this}; if (!settings_->isTrayEnabled()) startInTrayToggle_->setDisabled(true); - avatarCircles_ = new Toggle(this); - groupViewToggle_ = new Toggle(this); - typingNotifications_ = new Toggle(this); - readReceipts_ = new Toggle(this); - markdownEnabled_ = new Toggle(this); - desktopNotifications_ = new Toggle(this); - scaleFactorCombo_ = new QComboBox(this); + avatarCircles_->setFixedSize(64, 48); + + auto uiLabel_ = new QLabel{tr("INTERFACE"), this}; + uiLabel_->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); + uiLabel_->setFont(font); + for (double option = 1; option <= 3; option += 0.25) scaleFactorCombo_->addItem(QString::number(option)); - fontSizeCombo_ = new QComboBox(this); for (double option = 10; option < 17; option += 0.5) fontSizeCombo_->addItem(QString("%1 ").arg(QString::number(option))); - fontSelectionCombo_ = new QComboBox(this); - emojiFontSelectionCombo_ = new QComboBox(this); - QFontDatabase fontDb; auto fontFamilies = fontDb.families(); - - // TODO: Is there a way to limit to just emojis, rather than - // all emoji fonts? - auto emojiFamilies = fontDb.families(QFontDatabase::Symbol); - for (const auto &family : fontFamilies) { fontSelectionCombo_->addItem(family); } + // TODO: Is there a way to limit to just emojis, rather than + // all emoji fonts? + auto emojiFamilies = fontDb.families(QFontDatabase::Symbol); for (const auto &family : emojiFamilies) { emojiFontSelectionCombo_->addItem(family); } - int fontIndex = fontSelectionCombo_->findText(settings_->font()); - fontSelectionCombo_->setCurrentIndex(fontIndex); + fontSelectionCombo_->setCurrentIndex(fontSelectionCombo_->findText(settings_->font())); - fontIndex = emojiFontSelectionCombo_->findText(settings_->emojiFont()); - emojiFontSelectionCombo_->setCurrentIndex(fontIndex); + emojiFontSelectionCombo_->setCurrentIndex( + emojiFontSelectionCombo_->findText(settings_->emojiFont())); - themeCombo_ = new QComboBox(this); + themeCombo_ = new QComboBox{this}; themeCombo_->addItem("Light"); themeCombo_->addItem("Dark"); themeCombo_->addItem("System"); @@ -239,7 +241,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge int themeIndex = themeCombo_->findText(themeStr); themeCombo_->setCurrentIndex(themeIndex); - auto encryptionLabel_ = new QLabel(tr("ENCRYPTION"), this); + auto encryptionLabel_ = new QLabel{tr("ENCRYPTION"), this}; encryptionLabel_->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); encryptionLabel_->setFont(font); @@ -256,31 +258,34 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge deviceFingerprintValue_->setTextInteractionFlags(Qt::TextSelectableByMouse); deviceFingerprintValue_->setFont(monospaceFont); - auto sessionKeysLabel = new QLabel(tr("Session Keys"), this); + std::string fingerprintPlaceHolder_(44, 'x'); + deviceFingerprintValue_->setText(utils::humanReadableFingerprint(fingerprintPlaceHolder_)); + + auto sessionKeysLabel = new QLabel{tr("Session Keys"), this}; sessionKeysLabel->setFont(font); sessionKeysLabel->setMargin(OptionMargin); auto sessionKeysImportBtn = new QPushButton{tr("IMPORT"), this}; auto sessionKeysExportBtn = new QPushButton{tr("EXPORT"), this}; - auto sessionKeysLayout = new QHBoxLayout(this); - sessionKeysLayout->addWidget(new QLabel("", this), 1, Qt::AlignRight); + auto sessionKeysLayout = new QHBoxLayout; + sessionKeysLayout->addWidget(new QLabel{"", this}, 1, Qt::AlignRight); sessionKeysLayout->addWidget(sessionKeysExportBtn, 0, Qt::AlignRight); sessionKeysLayout->addWidget(sessionKeysImportBtn, 0, Qt::AlignRight); auto boxWrap = [this, &font](QString labelText, QWidget *field) { - auto label = new QLabel(labelText, this); + auto label = new QLabel{labelText, this}; label->setFont(font); label->setMargin(OptionMargin); - auto layout = new QHBoxLayout(this); + auto layout = new QHBoxLayout; layout->addWidget(field, 0, Qt::AlignRight); formLayout_->addRow(label, layout); }; formLayout_->addRow(general_); - formLayout_->addRow(new HorizontalLine(this)); + formLayout_->addRow(new HorizontalLine{this}); boxWrap(tr("Minimize to tray"), trayToggle_); boxWrap(tr("Start in tray"), startInTrayToggle_); formLayout_->addRow(new HorizontalLine{this}); @@ -291,36 +296,34 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge boxWrap(tr("Read receipts"), readReceipts_); boxWrap(tr("Send messages as Markdown"), markdownEnabled_); boxWrap(tr("Desktop notifications"), desktopNotifications_); - formLayout_->addRow(new QLabel("", this)); + formLayout_->addRow(new QLabel{"", this}); + formLayout_->addRow(uiLabel_); formLayout_->addRow(new HorizontalLine{this}); + +#if !defined(Q_OS_MAC) boxWrap(tr("Scale factor"), scaleFactorCombo_); - boxWrap(tr("Font size"), fontSizeCombo_); - formLayout_->addRow(new HorizontalLine(this)); - boxWrap(tr("Font Family"), fontSelectionCombo_); - boxWrap(tr("Emoji Font Family"), emojiFontSelectionCombo_); - boxWrap(tr("Theme"), themeCombo_); - formLayout_->addRow(new QLabel("", this)); - formLayout_->addRow(encryptionLabel_); - formLayout_->addRow(new HorizontalLine(this)); - boxWrap(tr("Device ID"), deviceIdValue_); - boxWrap(tr("Device Fingerprint"), deviceFingerprintValue_); - formLayout_->addRow(new HorizontalLine(this)); - formLayout_->addRow(sessionKeysLabel, sessionKeysLayout); - - mainLayout_ = new QVBoxLayout; - mainLayout_->setAlignment(Qt::AlignTop); - mainLayout_->setSpacing(7); - mainLayout_->setContentsMargins( - sideMargin_, LayoutTopMargin, sideMargin_, LayoutBottomMargin); - mainLayout_->addLayout(formLayout_); - -#if defined(Q_OS_MAC) - // TODO: hide these with formlayout +#else scaleFactorCombo_->hide(); +#endif + boxWrap(tr("Font size"), fontSizeCombo_); + boxWrap(tr("Font Family"), fontSelectionCombo_); + +#if !defined(Q_OS_MAC) + boxWrap(tr("Emoji Font Family"), emojiFontSelectionCombo_); +#else emojiFontSelectionCombo_->hide(); #endif - auto scrollArea_ = new QScrollArea(this); + boxWrap(tr("Theme"), themeCombo_); + formLayout_->addRow(new QLabel{"", this}); + formLayout_->addRow(encryptionLabel_); + formLayout_->addRow(new HorizontalLine{this}); + boxWrap(tr("Device ID"), deviceIdValue_); + boxWrap(tr("Device Fingerprint"), deviceFingerprintValue_); + formLayout_->addRow(new HorizontalLine{this}); + formLayout_->addRow(sessionKeysLabel, sessionKeysLayout); + + auto scrollArea_ = new QScrollArea{this}; scrollArea_->setFrameShape(QFrame::NoFrame); scrollArea_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); scrollArea_->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); @@ -329,9 +332,9 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge QScroller::grabGesture(scrollArea_, QScroller::TouchGesture); - auto scrollAreaContents_ = new QWidget(this); + auto scrollAreaContents_ = new QWidget{this}; scrollAreaContents_->setObjectName("UserSettingScrollWidget"); - scrollAreaContents_->setLayout(mainLayout_); + scrollAreaContents_->setLayout(formLayout_); scrollArea_->setWidget(scrollAreaContents_); topLayout_->addLayout(topBarLayout_); @@ -433,18 +436,20 @@ UserSettingsPage::showEvent(QShowEvent *) void UserSettingsPage::resizeEvent(QResizeEvent *event) { - mainLayout_->setContentsMargins(0, LayoutTopMargin, 0, LayoutBottomMargin); - double contentMinWidth = mainLayout_->minimumSize().width(); + auto preWidth_ = width(); - if (event->size().width() * 0.6 > contentMinWidth) - sideMargin_ = width() * 0.2; + formLayout_->setContentsMargins(0, LayoutTopMargin, 0, LayoutBottomMargin); + double contentMinWidth = formLayout_->minimumSize().width(); + + if (preWidth_ * 0.6 > contentMinWidth) + sideMargin_ = preWidth_ * 0.2; else - sideMargin_ = static_cast(event->size().width() - contentMinWidth) / 2.; + sideMargin_ = static_cast(preWidth_ - contentMinWidth) / 2.; - if (sideMargin_ < 70) + if (sideMargin_ < 40) sideMargin_ = 0; - mainLayout_->setContentsMargins( + formLayout_->setContentsMargins( sideMargin_, LayoutTopMargin, sideMargin_, LayoutBottomMargin); QWidget::resizeEvent(event); diff --git a/src/UserSettingsPage.h b/src/UserSettingsPage.h index 7b290073..ef8258b6 100644 --- a/src/UserSettingsPage.h +++ b/src/UserSettingsPage.h @@ -167,9 +167,8 @@ private slots: private: // Layouts QVBoxLayout *topLayout_; - QFormLayout *formLayout_; - QVBoxLayout *mainLayout_; QHBoxLayout *topBarLayout_; + QFormLayout *formLayout_; // Shared settings object. QSharedPointer settings_; From 53138d7f5c51cf37d9f92dda49a271ed2c953678 Mon Sep 17 00:00:00 2001 From: Adasauce Date: Wed, 19 Feb 2020 15:00:49 -0400 Subject: [PATCH 3/8] Clean up placeholder string use QString instead of std::string (QStringLiteral doesn't have a constructor with int, str.) remove temp variable, and just deal with it inline. --- src/UserSettingsPage.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index 5ab73fdf..2722001f 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -258,8 +258,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge deviceFingerprintValue_->setTextInteractionFlags(Qt::TextSelectableByMouse); deviceFingerprintValue_->setFont(monospaceFont); - std::string fingerprintPlaceHolder_(44, 'x'); - deviceFingerprintValue_->setText(utils::humanReadableFingerprint(fingerprintPlaceHolder_)); + deviceFingerprintValue_->setText(utils::humanReadableFingerprint(QString(44, 'X'))); auto sessionKeysLabel = new QLabel{tr("Session Keys"), this}; sessionKeysLabel->setFont(font); From b5aa615ef51a06204b6f3d3c01b4bdacceaad85c Mon Sep 17 00:00:00 2001 From: Adasauce Date: Wed, 19 Feb 2020 15:23:57 -0400 Subject: [PATCH 4/8] FormLayout cleanup Removed empty labels in favour of a fixed height and bottom alignment. --- src/UserSettingsPage.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index 2722001f..ace8bab9 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -205,7 +205,8 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge avatarCircles_->setFixedSize(64, 48); auto uiLabel_ = new QLabel{tr("INTERFACE"), this}; - uiLabel_->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); + uiLabel_->setFixedHeight(uiLabel_->minimumHeight() + LayoutTopMargin); + uiLabel_->setAlignment(Qt::AlignBottom); uiLabel_->setFont(font); for (double option = 1; option <= 3; option += 0.25) @@ -242,7 +243,8 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge themeCombo_->setCurrentIndex(themeIndex); auto encryptionLabel_ = new QLabel{tr("ENCRYPTION"), this}; - encryptionLabel_->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); + encryptionLabel_->setFixedHeight(encryptionLabel_->minimumHeight() + LayoutTopMargin); + encryptionLabel_->setAlignment(Qt::AlignBottom); encryptionLabel_->setFont(font); QFont monospaceFont; @@ -295,7 +297,6 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge boxWrap(tr("Read receipts"), readReceipts_); boxWrap(tr("Send messages as Markdown"), markdownEnabled_); boxWrap(tr("Desktop notifications"), desktopNotifications_); - formLayout_->addRow(new QLabel{"", this}); formLayout_->addRow(uiLabel_); formLayout_->addRow(new HorizontalLine{this}); @@ -314,7 +315,6 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge #endif boxWrap(tr("Theme"), themeCombo_); - formLayout_->addRow(new QLabel{"", this}); formLayout_->addRow(encryptionLabel_); formLayout_->addRow(new HorizontalLine{this}); boxWrap(tr("Device ID"), deviceIdValue_); From f86cbbe16a36c097a609e0bd1020136e6708eb32 Mon Sep 17 00:00:00 2001 From: Adasauce Date: Thu, 20 Feb 2020 11:50:56 -0400 Subject: [PATCH 5/8] Add constexpr for the minimum formlayout width to save on recalculation of the size and having to subtract the margins to do the tally, then re-apply. --- src/UserSettingsPage.cpp | 11 ++++------- src/UserSettingsPage.h | 5 +++++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index ace8bab9..4e134888 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -437,15 +437,12 @@ UserSettingsPage::resizeEvent(QResizeEvent *event) { auto preWidth_ = width(); - formLayout_->setContentsMargins(0, LayoutTopMargin, 0, LayoutBottomMargin); - double contentMinWidth = formLayout_->minimumSize().width(); - - if (preWidth_ * 0.6 > contentMinWidth) - sideMargin_ = preWidth_ * 0.2; + if (preWidth_ * 0.5 > LayoutMinWidth) + sideMargin_ = preWidth_ * 0.25; else - sideMargin_ = static_cast(preWidth_ - contentMinWidth) / 2.; + sideMargin_ = static_cast(preWidth_ - LayoutMinWidth) / 2.; - if (sideMargin_ < 40) + if (sideMargin_ < 60) sideMargin_ = 0; formLayout_->setContentsMargins( diff --git a/src/UserSettingsPage.h b/src/UserSettingsPage.h index ef8258b6..2b588412 100644 --- a/src/UserSettingsPage.h +++ b/src/UserSettingsPage.h @@ -33,6 +33,11 @@ constexpr int OptionMargin = 6; constexpr int LayoutTopMargin = 50; constexpr int LayoutBottomMargin = LayoutTopMargin; +// based on the width of the widest item currently in the layout (deviceFingerprintValue_) +// used for recalculating the margins of the formLayout_ on resize to help with small screens and +// mobile devices. +constexpr int LayoutMinWidth = 385; + class UserSettings : public QObject { Q_OBJECT From 105366f2b90b6f495beb3f68afea348bf33bec4e Mon Sep 17 00:00:00 2001 From: Adasauce Date: Thu, 20 Feb 2020 11:57:16 -0400 Subject: [PATCH 6/8] Clean up variable format don't use members format camelCaseTail_ --- src/UserSettingsPage.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index 4e134888..73da0169 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -435,12 +435,12 @@ UserSettingsPage::showEvent(QShowEvent *) void UserSettingsPage::resizeEvent(QResizeEvent *event) { - auto preWidth_ = width(); + auto preWidth = width(); - if (preWidth_ * 0.5 > LayoutMinWidth) - sideMargin_ = preWidth_ * 0.25; + if (preWidth * 0.5 > LayoutMinWidth) + sideMargin_ = preWidth * 0.25; else - sideMargin_ = static_cast(preWidth_ - LayoutMinWidth) / 2.; + sideMargin_ = static_cast(preWidth - LayoutMinWidth) / 2.; if (sideMargin_ < 60) sideMargin_ = 0; From 8aaf7e9e5d80bf54395793bab9218261419bd0ed Mon Sep 17 00:00:00 2001 From: Adasauce Date: Thu, 20 Feb 2020 12:31:07 -0400 Subject: [PATCH 7/8] Remove constant width, that was wrong. Use Nico's suggestion to just leverage the width of the field, and leave a comment. --- src/UserSettingsPage.cpp | 10 ++++++++-- src/UserSettingsPage.h | 5 ----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index 73da0169..63dcffbd 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -437,10 +437,16 @@ UserSettingsPage::resizeEvent(QResizeEvent *event) { auto preWidth = width(); - if (preWidth * 0.5 > LayoutMinWidth) + // based on the width of the widest item currently in the layout + // deviceFingerprintValue_ used for recalculating the margins of + // the formLayout_ on resize to help with small screens and mobile devices. + + double minFormWidth = deviceFingerprintValue_->width(); + + if (preWidth * 0.5 > minFormWidth) sideMargin_ = preWidth * 0.25; else - sideMargin_ = static_cast(preWidth - LayoutMinWidth) / 2.; + sideMargin_ = static_cast(preWidth - minFormWidth) / 2.; if (sideMargin_ < 60) sideMargin_ = 0; diff --git a/src/UserSettingsPage.h b/src/UserSettingsPage.h index 2b588412..ef8258b6 100644 --- a/src/UserSettingsPage.h +++ b/src/UserSettingsPage.h @@ -33,11 +33,6 @@ constexpr int OptionMargin = 6; constexpr int LayoutTopMargin = 50; constexpr int LayoutBottomMargin = LayoutTopMargin; -// based on the width of the widest item currently in the layout (deviceFingerprintValue_) -// used for recalculating the margins of the formLayout_ on resize to help with small screens and -// mobile devices. -constexpr int LayoutMinWidth = 385; - class UserSettings : public QObject { Q_OBJECT From 4500bcd5779e87d553c1e5fbb409ae6d80bec086 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Thu, 20 Feb 2020 18:11:30 +0100 Subject: [PATCH 8/8] Use spacing for layouting settings --- src/UserSettingsPage.cpp | 32 ++++++-------------------------- src/UserSettingsPage.h | 1 - 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index 63dcffbd..2cac783c 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -331,9 +331,14 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge QScroller::grabGesture(scrollArea_, QScroller::TouchGesture); + auto spacingAroundForm = new QHBoxLayout; + spacingAroundForm->addStretch(1); + spacingAroundForm->addLayout(formLayout_, 0); + spacingAroundForm->addStretch(1); + auto scrollAreaContents_ = new QWidget{this}; scrollAreaContents_->setObjectName("UserSettingScrollWidget"); - scrollAreaContents_->setLayout(formLayout_); + scrollAreaContents_->setLayout(spacingAroundForm); scrollArea_->setWidget(scrollAreaContents_); topLayout_->addLayout(topBarLayout_); @@ -432,31 +437,6 @@ UserSettingsPage::showEvent(QShowEvent *) utils::humanReadableFingerprint(olm::client()->identity_keys().ed25519)); } -void -UserSettingsPage::resizeEvent(QResizeEvent *event) -{ - auto preWidth = width(); - - // based on the width of the widest item currently in the layout - // deviceFingerprintValue_ used for recalculating the margins of - // the formLayout_ on resize to help with small screens and mobile devices. - - double minFormWidth = deviceFingerprintValue_->width(); - - if (preWidth * 0.5 > minFormWidth) - sideMargin_ = preWidth * 0.25; - else - sideMargin_ = static_cast(preWidth - minFormWidth) / 2.; - - if (sideMargin_ < 60) - sideMargin_ = 0; - - formLayout_->setContentsMargins( - sideMargin_, LayoutTopMargin, sideMargin_, LayoutBottomMargin); - - QWidget::resizeEvent(event); -} - void UserSettingsPage::paintEvent(QPaintEvent *) { diff --git a/src/UserSettingsPage.h b/src/UserSettingsPage.h index ef8258b6..a1b7b084 100644 --- a/src/UserSettingsPage.h +++ b/src/UserSettingsPage.h @@ -152,7 +152,6 @@ public: protected: void showEvent(QShowEvent *event) override; - void resizeEvent(QResizeEvent *event) override; void paintEvent(QPaintEvent *event) override; signals: