[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: Re: extragear/multimedia/amarok/src/widgets
From: Seb Ruiz <ruiz () kde ! org>
Date: 2009-06-29 23:44:16
Message-ID: 60ebdd0b0906291644v62308119heec2cd50d2497d19 () mail ! gmail ! com
[Download RAW message or body]
Nikolaj,
Please don't accept patches which don't conform to our styling, unless
you are going to reformat the code.
Thanks, and see you soon,
Seb
2009/6/30 Nikolaj Hald Nielsen <nhnFreespirit@gmail.com>:
> SVN commit 989288 by nhnielsen:
>
> Improvements to the "show cover" dialog.
>
> - Auto center on screen
> - Size matches cover size (if it fits on screen, scales down cover otherwise)
> - Zooming/resizing using mouse wheel
> - No more scrollbars
>
> Thanks to Pascal Pollet <pascal@bongosoft.de> for the patch! :-)
>
> BUG: 175901
>
>
>
> M +92 -31 PixmapViewer.cpp
> M +18 -11 PixmapViewer.h
>
>
> --- trunk/extragear/multimedia/amarok/src/widgets/PixmapViewer.cpp #989287:989288
> @@ -2,6 +2,7 @@
> * Copyright (c) 2005 Eyal Lotem <eyal.lotem@gmail.com> *
> * Copyright (c) 2005 Alexandre Pereira de Oliveira <aleprj@gmail.com> *
> * Copyright (c) 2007 Seb Ruiz <ruiz@kde.org> *
> + * Copyright (c) 2009 Pascal Pollet <pascal@bongosoft.de> *
> * *
> * This program is free software; you can redistribute it and/or modify it under *
> * the terms of the GNU General Public License as published by the Free Software *
> @@ -25,54 +26,114 @@
> #include <QMouseEvent>
> #include <QLabel>
> #include <QPixmap>
> -#include <QScrollBar>
> +#include <QPainter>
> +#include <QWheelEvent>
>
> -PixmapViewer::PixmapViewer( QWidget *widget, const QPixmap &pixmap )
> - : QScrollArea( widget )
> - , m_isDragging( false )
> - , m_pixmap( pixmap )
> +
> +PixmapViewer::PixmapViewer( QWidget *widget, const QPixmap pix )
> + : QWidget( widget )
> {
> - QLabel *imageLabel = new QLabel();
> - imageLabel->setPixmap( pixmap );
> - imageLabel->adjustSize();
>
> - setBackgroundRole( QPalette::Dark );
> - setWidget( imageLabel );
> -}
> + m_pixmap = new QPixmap( pix );
> + m_zoomFactor = 1.0; // initial zoom
>
> -void PixmapViewer::mousePressEvent(QMouseEvent *event)
> -{
> - if( Qt::LeftButton == event->button() )
> + if ( KApplication::desktop()->width() < m_pixmap->width() )
> {
> - m_currentPos = event->globalPos();
> - m_isDragging = true;
> + m_zoomFactor = (( float ) KApplication::desktop()->width() /
> + ( float ) m_pixmap->width() ) - 0.5;
> }
> +
> + setMinimumSize( m_pixmap->width()*m_zoomFactor, m_pixmap->height()*m_zoomFactor );
> +
> + // move window to the center of the screen
> + // (multiple screens: same screen as parent widget)
> + QWidget *p = dynamic_cast<QWidget*>( parent() );
> + p->move(( KApplication::desktop()->availableGeometry( p ).width()
> + - ( m_pixmap->width()*m_zoomFactor ) ) / 2,
> + ( KApplication::desktop()->availableGeometry( p ).height()
> + - ( m_pixmap->height()*m_zoomFactor ) ) / 2 );
> +
> }
>
> -void PixmapViewer::mouseReleaseEvent(QMouseEvent *event)
> +
> +void PixmapViewer::setZoomFactor( float f )
> {
> - if( Qt::LeftButton == event->button() )
> - {
> - m_currentPos = event->globalPos();
> - m_isDragging = false;
> - }
> + int w, h;
> +
> + if ( f == m_zoomFactor )
> + return;
> +
> + m_zoomFactor = f;
> + emit( zoomFactorChanged( m_zoomFactor ) );
> +
> + w = m_pixmap->width() * m_zoomFactor;
> + h = m_pixmap->height() * m_zoomFactor;
> + setMinimumSize( w, h );
> +
> + QWidget *p = dynamic_cast<QWidget*>( parent() );
> + if ( p )
> + resize( p->width(), p->height() );
> +
> + repaint();
> }
>
> -void PixmapViewer::mouseMoveEvent(QMouseEvent *event)
> +void PixmapViewer::paintEvent( QPaintEvent *event )
> {
> - if( m_isDragging )
> + int xoffset, yoffset;
> + bool drawBorder = false;
> +
> + if ( width() > m_pixmap->width()*m_zoomFactor )
> {
> - QPoint delta = m_currentPos - event->globalPos();
> - horizontalScrollBar()->setValue( horizontalScrollBar()->value() + delta.x() );
> - verticalScrollBar()->setValue( verticalScrollBar()->value() + delta.y() );
> - m_currentPos = event->globalPos();
> + xoffset = ( width() - m_pixmap->width() * m_zoomFactor ) / 2;
> + drawBorder = true;
> }
> + else
> + {
> +
> + xoffset = 0;
> +
> + }
> +
> + if ( height() > m_pixmap->height()*m_zoomFactor )
> + {
> + yoffset = ( height() - m_pixmap->height() * m_zoomFactor ) / 2;
> + drawBorder = true;
> + }
> + else
> + {
> +
> + yoffset = 0;
> + }
> +
> + QWidget *parentWidget = dynamic_cast<QWidget*>( parent() );
> + parentWidget->move(( KApplication::desktop()->availableGeometry( parentWidget ).width()
> + - ( m_pixmap->width()*m_zoomFactor ) ) / 2,
> + ( KApplication::desktop()->availableGeometry( parentWidget ).height()
> + - ( m_pixmap->height()*m_zoomFactor ) ) / 2 );
> +
> + QPainter p( this );
> + p.save();
> + p.translate( xoffset, yoffset );
> + p.scale( m_zoomFactor, m_zoomFactor );
> + p.drawPixmap( 0, 0, *m_pixmap );
> + p.restore();
> + if ( drawBorder )
> + {
> + p.setPen( Qt::black );
> + p.drawRect( xoffset - 1, yoffset - 1, m_pixmap->width()*m_zoomFactor + 1,
> + m_pixmap->height()*m_zoomFactor + 1 );
> + }
> }
>
> -QSize PixmapViewer::sizeHint() const
> +void PixmapViewer::wheelEvent( QWheelEvent *event )
> {
> - return QScrollArea::sizeHint().boundedTo( KApplication::desktop()->size() );
> + float f;
> +
> + f = m_zoomFactor + 0.001 * event->delta();
> + if ( f < 32.0 / m_pixmap->width() )
> + f = 32.0 / m_pixmap->width();
> +
> + setZoomFactor( f );
> }
>
> #include "PixmapViewer.moc"
> -
> --- trunk/extragear/multimedia/amarok/src/widgets/PixmapViewer.h #989287:989288
> @@ -1,6 +1,7 @@
> /****************************************************************************************
> * Copyright (c) 2005 Eyal Lotem <eyal.lotem@gmail.com> *
> * Copyright (c) 2007 Seb Ruiz <ruiz@kde.org> *
> + * Copyright (c) 2009 Pascal Pollet <pascal@bongosoft.de> *
> * *
> * This program is free software; you can redistribute it and/or modify it under *
> * the terms of the GNU General Public License as published by the Free Software *
> @@ -19,27 +20,33 @@
> #define PIXMAPVIEWER_H
>
> #include <QScrollArea>
> +#include <QWidget>
> +#include <QString>
> #include <QPixmap>
>
> class QMouseEvent;
> +class QPixmap;
>
> -class PixmapViewer : public QScrollArea
> +class PixmapViewer : public QWidget
> {
> Q_OBJECT
>
> - public:
> - PixmapViewer( QWidget *widget, const QPixmap &pixmap );
> +public:
> + PixmapViewer( QWidget *widget, const QPixmap pixmap );
>
> - virtual QSize sizeHint() const;
> +public slots:
> + void setZoomFactor( float );
>
> - void mousePressEvent( QMouseEvent *event );
> - void mouseReleaseEvent( QMouseEvent *event );
> - void mouseMoveEvent( QMouseEvent *event );
> +signals:
> + void zoomFactorChanged( float );
>
> - private:
> - bool m_isDragging;
> - QPoint m_currentPos;
> - const QPixmap &m_pixmap;
> +protected:
> + void paintEvent( QPaintEvent* );
> + void wheelEvent( QWheelEvent* );
> +
> +private:
> + QPixmap *m_pixmap;
> + float m_zoomFactor;
> };
>
> #endif
>
--
Seb Ruiz
http://www.sebruiz.net/
http://amarok.kde.org/
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic