refactor: consolidate font picking into one dialog (#6531)
Instead of three separate dropdowns in the setting dialog, we now expose a single label + button combo for modifying the font. When the button is pressed, we open a custom font dialog allowing the user to customize the font family, font size, and font weight. Reviewed-by: nerix <nerixdev@outlook.de> Reviewed-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
#include "widgets/helper/FontSettingWidget.hpp"
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "singletons/Fonts.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
#include "widgets/dialogs/font/FontSettingDialog.hpp"
|
||||
|
||||
#include <QFont>
|
||||
#include <QHBoxLayout>
|
||||
#include <QString>
|
||||
#include <QToolButton>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
FontSettingWidget::FontSettingWidget(QStringSetting &family, IntSetting &size,
|
||||
IntSetting &weight, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, familySetting(family)
|
||||
, sizeSetting(size)
|
||||
, weightSetting(weight)
|
||||
, currentLabel(new QLabel)
|
||||
, listener([this] {
|
||||
this->updateCurrentLabel();
|
||||
})
|
||||
{
|
||||
auto *layout = new QHBoxLayout;
|
||||
auto *button = new QToolButton;
|
||||
|
||||
this->setLayout(layout);
|
||||
this->updateCurrentLabel();
|
||||
|
||||
this->listener.add(getApp()->getFonts()->fontChanged);
|
||||
|
||||
layout->addWidget(new QLabel("Font:"));
|
||||
layout->addStretch(1);
|
||||
layout->addWidget(this->currentLabel);
|
||||
layout->addWidget(button);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
button->setIcon(QIcon(":/buttons/edit.svg"));
|
||||
|
||||
QObject::connect(button, &QToolButton::clicked, this,
|
||||
&FontSettingWidget::showDialog);
|
||||
}
|
||||
|
||||
void FontSettingWidget::updateCurrentLabel()
|
||||
{
|
||||
QFont font = getApp()->getFonts()->getFont(FontStyle::ChatMedium, 1);
|
||||
QString family = font.family();
|
||||
QString ptSize = QString::number(font.pointSize());
|
||||
this->currentLabel->setText(family + ", " + ptSize + "pt");
|
||||
}
|
||||
|
||||
void FontSettingWidget::showDialog()
|
||||
{
|
||||
if (!this->dialog)
|
||||
{
|
||||
this->dialog = new FontSettingDialog(
|
||||
this->familySetting, this->sizeSetting, this->weightSetting, this);
|
||||
|
||||
QObject::connect(this->dialog, &QObject::destroyed, [this] {
|
||||
this->dialog = nullptr;
|
||||
});
|
||||
}
|
||||
|
||||
this->dialog->show();
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/ChatterinoSetting.hpp"
|
||||
#include "util/SignalListener.hpp"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QWidget>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class FontSettingDialog;
|
||||
|
||||
/// FontSettingWidget includes a label showing the current font and its size, with a button
|
||||
/// that opens a FontSettingDialog
|
||||
class FontSettingWidget : public QWidget
|
||||
{
|
||||
public:
|
||||
FontSettingWidget(QStringSetting &family, IntSetting &size,
|
||||
IntSetting &weight, QWidget *parent = nullptr);
|
||||
|
||||
private:
|
||||
void updateCurrentLabel();
|
||||
void showDialog();
|
||||
|
||||
FontSettingDialog *dialog = nullptr;
|
||||
|
||||
QStringSetting &familySetting;
|
||||
IntSetting &sizeSetting;
|
||||
IntSetting &weightSetting;
|
||||
|
||||
QLabel *currentLabel;
|
||||
SignalListener listener;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
Reference in New Issue
Block a user