Hello Everyone,
I implemented zooming like ticket18 suggested but I was not able to map
it with the mousewheel?! Seems like the scrollbars are stealing the
wheel events?
So with my patch the selectMode button will zoom in and the drawMode
button will zoom out to demonstrate it works.

Maybe a ZoomIn and a ZoomOut button would be handy?

BTW: To do fast scrolling it helps to press ALT (wich enables scrolling
by mousewheel) + STRG (which enables fast scrolling).

Have a nice day,
Jakob
Index: gui/src/SongEditor/SongEditor.h
===================================================================
--- gui/src/SongEditor/SongEditor.h	(revision 232)
+++ gui/src/SongEditor/SongEditor.h	(working copy)
@@ -47,8 +47,11 @@
 class SongEditorPositionRuler;
 
 
-static const int SONG_EDITOR_GRID_WIDTH = 16;
+//static const int SONG_EDITOR_GRID_WIDTH = 16;
 
+static const int SONG_EDITOR_MIN_GRID_WIDTH = 8;
+static const int SONG_EDITOR_MAX_GRID_WIDTH = 16;
+
 ///
 /// Song editor
 ///
@@ -63,8 +66,12 @@
 		void updateEditor();
 		void createBackground();
 
+		unsigned getGridWidth ();
+		void setGridWidth (unsigned width);
+			
 	private:
 		unsigned m_nGridHeight;
+		unsigned m_nGridWidth;
 		static const unsigned m_nMaxPatternSequence = 400;
 		bool m_bSequenceChanged;
 		bool m_bIsMoving;
@@ -149,14 +156,17 @@
 
 		void createBackground();
 
+		uint getGridWidth();
+		void setGridWidth (uint width);
+		
 	public slots:
 		void updatePosition();
 
 	private:
 		QTimer *m_pTimer;
-		static const uint m_nGridWidth = 16;
+		uint m_nGridWidth;
 		static const uint m_nMaxPatternSequence = 400;
-		static const uint m_nInitialWidth = m_nMaxPatternSequence * m_nGridWidth;
+		static const uint m_nInitialWidth = m_nMaxPatternSequence * 16;
 		static const uint m_nHeight = 25;
 
 		QPixmap *m_pBackgroundPixmap;
Index: gui/src/SongEditor/SongEditor.cpp
===================================================================
--- gui/src/SongEditor/SongEditor.cpp	(revision 232)
+++ gui/src/SongEditor/SongEditor.cpp	(working copy)
@@ -61,9 +61,10 @@
 	setAttribute(Qt::WA_NoBackground);
 	setFocusPolicy (Qt::StrongFocus);
 
+	m_nGridWidth = 16;
 	m_nGridHeight = 18;
 
-	int m_nInitialWidth = 10 + m_nMaxPatternSequence * SONG_EDITOR_GRID_WIDTH;
+	int m_nInitialWidth = 10 + m_nMaxPatternSequence * m_nGridWidth;
 	int m_nInitialHeight = 10;
 
 	this->resize( QSize(m_nInitialWidth, m_nInitialHeight) );
@@ -80,7 +81,19 @@
 }
 
 
+unsigned int SongEditor::getGridWidth ()
+{
+	return m_nGridWidth;
+}
 
+void SongEditor::setGridWidth (unsigned width)
+{
+	if (SONG_EDITOR_MIN_GRID_WIDTH <= width && SONG_EDITOR_MAX_GRID_WIDTH >= width)
+	{
+		m_nGridWidth = width;
+		this->resize ( 10 + m_nMaxPatternSequence * m_nGridWidth, height() );
+	}
+}
 
 void SongEditor::keyPressEvent ( QKeyEvent * ev )
 {
@@ -118,7 +131,7 @@
 	}
 
 	int nRow = ev->y() / m_nGridHeight;
-	int nColumn = ( (int)ev->x() - 10 ) / (int)SONG_EDITOR_GRID_WIDTH;
+	int nColumn = ( (int)ev->x() - 10 ) / (int)m_nGridWidth;
 
 	if ( ev->modifiers() == Qt::ControlModifier ) {
 		INFOLOG( "[mousePressEvent] CTRL pressed!" );
@@ -240,7 +253,7 @@
 void SongEditor::mouseMoveEvent(QMouseEvent *ev)
 {
 	int nRow = ev->y() / m_nGridHeight;
-	int nColumn = ( (int)ev->x() - 10 ) / (int)SONG_EDITOR_GRID_WIDTH;
+	int nColumn = ( (int)ev->x() - 10 ) / (int)m_nGridWidth;
 	PatternList *pPatternList = Hydrogen::getInstance()->getSong()->getPatternList();
 	vector<PatternList*>* pColumns = Hydrogen::getInstance()->getSong()->getPatternGroupVector();
 
@@ -280,7 +293,7 @@
 		// aggiorno la lista di celle selezionate
 		m_selectedCells.clear();
 
-		int nStartColumn =  ( m_lasso.left() - 10.0 ) / SONG_EDITOR_GRID_WIDTH;
+		int nStartColumn =  ( m_lasso.left() - 10.0 ) / m_nGridWidth;
 		int nEndColumn = nColumn;
 		if ( nStartColumn > nEndColumn ) {
 			int nTemp = nEndColumn;
@@ -485,9 +498,9 @@
 	for (uint i = 0; i < nPatterns; i++) {
 		if ( ( i % 2) != 0) {
 			uint y = m_nGridHeight * i;
-			p.fillRect ( 0, y, m_nMaxPatternSequence * SONG_EDITOR_GRID_WIDTH, 2, backgroundColor );
-			p.fillRect ( 0, y + 2, m_nMaxPatternSequence * SONG_EDITOR_GRID_WIDTH, m_nGridHeight - 4, alternateRowColor );
-			p.fillRect ( 0, y + m_nGridHeight - 2, m_nMaxPatternSequence * SONG_EDITOR_GRID_WIDTH, 2, backgroundColor );
+			p.fillRect ( 0, y, m_nMaxPatternSequence * m_nGridWidth, 2, backgroundColor );
+			p.fillRect ( 0, y + 2, m_nMaxPatternSequence * m_nGridWidth, m_nGridHeight - 4, alternateRowColor );
+			p.fillRect ( 0, y + m_nGridHeight - 2, m_nMaxPatternSequence * m_nGridWidth, 2, backgroundColor );
 		}
 	}
 */
@@ -496,9 +509,9 @@
 
 	// vertical lines
 	for (uint i = 0; i < m_nMaxPatternSequence + 1; i++) {
-		uint x = 10 + i * SONG_EDITOR_GRID_WIDTH;
+		uint x = 10 + i * m_nGridWidth;
 		int x1 = x;
-		int x2 = x + SONG_EDITOR_GRID_WIDTH;
+		int x2 = x + m_nGridWidth;
 
 		p.drawLine( x1, 0, x1, m_nGridHeight * nPatterns );
 		p.drawLine( x2, 0, x2, m_nGridHeight * nPatterns );
@@ -512,8 +525,8 @@
 		int y1 = y + 2;
 		int y2 = y + m_nGridHeight - 2;
 
-		p.drawLine( 0, y1, (m_nMaxPatternSequence * SONG_EDITOR_GRID_WIDTH), y1 );
-		p.drawLine( 0, y2, (m_nMaxPatternSequence * SONG_EDITOR_GRID_WIDTH), y2 );
+		p.drawLine( 0, y1, (m_nMaxPatternSequence * m_nGridWidth), y1 );
+		p.drawLine( 0, y2, (m_nMaxPatternSequence * m_nGridWidth), y2 );
 	}
 
 
@@ -522,8 +535,8 @@
 	for (uint i = 0; i < nPatterns + 1; i++) {
 		uint y = m_nGridHeight * i;
 
-		p.fillRect( 0, y, m_nMaxPatternSequence * SONG_EDITOR_GRID_WIDTH, 2, backgroundColor );
-		p.drawLine( 0, y + m_nGridHeight - 1, m_nMaxPatternSequence * SONG_EDITOR_GRID_WIDTH, y + m_nGridHeight - 1 );
+		p.fillRect( 0, y, m_nMaxPatternSequence * m_nGridWidth, 2, backgroundColor );
+		p.drawLine( 0, y + m_nGridHeight - 1, m_nMaxPatternSequence * m_nGridWidth, y + m_nGridHeight - 1 );
 	}
 
 
@@ -575,12 +588,12 @@
 	pen.setStyle( Qt::DotLine );
 	p.setPen( pen );
 	for ( int i = 0; i < m_movingCells.size(); i++ ) {
-		int x = 10 + SONG_EDITOR_GRID_WIDTH * ( m_movingCells[ i ] ).x();
+		int x = 10 + m_nGridWidth * ( m_movingCells[ i ] ).x();
 		int y = m_nGridHeight * ( m_movingCells[ i ] ).y();
 
 		QColor patternColor;
 		patternColor.setRgb( 255, 255, 255 );
-		p.fillRect( x + 2, y + 4, SONG_EDITOR_GRID_WIDTH - 3, m_nGridHeight - 7, patternColor );
+		p.fillRect( x + 2, y + 4, m_nGridWidth - 3, m_nGridHeight - 7, patternColor );
 	}
 
 }
@@ -607,11 +620,11 @@
 		patternColor = patternColor.dark( 130 );
 	}
 
-	int x = 10 + SONG_EDITOR_GRID_WIDTH * pos;
+	int x = 10 + m_nGridWidth * pos;
 	int y = m_nGridHeight * number;
 
 // 	p.setPen( patternColor.light( 120 ) );  // willie - For the bevel - haven't yet figured how it's supposed to work...
-	p.fillRect( x + 1, y + 3, SONG_EDITOR_GRID_WIDTH - 1, m_nGridHeight - 5, patternColor );
+	p.fillRect( x + 1, y + 3, m_nGridWidth - 1, m_nGridHeight - 5, patternColor );
 }
 
 
@@ -1076,6 +1089,8 @@
 {
 	setAttribute(Qt::WA_NoBackground);
 
+	m_nGridWidth = 16;
+	
 	resize( m_nInitialWidth, m_nHeight );
 	setFixedHeight( m_nHeight );
 
@@ -1103,7 +1118,21 @@
 }
 
 
+uint SongEditorPositionRuler::getGridWidth()
+{
+	return m_nGridWidth;
+}
 
+void SongEditorPositionRuler::setGridWidth (uint width)
+{
+	if (SONG_EDITOR_MIN_GRID_WIDTH <= width && SONG_EDITOR_MAX_GRID_WIDTH >= width)
+	{
+		m_nGridWidth = width;
+		createBackground ();
+	}
+}
+
+
 void SongEditorPositionRuler::createBackground()
 {
 	UIStyle *pStyle = Preferences::getInstance()->getDefaultUIStyle();
@@ -1123,11 +1152,11 @@
 
 	char tmp[10];
 	for (uint i = 0; i < m_nMaxPatternSequence + 1; i++) {
-		uint x = 10 + i * SONG_EDITOR_GRID_WIDTH;
+		uint x = 10 + i * m_nGridWidth;
 		if ( (i % 4) == 0 ) {
 			p.setPen( textColor );
 			sprintf( tmp, "%d", i + 1 );
-			p.drawText( x - SONG_EDITOR_GRID_WIDTH, 0, SONG_EDITOR_GRID_WIDTH * 2, height(), Qt::AlignCenter, tmp );
+			p.drawText( x - m_nGridWidth, 0, m_nGridWidth * 2, height(), Qt::AlignCenter, tmp );
 		}
 		else {
 			p.setPen( textColor );
@@ -1153,7 +1182,7 @@
 
 void SongEditorPositionRuler::mousePressEvent( QMouseEvent *ev )
 {
-	int column = (ev->x() / SONG_EDITOR_GRID_WIDTH);
+	int column = (ev->x() / m_nGridWidth);
 
 	if ( column >= Hydrogen::getInstance()->getSong()->getPatternGroupVector()->size() ) {
 		return;
@@ -1198,7 +1227,7 @@
 	painter.drawPixmap( ev->rect(), *m_pBackgroundPixmap, ev->rect() );
 
 	if (fPos != -1) {
-		uint x = 10 + fPos * SONG_EDITOR_GRID_WIDTH - 11 / 2;
+		uint x = 10 + fPos * m_nGridWidth - 11 / 2;
 		painter.drawPixmap( QRect( x, height() / 2, 11, 8), m_tickPositionPixmap, QRect(0, 0, 11, 8) );
 	}
 }
Index: gui/src/SongEditor/SongEditorPanel.cpp
===================================================================
--- gui/src/SongEditor/SongEditorPanel.cpp	(revision 232)
+++ gui/src/SongEditor/SongEditorPanel.cpp	(working copy)
@@ -227,7 +227,7 @@
 
 //		int x = m_pPositionRulerScrollView->contentsX();
 //		int w = m_pPositionRulerScrollView->visibleWidth();
-		int nPlayHeadPosition = Hydrogen::getInstance()->getPatternPos() * SONG_EDITOR_GRID_WIDTH;
+		int nPlayHeadPosition = Hydrogen::getInstance()->getPatternPos() * m_pSongEditor->getGridWidth();
 
 		if ( nPlayHeadPosition > ( x + w - 50 ) ) {
 			m_pEditorScrollView->horizontalScrollBar()->setValue( m_pEditorScrollView->horizontalScrollBar()->value() + 100 );
@@ -429,12 +429,18 @@
 	resyncExternalScrollBar();
 }
 
-
 void SongEditorPanel::pointerActionBtnPressed( Button* pBtn )
 {
 	pBtn->setPressed( true );
 	m_pDrawActionBtn->setPressed( false );
 	m_actionMode = SELECT_ACTION;
+
+	// TEST: ZoomIn
+	unsigned width = m_pSongEditor->getGridWidth ();
+	--width;
+	m_pSongEditor->setGridWidth (width);
+	m_pPositionRuler->setGridWidth (width);
+	updateAll();
 }
 
 
@@ -444,4 +450,11 @@
 	pBtn->setPressed( true );
 	m_pPointerActionBtn->setPressed( false );
 	m_actionMode = DRAW_ACTION;
+
+	//Test: ZoomOut
+	unsigned width = m_pSongEditor->getGridWidth ();
+	++width;
+	m_pSongEditor->setGridWidth (width);
+	m_pPositionRuler->setGridWidth (width);
+	updateAll();
 }

Reply via email to