r22424 by jghali -
scribus-commit
scribus-commit at lists.scribus.net
Thu Mar 8 15:21:04 UTC 2018
Author: jghali
Date: Thu Mar 8 15:21:04 2018
New Revision: 22424
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22424
Log:
#15184: Writing in unavailable Font Family then trying to change it silently crashes application
Modified:
trunk/Scribus/scribus/ui/fontcombo.cpp
trunk/Scribus/scribus/ui/fontcombo.h
Modified: trunk/Scribus/scribus/ui/fontcombo.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22424&path=/trunk/Scribus/scribus/ui/fontcombo.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/fontcombo.cpp (original)
+++ trunk/Scribus/scribus/ui/fontcombo.cpp Thu Mar 8 15:21:04 2018
@@ -51,6 +51,8 @@
psFont = IconManager::instance()->loadPixmap("font_type1_16.png");
substFont = IconManager::instance()->loadPixmap("font_subst16.png");
setEditable(true);
+ setValidator(new FontComboValidator(this));
+ setInsertPolicy(QComboBox::NoInsert);
setItemDelegate(new FontFamilyDelegate(this));
RebuildList(0);
}
@@ -126,6 +128,8 @@
}
fontFamily = new ScComboBox(this);
fontFamily->setEditable(true);
+ fontFamily->setValidator(new FontComboValidator(fontFamily));
+ fontFamily->setInsertPolicy(QComboBox::NoInsert);
fontFamily->setItemDelegate(new FontFamilyDelegate(this));
fontComboLayout->addWidget(fontFamily,0,col);
fontStyle = new ScComboBox(this);
@@ -619,3 +623,31 @@
}
+FontComboValidator::FontComboValidator(QObject* parent)
+ : QValidator(parent)
+{
+ prefsManager = PrefsManager::instance();
+}
+
+QValidator::State FontComboValidator::validate(QString & input, int & pos) const
+{
+ QComboBox* comboBox = dynamic_cast<QComboBox*>(this->parent());
+ if (!comboBox)
+ return QValidator::Invalid;
+
+ int index = comboBox->findText(input, Qt::MatchFixedString);
+ if (index >= 0)
+ {
+ input = comboBox->itemText(index); // Matching is performed case insensitively
+ return QValidator::Acceptable;
+ }
+
+ for (int i = 0; i < comboBox->count(); ++i)
+ {
+ QString itemText = comboBox->itemText(i);
+ if (itemText.startsWith(input, Qt::CaseInsensitive))
+ return QValidator::Intermediate;
+ }
+
+ return QValidator::Invalid;
+}
Modified: trunk/Scribus/scribus/ui/fontcombo.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22424&path=/trunk/Scribus/scribus/ui/fontcombo.h
==============================================================================
--- trunk/Scribus/scribus/ui/fontcombo.h (original)
+++ trunk/Scribus/scribus/ui/fontcombo.h Thu Mar 8 15:21:04 2018
@@ -28,6 +28,7 @@
#include <QComboBox>
#include <QFontDatabase>
#include <QPixmapCache>
+#include <QValidator>
#include "scribusapi.h"
@@ -51,10 +52,9 @@
public:
FontCombo(QWidget* pa);
~FontCombo() {}
-
-
void RebuildList(ScribusDoc *currentDoc, bool forAnnotation = false, bool forSubstitute = false);
+
private:
PrefsManager* prefsManager;
QPixmap ttfFont;
@@ -65,7 +65,6 @@
class SCRIBUS_API FontComboH : public QWidget
{
-
Q_OBJECT
public:
@@ -125,4 +124,16 @@
QFont m_font;
static QPixmapCache pixmapCache;
};
+
+class FontComboValidator : public QValidator
+{
+ Q_OBJECT
+
+public:
+ FontComboValidator(QObject* parent = 0);
+ virtual State validate(QString & input, int & pos) const;
+
+protected:
+ PrefsManager* prefsManager;
+};
#endif
More information about the scribus-commit
mailing list