mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
play around with custom font dialog
This commit is contained in:
parent
61acba5480
commit
f6b482893b
|
@ -570,6 +570,8 @@ set(SOURCE_FILES
|
||||||
widgets/dialogs/EditHotkeyDialog.hpp
|
widgets/dialogs/EditHotkeyDialog.hpp
|
||||||
widgets/dialogs/EmotePopup.cpp
|
widgets/dialogs/EmotePopup.cpp
|
||||||
widgets/dialogs/EmotePopup.hpp
|
widgets/dialogs/EmotePopup.hpp
|
||||||
|
widgets/dialogs/FontPicker.cpp
|
||||||
|
widgets/dialogs/FontPicker.hpp
|
||||||
widgets/dialogs/LastRunCrashDialog.cpp
|
widgets/dialogs/LastRunCrashDialog.cpp
|
||||||
widgets/dialogs/LastRunCrashDialog.hpp
|
widgets/dialogs/LastRunCrashDialog.hpp
|
||||||
widgets/dialogs/LoginDialog.cpp
|
widgets/dialogs/LoginDialog.cpp
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "messages/MessageElement.hpp"
|
#include "messages/MessageElement.hpp"
|
||||||
#include "singletons/Theme.hpp"
|
#include "singletons/Theme.hpp"
|
||||||
#include "util/PostToThread.hpp"
|
#include "util/PostToThread.hpp"
|
||||||
|
#include "widgets/dialogs/FontPicker.hpp"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QLoggingCategory>
|
#include <QLoggingCategory>
|
||||||
|
@ -141,6 +142,10 @@ QString debugTest(const CommandContext &ctx)
|
||||||
|
|
||||||
ctx.channel->addSystemMessage("debug-test called");
|
ctx.channel->addSystemMessage("debug-test called");
|
||||||
|
|
||||||
|
FontPicker *fontPicker = new FontPicker;
|
||||||
|
|
||||||
|
fontPicker->show();
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
61
src/widgets/dialogs/FontPicker.cpp
Normal file
61
src/widgets/dialogs/FontPicker.cpp
Normal 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
|
13
src/widgets/dialogs/FontPicker.hpp
Normal file
13
src/widgets/dialogs/FontPicker.hpp
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <qdialog.h>
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
|
||||||
|
class FontPicker : public QDialog
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FontPicker();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace chatterino
|
Loading…
Reference in a new issue