Krita Source Code Documentation
Loading...
Searching...
No Matches
GlyphPaletteAltPopup.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#include <QHBoxLayout>
8#include <QQmlEngine>
9#include <QQmlContext>
10#include <QQuickItem>
11#include <KoResourcePaths.h>
12#include <klocalizedstring.h>
14
16 : QFrame(parent)
17{
18 setWindowFlags(Qt::Popup);
19 setFrameStyle(QFrame::Box | QFrame::Plain);
21 QHBoxLayout *layout = new QHBoxLayout(this);
22
23 m_quickWidget->setFixedSize(300, 400);
24
25 layout->addWidget(m_quickWidget);
26 layout->setContentsMargins(0, 0, 0, 0);
27
28 setSizePolicy(QSizePolicy::Policy::Fixed, QSizePolicy::Policy::Fixed);
29 layout->setSizeConstraint(QLayout::SizeConstraint::SetFixedSize);
30
31 m_quickWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
32
33 m_quickWidget->setSource(QUrl("qrc:/GlyphPaletteAlts.qml"));
34 if (!m_quickWidget->errors().empty()) {
35 qWarning() << "Errors in " << windowTitle() << ":" << m_quickWidget->errors();
36 } else if (m_quickWidget->rootObject()){
37 m_quickWidget->rootObject()->setProperty("columns", QVariant::fromValue(3));
38 }
39 m_quickWidget->setPalette(this->palette());
40}
41
43{
48 m_quickWidget->setParent(nullptr);
49 delete m_quickWidget;
50}
51
53{
54 if (m_charMapModel) {
55 QModelIndex idx = m_charMapModel->index(index, 0);
56 if (idx.isValid()) {
57 m_quickWidget->rootObject()->setProperty("parentIndex", QVariant::fromValue(index));
58 }
59 }
60}
61
62void GlyphPaletteAltPopup::setCellSize(const int width, const int height)
63{
64 m_quickWidget->setFixedSize(width*3, height*4);
65}
66
67void GlyphPaletteAltPopup::setModel(QAbstractItemModel *model)
68{
69 m_charMapModel = model;
70 if (m_quickWidget->rootObject() && m_charMapModel) {
71 m_quickWidget->rootObject()->setProperty("glyphModel", QVariant::fromValue(m_charMapModel));
72 m_quickWidget->rootObject()->setProperty("useCharMap", QVariant::fromValue(true));
73 }
74}
75
76void GlyphPaletteAltPopup::setMarkup(const QStringList &families, const int size, const int weight, const int width, const QFont::Style style, const QVariantMap &axes, const QString &language)
77{
78 if (m_quickWidget->rootObject()) {
79 m_quickWidget->rootObject()->setProperty("fontFamilies", QVariant::fromValue(families));
80 m_quickWidget->rootObject()->setProperty("fontSize", QVariant::fromValue(size));
81 m_quickWidget->rootObject()->setProperty("fontWeight", QVariant::fromValue(weight));
82 m_quickWidget->rootObject()->setProperty("fontWidth", QVariant::fromValue(width));
83 m_quickWidget->rootObject()->setProperty("fontStyle", QVariant::fromValue(style));
84 m_quickWidget->rootObject()->setProperty("fontAxesValues", QVariant::fromValue(axes));
85 m_quickWidget->rootObject()->setProperty("language", QVariant::fromValue(language));
86 }
87}
88
89void GlyphPaletteAltPopup::slotInsertRichText(const int charRow, const int glyphRow, const bool replace, const bool useCharMap)
90{
91 emit sigInsertRichText(charRow, glyphRow, replace, useCharMap);
92}
KisQQuickWidget * m_quickWidget
void setModel(QAbstractItemModel *model)
setModel Set the glyph proxy model.
void sigInsertRichText(int charRow, int glyphRow, bool replace, bool useCharMap)
void setCellSize(const int width, const int height)
setCellSize Set the size of the pop-up relative to its cellsize. The popup is 3 cells wide and 4 high...
void setMarkup(const QStringList &families, const int size, const int weight, const int width, const QFont::Style style, const QVariantMap &axes, const QString &language)
setMarkup Set the css font markup to be used inside the palette.
GlyphPaletteAltPopup(QWidget *parent=nullptr)
void setRootIndex(const int index)
setRootIndex Set the charmap root index to show glyph alts for.
QAbstractItemModel * m_charMapModel
void slotInsertRichText(const int charRow, const int glyphRow=-1, const bool replace=false, const bool useCharMap=false)
The KisQQuickWidget class.
rgba palette[MAX_PALETTE]
Definition palette.c:35