play around with custom font dialog

This commit is contained in:
Rasmus Karlsson 2024-09-17 16:15:09 +02:00
parent 61acba5480
commit f6b482893b
4 changed files with 81 additions and 0 deletions

View file

@ -570,6 +570,8 @@ set(SOURCE_FILES
widgets/dialogs/EditHotkeyDialog.hpp
widgets/dialogs/EmotePopup.cpp
widgets/dialogs/EmotePopup.hpp
widgets/dialogs/FontPicker.cpp
widgets/dialogs/FontPicker.hpp
widgets/dialogs/LastRunCrashDialog.cpp
widgets/dialogs/LastRunCrashDialog.hpp
widgets/dialogs/LoginDialog.cpp

View file

@ -9,6 +9,7 @@
#include "messages/MessageElement.hpp"
#include "singletons/Theme.hpp"
#include "util/PostToThread.hpp"
#include "widgets/dialogs/FontPicker.hpp"
#include <QApplication>
#include <QLoggingCategory>
@ -141,6 +142,10 @@ QString debugTest(const CommandContext &ctx)
ctx.channel->addSystemMessage("debug-test called");
FontPicker *fontPicker = new FontPicker;
fontPicker->show();
return "";
}

View file

@ -0,0 +1,61 @@
#include "widgets/dialogs/FontPicker.hpp"
#include <qabstractitemview.h>
#include <QFontDatabase>
#include <qlabel.h>
#include <qstringlistmodel.h>
#include <QtWidgets/qboxlayout.h>
#include <QtWidgets/qlistview.h>
namespace {
constexpr auto SAMPLE_POINT_SIZE = 12;
} // namespace
namespace chatterino {
FontPicker::FontPicker()
{
auto *layout = new QVBoxLayout(this);
auto *fontList = new QListView(this);
layout->addWidget(fontList);
auto *model = new QStringListModel(this);
auto *selectionModel = new QItemSelectionModel(model);
qInfo() << "font families:"
<< QFontDatabase::families(QFontDatabase::WritingSystem::Latin);
QStringList fonts;
for (const auto &font :
QFontDatabase::families(QFontDatabase::WritingSystem::Latin))
{
if (QFontDatabase::isPrivateFamily(font))
{
continue;
}
fonts << font;
}
model->setStringList(fonts);
fontList->setModel(model);
fontList->setEditTriggers(QAbstractItemView::NoEditTriggers);
fontList->setSelectionModel(selectionModel);
auto *sample = new QLabel(this);
sample->setText("forsen: This is some sample text xD");
layout->addWidget(sample);
QObject::connect(
selectionModel, &QItemSelectionModel::currentChanged,
[sample](const QModelIndex &selected, const QModelIndex &deselected) {
(void)deselected;
sample->setFont(QFontDatabase::font(selected.data().toString(),
"Normal", SAMPLE_POINT_SIZE));
qInfo() << "clicked font xd" << selected.data();
// selcetion changed? xd
});
}
} // namespace chatterino

View file

@ -0,0 +1,13 @@
#pragma once
#include <qdialog.h>
namespace chatterino {
class FontPicker : public QDialog
{
public:
FontPicker();
};
} // namespace chatterino