__author__ = 'snake'

from PyQt4 import QtGui, QtCore


class SiteItems(QtGui.QListWidget):

    def __init__(self):
        super(SiteItems, self).__init__()

    def startDrag(self, dropAction):
        # create mime data object

        #get all selected items
        selitems = ""

        for i in self.selectedItems():
            selitems += i.text() + ","

        mime = QtCore.QMimeData()
        mime.setText(str(selitems).strip(","))
        # start drag
        drag = QtGui.QDrag(self)
        drag.setMimeData(mime)
        drag.start(QtCore.Qt.CopyAction | QtCore.Qt.CopyAction)

    def dragEnterEvent(self, event):
        if event.mimeData().hasText():
            event.accept()
        else:
            event.ignore()

    def dragMoveEvent(self, event):
        


    def dropEvent(self, event):
        if event.mimeData().hasText():
            sites =  event.mimeData().text()

            for site in sites.split(","):
                self.addItem(site)

            event.setDropAction(QtCore.Qt.CopyAction)
            event.accept()

        else:
            event.ignore()
if event.mimeData().hasText():
            event.setDropAction(QtCore.Qt.CopyAction)
            event.accept()
        else:
            event.ignore()