refactor(SettingsWizard): Ui Less

This commit is contained in:
sithlord48 2024-10-18 21:48:17 -04:00 committed by Nick Bolton
parent db6b6b9386
commit f0a946a0f1
3 changed files with 63 additions and 243 deletions

View file

@ -1,59 +1,85 @@
/*
* Deskflow -- mouse and keyboard sharing utility
* Copyright (C) 2012 Symless Ltd.
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* SPDX-FileCopyrightText: Copyright (C) 2024 Chris Rizzitello <sithlord48@gmail.com>
* SPDX-FileCopyrightText: Copyright (C) 2012 Symless Ltd.
* SPDX-License-Identifier: GPL-2.0
*/
#include "SetupWizard.h"
#include "ui_SetupWizard.h"
#include <QApplication>
#include <QFormLayout>
#include <QPushButton>
#include "gui/config/AppConfig.h"
#include "gui/styles.h"
#include "gui/validators/ScreenNameValidator.h"
#include "gui/validators/ValidationError.h"
using namespace deskflow::gui;
SetupWizard::SetupWizard(AppConfig &appConfig) : ui{std::make_unique<Ui::SetupWizard>()}, m_appConfig(appConfig)
SetupWizard::SetupWizard(AppConfig &appConfig)
: m_appConfig{appConfig},
m_lblError{new QLabel(this)},
m_lineName{new QLineEdit(this)},
m_btnApply{new QPushButton(tr("Continue"), this)}
{
ui->setupUi(this);
setWindowTitle(tr("Setup %1").arg(DESKFLOW_APP_NAME));
setWindowTitle(QString("Setup %1").arg(DESKFLOW_APP_NAME));
setFixedSize(740, 550);
ui->m_pLabelError->setStyleSheet(kStyleErrorActiveLabel);
auto headerFont = QFont(QStringLiteral("Cantarell"), 18, 600);
ui->m_pLineEditName->setText(appConfig.screenName());
ui->m_pLineEditName->setValidator(
new validators::ScreenNameValidator(ui->m_pLineEditName, new validators::ValidationError(this, ui->m_pLabelError))
auto labelTitle = new QLabel(this);
labelTitle->setFont(headerFont);
labelTitle->setText(tr("Name your computer"));
labelTitle->setAlignment(Qt::AlignHCenter | Qt::AlignHCenter);
auto labelName = new QLabel(this);
labelName->setText(tr("Computer Name"));
auto formLayout = new QFormLayout();
formLayout->addRow(labelName, m_lineName);
formLayout->addWidget(m_lblError);
formLayout->addWidget(new QLabel(tr("Call your computer something short and meaningful, but it must have:"), this));
formLayout->addWidget(new QLabel(tr("\t⬤ No spaces"), this));
formLayout->addWidget(new QLabel(tr("\t⬤ Only these special characters: _ - ."), this));
formLayout->addWidget(new QLabel(tr("\t⬤ Only English characters and numbers"), this));
formLayout->addWidget(new QLabel(tr("\t⬤ A different name from other computers"), this));
auto labelImage = new QLabel(this);
labelImage->setPixmap(QPixmap(QStringLiteral(":/image/welcome.png")));
auto mainLayout = new QVBoxLayout();
mainLayout->setContentsMargins(9, 30, 9, 9);
mainLayout->addWidget(labelImage, 0, Qt::AlignHCenter);
mainLayout->addWidget(labelTitle);
mainLayout->addLayout(formLayout);
mainLayout->addSpacerItem(new QSpacerItem(0, 25, QSizePolicy::Fixed, QSizePolicy::Fixed));
mainLayout->addWidget(m_btnApply);
setLayout(mainLayout);
m_lblError->setStyleSheet(deskflow::gui::kStyleErrorActiveLabel);
m_lineName->setText(appConfig.screenName());
m_lineName->setValidator(
new validators::ScreenNameValidator(m_lineName, new validators::ValidationError(this, m_lblError))
);
connect(ui->m_pButtonApply, &QPushButton::clicked, this, &SetupWizard::accept);
connect(ui->m_pLineEditName, &QLineEdit::textChanged, this, &SetupWizard::nameChanged);
connect(m_btnApply, &QPushButton::clicked, this, &SetupWizard::accept);
connect(m_lineName, &QLineEdit::textChanged, this, &SetupWizard::nameChanged);
}
SetupWizard::~SetupWizard() = default;
void SetupWizard::accept()
{
m_appConfig.setWizardHasRun();
m_appConfig.setScreenName(ui->m_pLineEditName->text());
m_appConfig.setScreenName(m_lineName->text());
QDialog::accept();
}
void SetupWizard::nameChanged(const QString &error)
{
ui->m_pButtonApply->setEnabled(ui->m_pLineEditName->hasAcceptableInput());
m_btnApply->setEnabled(m_lineName->hasAcceptableInput());
}
void SetupWizard::reject()

View file

@ -1,36 +1,18 @@
/*
* Deskflow -- mouse and keyboard sharing utility
* Copyright (C) 2012 Symless Ltd.
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* SPDX-FileCopyrightText: Copyright (C) 2024 Chris Rizzitello <sithlord48@gmail.com>
* SPDX-FileCopyrightText: Copyright (C) 2012 Symless Ltd.
* SPDX-License-Identifier: GPL-2.0
*/
#pragma once
#include <QDialog>
#include <QObject>
class MainWindow;
namespace Ui {
class SetupWizard;
}
class AppConfig;
namespace Ui {
class SetupWizard;
}
class QLabel;
class QLineEdit;
class SetupWizard : public QDialog
{
@ -38,7 +20,7 @@ class SetupWizard : public QDialog
public:
explicit SetupWizard(AppConfig &appConfig);
~SetupWizard();
~SetupWizard() = default;
protected:
void accept() override;
@ -47,6 +29,8 @@ protected:
private:
void nameChanged(const QString &error);
std::unique_ptr<Ui::SetupWizard> ui;
AppConfig &m_appConfig;
QLabel *m_lblError = nullptr;
QLineEdit *m_lineName = nullptr;
QPushButton *m_btnApply = nullptr;
};

View file

@ -1,190 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SetupWizard</class>
<widget class="QDialog" name="SetupWizard">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>764</width>
<height>612</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="baseSize">
<size>
<width>720</width>
<height>552</height>
</size>
</property>
<property name="contextMenuPolicy">
<enum>Qt::NoContextMenu</enum>
</property>
<property name="windowTitle">
<string>Setup Deskflow</string>
</property>
<property name="windowOpacity">
<double>1.000000000000000</double>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>20</number>
</property>
<property name="leftMargin">
<number>150</number>
</property>
<property name="rightMargin">
<number>150</number>
</property>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item alignment="Qt::AlignHCenter|Qt::AlignTop">
<widget class="QLabel" name="m_pLabelImage">
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap>:/image/welcome.png</pixmap>
</property>
<property name="margin">
<number>1</number>
</property>
</widget>
</item>
<item alignment="Qt::AlignHCenter|Qt::AlignTop">
<widget class="QLabel" name="m_pLabelTitle">
<property name="font">
<font>
<family>Cantarell</family>
<pointsize>18</pointsize>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Name your computer</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
</widget>
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<property name="leftMargin">
<number>50</number>
</property>
<property name="topMargin">
<number>30</number>
</property>
<property name="rightMargin">
<number>50</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="m_pLabelName">
<property name="text">
<string>Computer name</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="margin">
<number>2</number>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="m_pLineEditName">
<property name="minimumSize">
<size>
<width>230</width>
<height>20</height>
</size>
</property>
<property name="maxLength">
<number>255</number>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="m_pLabelError">
<property name="text">
<string>m_pLabelError</string>
</property>
</widget>
</item>
</layout>
</item>
<item alignment="Qt::AlignHCenter|Qt::AlignTop">
<widget class="QLabel" name="m_pHelpList">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Call your computer something short and meaningful, but it must have:
- No spaces
- Only these special characters: _ - .
- Only English characters and numbers
- A different name from other computers
</string>
</property>
<property name="textFormat">
<enum>Qt::MarkdownText</enum>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item alignment="Qt::AlignHCenter">
<widget class="QPushButton" name="m_pButtonApply">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>40</height>
</size>
</property>
<property name="text">
<string>Continue</string>
</property>
</widget>
</item>
</layout>
</widget>
<connections/>
</ui>