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

List:       kde-commits
Subject:    koffice/karbon
From:       Jan Hambrecht <jaham () gmx ! net>
Date:       2009-03-29 14:16:56
Message-ID: 1238336216.538271.4735.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 946476 by jaham:

only show style buttons applicable to the current selection as requested by Thomas



 M  +51 -8     plugins/dockers/KarbonStyleDocker.cpp  
 M  +6 -0      plugins/dockers/KarbonStyleDocker.h  
 M  +6 -11     ui/widgets/KarbonStyleButtonBox.cpp  
 M  +13 -12    ui/widgets/KarbonStyleButtonBox.h  


--- trunk/koffice/karbon/plugins/dockers/KarbonStyleDocker.cpp #946475:946476
@@ -53,6 +53,12 @@
 
 const int MsecsThresholdForMergingCommands = 2000;
 
+KarbonStyleButtonBox::StyleButtons StrokeButtons = \
KarbonStyleButtonBox::None|KarbonStyleButtonBox::Solid|KarbonStyleButtonBox::Gradient;
 +
+KarbonStyleButtonBox::StyleButtons FillButtons = \
KarbonStyleButtonBox::None|KarbonStyleButtonBox::Solid|KarbonStyleButtonBox::Gradient|KarbonStyleButtonBox::Pattern;
 +
+KarbonStyleButtonBox::StyleButtons FillRuleButtons = \
KarbonStyleButtonBox::EvenOdd|KarbonStyleButtonBox::Winding; +
 KarbonStyleDocker::KarbonStyleDocker( QWidget * parent )
     : QDockWidget( parent ), m_canvas(0)
     , m_lastFillCommand(0), m_lastStrokeCommand(0)
@@ -207,7 +213,7 @@
             qColor = m_canvas->resourceProvider()->backgroundColor().toQColor();
     }
     m_actionColor->setCurrentColor( qColor );
-
+    updateStyleButtons( activeStyle );
     m_preview->update( stroke, fill );
 }
 
@@ -217,7 +223,8 @@
         return;
 
     m_canvas->resourceProvider()->setResource( Karbon::ActiveStyle, \
                Karbon::Background );
-    m_buttons->setFill();
+    updateStyleButtons( Karbon::Background );
+    
 }
 
 void KarbonStyleDocker::strokeSelected()
@@ -226,7 +233,7 @@
         return;
 
     m_canvas->resourceProvider()->setResource( Karbon::ActiveStyle, \
                Karbon::Foreground );
-    m_buttons->setStroke();
+    updateStyleButtons( Karbon::Foreground );
 }
 
 void KarbonStyleDocker::resourceChanged( int key, const QVariant& )
@@ -488,15 +495,51 @@
     if( ! selection || ! selection->count() )
         return;
 
-    QList<KoPathShape*> shapes;
+    QList<KoPathShape*> selectedPaths = selectedPathShapes();
+    QList<KoPathShape*> pathsToChange;
+    foreach( KoPathShape * path, selectedPaths )
+    {
+        if( path->fillRule() != fillRule )
+            pathsToChange.append( path );
+    }
+    if( pathsToChange.count() )
+        m_canvas->addCommand( new KoPathFillRuleCommand( pathsToChange, fillRule ) \
); +}
+
+QList<KoPathShape*> KarbonStyleDocker::selectedPathShapes()
+{
+    QList<KoPathShape*> pathShapes;
+
+    if( ! m_canvas )
+        return pathShapes;
+    
+    KoSelection *selection = m_canvas->shapeManager()->selection();
+    if( ! selection || ! selection->count() )
+        return pathShapes;
+
     foreach( KoShape * shape, selection->selectedShapes() )
     {
         KoPathShape * path = dynamic_cast<KoPathShape*>( shape );
-        if( path && path->fillRule() != fillRule )
-            shapes.append( path );
+        if( path )
+            pathShapes.append( path );
     }
-    if( shapes.count() )
-        m_canvas->addCommand( new KoPathFillRuleCommand( shapes, fillRule ) );
+    
+    return pathShapes;
 }
 
+void KarbonStyleDocker::updateStyleButtons( int activeStyle )
+{
+    if( activeStyle == Karbon::Background ) {
+        if( selectedPathShapes().count() )
+            m_buttons->showButtons( FillButtons|FillRuleButtons );
+        else
+            m_buttons->showButtons( FillButtons );
+    }
+    else {
+        m_buttons->showButtons( StrokeButtons );
+        if( m_stack->currentIndex() == 2 )
+            m_stack->setCurrentIndex( 0 );
+    }
+}
+
 #include "KarbonStyleDocker.moc"
--- trunk/koffice/karbon/plugins/dockers/KarbonStyleDocker.h #946475:946476
@@ -38,6 +38,7 @@
 class QToolButton;
 class QStackedWidget;
 class KoColorPopupAction;
+class KoPathShape;
 
 class KarbonStyleDocker : public QDockWidget, public KoCanvasObserver
 {
@@ -69,6 +70,11 @@
     /// Resets color related commands which are used to combine multiple color \
changes  void resetColorCommands();
     
+    /// Returns list of selected path shapes
+    QList<KoPathShape*> selectedPathShapes();
+    
+    void updateStyleButtons( int activeStyle );
+    
     KarbonStylePreview * m_preview;
     KarbonStyleButtonBox * m_buttons;
     QStackedWidget * m_stack;
--- trunk/koffice/karbon/ui/widgets/KarbonStyleButtonBox.cpp #946475:946476
@@ -317,13 +317,13 @@
     button->setToolTip( i18n( "Winding Fill" ) );
     d->group->addButton( button, Winding );
 
-    int index = 0;
+    int index = 1;
     for( int row = 0; row < d->rowCount; ++row )
     {
         for( int col = 0; col < d->columnCount; ++col )
         {
             layout->addWidget( d->group->button( index ), row, col );
-            index ++;
+            index = index<<1;
             if( index > Winding )
                 break;
         }
@@ -345,17 +345,12 @@
     delete d;
 }
 
-void KarbonStyleButtonBox::setStroke()
+void KarbonStyleButtonBox::showButtons(StyleButtons buttons)
 {
-    d->group->button( EvenOdd )->setEnabled( false );
-    d->group->button( Winding )->setEnabled( false );
+    foreach( QAbstractButton * b, d->group->buttons() ) {
+        b->setVisible( buttons & d->group->id( b ) );
+    }
 }
 
-void KarbonStyleButtonBox::setFill()
-{
-    d->group->button( EvenOdd )->setEnabled( true );
-    d->group->button( Winding )->setEnabled( true );
-}
-
 #include "KarbonStyleButtonBox.moc"
 
--- trunk/koffice/karbon/ui/widgets/KarbonStyleButtonBox.h #946475:946476
@@ -32,23 +32,22 @@
     Q_OBJECT
 
 public:
-    enum ButtonType {
-        None     = 0,
-        Solid    = 1,
-        Gradient = 2,
-        Pattern  = 3,
-        EvenOdd  = 4,
-        Winding  = 5
+    enum StyleButton {
+        None     = 1,
+        Solid    = 2,
+        Gradient = 4,
+        Pattern  = 8,
+        EvenOdd  = 16,
+        Winding  = 32
     };
-
+    Q_DECLARE_FLAGS(StyleButtons, StyleButton)
+    
     KarbonStyleButtonBox( QWidget* parent = 0L );
     virtual ~KarbonStyleButtonBox();
 
 public slots:
-    /// enables the winding buttons
-    void setFill();
-    /// disables the winding buttons
-    void setStroke();
+    /// shows specified buttons
+    void showButtons(StyleButtons buttons);
 
 signals:
     void buttonPressed( int buttonId );
@@ -58,5 +57,7 @@
     Private * const d;
 };
 
+Q_DECLARE_OPERATORS_FOR_FLAGS(KarbonStyleButtonBox::StyleButtons)
+
 #endif // KARBONSTYLEBUTTONBOX_H
 


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

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