Dragging now shows plasmoid icons instead of ItemViewDelegate painted items.
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=718817
This commit is contained in:
parent
2cc9877463
commit
8f9c48ce04
@ -22,6 +22,7 @@ set(plasma_LIB_SRCS
|
|||||||
appletbrowser/kcategorizeditemsviewdelegate.cpp
|
appletbrowser/kcategorizeditemsviewdelegate.cpp
|
||||||
appletbrowser/kcategorizeditemsviewmodels.cpp
|
appletbrowser/kcategorizeditemsviewmodels.cpp
|
||||||
appletbrowser/plasmaappletitemmodel.cpp
|
appletbrowser/plasmaappletitemmodel.cpp
|
||||||
|
appletbrowser/customdragtreeview.cpp
|
||||||
configxml.cpp
|
configxml.cpp
|
||||||
containment.cpp
|
containment.cpp
|
||||||
corona.cpp
|
corona.cpp
|
||||||
|
65
appletbrowser/customdragtreeview.cpp
Normal file
65
appletbrowser/customdragtreeview.cpp
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
#include "kcategorizeditemsview_p.h"
|
||||||
|
|
||||||
|
#define PIX_SIZE 64
|
||||||
|
#define MAX_OFFSET 16
|
||||||
|
#define MAX_COUNT 5
|
||||||
|
#define min(A, B) (((A) < (B)) ? (A) : (B))
|
||||||
|
|
||||||
|
CustomDragTreeView::CustomDragTreeView(QWidget * parent)
|
||||||
|
: QTreeView(parent) {};
|
||||||
|
|
||||||
|
void CustomDragTreeView::startDrag ( Qt::DropActions supportedActions )
|
||||||
|
{
|
||||||
|
Q_UNUSED(supportedActions);
|
||||||
|
|
||||||
|
// TODO: calculate real size for pixmap - using the icon sizes, not fixed
|
||||||
|
// like now
|
||||||
|
|
||||||
|
if (!m_view) return;
|
||||||
|
|
||||||
|
QModelIndexList indexes = selectedIndexes();
|
||||||
|
if (indexes.count() > 0) {
|
||||||
|
QMimeData *data = model()->mimeData(indexes);
|
||||||
|
if (!data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int size = PIX_SIZE + (min(MAX_COUNT, indexes.count()) * MAX_OFFSET);
|
||||||
|
int off = MAX_OFFSET;
|
||||||
|
if (indexes.count() > MAX_COUNT) {
|
||||||
|
off = (MAX_OFFSET * MAX_COUNT) / indexes.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
kDebug() << "Size: " << size << " Off: " << off << "\n";
|
||||||
|
|
||||||
|
QPixmap pixmap(size, size);
|
||||||
|
pixmap.fill(QColor(255, 255, 255, 0)); // TODO: Transparent. Now it flickers when it's transparent
|
||||||
|
QPainter painter(&pixmap);
|
||||||
|
QRect rect(0, 0, PIX_SIZE, PIX_SIZE);
|
||||||
|
|
||||||
|
foreach (QModelIndex index, indexes) {
|
||||||
|
if (index.column() == 1) continue;
|
||||||
|
|
||||||
|
KCategorizedItemsViewModels::AbstractItem * item =
|
||||||
|
m_view->getItemByProxyIndex(index);
|
||||||
|
|
||||||
|
if (item) {
|
||||||
|
rect.setSize(item->icon().actualSize(QSize(PIX_SIZE, PIX_SIZE)));
|
||||||
|
//painter.fillRect(rect, QBrush(QColor(255, 255, 255))); // TODO: Use global palettes
|
||||||
|
item->icon().paint(&painter, rect);
|
||||||
|
rect.moveTopLeft(rect.topLeft() + QPoint(off, off));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
painter.end();
|
||||||
|
|
||||||
|
|
||||||
|
QDrag *drag = new QDrag(this);
|
||||||
|
drag->setPixmap(pixmap);
|
||||||
|
drag->setMimeData(data);
|
||||||
|
drag->start(supportedActions);
|
||||||
|
//drag->setHotSpot(d->pressedPosition - rect.topLeft());
|
||||||
|
//if (drag->start(supportedActions) == Qt::MoveAction)
|
||||||
|
// d->clearOrRemove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
18
appletbrowser/customdragtreeview_p.h
Normal file
18
appletbrowser/customdragtreeview_p.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#include <QTreeView>
|
||||||
|
#include "kcategorizeditemsviewmodels_p.h"
|
||||||
|
|
||||||
|
class KCategorizedItemsView;
|
||||||
|
|
||||||
|
class CustomDragTreeView: public QTreeView
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CustomDragTreeView(QWidget * parent = 0);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void startDrag ( Qt::DropActions supportedActions );
|
||||||
|
|
||||||
|
private:
|
||||||
|
KCategorizedItemsView * m_view;
|
||||||
|
|
||||||
|
friend class KCategorizedItemsView;
|
||||||
|
};
|
@ -30,6 +30,8 @@ KCategorizedItemsView::KCategorizedItemsView(QWidget * parent, Qt::WindowFlags f
|
|||||||
m_modelItems(NULL), m_modelFilterItems(NULL), m_delegate(NULL)
|
m_modelItems(NULL), m_modelFilterItems(NULL), m_delegate(NULL)
|
||||||
{
|
{
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
|
itemsView->m_view = this;
|
||||||
|
|
||||||
textSearch->setClickMessage(i18n("Enter search phrase here"));
|
textSearch->setClickMessage(i18n("Enter search phrase here"));
|
||||||
|
|
||||||
connect(textSearch, SIGNAL(textChanged(QString)),
|
connect(textSearch, SIGNAL(textChanged(QString)),
|
||||||
|
@ -87,6 +87,7 @@ private:
|
|||||||
AbstractItem * getItemByProxyIndex(const QModelIndex & index) const;
|
AbstractItem * getItemByProxyIndex(const QModelIndex & index) const;
|
||||||
|
|
||||||
friend class KCategorizedItemsViewDelegate;
|
friend class KCategorizedItemsViewDelegate;
|
||||||
|
friend class CustomDragTreeView;
|
||||||
};
|
};
|
||||||
|
|
||||||
//Q_DECLARE_METATYPE(KCategorizedItemsView::Filter)
|
//Q_DECLARE_METATYPE(KCategorizedItemsView::Filter)
|
||||||
|
@ -83,7 +83,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTreeView" name="itemsView" >
|
<widget class="CustomDragTreeView" name="itemsView" >
|
||||||
<property name="frameShape" >
|
<property name="frameShape" >
|
||||||
<enum>QFrame::NoFrame</enum>
|
<enum>QFrame::NoFrame</enum>
|
||||||
</property>
|
</property>
|
||||||
@ -125,6 +125,11 @@
|
|||||||
<extends>QLineEdit</extends>
|
<extends>QLineEdit</extends>
|
||||||
<header>klineedit.h</header>
|
<header>klineedit.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>CustomDragTreeView</class>
|
||||||
|
<extends>QTreeView</extends>
|
||||||
|
<header>appletbrowser/customdragtreeview_p.h</header>
|
||||||
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<tabstops>
|
<tabstops>
|
||||||
<tabstop>comboFilters</tabstop>
|
<tabstop>comboFilters</tabstop>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user