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

libplasma

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 "kcategorizeditemsview_p.h"
00021 
00022 #define PIX_SIZE 64
00023 #define MAX_OFFSET 16
00024 #define MAX_COUNT 5
00025 
00026 CustomDragTreeView::CustomDragTreeView(QWidget * parent)
00027     : QTreeView(parent) {}
00028 
00029 void CustomDragTreeView::startDrag ( Qt::DropActions supportedActions )
00030 {
00031     Q_UNUSED(supportedActions);
00032 
00033     // TODO: calculate real size for pixmap - using the icon sizes, not fixed
00034     //       like now
00035 
00036     if (!m_view) {
00037         return;
00038     }
00039 
00040     QModelIndexList indexes = selectedIndexes();
00041     if (indexes.count() > 0) {
00042         QMimeData *data = model()->mimeData(indexes);
00043         if (!data) {
00044             return;
00045         }
00046 
00047         int size = PIX_SIZE + (qMin(MAX_COUNT, indexes.count()) * MAX_OFFSET);
00048         int off  = MAX_OFFSET;
00049         if (indexes.count() > MAX_COUNT) {
00050             off = (MAX_OFFSET * MAX_COUNT) / indexes.count();
00051         }
00052 
00053         //kDebug() << "Size: " << size << " Off: " << off << "\n";
00054 
00055         QPixmap pixmap(size, size);
00056         pixmap.fill(QColor(255, 255, 255, 0)); // TODO: Transparent. Now it flickers when it's transparent
00057         QPainter painter(&pixmap);
00058         QRect rect(0, 0, PIX_SIZE, PIX_SIZE);
00059 
00060         foreach (const QModelIndex &index, indexes) {
00061             if (index.column() != 0) {
00062                 continue;
00063             }
00064 
00065             KCategorizedItemsViewModels::AbstractItem * item =
00066                 m_view->getItemByProxyIndex(index);
00067 
00068             if (item) {
00069                 rect.setSize(item->icon().actualSize(QSize(PIX_SIZE, PIX_SIZE)));
00070                 //painter.fillRect(rect, QBrush(QColor(255, 255, 255))); // TODO: Use global palettes
00071                 item->icon().paint(&painter, rect);
00072                 rect.moveTopLeft(rect.topLeft() + QPoint(off, off));
00073             }
00074         }
00075         painter.end();
00076 
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 

libplasma

Skip menu "libplasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libplasma
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
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