Krita Source Code Documentation
Loading...
Searching...
No Matches
GlyphPaletteDialog Class Reference

The GlyphPaletteDialog class. More...

#include <GlyphPaletteDialog.h>

+ Inheritance diagram for GlyphPaletteDialog:

Public Slots

void slotHidePopupPalette ()
 
void slotInsertRichText (const int charRow, const int glyphRow=-1, const bool replace=false, const bool useCharMap=false)
 
void slotShowPopupPalette (const int charRow, const int x=0, const int y=0, const int cellWidth=100, const int cellHeight=100)
 
- Public Slots inherited from KoDialog
void delayedDestruct ()
 
void enableButton (ButtonCode id, bool state)
 
void enableButtonApply (bool state)
 
void enableButtonCancel (bool state)
 
void enableButtonOk (bool state)
 
void enableLinkedHelp (bool state)
 
bool isDetailsWidgetVisible () const
 
virtual void setCaption (const QString &caption)
 
virtual void setCaption (const QString &caption, bool modified)
 
void setDetailsWidget (QWidget *detailsWidget)
 
void setDetailsWidgetVisible (bool visible)
 
void setHelp (const QString &anchor, const QString &appname=QString())
 
void setHelpLinkText (const QString &text)
 
virtual void setPlainCaption (const QString &caption)
 

Signals

void signalInsertRichText (KoSvgTextShape *text, bool replace)
 
- Signals inherited from KoDialog
void aboutToShowDetails ()
 
void applyClicked ()
 
void buttonClicked (KoDialog::ButtonCode button)
 
void cancelClicked ()
 
void closeClicked ()
 
void defaultClicked ()
 
void finished ()
 
void helpClicked ()
 
void hidden ()
 
void layoutHintChanged ()
 
void noClicked ()
 
void okClicked ()
 
void resetClicked ()
 
void tryClicked ()
 
void user1Clicked ()
 
void user2Clicked ()
 
void user3Clicked ()
 
void yesClicked ()
 

Public Member Functions

 GlyphPaletteDialog (QWidget *parent=nullptr)
 
void setGlyphModelFromProperties (const QPair< KoSvgTextProperties, KoSvgTextProperties > &properties, const QString &text)
 setGlyphModelFromProperties This updates the glyph model.
 
 ~GlyphPaletteDialog ()
 
- Public Member Functions inherited from KoDialog
QPushButton * button (ButtonCode id) const
 
QIcon buttonIcon (ButtonCode id) const
 
QString buttonText (ButtonCode id) const
 
QString buttonToolTip (ButtonCode id) const
 
QString buttonWhatsThis (ButtonCode id) const
 
ButtonCode defaultButton () const
 
QString helpLinkText () const
 
void incrementInitialSize (const QSize &size)
 
bool isButtonEnabled (ButtonCode id) const
 
 KoDialog (QWidget *parent=0, Qt::WindowFlags f=Qt::WindowFlags())
 
QWidget * mainWidget ()
 
QSize minimumSizeHint () const override
 
void setButtonFocus (ButtonCode id)
 
void setButtonGuiItem (ButtonCode id, const KGuiItem &item)
 
void setButtonIcon (ButtonCode id, const QIcon &icon)
 
void setButtons (ButtonCodes buttonMask)
 
void setButtonsOrientation (Qt::Orientation orientation)
 
void setButtonText (ButtonCode id, const QString &text)
 
void setButtonToolTip (ButtonCode id, const QString &text)
 
void setButtonWhatsThis (ButtonCode id, const QString &text)
 
void setDefaultButton (ButtonCode id)
 
void setEscapeButton (ButtonCode id)
 
void setInitialSize (const QSize &size)
 
void setMainWidget (QWidget *widget)
 
void showButton (ButtonCode id, bool state)
 
void showButtonSeparator (bool state)
 
QSize sizeHint () const override
 
 ~KoDialog () override
 

Private Attributes

GlyphPaletteAltPopupm_altPopup {0}
 
GlyphPaletteProxyModelm_charMapModel
 
QPair< KoSvgTextProperties, KoSvgTextPropertiesm_lastUsedProperties
 
KoFontGlyphModelm_model
 
KisQQuickWidgetm_quickWidget {0}
 

Additional Inherited Members

- Public Types inherited from KoDialog
enum  ButtonCode {
  None = 0x00000000 , Help = 0x00000001 , Default = 0x00000002 , Ok = 0x00000004 ,
  Apply = 0x00000008 , Try = 0x00000010 , Cancel = 0x00000020 , Close = 0x00000040 ,
  No = 0x00000080 , Yes = 0x00000100 , Reset = 0x00000200 , Details = 0x00000400 ,
  User1 = 0x00001000 , User2 = 0x00002000 , User3 = 0x00004000 , NoDefault = 0x00008000
}
 
enum  ButtonPopupMode { InstantPopup = 0 , DelayedPopup = 1 }
 
enum  CaptionFlag { NoCaptionFlags = 0 , AppNameCaption = 1 , ModifiedCaption = 2 , HIGCompliantCaption = AppNameCaption }
 
- Static Public Member Functions inherited from KoDialog
static int groupSpacingHint ()
 
static QString makeStandardCaption (const QString &userCaption, QWidget *window=0, CaptionFlags flags=HIGCompliantCaption)
 
static int marginHint ()
 
static void resizeLayout (QLayout *lay, int margin, int spacing)
 
static void resizeLayout (QWidget *widget, int margin, int spacing)
 
static int spacingHint ()
 
- Protected Slots inherited from KoDialog
virtual void slotButtonClicked (int button)
 
- Protected Member Functions inherited from KoDialog
void closeEvent (QCloseEvent *e) override
 
void hideEvent (QHideEvent *) override
 
void keyPressEvent (QKeyEvent *) override
 
void showEvent (QShowEvent *e) override
 

Detailed Description

The GlyphPaletteDialog class.

This dialog holds the glyph palette/character map for a given font. It can show both the alternate glyphs for the current text, and show a character map with selectable glyph alternates.

Definition at line 27 of file GlyphPaletteDialog.h.

Constructor & Destructor Documentation

◆ GlyphPaletteDialog()

GlyphPaletteDialog::GlyphPaletteDialog ( QWidget * parent = nullptr)

Definition at line 20 of file GlyphPaletteDialog.cpp.

21 : KoDialog(parent)
23 , m_model(new KoFontGlyphModel(this))
25{
26 setMinimumSize(500, 300);
27
30 m_quickWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
31
32 this->setWindowTitle(i18nc("@title:window", "Glyph Palette"));
33
34 m_charMapModel->setSourceModel(m_model);
36 connect(m_model, SIGNAL(modelReset()), m_charMapModel, SLOT(emitBlockLabelsChanged()));
37
38 m_quickWidget->rootContext()->setContextProperty("glyphModel", QVariant::fromValue(m_model));
39 m_quickWidget->rootContext()->setContextProperty("charMapProxyModel", QVariant::fromValue(m_charMapModel));
40
41 m_quickWidget->setSource(QUrl("qrc:/GlyphPalette.qml"));
42 if (!m_quickWidget->errors().empty()) {
43 qWarning() << "Errors in " << windowTitle() << ":" << m_quickWidget->errors();
44 }
45 connect(m_altPopup, SIGNAL(sigInsertRichText(int,int,bool,bool)), this, SLOT(slotInsertRichText(int,int,bool,bool)));
46 m_quickWidget->setPalette(this->palette());
47}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
The GlyphPaletteAltPopup class.
void setModel(QAbstractItemModel *model)
setModel Set the glyph proxy model.
void slotInsertRichText(const int charRow, const int glyphRow=-1, const bool replace=false, const bool useCharMap=false)
KoFontGlyphModel * m_model
GlyphPaletteProxyModel * m_charMapModel
GlyphPaletteAltPopup * m_altPopup
KisQQuickWidget * m_quickWidget
The GlyphPaletteProxyModel class.
The KisQQuickWidget class.
void setMainWidget(QWidget *widget)
Definition KoDialog.cpp:354
KoDialog(QWidget *parent=0, Qt::WindowFlags f=Qt::WindowFlags())
Definition KoDialog.cpp:176
The KoFontGlyphModel class Creates a tree model of all the glyphs in a given face.
rgba palette[MAX_PALETTE]
Definition palette.c:35

References connect(), m_altPopup, m_charMapModel, m_model, m_quickWidget, palette, KoDialog::setMainWidget(), GlyphPaletteAltPopup::setModel(), and slotInsertRichText().

◆ ~GlyphPaletteDialog()

GlyphPaletteDialog::~GlyphPaletteDialog ( )

Definition at line 49 of file GlyphPaletteDialog.cpp.

50{
51 delete m_quickWidget;
52
53}

References m_quickWidget.

Member Function Documentation

◆ setGlyphModelFromProperties()

void GlyphPaletteDialog::setGlyphModelFromProperties ( const QPair< KoSvgTextProperties, KoSvgTextProperties > & properties,
const QString & text )

setGlyphModelFromProperties This updates the glyph model.

Parameters
properties– text properties, first is non-inherited, second is inherited.
text– the current text to display alternate glyphs for.

Definition at line 55 of file GlyphPaletteDialog.cpp.

56{
57 if (m_lastUsedProperties.second.cssFontInfo() == properties.second.cssFontInfo()) {
58 if (m_model && m_model->rowCount() > 0) {
59 if (text.isEmpty()) return;
60 QModelIndex idx = m_model->indexForString(text);
61 if (idx.isValid() && m_quickWidget->rootObject()) {
62 m_quickWidget->rootObject()->setProperty("currentIndex", QVariant::fromValue(idx.row()));
63 return;
64 }
65 }
66 }
67 const qreal res = 72.0;
68 QVector<int> lengths;
69 const KoCSSFontInfo info = properties.second.cssFontInfo();
70 const std::vector<FT_FaceSP> faces = KoFontRegistry::instance()->facesForCSSValues(
71 lengths,
72 info,
73 text,
74 static_cast<quint32>(res),
75 static_cast<quint32>(res));
76
77 QString language = properties.second.propertyOrDefault(KoSvgTextProperties::TextLanguage).toString();
78 if (faces.empty()) return;
79 m_model->setFace(faces.front(), QLatin1String(language.toLatin1()));
80
81 QVariantMap map = properties.second.propertyOrDefault(KoSvgTextProperties::FontVariationSettingsId).toMap();
82
83 QModelIndex idx = m_model->indexForString(text);
84 if (m_quickWidget->rootObject()) {
85 m_quickWidget->rootObject()->setProperty("fontFamilies", QVariant::fromValue(info.families));
86 m_quickWidget->rootObject()->setProperty("fontSize", QVariant::fromValue(info.size));
87 m_quickWidget->rootObject()->setProperty("fontWeight", QVariant::fromValue(info.weight));
88 m_quickWidget->rootObject()->setProperty("fontWidth", QVariant::fromValue(info.width));
89 m_quickWidget->rootObject()->setProperty("fontStyle", QVariant::fromValue(info.slantMode));
90 m_quickWidget->rootObject()->setProperty("fontAxesValues", QVariant::fromValue(map));
91 m_quickWidget->rootObject()->setProperty("language", QVariant::fromValue(language));
92 if (idx.isValid()) {
93 m_quickWidget->rootObject()->setProperty("currentIndex", QVariant::fromValue(idx.row()));
94 }
95 }
96 if (m_altPopup) {
97 m_altPopup->setMarkup(info.families, info.size, info.weight, info.width, info.slantMode, map, language);
98 }
99 m_lastUsedProperties = properties;
100}
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.
QPair< KoSvgTextProperties, KoSvgTextProperties > m_lastUsedProperties
void setFace(FT_FaceSP face, QLatin1String language=QLatin1String(), bool samplesOnly=false)
setFace set the face to retrieve glyph data for.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QModelIndex indexForString(QString grapheme)
std::vector< FT_FaceSP > facesForCSSValues(QVector< int > &lengths, KoCSSFontInfo info=KoCSSFontInfo(), const QString &text="", quint32 xRes=72, quint32 yRes=72, bool disableFontMatching=false, const QString &language=QString())
facesForCSSValues This selects a font with fontconfig using the given values. If "text" is not empty ...
static KoFontRegistry * instance()
@ FontVariationSettingsId
QStringList.
@ TextLanguage
a language string.
The KoCSSFontInfo class Convenience struct to make it easier to use KoFontRegistry....
QStringList families
QFont::Style slantMode

References KoFontRegistry::facesForCSSValues(), KoCSSFontInfo::families, KoSvgTextProperties::FontVariationSettingsId, KoFontGlyphModel::indexForString(), KoFontRegistry::instance(), m_altPopup, m_lastUsedProperties, m_model, m_quickWidget, KoFontGlyphModel::rowCount(), KoFontGlyphModel::setFace(), GlyphPaletteAltPopup::setMarkup(), KoCSSFontInfo::size, KoCSSFontInfo::slantMode, KoSvgTextProperties::TextLanguage, KoCSSFontInfo::weight, and KoCSSFontInfo::width.

◆ signalInsertRichText

void GlyphPaletteDialog::signalInsertRichText ( KoSvgTextShape * text,
bool replace )
signal

◆ slotHidePopupPalette

void GlyphPaletteDialog::slotHidePopupPalette ( )
slot

Definition at line 145 of file GlyphPaletteDialog.cpp.

146{
147 m_altPopup->hide();
148}

References m_altPopup.

◆ slotInsertRichText

void GlyphPaletteDialog::slotInsertRichText ( const int charRow,
const int glyphRow = -1,
const bool replace = false,
const bool useCharMap = false )
slot

Definition at line 102 of file GlyphPaletteDialog.cpp.

103{
104 if (m_quickWidget->rootObject()) {
105 QAbstractItemModel *model = useCharMap? qobject_cast<QAbstractItemModel*>(m_charMapModel): qobject_cast<QAbstractItemModel*>(m_model);
106 QModelIndex idx = model->index(charRow, 0);
107 QString text = idx.isValid()? model->data(idx, Qt::DisplayRole).toString(): QString();
109 QVariantMap otf;
110
111 if (glyphRow > -1) {
112 idx = model->index(glyphRow, 0, idx);
113 text = model->data(idx, Qt::DisplayRole).toString();
114 otf = model->data(idx, KoFontGlyphModel::OpenTypeFeatures).toMap();
115 }
116
117 if (!text.isEmpty()) {
118 KoSvgTextShape *richText = new KoSvgTextShape();
119
120 if (!otf.isEmpty()) {
121 props.setProperty(KoSvgTextProperties::FontFeatureSettingsId, QVariant::fromValue(otf));
122 }
123
124 richText->setPropertiesAtPos(-1, props);
125 richText->insertText(0, text);
126 emit signalInsertRichText(richText, replace);
127 }
128 if (m_altPopup->isVisible()) {
130 }
131 }
132
133}
void signalInsertRichText(KoSvgTextShape *text, bool replace)
@ FontFeatureSettingsId
QStringList.
void setProperty(PropertyId id, const QVariant &value)
void setPropertiesAtPos(int pos, KoSvgTextProperties properties)
setPropertiesAtPos will set the properties at pos.
bool insertText(int pos, QString text)
insertText Insert a text somewhere in the KoTextShape.

References KoSvgTextProperties::FontFeatureSettingsId, KoSvgTextShape::insertText(), m_altPopup, m_charMapModel, m_lastUsedProperties, m_model, m_quickWidget, KoFontGlyphModel::OpenTypeFeatures, KoSvgTextShape::setPropertiesAtPos(), KoSvgTextProperties::setProperty(), signalInsertRichText(), and slotHidePopupPalette().

◆ slotShowPopupPalette

void GlyphPaletteDialog::slotShowPopupPalette ( const int charRow,
const int x = 0,
const int y = 0,
const int cellWidth = 100,
const int cellHeight = 100 )
slot

Definition at line 135 of file GlyphPaletteDialog.cpp.

136{
137 m_altPopup->setRootIndex(charRow);
138 m_altPopup->setCellSize(cellWidth, cellHeight);
139 m_altPopup->raise();
140 m_altPopup->show();
141 m_altPopup->move(this->mapToGlobal(QPoint(x, y)+m_quickWidget->pos()));
142 m_altPopup->activateWindow();
143}
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 setRootIndex(const int index)
setRootIndex Set the charmap root index to show glyph alts for.

References m_altPopup, m_quickWidget, GlyphPaletteAltPopup::setCellSize(), and GlyphPaletteAltPopup::setRootIndex().

Member Data Documentation

◆ m_altPopup

GlyphPaletteAltPopup* GlyphPaletteDialog::m_altPopup {0}
private

Definition at line 53 of file GlyphPaletteDialog.h.

53{0};

◆ m_charMapModel

GlyphPaletteProxyModel* GlyphPaletteDialog::m_charMapModel
private

Definition at line 56 of file GlyphPaletteDialog.h.

◆ m_lastUsedProperties

QPair<KoSvgTextProperties, KoSvgTextProperties> GlyphPaletteDialog::m_lastUsedProperties
private

Definition at line 54 of file GlyphPaletteDialog.h.

◆ m_model

KoFontGlyphModel* GlyphPaletteDialog::m_model
private

Definition at line 55 of file GlyphPaletteDialog.h.

◆ m_quickWidget

KisQQuickWidget* GlyphPaletteDialog::m_quickWidget {0}
private

Definition at line 52 of file GlyphPaletteDialog.h.

52{0};

The documentation for this class was generated from the following files: