r22664 by jghali - #15415: Add tooltips for font names in font selectors

scribus-commit scribus-commit at lists.scribus.net
Sat Sep 1 21:31:40 UTC 2018


Author: jghali
Date: Sat Sep  1 21:31:40 2018
New Revision: 22664

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22664
Log:
#15415: Add tooltips for font names in font selectors

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=22664&path=/trunk/Scribus/scribus/ui/fontcombo.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/fontcombo.cpp	(original)
+++ trunk/Scribus/scribus/ui/fontcombo.cpp	Sat Sep  1 21:31:40 2018
@@ -29,6 +29,7 @@
 #include <QLabel>
 #include <QPixmap>
 #include <QStringList>
+#include <QTooltip>
 
 #include "fontcombo.h"
 #include "iconmanager.h"
@@ -457,14 +458,14 @@
 	return QFontDatabase::Any;
 }
 
-const ScFace& getScFace(const QString& classname, const QString& text)
+const ScFace& getScFace(const QString& className, const QString& text)
 {
 	QFontDatabase& fontDb = ScQApp->qtFontDatabase();
 	PrefsManager* prefsManager = PrefsManager::instance();
 	SCFonts& availableFonts = prefsManager->appPrefs.fontPrefs.AvailFonts;
 
 	// Handle FontComboH class witch has only Family names in the combo class.
-	if (classname == "FontComboH" || classname == "SMFontComboH")
+	if (className == "FontComboH" || className == "SMFontComboH")
 	{
 		// SMFontComboH's "Use Parent Font" case
 		if (!availableFonts.fontMap.contains(text))
@@ -619,6 +620,34 @@
 	pixmapCache.insert(cacheKey+"-selected", invPixmap);
 }
 
+bool FontFamilyDelegate::helpEvent(QHelpEvent * event, QAbstractItemView * view,
+	const QStyleOptionViewItem & option, const QModelIndex & index)
+{
+	if (!event || !view)
+		return false;
+
+	if (event->type() == QEvent::ToolTip)
+	{
+		QString text(index.data(Qt::DisplayRole).toString());
+		QString className = this->parent()->metaObject()->className();
+		const ScFace& scFace = getScFace(className, text);
+		if (!scFace.isNone())
+		{
+			QString tooltip = scFace.family();
+			if (className == QLatin1String("FontCombo"))
+			{
+				tooltip += QLatin1String(" ");
+				tooltip += scFace.style();
+			}
+			QHelpEvent *helpEvent = static_cast<QHelpEvent*>(event);
+			QToolTip::showText(helpEvent->globalPos(), tooltip, view);
+			return true;
+		}
+	}
+	
+	return QAbstractItemDelegate::helpEvent(event, view, option, index);
+}
+
 QSize FontFamilyDelegate::sizeHint(const QStyleOptionViewItem &option,
 								   const QModelIndex &index) const
 {

Modified: trunk/Scribus/scribus/ui/fontcombo.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22664&path=/trunk/Scribus/scribus/ui/fontcombo.h
==============================================================================
--- trunk/Scribus/scribus/ui/fontcombo.h	(original)
+++ trunk/Scribus/scribus/ui/fontcombo.h	Sat Sep  1 21:31:40 2018
@@ -115,6 +115,9 @@
 			   const QStyleOptionViewItem &option,
 			   const QModelIndex &index) const Q_DECL_OVERRIDE;
 
+	bool helpEvent(QHelpEvent * event, QAbstractItemView * view, 
+	               const QStyleOptionViewItem & option, const QModelIndex & index) Q_DECL_OVERRIDE;
+
 	QSize sizeHint(const QStyleOptionViewItem &option,
 				   const QModelIndex &index) const Q_DECL_OVERRIDE;
 




More information about the scribus-commit mailing list