r20195 by craig - Allow IconManager::loadCursor to deal with cursor hotspots and reduce code elsewhere

scribus-commit scribus-commit at lists.scribus.net
Tue Jun 23 08:07:07 UTC 2015


Author: craig
Date: Tue Jun 23 08:07:06 2015
New Revision: 20195

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=20195
Log:
Allow IconManager::loadCursor to deal with cursor hotspots and reduce code elsewhere

Modified:
    trunk/Scribus/scribus/canvasmode.cpp
    trunk/Scribus/scribus/canvasmode_nodeedit.cpp
    trunk/Scribus/scribus/iconmanager.cpp
    trunk/Scribus/scribus/iconmanager.h
    trunk/Scribus/scribus/scribusview.cpp
    trunk/Scribus/scribus/ui/dasheditor.cpp
    trunk/Scribus/scribus/ui/gradientpreview.cpp
    trunk/Scribus/scribus/ui/hruler.cpp
    trunk/Scribus/scribus/ui/tabruler.cpp

Modified: trunk/Scribus/scribus/canvasmode.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20195&path=/trunk/Scribus/scribus/canvasmode.cpp
==============================================================================
--- trunk/Scribus/scribus/canvasmode.cpp (original)
+++ trunk/Scribus/scribus/canvasmode.cpp Tue Jun 23 08:07:06 2015
@@ -776,10 +776,10 @@
 			cursor = QCursor(Qt::CrossCursor);
 			break;
 		case modeDrawFreehandLine:
-			cursor = QCursor(im->loadPixmap("DrawFreeLine.png"), 0, 31);
+			cursor = im->loadCursor("DrawFreeLine.png", 0, 31);
 			break;
 		case modeDrawCalligraphicLine:
-			cursor = QCursor(im->loadPixmap("DrawCalligraphy.xpm"), 4, 4);
+			cursor = im->loadCursor("DrawCalligraphy.xpm", 4, 4);
 			break;
 		case modeImportObject:
 			cursor = im->loadCursor("DragPix.xpm");
@@ -794,10 +794,10 @@
 			cursor = im->loadCursor("HandC.xpm");
 			break;
 		case modeEyeDropper:
-			cursor = QCursor(im->loadPixmap("colorpickercursor.png"), 0, 31);
+			cursor = im->loadCursor("colorpickercursor.png", 0, 31);
 			break;
 		case modeLinkFrames:
-			cursor = QCursor(im->loadPixmap("LinkTextFrame.png"), 0, 31);
+			cursor = im->loadCursor("LinkTextFrame.png", 0, 31);
 			break;
 		case modeMeasurementTool:
 		case modeEditGradientVectors:
@@ -856,10 +856,10 @@
 			m_view->setCursor(QCursor(Qt::CrossCursor));
 			break;
 		case modeDrawFreehandLine:
-			m_view->setCursor(QCursor(im->loadPixmap("DrawFreeLine.png"), 0, 31));
+			m_view->setCursor(im->loadCursor("DrawFreeLine.png", 0, 31));
 			break;
 		case modeDrawCalligraphicLine:
-			m_view->setCursor(QCursor(im->loadPixmap("DrawCalligraphy.xpm"), 4, 4));
+			m_view->setCursor(im->loadCursor("DrawCalligraphy.xpm", 4, 4));
 			break;
 		case modeImportObject:
 			m_view->setCursor(im->loadCursor("DragPix.xpm"));
@@ -874,10 +874,10 @@
 			m_view->setCursor(im->loadCursor("HandC.xpm"));
 			break;
 		case modeEyeDropper:
-			m_view->setCursor(QCursor(im->loadPixmap("colorpickercursor.png"), 0, 31));
+			m_view->setCursor(im->loadCursor("colorpickercursor.png", 0, 31));
 			break;
 		case modeLinkFrames:
-			m_view->setCursor(QCursor(im->loadPixmap("LinkTextFrame.png"), 0, 31));
+			m_view->setCursor(im->loadCursor("LinkTextFrame.png", 0, 31));
 			break;
 		case modeMeasurementTool:
 		case modeEditGradientVectors:

Modified: trunk/Scribus/scribus/canvasmode_nodeedit.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20195&path=/trunk/Scribus/scribus/canvasmode_nodeedit.cpp
==============================================================================
--- trunk/Scribus/scribus/canvasmode_nodeedit.cpp (original)
+++ trunk/Scribus/scribus/canvasmode_nodeedit.cpp Tue Jun 23 08:07:06 2015
@@ -1017,9 +1017,9 @@
 				if (m_doc->nodeEdit.submode() == NodeEditContext::MOVE_POINT)
 					m_view->setCursor(QCursor(Qt::SizeAllCursor));
 				if (m_doc->nodeEdit.submode() == NodeEditContext::DEL_POINT)
-					m_view->setCursor(QCursor(IconManager::instance()->loadPixmap("DelPoint.png"), 1, 1));
+					m_view->setCursor(IconManager::instance()->loadCursor("DelPoint.png", 1, 1));
 				if (m_doc->nodeEdit.submode() == NodeEditContext::SPLIT_PATH)
-					m_view->setCursor(QCursor(IconManager::instance()->loadPixmap("Split.png"), 1, 1));
+					m_view->setCursor(IconManager::instance()->loadCursor("Split.png", 1, 1));
 				return true;
 			}
 		}
@@ -1050,9 +1050,9 @@
 						if (m_doc->nodeEdit.submode() == NodeEditContext::MOVE_POINT)
 							m_view->setCursor(IconManager::instance()->loadCursor("HandC.xpm"));
 						else if (m_doc->nodeEdit.submode() == NodeEditContext::ADD_POINT)
-							m_view->setCursor(QCursor(IconManager::instance()->loadPixmap("AddPoint.png"), 1, 1));
+							m_view->setCursor(IconManager::instance()->loadCursor("AddPoint.png", 1, 1));
 						else if (m_doc->nodeEdit.submode() == NodeEditContext::SPLIT_PATH)
-							m_view->setCursor(QCursor(IconManager::instance()->loadPixmap("Split.png"), 1, 1));
+							m_view->setCursor(IconManager::instance()->loadCursor("Split.png", 1, 1));
 						else
 							m_view->setCursor(QCursor(Qt::ArrowCursor));
 						m_doc->nodeEdit.setClre2(poi);

Modified: trunk/Scribus/scribus/iconmanager.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20195&path=/trunk/Scribus/scribus/iconmanager.cpp
==============================================================================
--- trunk/Scribus/scribus/iconmanager.cpp (original)
+++ trunk/Scribus/scribus/iconmanager.cpp Tue Jun 23 08:07:06 2015
@@ -189,9 +189,9 @@
 	}
 }
 
-QCursor IconManager::loadCursor(const QString nam, bool forceUseColor)
-{
-	return QCursor(loadPixmap(nam, forceUseColor));
+QCursor IconManager::loadCursor(const QString nam, int hotX, int hotY, bool forceUseColor)
+{
+	return QCursor(loadPixmap(nam, forceUseColor), hotX, hotY);
 }
 
 QIcon IconManager::loadIcon(const QString nam, bool forceUseColor)

Modified: trunk/Scribus/scribus/iconmanager.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20195&path=/trunk/Scribus/scribus/iconmanager.h
==============================================================================
--- trunk/Scribus/scribus/iconmanager.h (original)
+++ trunk/Scribus/scribus/iconmanager.h Tue Jun 23 08:07:06 2015
@@ -33,57 +33,59 @@
   */
 class SCRIBUS_API IconManager : public QObject
 {
-Q_OBJECT
-public:
-	IconManager(QObject *parent = 0);
-	~IconManager();
 
-	/**
-	* @brief Returns a pointer to the IconManager instance
-	* @return A pointer to the IconManager instance
-	*/
-	static IconManager* instance();
-	/**
-	* @brief Deletes the IconManager Instance
-	* Must be called when IconManager is no longer needed.
-	*/
-	static void deleteInstance();
-	bool setup();
-	QCursor loadCursor(const QString nam, bool forceUseColor=false);
-	QIcon loadIcon(const QString nam, bool forceUseColor=false);
-	QPixmap loadPixmap(const QString nam, bool forceUseColor=false);
-	QString pathForIcon(const QString nam);
-	QStringList pathList();
-	QStringList nameList(QString language);
-	void iconToGrayscale(QPixmap *pm);
-	bool setActiveFromPrefs(QString prefsSet);
-	QString activeSetBasename() { return m_activeSetBasename; }
-	QString baseNameForTranslation(QString transName);
+	Q_OBJECT
 
-public slots:
-	void languageChange();
+	public:
+		IconManager(QObject *parent = 0);
+		~IconManager();
 
-private:
-	/**
-	* @brief The only instance of IconManager available.
-	*
-	* IconManager is singleton and the instance can be queried with the method
-	* instance().
-	*/
-	static IconManager* _instance;
-	QMap<QString, ScIconSetData> m_iconSets;
-	ScPixmapCache<QString> m_pxCache;
-	QString m_activeSetBasename;
-	QString m_activeSetVersion;
-	QString m_backupSetBasename;
-	QString m_backupSetVersion;
+		/**
+		* @brief Returns a pointer to the IconManager instance
+		* @return A pointer to the IconManager instance
+		*/
+		static IconManager* instance();
+		/**
+		* @brief Deletes the IconManager Instance
+		* Must be called when IconManager is no longer needed.
+		*/
+		static void deleteInstance();
+		bool setup();
+		QCursor loadCursor(const QString nam, int hotX = -1, int hotY = -1, bool forceUseColor=false);
+		QIcon loadIcon(const QString nam, bool forceUseColor=false);
+		QPixmap loadPixmap(const QString nam, bool forceUseColor=false);
+		QString pathForIcon(const QString nam);
+		QStringList pathList();
+		QStringList nameList(QString language);
+		void iconToGrayscale(QPixmap *pm);
+		bool setActiveFromPrefs(QString prefsSet);
+		QString activeSetBasename() { return m_activeSetBasename; }
+		QString baseNameForTranslation(QString transName);
 
-	bool initIcons();
-	void readIconConfigFiles();
+	public slots:
+		void languageChange();
+
+	private:
+		/**
+		* @brief The only instance of IconManager available.
+		*
+		* IconManager is singleton and the instance can be queried with the method
+		* instance().
+		*/
+		static IconManager* _instance;
+		QMap<QString, ScIconSetData> m_iconSets;
+		ScPixmapCache<QString> m_pxCache;
+		QString m_activeSetBasename;
+		QString m_activeSetVersion;
+		QString m_backupSetBasename;
+		QString m_backupSetVersion;
+
+		bool initIcons();
+		void readIconConfigFiles();
 
 
-signals:
-	void prefsChanged();
+	signals:
+		void prefsChanged();
 };
 
 #endif

Modified: trunk/Scribus/scribus/scribusview.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20195&path=/trunk/Scribus/scribus/scribusview.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusview.cpp (original)
+++ trunk/Scribus/scribus/scribusview.cpp Tue Jun 23 08:07:06 2015
@@ -562,10 +562,10 @@
 			break;
 		case modeDrawCalligraphicLine:
 		case modeDrawFreehandLine:
-			setCursor(QCursor(im->loadPixmap("DrawFreeLine.png"), 0, 32));
+			setCursor(im->loadCursor("DrawFreeLine.png", 0, 32));
 			break;
 		case modeEyeDropper:
-			setCursor(QCursor(im->loadPixmap("colorpickercursor.png"), 0, 32));
+			setCursor(im->loadCursor("colorpickercursor.png", 0, 32));
 			break;
 		case modeInsertPDFButton:
 		case modeInsertPDFRadioButton:

Modified: trunk/Scribus/scribus/ui/dasheditor.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20195&path=/trunk/Scribus/scribus/ui/dasheditor.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/dasheditor.cpp (original)
+++ trunk/Scribus/scribus/ui/dasheditor.cpp Tue Jun 23 08:07:06 2015
@@ -200,7 +200,7 @@
 	QRect fpo;
 	if ((!Mpressed) && (m->y() < height()) && (m->y() > 16) && (m->x() > 9) && (m->x() < width()-9) && (DashValues.count() < 10))
 	{
-		setCursor(QCursor(IconManager::instance()->loadPixmap("AddPoint.png"), 1, 1));
+		setCursor(IconManager::instance()->loadCursor("AddPoint.png", 1, 1));
 		for (int yg = 0; yg < StopM.count(); ++yg)
 		{
 			fpo = QRect(static_cast<int>(StopM[yg])+6, 16, 8, 13);
@@ -243,7 +243,7 @@
 		emit currStep(StopM[ActStop] / 10.0 - startX);
 	}
 	if ((Mpressed) && (outside || m->y() > 30) && (ActStop >= 0) && (StopM.count() > 2))
-		qApp->changeOverrideCursor(QCursor(IconManager::instance()->loadPixmap("DelPoint.png"), 1, 1));
+		qApp->changeOverrideCursor(IconManager::instance()->loadCursor("DelPoint.png", 1, 1));
 }
 
 void DashPreview::leaveEvent(QEvent*)
@@ -251,7 +251,7 @@
 	if (Mpressed)
 	{
 		if ((ActStop >= 0) && (StopM.count() > 2))
-			qApp->changeOverrideCursor(QCursor(IconManager::instance()->loadPixmap("DelPoint.png"), 1, 1));
+			qApp->changeOverrideCursor(IconManager::instance()->loadCursor("DelPoint.png", 1, 1));
 		else
 			qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
 	}

Modified: trunk/Scribus/scribus/ui/gradientpreview.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20195&path=/trunk/Scribus/scribus/ui/gradientpreview.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/gradientpreview.cpp (original)
+++ trunk/Scribus/scribus/ui/gradientpreview.cpp Tue Jun 23 08:07:06 2015
@@ -243,7 +243,7 @@
 		qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
 		if ((!Mpressed) && (m->y() < height()) && (m->y() > 43) && (m->x() > 9) && (m->x() < width()-9))
 		{
-			setCursor(QCursor(IconManager::instance()->loadPixmap("AddPoint.png"), 1, 1));
+			setCursor(IconManager::instance()->loadCursor("AddPoint.png", 1, 1));
 			for (int yg = 0; yg < static_cast<int>(StopM.count()); ++yg)
 			{
 				fpo = QRect(static_cast<int>(StopM[yg])-4, 43, 8, 13);
@@ -278,7 +278,7 @@
 				repaint();
 			}
 			if ((Mpressed) && (outside || !insideRect.contains(m->pos())) && (ActStop > 0) && (ActStop != static_cast<int>(StopM.count()-1)))
-				qApp->changeOverrideCursor(QCursor(IconManager::instance()->loadPixmap("DelPoint.png"), 1, 1));
+				qApp->changeOverrideCursor(IconManager::instance()->loadCursor("DelPoint.png", 1, 1));
 		}
 	}
 }
@@ -290,7 +290,7 @@
 		if (Mpressed)
 		{
 			if ((ActStop > 0) && (ActStop != static_cast<int>(StopM.count()-1)))
-				qApp->changeOverrideCursor(QCursor(IconManager::instance()->loadPixmap("DelPoint.png"), 1, 1));
+				qApp->changeOverrideCursor(IconManager::instance()->loadCursor("DelPoint.png", 1, 1));
 			else
 				qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
 		}

Modified: trunk/Scribus/scribus/ui/hruler.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20195&path=/trunk/Scribus/scribus/ui/hruler.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/hruler.cpp (original)
+++ trunk/Scribus/scribus/ui/hruler.cpp Tue Jun 23 08:07:06 2015
@@ -332,7 +332,7 @@
 void Hruler::enterEvent(QEvent *e)
 {
 	if (textEditMode)
-		qApp->changeOverrideCursor(QCursor(IconManager::instance()->loadPixmap("tab.png"), 3));
+		qApp->changeOverrideCursor(IconManager::instance()->loadCursor("tab.png", 3));
 }
 
 void Hruler::leaveEvent(QEvent *m)
@@ -446,7 +446,7 @@
 		}
 		if ((!Mpressed) && (m->y() < height()) && (m->y() > 0) && (m->x() > ColStart - 2*m_doc->guidesPrefs().grabRadius) && (m->x() < ColEnd + 2*m_doc->guidesPrefs().grabRadius))
 		{
-			setCursor(QCursor(IconManager::instance()->loadPixmap("tab.png"), 3));
+			setCursor(IconManager::instance()->loadCursor("tab.png", 3));
 			switch(findRulerHandle(m->pos(), m_doc->guidesPrefs().grabRadius))
 			{
 				case rc_leftFrameDist: 
@@ -475,7 +475,7 @@
 		}
 		if ((Mpressed) && (RulerCode == rc_tab) && ((m->y() > height()) || (m->y() < 0)))
 		{
-			setCursor(QCursor(IconManager::instance()->loadPixmap("DelPoint.png"), 1, 1));
+			setCursor(IconManager::instance()->loadCursor("DelPoint.png", 1, 1));
 			return;
 		}
 		setCursor(QCursor(Qt::ArrowCursor));

Modified: trunk/Scribus/scribus/ui/tabruler.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20195&path=/trunk/Scribus/scribus/ui/tabruler.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/tabruler.cpp (original)
+++ trunk/Scribus/scribus/ui/tabruler.cpp Tue Jun 23 08:07:06 2015
@@ -317,7 +317,7 @@
 	}
 	if ((!mousePressed) && (m->y() < height()) && (m->y() > 0) && (m->x() > 0) && (m->x() < width()))
 	{
-		setCursor(QCursor(IconManager::instance()->loadPixmap("tab.png"), 3));
+		setCursor(IconManager::instance()->loadCursor("tab.png", 3));
 		if (haveInd)
 		{
 			fpo = QRect(static_cast<int>(firstLine+leftIndent-offset)-4, 0, 8, 12);
@@ -348,7 +348,7 @@
 	}
 	if ((mousePressed) && ((m->y() > height()) || (m->y() < 0) || (m->x() < 0) || (m->x() > width())))
 	{
-		qApp->changeOverrideCursor(QCursor(IconManager::instance()->loadPixmap("DelPoint.png"), 1, 1));
+		qApp->changeOverrideCursor(IconManager::instance()->loadCursor("DelPoint.png", 1, 1));
 	}
 }
 
@@ -357,7 +357,7 @@
 	if (mousePressed)
 	{
 		if (rulerCode == 3)
-			qApp->changeOverrideCursor(QCursor(IconManager::instance()->loadPixmap("DelPoint.png"), 1, 1));
+			qApp->changeOverrideCursor(IconManager::instance()->loadCursor("DelPoint.png", 1, 1));
 		else
 			qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
 	}




More information about the scribus-commit mailing list