• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Plasma

customdragtreeview.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
00003  *
00004  *   This program is free software; you can redistribute it and/or modify
00005  *   it under the terms of the GNU Library/Lesser General Public License
00006  *   version 2, or (at your option) any later version, as published by the
00007  *   Free Software Foundation
00008  *
00009  *   This program is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details
00013  *
00014  *   You should have received a copy of the GNU Library/Lesser General Public
00015  *   License along with this program; if not, write to the
00016  *   Free Software Foundation, Inc.,
00017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018  */
00019 
00020 #include "customdragtreeview_p.h"
00021 #include "kcategorizeditemsview_p.h"
00022 
00023 #define PIX_SIZE 64
00024 #define MAX_OFFSET 16
00025 #define MAX_COUNT 5
00026 
00027 CustomDragTreeView::CustomDragTreeView(QWidget * parent)
00028     : QTreeView(parent) {}
00029 
00030 void CustomDragTreeView::startDrag(Qt::DropActions supportedActions)
00031 {
00032     Q_UNUSED(supportedActions);
00033 
00034     // TODO: calculate real size for pixmap - using the icon sizes, not fixed
00035     //       like now
00036 
00037     if (!m_view) {
00038         return;
00039     }
00040 
00041     QModelIndexList indexes = selectedIndexes();
00042     if (indexes.count() > 0) {
00043         QMimeData *data = model()->mimeData(indexes);
00044         if (!data) {
00045             return;
00046         }
00047 
00048         int size = PIX_SIZE + (qMin(MAX_COUNT, indexes.count()) * MAX_OFFSET);
00049         int off  = MAX_OFFSET;
00050         if (indexes.count() > MAX_COUNT) {
00051             off = (MAX_OFFSET * MAX_COUNT) / indexes.count();
00052         }
00053 
00054         //kDebug() << "Size: " << size << " Off: " << off << "\n";
00055 
00056         QPixmap pixmap(size, size);
00057         pixmap.fill(QColor(255, 255, 255, 0)); // TODO: Transparent. Now it flickers when it's transparent
00058         QPainter painter(&pixmap);
00059         QRect rect(0, 0, PIX_SIZE, PIX_SIZE);
00060 
00061         foreach (const QModelIndex &index, indexes) {
00062             if (index.column() != 0) {
00063                 continue;
00064             }
00065 
00066             KCategorizedItemsViewModels::AbstractItem * item =
00067                 m_view->getItemByProxyIndex(index);
00068 
00069             if (item) {
00070                 rect.setSize(item->icon().actualSize(QSize(PIX_SIZE, PIX_SIZE)));
00071                 //painter.fillRect(rect, QBrush(QColor(255, 255, 255))); // TODO: Use global palettes
00072                 item->icon().paint(&painter, rect);
00073                 rect.moveTopLeft(rect.topLeft() + QPoint(off, off));
00074             }
00075         }
00076         painter.end();
00077 
00078         QDrag *drag = new QDrag(this);
00079         drag->setPixmap(pixmap);
00080         drag->setMimeData(data);
00081         drag->start(supportedActions);
00082         //drag->setHotSpot(d->pressedPosition - rect.topLeft());
00083         //if (drag->start(supportedActions) == Qt::MoveAction)
00084         //    d->clearOrRemove();
00085     }
00086 }
00087 

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal