[Digikam-devel] extragear/graphics/digikam/digikam

Gilles Caulier caulier.gilles at gmail.com
Mon Jul 16 09:01:06 BST 2007


SVN commit 688490 by cgilles:

KDE4 port : use QRubberBand in IconView.
Marcel, please look if all is fine for you...

NOTE: still one file to port (tagspopupmenu.cpp) and digiKam KDE4 port will be complete...

CCMAIL: marcel.wiesweg at gmx.de
CCMAIL: digikam-devel at kde.org



 M  +45 -105   iconview.cpp  
 M  +0 -2      iconview.h  


--- trunk/extragear/graphics/digikam/digikam/iconview.cpp #688489:688490
@@ -41,6 +41,7 @@
 #include <QDropEvent>
 #include <QMouseEvent>
 #include <QStyleOption>
+#include <QRubberBand>
 
 // KDE includes.
 
@@ -87,34 +88,33 @@
         needEmitSelectionChanged = false;
     }
 
-    bool               clearing;
-    bool               showTips;
-    bool               pressedMoved;
-    bool               dragging;
-    bool               needEmitSelectionChanged; // store for slotRearrange
+    bool                 clearing;
+    bool                 showTips;
+    bool                 pressedMoved;
+    bool                 dragging;
+    bool                 needEmitSelectionChanged; // store for slotRearrange
 
-    int                spacing;
+    int                  rearrangeTimerInterval;
+    int                  spacing;
 
-    Q3PtrDict<IconItem> selectedItems;
-    Q3PtrDict<IconItem> prevSelectedItems;
+    Q3PtrDict<IconItem>  selectedItems;
+    Q3PtrDict<IconItem>  prevSelectedItems;
 
-    QRect*             rubber;
+    QRubberBand         *rubber;
 
-    QPoint             dragStartPos;
+    QPoint               dragStartPos;
 
-    QTimer*            rearrangeTimer;
-    QTimer*            toolTipTimer;
+    QTimer              *rearrangeTimer;
+    QTimer              *toolTipTimer;
 
-    IconItem*          toolTipItem;
-    IconItem*          currItem;
-    IconItem*          anchorItem;
-    IconItem*          storedVisibleItem; // store position for slotRearrange
+    IconItem            *toolTipItem;
+    IconItem            *currItem;
+    IconItem            *anchorItem;
+    IconItem            *storedVisibleItem; // store position for slotRearrange
 
-    IconGroupItem*     firstGroup;
-    IconGroupItem*     lastGroup;
+    IconGroupItem       *firstGroup;
+    IconGroupItem       *lastGroup;
 
-    int                rearrangeTimerInterval;
-
     struct ItemContainer 
     {
         ItemContainer(ItemContainer *p, ItemContainer *n, const QRect &r) 
@@ -150,6 +150,8 @@
     d = new IconViewPriv;
     d->rearrangeTimer  = new QTimer(this);
     d->toolTipTimer    = new QTimer(this);
+    d->rubber          = new QRubberBand(QRubberBand::Rectangle, this);
+    d->rubber->hide();
     
     connect(d->rearrangeTimer, SIGNAL(timeout()),
             this, SLOT(slotRearrange()));
@@ -890,22 +892,9 @@
     d->toolTipTimer->stop();
     slotToolTip();
     
-    // Delete any existing rubber -------------------------------
+    // Clear any existing rubber -------------------------------
+    d->rubber->hide();
 
-    if ( d->rubber )
-    {
-        QPainter p;
-        p.begin(viewport());
-        p.setRasterOp(NotROP);
-        p.setPen(QPen(Qt::color0, 1));
-        p.setBrush(Qt::NoBrush);
-
-        drawRubber(&p);
-        p.end();
-        delete d->rubber;
-        d->rubber = 0;
-    }
-
     if (e->button() == Qt::RightButton)
     {
         IconItem* item = findItem(e->pos());
@@ -1026,38 +1015,13 @@
         }
     }
     
-    d->rubber = new QRect( e->x(), e->y(), 0, 0 );
-
-    QPainter p;
-    p.begin( viewport() );
-    p.setRasterOp( NotROP );
-    p.setPen( QPen( Qt::color0, 1 ) );
-    p.setBrush( Qt::NoBrush );
-    drawRubber( &p );
-    p.end();
+    d->rubber->setGeometry(QRect(e->pos(), QSize()));
+    d->rubber->show();
 }
 
-void IconView::drawRubber(QPainter* p)
-{
-    if ( !p || !d->rubber )
-        return;
-
-    QRect r(d->rubber->normalized());
-
-    r = contentsRectToViewport(r);
-
-    QPoint pnt(r.x(), r.y());
-
-    style().drawPrimitive(QStyle::PE_FocusRect, p,
-                          QRect( pnt.x(), pnt.y(),
-                                 r.width(), r.height() ),
-                          colorGroup(), QStyle::Style_Default,
-                          QStyleOption(colorGroup().base()));
-}
-
 void IconView::contentsMouseMoveEvent(QMouseEvent* e)
 {
-    if (e->buttons() == NoButton)
+    if (e->buttons() == Qt::NoButton)
     {
         IconItem* item = findItem(e->pos());
 
@@ -1080,7 +1044,7 @@
                 if(acceptToolTip(item, e->pos()))
                 {
                     d->toolTipItem = item;
-                    d->toolTipTimer->setSingleShoot(true);
+                    d->toolTipTimer->setSingleShot(true);
                     d->toolTipTimer->start(500);
                 }
             }
@@ -1117,19 +1081,19 @@
         return;
     }
 
-    if (!d->rubber)
+    if (!d->rubber->isVisible())
         return;
 
-    QRect oldRubber = QRect(*d->rubber);
+    QRect oldRubber = d->rubber->geometry();
+    QRect newRubber = oldRubber;
+    newRubber.setRight(e->pos().x());
+    newRubber.setBottom(e->pos().y());
+    d->rubber->setGeometry(newRubber);
 
-    d->rubber->setRight( e->pos().x() );
-    d->rubber->setBottom( e->pos().y() );
-
-    QRect nr = d->rubber->normalized();
+    QRect nr          = d->rubber->geometry().normalized();
     QRect rubberUnion = nr.unite(oldRubber.normalized());
+    bool changed      = false;
 
-    bool changed = false;
-
     QRegion paintRegion;
     viewport()->setUpdatesEnabled(false);
     blockSignals(true);
@@ -1168,17 +1132,11 @@
     blockSignals(false);
     viewport()->setUpdatesEnabled(true);
 
-    QRect r = *d->rubber;
-    *d->rubber = oldRubber;
+    QRect r = d->rubber->geometry();
+    
+    d->rubber->setGeometry(oldRubber);
+    d->rubber->show();
 
-    QPainter p;
-    p.begin( viewport() );
-    p.setRasterOp( NotROP );
-    p.setPen( QPen( Qt::color0, 1 ) );
-    p.setBrush( Qt::NoBrush );
-    drawRubber( &p );
-    p.end();
-
     if (changed)
     {
         paintRegion.translate(-contentsX(), -contentsY());
@@ -1187,15 +1145,9 @@
 
     ensureVisible(e->pos().x(), e->pos().y());
 
-    *d->rubber = r;
+    d->rubber->setGeometry(r);
+    d->rubber->show();
 
-    p.begin(viewport());
-    p.setRasterOp(NotROP);
-    p.setPen(QPen(Qt::color0, 1));
-    p.setBrush(Qt::NoBrush);
-    drawRubber(&p);
-    p.end();
-
     d->pressedMoved = true;
 
     if (changed)
@@ -1207,21 +1159,9 @@
     d->dragging = false;
     d->prevSelectedItems.clear();
 
-    if (d->rubber)
-    {
-        QPainter p;
-        p.begin( viewport() );
-        p.setRasterOp( NotROP );
-        p.setPen( QPen( Qt::color0, 1 ) );
-        p.setBrush( Qt::NoBrush );
-
-        drawRubber( &p );
-        p.end();
-
-        delete d->rubber;
-        d->rubber = 0;
-    }
-
+    if (d->rubber->isVisible())
+        d->rubber->hide();
+    
     if (e->buttons() == Qt::LeftButton)
     {
         if (d->pressedMoved)
--- trunk/extragear/graphics/digikam/digikam/iconview.h #688489:688490
@@ -133,8 +133,6 @@
     void appendContainer();
     void deleteContainers();
 
-    void drawRubber(QPainter* p);
-
     void itemClickedToOpen(IconItem* item);
 
     bool anchorIsBehind() const;



More information about the Digikam-devel mailing list