r23423 by jghali - cleanups for ScListBoxPixmap and ColorListBox

scribus-commit scribus-commit at lists.scribus.net
Thu Dec 12 22:19:29 UTC 2019


Author: jghali
Date: Thu Dec 12 22:19:29 2019
New Revision: 23423

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23423
Log:
cleanups for ScListBoxPixmap and ColorListBox

Modified:
    trunk/Scribus/scribus/sclistboxpixmap.h
    trunk/Scribus/scribus/ui/colorlistbox.cpp

Modified: trunk/Scribus/scribus/sclistboxpixmap.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23423&path=/trunk/Scribus/scribus/sclistboxpixmap.h
==============================================================================
--- trunk/Scribus/scribus/sclistboxpixmap.h	(original)
+++ trunk/Scribus/scribus/sclistboxpixmap.h	Thu Dec 12 22:19:29 2019
@@ -30,8 +30,11 @@
 	ScListBoxPixmap(void);
 
 	virtual QString text(const QVariant&) const = 0;
-	virtual QSize sizeHint (const QStyleOptionViewItem & option, const QModelIndex & index ) const;
-	virtual void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
+
+	// Functions reimplemented from QAbstractItemDelegate
+	QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const override;
+	void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const override;
+
 protected:
 	static QScopedPointer<QPixmap> pmap;
 	// The drawPixmap function must not modify pixmap size
@@ -48,14 +51,15 @@
 		pmap.reset(new QPixmap(pixWidth, pixHeight));
 }
 
-
 template<unsigned int pixWidth, unsigned int pixHeight>
 QSize ScListBoxPixmap<pixWidth, pixHeight>::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const
 {
 	int h,w;
 	QFontMetrics metrics(option.font);
 	const QVariant data(index.data(Qt::DisplayRole));
-	if (text(data).isEmpty())
+	
+	QString textData = text(data);
+	if (textData.isEmpty())
 	{
 		h = pmap->height();
 		w = pmap->width() + 6;
@@ -64,11 +68,12 @@
 	{
 		h = qMax(pmap->height(), metrics.lineSpacing() + 2);
 		//FIXME: metrics.width replacement by horizontalAdvance requires Qt 5.11+
-		w = pmap->width() + metrics.width(text(data)) + 6;
+		w = pmap->width() + metrics.width(textData) + 6;
 	}
-	return QSize(qMax(w, QApplication::globalStrut().width()), qMax( h, QApplication::globalStrut().height()));
+
+	QSize globalStrut = QApplication::globalStrut();
+	return QSize(qMax(w, globalStrut.width()), qMax(h, globalStrut.height()));
 }
-
 
 template<unsigned int pixWidth, unsigned int pixHeight>
 void ScListBoxPixmap<pixWidth, pixHeight>::paint(QPainter * qpainter, const QStyleOptionViewItem & option, const QModelIndex & index) const

Modified: trunk/Scribus/scribus/ui/colorlistbox.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23423&path=/trunk/Scribus/scribus/ui/colorlistbox.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/colorlistbox.cpp	(original)
+++ trunk/Scribus/scribus/ui/colorlistbox.cpp	Thu Dec 12 22:19:29 2019
@@ -26,43 +26,40 @@
 #include "scribusdoc.h"
 #include "util_color.h"
 
-class SCRIBUS_API ColorSmallItemDelegate : public ScListBoxPixmap<15,15>
+class SCRIBUS_API ColorSmallItemDelegate : public ScListBoxPixmap<15, 15>
 {
 public:
-	ColorSmallItemDelegate(): ScListBoxPixmap<15,15>() {};
+	ColorSmallItemDelegate(): ScListBoxPixmap<15, 15>() {};
 	~ColorSmallItemDelegate() {};
 	
-	virtual void redraw(const QVariant&) const;
-	virtual QString text(const QVariant&) const;
-	virtual int rtti() const { return 654873547; };
+	void redraw(const QVariant&) const override;
+	QString text(const QVariant&) const override;
 };
 
-class SCRIBUS_API ColorWideItemDelegate : public ScListBoxPixmap<30,15>
+class SCRIBUS_API ColorWideItemDelegate : public ScListBoxPixmap<30, 15>
 {
 public:
-	ColorWideItemDelegate(): ScListBoxPixmap<30,15>() {};
+	ColorWideItemDelegate(): ScListBoxPixmap<30, 15>() {};
 	~ColorWideItemDelegate() {};
 	
-	virtual void redraw(const QVariant&) const;
-	virtual QString text(const QVariant&) const;
-	virtual int rtti() const { return 654873548; };
+	void redraw(const QVariant&) const override;
+	QString text(const QVariant&) const override;
 };
 
-class SCRIBUS_API ColorFancyItemDelegate : public ScListBoxPixmap<60,15>
+class SCRIBUS_API ColorFancyItemDelegate : public ScListBoxPixmap<60, 15>
 {
 public:
-	ColorFancyItemDelegate(): ScListBoxPixmap<60,15>() {};
+	ColorFancyItemDelegate(): ScListBoxPixmap<60, 15>() {};
 	~ColorFancyItemDelegate() {};
 	
-	virtual void redraw(const QVariant&) const;
-	virtual QString text(const QVariant&) const;
-	virtual int rtti() const { return 654873549; };
+	void redraw(const QVariant&) const override;
+	QString text(const QVariant&) const override;
 };
 
 
 void ColorSmallItemDelegate::redraw(const QVariant& data) const
 {
-	QPixmap* pPixmap = ScListBoxPixmap<15,15>::pmap.data();
+	QPixmap* pPixmap = ScListBoxPixmap<15, 15>::pmap.data();
 	pPixmap->fill(Qt::transparent);
 	if (data.canConvert<ColorPixmapValue>())
 	{
@@ -80,7 +77,7 @@
 
 void ColorWideItemDelegate::redraw(const QVariant& data) const
 {
-	QPixmap* pPixmap = ScListBoxPixmap<30,15>::pmap.data();
+	QPixmap* pPixmap = ScListBoxPixmap<30, 15>::pmap.data();
 	pPixmap->fill(Qt::transparent);
 	if (data.canConvert<ColorPixmapValue>())
 	{
@@ -113,7 +110,7 @@
 		iconsInitialized = true;
 	}
 
-	QPixmap* pPixmap = ScListBoxPixmap<60,15>::pmap.data();
+	QPixmap* pPixmap = ScListBoxPixmap<60, 15>::pmap.data();
 	pPixmap->fill(Qt::transparent);
 
 	if (data.canConvert<ColorPixmapValue>())




More information about the scribus-commit mailing list