r23130 by craig - Clean up ruler code a little

scribus-commit scribus-commit at lists.scribus.net
Thu Aug 15 21:00:22 UTC 2019


Author: craig
Date: Thu Aug 15 21:00:21 2019
New Revision: 23130

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23130
Log:
Clean up ruler code a little

Modified:
    trunk/Scribus/scribus/ui/hruler.cpp
    trunk/Scribus/scribus/ui/hruler.h
    trunk/Scribus/scribus/ui/vruler.cpp
    trunk/Scribus/scribus/ui/vruler.h

Modified: trunk/Scribus/scribus/ui/hruler.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23130&path=/trunk/Scribus/scribus/ui/hruler.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/hruler.cpp	(original)
+++ trunk/Scribus/scribus/ui/hruler.cpp	Thu Aug 15 21:00:21 2019
@@ -55,45 +55,11 @@
 #define midline (topline + rulerheight/2)
 #define tabline 7
 
-enum ruler_code 
-{ 
-	rc_none = 0,
-	rc_leftFrameDist = 1,
-	rc_rightFrameDist = 2,
-	rc_indentFirst = 3,
-	rc_leftMargin = 4,
-	rc_tab = 5,
-	rc_rightMargin = 6
-};
 
 
 Hruler::Hruler(ScribusView *pa, ScribusDoc *doc) : QWidget(pa),
-	m_textEditMode(false),
-	m_colGap(0.0),
-	m_lineCorr(0.0),
-	m_cols(0),
-	m_distLeft(0.0),
-	m_distRight(0.0),
-	m_firstIndent(0.0),
-	m_leftMargin(0.0),
-	m_rightMargin(0.0),
-	m_reverse(false),
-	m_currItem(nullptr),
-	m_itemPos(0.0),
-	m_itemEndPos(0.0),
-	m_offset(0.0),
-	m_itemScale(1.0),
-	m_oldMark(0),
-	m_mousePressed(false),
-	m_currCol(1),
-	m_currTab(0),
-	m_scaling(0.0),
-	m_rulerCode(rc_none),
-	m_mouseX(0),
 	m_doc(doc),
-	m_view(pa),
-	m_whereToDraw(0),
-	m_drawMark(false)
+	m_view(pa)
 {
 	setBackgroundRole(QPalette::Window);
 	setAutoFillBackground(true);
@@ -104,7 +70,6 @@
 	rulerGesture = new RulerGesture(m_view, RulerGesture::HORIZONTAL);
 	unitChange();
 }
-
 
 double Hruler::textBase() const
 {

Modified: trunk/Scribus/scribus/ui/hruler.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23130&path=/trunk/Scribus/scribus/ui/hruler.h
==============================================================================
--- trunk/Scribus/scribus/ui/hruler.h	(original)
+++ trunk/Scribus/scribus/ui/hruler.h	Thu Aug 15 21:00:21 2019
@@ -42,6 +42,19 @@
 /** \brief Horizontal ruler
 \author Franz Schmid
 */
+
+
+enum ruler_code
+{
+	rc_none = 0,
+	rc_leftFrameDist = 1,
+	rc_rightFrameDist = 2,
+	rc_indentFirst = 3,
+	rc_leftMargin = 4,
+	rc_tab = 5,
+	rc_rightMargin = 6
+};
+
 class SCRIBUS_API Hruler : public QWidget
 {
 	Q_OBJECT
@@ -50,26 +63,6 @@
 	Hruler(ScribusView *pa, ScribusDoc *doc);
 	~Hruler() {}
 
-private:
-	bool   m_textEditMode;
-	double m_colGap;
-	double m_lineCorr;
-	int    m_cols;
-	double m_distLeft;
-	double m_distRight;
-	double m_firstIndent;
-	double m_leftMargin;
-	double m_rightMargin;
-	bool   m_reverse;
-	QList<ParagraphStyle::TabRecord> m_tabValues;
-	PageItem * m_currItem;
-
-	double m_itemPos;
-	double m_itemEndPos;
-	double m_offset;
-	double m_itemScale;
-
-public:
 	double ruleSpacing();
 	void   setItem(PageItem * item);
 	void   textMode(bool state) { m_textEditMode = state; }
@@ -98,22 +91,36 @@
 	void drawNumber(const QString& num, int startx, int starty, QPainter & p);
 	void updateTabList();
 
-	int  m_oldMark;
-	int  m_currCol;
-	int  m_currTab;
-	double m_scaling;
-	int m_rulerCode;
-
-	bool m_mousePressed;
-	int  m_mouseX;
-	
-	double m_iter, m_iter2;
-	double m_cor;
-	int  m_whereToDraw;
-	bool m_drawMark;
-
-	ScribusDoc *m_doc;
-	ScribusView *m_view;
+	PageItem* m_currItem {nullptr};
+	QList<ParagraphStyle::TabRecord> m_tabValues;
+	ScribusDoc *m_doc {nullptr};
+	ScribusView *m_view {nullptr};
+	bool m_drawMark {false};
+	bool m_mousePressed {false};
+	bool m_reverse {false};
+	bool m_textEditMode {false};
+	double m_colGap {0.0};
+	double m_cor {0.0};
+	double m_distLeft {0.0};
+	double m_distRight {0.0};
+	double m_firstIndent {0.0};
+	double m_itemEndPos {0.0};
+	double m_itemPos {0.0};
+	double m_itemScale {1.0};
+	double m_iter {0.0};
+	double m_iter2 {0.0};
+	double m_leftMargin {0.0};
+	double m_lineCorr {0.0};
+	double m_offset {0.0};
+	double m_rightMargin {0.0};
+	double m_scaling {0.0};
+	int m_cols {0};
+	int m_currCol {1};
+	int m_currTab {0};
+	int m_mouseX {0};
+	int m_oldMark {0};
+	int m_rulerCode {rc_none};
+	int m_whereToDraw {0};
 	
 public slots: // Public slots
 	/** \brief draw mark

Modified: trunk/Scribus/scribus/ui/vruler.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23130&path=/trunk/Scribus/scribus/ui/vruler.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/vruler.cpp	(original)
+++ trunk/Scribus/scribus/ui/vruler.cpp	Thu Aug 15 21:00:21 2019
@@ -24,7 +24,7 @@
 #include "vruler.h"
 
 #include <QCursor>
-//#include <QDebug>
+#include <QDebug>
 #include <QMouseEvent>
 #include <QPaintEvent>
 #include <QPainter>
@@ -42,13 +42,8 @@
 #include "units.h"
 
 Vruler::Vruler(ScribusView *pa, ScribusDoc *doc) : QWidget(pa),
-	m_offset(0.0),
-	m_oldMark(0),
-	m_mousePressed(false),
 	m_doc(doc),
-	m_view(pa),
-	m_drawMark(false),
-	m_whereToDraw(0)
+	m_view(pa)
 {
 	setBackgroundRole(QPalette::Window);
 	setAutoFillBackground(true);
@@ -63,22 +58,20 @@
 void Vruler::mousePressEvent(QMouseEvent *m)
 {
 	m_mousePressed = true;
-	if (m_doc->guidesPrefs().guidesShown)
-	{
-		qApp->setOverrideCursor(QCursor(Qt::SplitHCursor));
-		m_view->startGesture(rulerGesture);
-		m_view->registerMousePress(m->globalPos());
-	}
+	if (!m_doc->guidesPrefs().guidesShown)
+		return;
+	qApp->setOverrideCursor(QCursor(Qt::SplitHCursor));
+	m_view->startGesture(rulerGesture);
+	m_view->registerMousePress(m->globalPos());
 }
 
 void Vruler::mouseReleaseEvent(QMouseEvent *m)
 {
-	if (m_mousePressed)
-	{
-		rulerGesture->mouseReleaseEvent(m);
-		qApp->restoreOverrideCursor();
-		m_mousePressed = false;
-	}
+	if (!m_mousePressed)
+		return;
+	rulerGesture->mouseReleaseEvent(m);
+	qApp->restoreOverrideCursor();
+	m_mousePressed = false;
 }
 
 void Vruler::mouseMoveEvent(QMouseEvent *m)
@@ -91,8 +84,7 @@
 {
 	if (m_doc->isLoading())
 		return;
-	QString tx = "";
-	double xl, frac;
+	QString tx;
 	double sc = m_view->scale();
 	QFont ff = font();
 	ff.setPointSize(6);
@@ -124,18 +116,20 @@
 				tx = QString::number(markC * m_iter2 / (m_iter2 / 100) / m_cor);
 				break;
 			case SC_IN:
-				xl = (markC * m_iter2 / m_iter2) / m_cor;
-				tx = QString::number(static_cast<int>(xl));
-				frac = fabs(xl - static_cast<int>(xl));
-				if ((static_cast<int>(xl) == 0) && (frac > 0.1))
-					tx = "";
-				if ((frac > 0.24) && (frac < 0.26))
-					tx += QChar(0xBC);
-				if ((frac > 0.49) && (frac < 0.51))
-					tx += QChar(0xBD);
-				if ((frac > 0.74) && (frac < 0.76))
-					tx += QChar(0xBE);
-				tx = tx;
+				{
+					double xl = (markC * m_iter2 / m_iter2) / m_cor;
+					tx = QString::number(static_cast<int>(xl));
+					double frac = fabs(xl - static_cast<int>(xl));
+					if ((static_cast<int>(xl) == 0) && (frac > 0.1))
+						tx = "";
+					if ((frac > 0.24) && (frac < 0.26))
+						tx += QChar(0xBC);
+					if ((frac > 0.49) && (frac < 0.51))
+						tx += QChar(0xBD);
+					if ((frac > 0.74) && (frac < 0.76))
+						tx += QChar(0xBE);
+					tx = tx;
+				}
 				break;
 			case SC_P:
 			case SC_C:
@@ -207,10 +201,9 @@
 void Vruler::drawNumber(const QString& num, int starty, QPainter *p)
 {
 	int textY = starty;
-	for (int a = 0; a < num.length(); ++a)
-	{
-		QString txt = num.mid(a, 1);
-		p->drawText(1, textY, txt);
+	for (int i = 0; i < num.length(); ++i)
+	{
+		p->drawText(1, textY, num.mid(i, 1));
 		textY += 8;
 	}
 }

Modified: trunk/Scribus/scribus/ui/vruler.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23130&path=/trunk/Scribus/scribus/ui/vruler.h
==============================================================================
--- trunk/Scribus/scribus/ui/vruler.h	(original)
+++ trunk/Scribus/scribus/ui/vruler.h	Thu Aug 15 21:00:21 2019
@@ -27,12 +27,14 @@
 #include <QWidget>
 #include "scribusapi.h"
 
+class QMouseEvent;
 class QPaintEvent;
-class QMouseEvent;
+
 class PrefsManager;
 class RulerGesture;
 class ScribusDoc;
 class ScribusView;
+
 
 /** \brief Vertical ruler
 \author Franz Schmid
@@ -46,26 +48,8 @@
 	~Vruler() {}
 	
 	double ruleSpacing();
-	void   shift(double pos) { m_offset = pos; }
-	void   shiftRel(double dist) { m_offset += dist; }
-
-private: // Private attributes
-	virtual void paintEvent(QPaintEvent *e);
-	virtual void mousePressEvent(QMouseEvent *m);
-	virtual void mouseReleaseEvent(QMouseEvent *m);
-	virtual void mouseMoveEvent(QMouseEvent *m);
-
-	void drawNumber(const QString& num, int starty, QPainter *p);
-	double m_offset;
-	int   m_oldMark;
-	bool  m_mousePressed;
-	ScribusDoc *m_doc;
-	ScribusView *m_view;
-
-	double m_iter, m_iter2;
-	double m_cor;
-	bool   m_drawMark;
-	int    m_whereToDraw;
+	void shift(double pos) { m_offset = pos; }
+	void shiftRel(double dist) { m_offset += dist; }
 
 public slots: // Public slots
 	/** \brief draw mark
@@ -74,7 +58,23 @@
 	void unitChange();
 
 private:
-	RulerGesture* rulerGesture;
+	virtual void paintEvent(QPaintEvent *e);
+	virtual void mousePressEvent(QMouseEvent *m);
+	virtual void mouseReleaseEvent(QMouseEvent *m);
+	virtual void mouseMoveEvent(QMouseEvent *m);
+	void drawNumber(const QString& num, int starty, QPainter *p);
+
+	RulerGesture* rulerGesture {nullptr};
+	ScribusDoc* m_doc {nullptr};
+	ScribusView* m_view {nullptr};
+	bool m_drawMark {false};
+	bool m_mousePressed {false};
+	double m_cor {0.0};
+	double m_iter {0.0};
+	double m_iter2 {0.0};
+	double m_offset {0.0};
+	int m_oldMark {0};
+	int m_whereToDraw {0};
 };
 
 #endif




More information about the scribus-commit mailing list