[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    extragear/multimedia/amarok/src/widgets
From:       Nikolaj Hald Nielsen <nhnFreespirit () gmail ! com>
Date:       2009-06-30 7:25:30
Message-ID: 1246346730.029210.8131.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 989373 by nhnielsen:

fix minor style issues


 M  +12 -13    PixmapViewer.cpp  
 M  +3 -3      PixmapViewer.h  
 M  +111 -8    TokenWithLayout.cpp  
 M  +23 -1     TokenWithLayout.h  


--- trunk/extragear/multimedia/amarok/src/widgets/PixmapViewer.cpp #989372:989373
@@ -33,22 +33,21 @@
 PixmapViewer::PixmapViewer( QWidget *widget, const QPixmap pix )
         : QWidget( widget )
 {
-
     m_pixmap = new QPixmap( pix );
     m_zoomFactor = 1.0; // initial zoom
 
     if ( KApplication::desktop()->width() < m_pixmap->width() )
     {
-        m_zoomFactor = (( float ) KApplication::desktop()->width() /
+        m_zoomFactor = ( ( float ) KApplication::desktop()->width() /
                         ( float ) m_pixmap->width() ) - 0.5;
     }
 
-    setMinimumSize( m_pixmap->width()*m_zoomFactor, m_pixmap->height()*m_zoomFactor \
); +    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()
+    p->move( ( KApplication::desktop()->availableGeometry( p ).width()
               - ( m_pixmap->width()*m_zoomFactor ) ) / 2,
             ( KApplication::desktop()->availableGeometry( p ).height()
               - ( m_pixmap->height()*m_zoomFactor ) ) / 2 );
@@ -56,7 +55,8 @@
 }
 
 
-void PixmapViewer::setZoomFactor( float f )
+void
+PixmapViewer::setZoomFactor( float f )
 {
     int w, h;
 
@@ -77,7 +77,8 @@
     repaint();
 }
 
-void PixmapViewer::paintEvent( QPaintEvent *event )
+void
+PixmapViewer::paintEvent( QPaintEvent *event )
 {
     int xoffset, yoffset;
     bool drawBorder = false;
@@ -89,9 +90,7 @@
     }
     else
     {
-
         xoffset = 0;
-
     }
 
     if ( height() > m_pixmap->height()*m_zoomFactor )
@@ -101,12 +100,11 @@
     }
     else
     {
-
         yoffset = 0;
     }
 
     QWidget *parentWidget = dynamic_cast<QWidget*>( parent() );
-    parentWidget->move(( KApplication::desktop()->availableGeometry( parentWidget \
).width() +    parentWidget->move( ( KApplication::desktop()->availableGeometry( \
                parentWidget ).width()
                          - ( m_pixmap->width()*m_zoomFactor ) ) / 2,
                        ( KApplication::desktop()->availableGeometry( parentWidget \
                ).height()
                          - ( m_pixmap->height()*m_zoomFactor ) ) / 2 );
@@ -121,16 +119,17 @@
     {
         p.setPen( Qt::black );
         p.drawRect( xoffset - 1, yoffset - 1, m_pixmap->width()*m_zoomFactor + 1,
-                    m_pixmap->height()*m_zoomFactor + 1 );
+                    m_pixmap->height() * m_zoomFactor + 1 );
     }
 }
 
-void PixmapViewer::wheelEvent( QWheelEvent *event )
+void
+PixmapViewer::wheelEvent( QWheelEvent *event )
 {
     float f;
 
     f = m_zoomFactor + 0.001 * event->delta();
-    if ( f < 32.0 / m_pixmap->width() )
+    if( f < 32.0 / m_pixmap->width() )
         f = 32.0 / m_pixmap->width();
 
     setZoomFactor( f );
--- trunk/extragear/multimedia/amarok/src/widgets/PixmapViewer.h #989372:989373
@@ -35,14 +35,14 @@
     PixmapViewer( QWidget *widget, const QPixmap pixmap );
 
 public slots:
-    void setZoomFactor( float );
+    void setZoomFactor( float f );
 
 signals:
     void zoomFactorChanged( float );
 
 protected:
-    void paintEvent( QPaintEvent* );
-    void wheelEvent( QWheelEvent* );
+    void paintEvent( QPaintEvent *event );
+    void wheelEvent( QWheelEvent *event );
 
 private:
     QPixmap *m_pixmap;
--- trunk/extragear/multimedia/amarok/src/widgets/TokenWithLayout.cpp #989372:989373
@@ -21,43 +21,123 @@
 #include "TokenDropTarget.h"
 
 #include <KAction>
+#include <KColorScheme>
 #include <KHBox>
+#include <KIcon>
 #include <KLocale>
 
 #include <QActionGroup>
 #include <QContextMenuEvent>
 #include <QLayout>
+#include <QLCDNumber>
 #include <QMenu>
+#include <QPainter>
+#include <QPushButton>
 #include <QSlider>
-#include <QLCDNumber>
+#include <QTimerEvent>
 
+Wrench::Wrench( QWidget *parent ) : QLabel( parent )
+{
+    setCursor( Qt::ArrowCursor );
+    setPixmap( KIcon( "configure" ).pixmap( 64 ) );
+    setScaledContents( true );
+    setMargin( 4 );
+}
+
+void Wrench::enterEvent( QEvent * )
+{
+    setMargin( 1 );
+    update();
+}
+
+void Wrench::leaveEvent( QEvent * )
+{
+    setMargin( 4 );
+    update();
+}
+
+void Wrench::mouseReleaseEvent( QMouseEvent * )
+{
+    emit clicked();
+}
+
+void Wrench::paintEvent( QPaintEvent *pe )
+{
+    QPainter p( this );
+    QColor c = palette().color( backgroundRole() );
+//     if ( underMouse() )
+//         c = KColorScheme( QPalette::Active ).decoration( KColorScheme::HoverColor \
).color(); +//     p.setPen( QPen ( c, 2 ) );
+    p.setPen( Qt::NoPen );
+    c = palette().color( backgroundRole() );
+    c.setAlpha( 212 );
+    p.setBrush( c );
+    p.setRenderHint( QPainter::Antialiasing );
+    p.drawEllipse( rect() );
+    p.end();
+    QLabel::paintEvent( pe );
+}
+
+
 const QString ActionBoldName = QLatin1String( "ActionBold" );
 const QString ActionItalicName = QLatin1String( "ActionItalic" );
 const QString ActionAlignLeftName = QLatin1String( "ActionAlignLeft" );
 const QString ActionAlignCenterName = QLatin1String( "ActionAlignCenter" );
 const QString ActionAlignRightName = QLatin1String( "ActionAlignRight" );
 
-Token * TokenWithLayoutFactory::createToken(const QString &text, const QString \
&iconName, int value, QWidget *parent) +Token * TokenWithLayoutFactory::createToken( \
const QString &text, const QString &iconName, int value, QWidget *parent )  {
     return new TokenWithLayout( text, iconName, value, parent );
 }
 
 TokenWithLayout::TokenWithLayout( const QString &text, const QString &iconName, int \
value, QWidget *parent )  : Token( text, iconName, value, parent  )
-    , m_width( 0.0 )
+    , m_width( 0.0 ), m_wrenchTimer( 0 )
 {
     m_widthForced = m_width > 0.0;
     m_alignment = Qt::AlignCenter;
     m_bold = false;
     m_italic = false;
+    m_wrench = new Wrench( this );
+    m_wrench->installEventFilter( this );
+    m_wrench->hide();
+    connect ( m_wrench, SIGNAL( clicked() ), this, SLOT( showConfig() ) );
     setFocusPolicy( Qt::ClickFocus );
 }
 
 
 TokenWithLayout::~TokenWithLayout()
 {
+    delete m_wrench;
 }
 
+void TokenWithLayout::enterEvent( QEvent *e )
+{
+    QWidget *win = window();
+    const int sz = 2*height();
+    QPoint pt = mapTo( win, rect().topLeft() );
+
+    m_wrench->setParent( win );
+    m_wrench->setFixedSize( sz, sz );
+    m_wrench->move( pt - QPoint( m_wrench->width()/3, m_wrench->height()/3 ) );
+    m_wrench->setCursor( Qt::PointingHandCursor );
+    m_wrench->raise();
+    m_wrench->show();
+
+    Token::enterEvent( e );
+}
+
+bool TokenWithLayout::eventFilter( QObject *o, QEvent *e )
+{
+    if ( e->type() == QEvent::Leave && o == m_wrench )
+    {
+        if ( m_wrenchTimer )
+            killTimer( m_wrenchTimer );
+        m_wrenchTimer = startTimer( 40 );
+    }
+    return false;
+}
+
 void TokenWithLayout::fillMenu( QMenu * menu )
 {
     DEBUG_BLOCK
@@ -124,9 +204,9 @@
             if ( row > -1 )
             {
                 QList<Token*> tokens = editWidget->drags( row );
-                foreach (Token *t, tokens)
+                foreach ( Token *t, tokens )
                 {
-                    if (t == this)
+                    if ( t == this )
                         continue;
                     if ( TokenWithLayout *twl = qobject_cast<TokenWithLayout*>( t ) \
)  spareWidth -= twl->width() * 100.0;
@@ -154,6 +234,14 @@
 
 }
 
+void TokenWithLayout::leaveEvent( QEvent *e )
+{
+    Token::leaveEvent( e );
+    if ( m_wrenchTimer )
+        killTimer( m_wrenchTimer );
+    m_wrenchTimer = startTimer( 40 );
+}
+
 void TokenWithLayout::menuExecuted( const QAction* action )
 {
     if( action->objectName() == ActionAlignLeftName )
@@ -168,7 +256,7 @@
         setItalic( action->isChecked() );
 }
 
-void TokenWithLayout::contextMenuEvent( QContextMenuEvent * event )
+void TokenWithLayout::showConfig()
 {
     QMenu* menu = new QMenu();
 
@@ -176,13 +264,28 @@
 
     fillMenu( menu );
 
-    QAction* action = menu->exec( mapToGlobal( event->pos() ) );
+    QAction* action = menu->exec( QCursor::pos() - QPoint( menu->width()/2, -2 ) );
     if ( action )
         menuExecuted( action );
 
     delete menu;
 }
 
+void TokenWithLayout::timerEvent( QTimerEvent *te )
+{
+    if ( te->timerId() == m_wrenchTimer )
+    {
+        killTimer( m_wrenchTimer );
+        m_wrenchTimer = 0;
+        QRegion rgn;
+        rgn |= QRect( mapToGlobal( QPoint( 0, 0 ) ), QWidget::size() );
+        rgn |= QRect( m_wrench->mapToGlobal( QPoint( 0, 0 ) ), m_wrench->size() );
+        if ( !rgn.contains( QCursor::pos() ) )
+            m_wrench->hide();
+    }
+    Token::timerEvent( te );
+}
+
 Qt::Alignment TokenWithLayout::alignment()
 {
     return m_alignment;
@@ -254,7 +357,7 @@
 void TokenWithLayout::setWidth( int size )
 {
     m_width = qMax( qMin( 1.0, size/100.0 ), 0.0 ) ;
-    if ( (m_width) > 0.0 )
+    if ( m_width > 0.0 )
         m_widthForced = true;
 
     emit changed();
--- trunk/extragear/multimedia/amarok/src/widgets/TokenWithLayout.h #989372:989373
@@ -21,6 +21,20 @@
 
 class QMenu;
 
+class Wrench : public QLabel
+{
+    Q_OBJECT
+public:
+    Wrench( QWidget *parent );
+protected:
+    void enterEvent(QEvent *);
+    void leaveEvent(QEvent *);
+    void mouseReleaseEvent( QMouseEvent *e );
+    void paintEvent( QPaintEvent *pe );
+signals:
+    void clicked();
+};
+
 class TokenWithLayoutFactory : public TokenFactory
 {
 public:
@@ -62,10 +76,16 @@
     void setWidthForced( bool );
 
 protected:
+    virtual void enterEvent(QEvent *);
+    virtual bool eventFilter( QObject*, QEvent* );
     virtual void fillMenu( QMenu * menu );
+    virtual void leaveEvent(QEvent *);
     virtual void menuExecuted( const QAction* action );
-    virtual void contextMenuEvent( QContextMenuEvent * event );
+    virtual void timerEvent( QTimerEvent* );
 
+private slots:
+    void showConfig();
+
 private:
 
     Qt::Alignment m_alignment;
@@ -74,6 +94,8 @@
     bool m_widthForced;
     qreal m_width;
     QString m_prefix, m_suffix;
+    Wrench *m_wrench;
+    int m_wrenchTimer;
 
 };
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic