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

List:       kde-commits
Subject:    KDE/kdegraphics/kolourpaint/lgpl/generic/widgets
From:       Clarence Dang <dang () kde ! org>
Date:       2007-09-26 2:28:06
Message-ID: 1190773686.824810.1248.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 717088 by dang:

* Add setSupportsAlpha()

* +TODO, debug changes


 M  +23 -4     kpColorCellsBase.cpp  
 M  +12 -0     kpColorCellsBase.h  


--- trunk/KDE/kdegraphics/kolourpaint/lgpl/generic/widgets/kpColorCellsBase.cpp \
#717087:717088 @@ -55,6 +55,7 @@
         shade = false;
         acceptDrags = false;
         cellsResizable = true;
+        supportsAlpha = true;
     }
 
     kpColorCellsBase *q;
@@ -78,6 +79,7 @@
     bool shade;
     bool acceptDrags;
     bool cellsResizable;
+    bool supportsAlpha;
     bool inMouse;
 };
 
@@ -187,6 +189,11 @@
     d->acceptDrags = _acceptDrags;
 }
 
+void kpColorCellsBase::setSupportsAlpha(bool yes)
+{
+    d->supportsAlpha = yes;
+}
+
 void kpColorCellsBase::setCellsResizable(bool yes)
 {
     d->cellsResizable = yes;
@@ -211,7 +218,7 @@
     tableItem->setData(Qt::BackgroundRole , QBrush(color));
 }
 
-void kpColorCellsBase::setColor( int column, const QColor &color )
+void kpColorCellsBase::setColor( int column, const QColor &colorIn )
 {
     const int tableRow = column / columnCount();
     const int tableColumn = column % columnCount();
@@ -219,6 +226,13 @@
     Q_ASSERT( tableRow >= 0 && tableRow < rowCount() );
     Q_ASSERT( tableColumn >= 0 && tableColumn < columnCount() );
 
+    QColor color = colorIn;
+    if (color.isValid ())
+    {
+        if (!d->supportsAlpha)
+            color = QColor (color.rgb ());
+    }
+
     d->colors[column] = color;
 
     QTableWidgetItem* tableItem = item(tableRow,tableColumn);
@@ -390,7 +404,7 @@
             #if DEBUG_KP_COLOR_CELLS_BASE
                kDebug () << "beginning drag from cell=" << cell;
             #endif
-               KColorMimeData::createDrag( d->colors[cell], \
this)->start(Qt::CopyAction | Qt::MoveAction); +               \
KColorMimeData::createDrag(d->colors[cell], this)->start(Qt::CopyAction | \
Qt::MoveAction);  #if DEBUG_KP_COLOR_CELLS_BASE
                kDebug () << "finished drag";
             #endif
@@ -426,6 +440,7 @@
                << " canDecode=" << KColorMimeData::canDecode(event->mimeData())
                << endl;
 #endif
+     // TODO: Disallow drag that isn't onto a cell.
      event->setAccepted( d->acceptDrags && KColorMimeData::canDecode( \
event->mimeData()));  if (event->isAccepted ())
          ::SetDropAction (this, event);
@@ -448,15 +463,19 @@
 void kpColorCellsBase::dropEvent( QDropEvent *event)
 {
      QColor c=KColorMimeData::fromMimeData(event->mimeData());
+
      const int dragSourceCell = event->source () == this ?
          positionToCell (d->mousePos, true) :
          -1;
 #if DEBUG_KP_COLOR_CELLS_BASE
      kDebug () << "kpColorCellsBase::dropEvent()"
-               << "color: rgb=" << (const int *) c.rgb () << "isValid=" << \
c.isValid() +               << "color: rgba=" << (const int *) c.rgba () << \
                "isValid=" << c.isValid()
                << "source=" << event->source () << "dragSourceCell=" << \
dragSourceCell;  #endif
      if( c.isValid()) {
+          if (!d->supportsAlpha)
+            c = QColor (c.rgb ());
+
           ::SetDropAction (this, event);
 
           int cell = positionToCell(event->pos(), true, true/*allow empty cell*/);
@@ -476,7 +495,7 @@
 
     #if DEBUG_KP_COLOR_CELLS_BASE
           kDebug () << "\tdropAction=" << event->dropAction ()
-                    << "destOldColor=" << (const int *) destOldColor.rgb ();
+                    << "destOldColor.rgba=" << (const int *) destOldColor.rgba ();
     #endif
           if (event->dropAction () == Qt::MoveAction && dragSourceCell != -1) {
               setColor(dragSourceCell, destOldColor);
--- trunk/KDE/kdegraphics/kolourpaint/lgpl/generic/widgets/kpColorCellsBase.h \
#717087:717088 @@ -107,6 +107,18 @@
   void setShading(bool shade);
   void setAcceptDrags(bool acceptDrags);
 
+  /** Whether the alpha values (e.g. as passed to setColor() and received
+      from a drop) will be ignored for colors 
+      Default is false.
+
+      Call this in your constructor before you've set any colors.
+
+      Added for KolourPaint since none of the drawing routines support
+      alpha, other than pure transparency, which we don't currently
+      support drags/drops of, anyway (into the color cells).
+  */
+  void setSupportsAlpha(bool yes);
+
   /** Whether component cells should resize with the entire widget.
       Default is true.
 


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

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