7#include <QtQuickTemplates2/private/qquickdialogbuttonbox_p_p.h>
8#include <private/qfontdatabase_p.h>
10#include <QRegularExpression>
14Q_LOGGING_CATEGORY(lcAttachedProperty,
"qt.quick.dialogs.quickfontdialogimpl.attachedOrWarn")
24 qmlAttachedPropertiesObject<QQuickFontDialogImpl>(
q));
27 <<
"Expected FontDialogImpl attached object to be present on" <<
this;
75 return d->currentFont;
82 if (
font ==
d->currentFont)
85 d->currentFont =
font;
89 if (!selectInListViews)
130 if (window()->activeFocusItem() == attached->
familyEdit())
132 else if (window()->activeFocusItem() == attached->
styleEdit())
153 m_smoothlyScalable(
false),
154 m_ignoreFamilyUpdate(
false),
155 m_ignoreStyleUpdate(
false)
157 if (!qobject_cast<QQuickFontDialogImpl *>(
parent)) {
158 qmlWarning(
this) <<
"FontDialogImpl attached properties should only be "
159 <<
"accessed through the root FileDialogImpl instance";
166 return d->familyListView;
175 if (
d->familyListView) {
177 this, &QQuickFontDialogImplAttached::_q_familyChanged);
184 this, &QQuickFontDialogImplAttached::_q_familyChanged);
193 return d->styleListView;
202 if (
d->styleListView) {
204 this, &QQuickFontDialogImplAttached::_q_styleChanged);
211 this, &QQuickFontDialogImplAttached::_q_styleChanged);
220 return d->sizeListView;
229 if (
d->sizeListView) {
231 this, &QQuickFontDialogImplAttached::_q_sizeChanged);
236 if (
d->sizeListView) {
238 this, &QQuickFontDialogImplAttached::_q_sizeChanged);
247 return d->sampleEdit;
259 d, &QQuickFontDialogImplAttachedPrivate::currentFontChanged);
266 d, &QQuickFontDialogImplAttachedPrivate::currentFontChanged);
288 if (fontDialogImpl) {
303 if (fontDialogImpl) {
320 return d->writingSystemComboBox;
330 if (
d->writingSystemComboBox) {
332 this, &QQuickFontDialogImplAttached::_q_writingSystemChanged);
337 if (
d->writingSystemComboBox) {
344 writingSystemModel.append(wsName);
347 d->writingSystemComboBox->setModel(writingSystemModel);
350 this, &QQuickFontDialogImplAttached::_q_writingSystemChanged);
359 return d->underlineCheckBox;
369 if (
d->underlineCheckBox) {
371 this, &QQuickFontDialogImplAttached::_q_updateSample);
376 if (
d->underlineCheckBox) {
378 this, &QQuickFontDialogImplAttached::_q_updateSample);
387 return d->strikeoutCheckBox;
397 if (
d->strikeoutCheckBox) {
399 this, &QQuickFontDialogImplAttached::_q_updateSample);
404 if (
d->strikeoutCheckBox) {
406 this, &QQuickFontDialogImplAttached::_q_updateSample);
415 return d->familyEdit;
463 this, &QQuickFontDialogImplAttached::_q_sizeEdited);
470 this, &QQuickFontDialogImplAttached::_q_sizeEdited);
478 enum match_t { MATCH_NONE = 0, MATCH_LAST_RESORT = 1, MATCH_APP = 2, MATCH_FAMILY = 3 };
479 QString foundryName1, familyName1, foundryName2, familyName2;
480 int bestFamilyMatch = -1;
481 match_t bestFamilyType = MATCH_NONE;
490 if (familyName1 == familyName2) {
491 bestFamilyType = MATCH_FAMILY;
492 if (foundryName1 == foundryName2)
499 match_t
type = MATCH_NONE;
500 if (bestFamilyType <= MATCH_NONE && familyName2 ==
QStringLiteral(
"helvetica"))
501 type = MATCH_LAST_RESORT;
502 if (bestFamilyType <= MATCH_LAST_RESORT && familyName2 ==
f.families().constFirst())
504 if (
type != MATCH_NONE) {
505 bestFamilyType =
type;
510 return bestFamilyMatch;
518 if (!selectedStyle.
isEmpty()) {
524 auto classifyStyleFallback = [](
const QString & style) {
526 return StyleClass::Italic;
528 return StyleClass::Normal;
529 return StyleClass::Unknown;
532 auto styleClass = classifyStyleFallback(selectedStyle);
534 if (styleClass != StyleClass::Unknown)
535 for (
int i = 0;
i <
model.size(); ++
i)
536 if (classifyStyleFallback(
model.at(
i)) == styleClass)
550 const QFontDialogOptions::FontDialogOptions scalableMask(
556 const auto p = qobject_cast<QQuickFontDialogImpl *>(
parent());
558 const auto options =
p->options()->options();
562 for (
const auto &family : families) {
566 if ((options & scalableMask) && (options & scalableMask) != scalableMask) {
572 if ((options & spacingMask) && (options & scalableMask) != spacingMask) {
578 familyNames << family;
584 m_ignoreFamilyUpdate = !m_selectedFamily.
isEmpty();
586 m_ignoreFamilyUpdate =
false;
591 if (familyNames.isEmpty())
603void QQuickFontDialogImplAttached::updateStyles()
610 m_ignoreStyleUpdate = !m_selectedStyle.
isEmpty();
613 if (styles.isEmpty()) {
615 m_smoothlyScalable =
false;
621 m_selectedStyle = styles.at(newIndex);
627 m_ignoreStyleUpdate =
false;
638void QQuickFontDialogImplAttached::updateSizes()
640 if (!m_selectedFamily.
isEmpty()) {
645 str_sizes.reserve(
sizes.size());
647 int idx = 0, current = -1;
650 if (current == -1 && m_selectedSize == *
it) {
668 qCWarning(lcAttachedProperty) <<
"Warning! selectedFamily is empty";
675void QQuickFontDialogImplAttached::_q_updateSample()
677 if (m_selectedFamily.
isEmpty())
690void QQuickFontDialogImplAttached::_q_writingSystemChanged(
int index)
710 for (
int i = 0;
i <
model.size(); ++
i) {
728void QQuickFontDialogImplAttached::_q_familyChanged()
730 if (m_ignoreFamilyUpdate)
745void QQuickFontDialogImplAttached::_q_styleChanged()
747 if (m_ignoreStyleUpdate)
753 qCWarning(lcAttachedProperty) <<
"currentIndex changed to -1";
764void QQuickFontDialogImplAttached::_q_sizeEdited()
768 if (
size == m_selectedSize)
771 m_selectedSize =
size;
777 for (
i = 0;
i <
model.size() - 1; ++
i) {
792void QQuickFontDialogImplAttached::_q_sizeChanged()
797 qCWarning(lcAttachedProperty) <<
"currentIndex changed to -1";
802 m_selectedSize =
s.toInt();
809void QQuickFontDialogImplAttachedPrivate::currentFontChanged(
const QFont &
font)
811 auto fontDialogImpl = qobject_cast<QQuickFontDialogImpl *>(
parent);
813 if (!fontDialogImpl) {
817 fontDialogImpl->setCurrentFont(
font);
837#include "moc_qquickfontdialogimpl_p.cpp"
QAbstractItemModel * model() const
Returns the model that this view is presenting.
void setCurrentIndex(const QModelIndex &index)
Sets the current item to be the item at index.
QModelIndex currentIndex() const
Returns the model index of the current item.
virtual void setModel(QAbstractItemModel *model)
Sets the model for the view to present.
The QFocusEvent class contains event parameters for widget focus events.
static void parseFontName(const QString &name, QString &foundry, QString &family)
\threadsafe \inmodule QtGui
static QString writingSystemName(WritingSystem writingSystem)
Returns the names the writingSystem (e.g.
WritingSystem
\value Any \value Latin \value Greek \value Cyrillic \value Armenian \value Hebrew \value Arabic \val...
static bool isSmoothlyScalable(const QString &family, const QString &style=QString())
Returns true if the font that has family family and style style is smoothly scalable; otherwise retur...
static bool isPrivateFamily(const QString &family)
static QString styleString(const QFont &font)
Returns a string that describes the style of the font.
static QFont font(const QString &family, const QString &style, int pointSize)
Returns a QFont object that has family family, style style and point size pointSize.
static QString writingSystemSample(WritingSystem writingSystem)
Returns a string with sample characters from writingSystem.
static QStringList families(WritingSystem writingSystem=Any)
Returns a sorted list of the available font families which support the writingSystem.
static QList< int > pointSizes(const QString &family, const QString &style=QString())
Returns a list of the point sizes available for the font that has family family and style styleName.
static QStringList styles(const QString &family)
Returns a list of the styles available for the font family family.
static bool isFixedPitch(const QString &family, const QString &style=QString())
Returns true if the font that has family family and style style is fixed pitch; otherwise returns fal...
void setStrikeOut(bool)
If enable is true, sets strikeout on; otherwise sets strikeout off.
bool strikeOut() const
Returns true if strikeout has been set; otherwise returns false.
bool underline() const
Returns true if underline has been set; otherwise returns false.
QStringList families() const
int pointSize() const
Returns the point size of the font.
void setUnderline(bool)
If enable is true, sets underline on; otherwise sets underline off.
The QKeyEvent class describes a key event.
static QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiverPrivate, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
static bool disconnect(const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiverPrivate, Func2 slot)
QObject * parent() const
Returns a pointer to the parent object.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
void activated(int index)
virtual void handleClick(QQuickAbstractButton *button)
static QQuickDialogPrivate * get(QQuickDialog *dialog)
virtual void handleAccept()
static QPlatformDialogHelper::ButtonRole buttonRole(QQuickAbstractButton *button)
Popup dialog with standard buttons and a title, used for short-term interaction with the user.
virtual void handleReject()
QQuickTextField * styleEdit
void writingSystemComboBoxChanged()
QQuickTextField * familyEdit
void selectFontInListViews(const QFont &font)
void setButtonBox(QQuickDialogButtonBox *buttonBox)
void styleListViewChanged()
void setSizeEdit(QQuickTextField *sizeEdit)
QQuickListView * familyListView
QQuickComboBox * writingSystemComboBox
QQuickCheckBox * strikeoutCheckBox
void familyListViewChanged()
void searchStyle(const QString &s)
void searchFamily(const QString &s)
QQuickCheckBox * underlineCheckBox
void setFamilyEdit(QQuickTextField *familyEdit)
void setSampleEdit(QQuickTextEdit *sampleEdit)
void setStyleEdit(QQuickTextField *styleEdit)
void setSizeListView(QQuickListView *sizeListView)
void setUnderlineCheckBox(QQuickCheckBox *underlineCheckBox)
QQuickTextEdit * sampleEdit
void setFamilyListView(QQuickListView *familyListView)
QQuickFontDialogImplAttached(QObject *parent=nullptr)
QQuickTextField * sizeEdit
void setWritingSystemComboBox(QQuickComboBox *writingSystemComboBox)
void sizeListViewChanged()
QQuickListView * sizeListView
void setStrikeoutCheckBox(QQuickCheckBox *strikethroughCheckBox)
void strikeoutCheckBoxChanged()
void underlineCheckBoxChanged()
void setStyleListView(QQuickListView *styleListView)
QQuickListView * styleListView
QQuickDialogButtonBox * buttonBox
void handleClick(QQuickAbstractButton *button) override
void handleAccept() override
QQuickFontDialogImplAttached * attachedOrWarn()
static QQuickFontDialogImplAttached * qmlAttachedProperties(QObject *object)
QSharedPointer< QFontDialogOptions > options() const
void currentFontChanged(const QFont &font)
void setCurrentFont(const QFont &font, bool selectInListViews=false)
QQuickFontDialogImpl(QObject *parent=nullptr)
void setOptions(const QSharedPointer< QFontDialogOptions > &options)
void keyReleaseEvent(QKeyEvent *event) override
void focusOutEvent(QFocusEvent *event) override
void currentIndexChanged()
void setCurrentIndex(int idx)
void setFont(const QFont &font)
void fontChanged(const QFont &font)
void setText(const QString &)
\qmlproperty string QtQuick::TextEdit::font.family
void setText(const QString &)
\inmodule QtCore \reentrant
static QString escape(const QString &str)
This is an overloaded member function, provided for convenience. It differs from the above function o...
const_iterator constBegin() const noexcept
const_iterator constEnd() const noexcept
Exception-safe wrapper around QObject::blockSignals().
\macro QT_RESTRICTED_CAST_FROM_ASCII
int toInt(bool *ok=nullptr, int base=10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 ...
void clear()
Clears the contents of the string and makes it null.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QString & append(QChar c)
bool isValid() const
Returns true if the storage type of this variant is not QMetaType::UnknownType; otherwise returns fal...
QStringList toStringList() const
Returns the variant as a QStringList if the variant has userType() \l QMetaType::QStringList,...
QSet< QString >::iterator it
Combined button and popup list for selecting options.
#define Q_LOGGING_CATEGORY(name,...)
#define qCWarning(category,...)
constexpr T qAbs(const T &t)
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLenum GLsizei count
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
GLdouble GLdouble GLdouble GLdouble q
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
static int findFamilyInModel(const QString &selectedFamily, const QStringList &model)
static int findStyleInModel(const QString &selectedStyle, const QStringList &model)
QLatin1StringView QLatin1String
#define QStringLiteral(str)
static QStringList toStringList(const QJsonArray &jsonArray)
static int toInt(const QChar &qc, int R)
QSqlQueryModel * model
[16]
myObject disconnect()
[26]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent