Logo Search packages:      
Sourcecode: basket version File versions  Download package

ItemMultipleDrag::ItemMultipleDrag ( Item item,
bool  cutting,
QWidget *  parent = 0,
const char *  name = 0 
)

ItemMultipleDrag

Definition at line 317 of file itemdrag.cpp.

References Item::color(), Item::fullPath(), Item::html(), Item::icon(), Item::movie(), Item::pixmap(), Item::text(), Item::title(), Item::type(), Item::url(), and Item::useFile().

 : KMultipleDrag(parent, name)
{
      KColorDrag *cDrag = 0;

      // We do it now because we're not sure when the file moving (in new ItemDrag) will be done:
      QString iconOfFile = ItemFactory::iconForURL(item->fullPath());

      /* Main format for item content */
      ItemDrag *itemDrag = new ItemDrag(item, cutting, 0);
      addDragObject(itemDrag);

      /* Alternative formats for item content */
      QTextDrag   *text;
      QTextDrag   *html;
      // To process Unknow item:
      QFile       *file;
      QString      line;
      QValueList<QString> *mimes;
      uint         i;
      Q_UINT32     size;
      QByteArray  *array = 0L;
      QStoredDrag *storedDrag = 0L;
      switch (item->type()) {
            case Item::Text:
                  addDragObject(new QTextDrag( item->text(), 0 ));
                  break;
            case Item::Html:
                  text = new QTextDrag(htmlToText(item->html()), 0);
                  html = new QTextDrag(item->html(), 0);
                  html->setSubtype("html");
                  addDragObject(text);
                  addDragObject(html);
                  // FIXME: Is it useful to also provie "application/x-qrichtext" MIME type to dorp in Rich Text editors?
                  break;
            case Item::Image:
                  addDragObject(new QImageDrag( item->pixmap()->convertToImage(), 0 ));
                  break;
            case Item::Link:
                  {
                        // Html version of the link:
                        html = new QTextDrag( QString("<a href=\"%1\">%2</a>").arg(item->url().prettyURL(), item->title()), 0 );
                        html->setSubtype("html");
                        // A version for Mozilla applications (convert "theUrl\ntheTitle" into UTF-16):
                        QString xMozUrl = item->title() + "\n" + item->url().prettyURL();
                        QByteArray baMozUrl;
                        QTextStream stream(baMozUrl, IO_WriteOnly);
                        stream.setEncoding(QTextStream::RawUnicode); // It's UTF16 (aka UCS2), but with the first two order bytes
                        stream << xMozUrl;
                        QStoredDrag *xMozUrlDrag = new QStoredDrag("text/x-moz-url");
                        xMozUrlDrag->setEncodedData(baMozUrl);
                        // OK: add them:
                        addDragObject(new KURLDrag( KURL::List(item->url()), 0, "" ));
                        addDragObject(html);
                        addDragObject(xMozUrlDrag);
                  }
                  break;
            case Item::Color:
                  addDragObject(cDrag = new KColorDrag( item->color(), 0 ));
                  addDragObject(new QTextDrag( item->color().name(), 0 ));
                  break;
            case Item::Animation:
            case Item::Sound:
            case Item::File:
            case Item::Launcher:
                  // Will be done below
                  break;
            case Item::Unknow:
                  file = new QFile(itemDrag->fullPath());
                  if (file->open(IO_ReadOnly)) {
                        QDataStream stream(file);
                        mimes = new QValueList<QString>;
                        // Get the MIME types names:
                        do {
                              stream >> line;
                              if (!line.isEmpty())
                                    mimes->append(line);
                        } while (!line.isEmpty());
                        // Add the streams:
                        for (i = 0; i < mimes->count(); ++i) {
                              // Get the size:
                              stream >> size;
                              // Allocate memory to retreive size bytes and store them:
                              array = new QByteArray(size);
                              stream.readRawBytes(array->data(), size);
                              // Creata and add the QDragObject:
                              storedDrag = new QStoredDrag(*(mimes->at(i)));
                              storedDrag->setEncodedData(*array);
                              addDragObject(storedDrag);
                              delete array; // FIXME: Should we?
                        }
                        file->close();
                  }
                  delete file;
                  break;
      }

      /* Alternative format (the path) for items stored in files */
      if (item->useFile() && item->type() != Item::Unknow) { // ... but not for Unknow objects since they are stored in an
            addDragObject( new KURLDrag(KURL(itemDrag->fullPath()), 0, "") );                          // internal format only

            if (cutting) {
                  // Warning: We're reusing variables...
                  QByteArray  arrayCut(2);
                  QStoredDrag *storedDragCut = new QStoredDrag("application/x-kde-cutselection");
                  arrayCut[0] = '1';
                  arrayCut[1] = 0;
                  storedDragCut->setEncodedData(arrayCut);
                  addDragObject(storedDragCut);
            }
      }

      /* Init icon that is shown during drag */
      QPixmap      icon;
      QImage       image; // For temporary scale purpose
      const int    iconSize = 22;
      const QPoint iconHotPoint = QPoint(-5, -7); //iconSize / 2;

      switch (item->type()) {
            case Item::Text:
                  icon = kapp->iconLoader()->loadIcon("text", KIcon::NoGroup, iconSize);
                  setPixmap(icon, iconHotPoint);
                  break;
            case Item::Html:
                  icon = kapp->iconLoader()->loadIcon("html", KIcon::NoGroup, iconSize);
                  setPixmap(icon, iconHotPoint);
                  break;
            case Item::Image:
                  image = item->pixmap()->convertToImage();
                  image = image.smoothScale(40, 30, QImage::ScaleMin);
                  icon = QPixmap(image);
                  setPixmap(icon, iconHotPoint);
                  break;
            case Item::Animation:
                  image = item->movie()->frameImage();
                  image = image.smoothScale(40, 30, QImage::ScaleMin);
                  icon = QPixmap(image);
                  setPixmap(icon, iconHotPoint);
                  break;
            case Item::Link:
                  icon = kapp->iconLoader()->loadIcon(item->icon(), KIcon::NoGroup, iconSize);
                  setPixmap(icon, iconHotPoint);
                  break;
            case Item::Color:
                  setPixmap(cDrag->pixmap(), cDrag->pixmapHotSpot());
                  break;
            case Item::Sound:
            case Item::File:
            case Item::Launcher:
                  icon = kapp->iconLoader()->loadIcon(iconOfFile, KIcon::NoGroup, iconSize);
                  setPixmap(icon, iconHotPoint);
                  break;
            case Item::Unknow:
                  icon = kapp->iconLoader()->loadIcon("unknown", KIcon::NoGroup, iconSize);
                  setPixmap(icon, iconHotPoint);
                  break;
      }
}


Generated by  Doxygen 1.6.0   Back to index