• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
  • widgets
draglistbox.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  draglistbox.cpp - description
3  -------------------
4  begin : Sun May 29 2005
5  copyright : (C) 2005 by Jason Harris
6  email : kstars@30doradus.org
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "draglistbox.h"
19 
20 #include <QDragEnterEvent>
21 #include <QMimeData>
22 #include <QMouseEvent>
23 #include <QDropEvent>
24 
25 #include <klocale.h>
26 #include <kdebug.h>
27 
28 DragListBox::DragListBox( QWidget *parent, const char *name )
29  : KListWidget( parent ) {
30 
31  if ( name ) {
32  setObjectName( name );
33  }
34  setAcceptDrops( true );
35  leftButtonDown = false;
36 }
37 
38 DragListBox::~DragListBox() {}
39 
40 bool DragListBox::contains( const QString &s ) const {
41  QList<QListWidgetItem*> foundList = findItems( s, Qt::MatchExactly );
42  if ( foundList.isEmpty() ) return false;
43  else return true;
44 }
45 
46 void DragListBox::dragEnterEvent( QDragEnterEvent *evt )
47 {
48  if ( evt->mimeData()->hasText() ) {
49  evt->acceptProposedAction();
50  } else {
51  evt->ignore();
52  }
53 }
54 
55 void DragListBox::dragMoveEvent( QDragMoveEvent *evt )
56 {
57  if ( evt->mimeData()->hasText() ) {
58  evt->acceptProposedAction();
59  } else {
60  evt->ignore();
61  }
62 }
63 
64 void DragListBox::dropEvent( QDropEvent *evt ) {
65  QString text;
66 
67  if ( evt->mimeData()->hasText() ) {
68  text = evt->mimeData()->text();
69 
70  //Copy an item dragged from FieldPool to FieldList
71  //If we dragged an "Ignore" item from the FieldPool to the FieldList, then we don't
72  //need to insert the item, because FieldPool already has a persistent Ignore item.
73  if ( !( text == i18n("Ignore" ) && QString(evt->source()->objectName()) == "FieldList" &&
74  evt->source() != this )) {
75  QListWidgetItem *lwi = itemAt( evt->pos() );
76  if ( lwi == 0 && evt->pos().y() > visualItemRect(item(count()-1)).bottom() ) {
77  addItem( text );
78  } else {
79  int i = row( itemAt( evt->pos() ) );
80  insertItem( i, text );
81  }
82  }
83 
84  //Remove an item dragged from FieldList to FieldPool.
85  //If we dragged the "Ignore" item from FieldList to FieldPool, then we don't
86  //want to remove the item from the FieldPool
87  if ( !( text == i18n("Ignore" ) && QString(evt->source()->objectName()) == "FieldPool" &&
88  evt->source() != this ) ) {
89  DragListBox *fp = (DragListBox*)evt->source();
90  delete fp->takeItem( fp->currentRow() );
91  }
92  }
93  evt->acceptProposedAction();
94 }
95 
96 
97 void DragListBox::mousePressEvent( QMouseEvent *evt ) {
98  QListWidget::mousePressEvent( evt );
99 
100  if ( evt->button() == Qt::LeftButton ) {
101  leftButtonDown = true;
102  }
103 }
104 
105 void DragListBox::mouseReleaseEvent( QMouseEvent *evt ) {
106  QListWidget::mouseReleaseEvent( evt );
107 
108  if ( evt->button() == Qt::LeftButton ) {
109  leftButtonDown = false;
110  }
111 }
112 
113 void DragListBox::mouseMoveEvent( QMouseEvent *evt ) {
114 
115  if ( leftButtonDown ) {
116  leftButtonDown = false; //Don't create multiple QDrag objects!
117 
118  QDrag *drag = new QDrag( this );
119  QMimeData *mimeData = new QMimeData;
120  mimeData->setText( currentItem()->text() );
121  drag->setMimeData( mimeData );
122 
123  drag->exec();
124  evt->accept();
125  }
126 }
127 
128 #include "draglistbox.moc"
DragListBox::contains
bool contains(const QString &s) const
Definition: draglistbox.cpp:40
DragListBox::dropEvent
void dropEvent(QDropEvent *evt)
Definition: draglistbox.cpp:64
QWidget
DragListBox::mouseReleaseEvent
void mouseReleaseEvent(QMouseEvent *)
Definition: draglistbox.cpp:105
DragListBox
Extension of KListWidget that allows Drag-and-Drop with other DragListBoxes.
Definition: draglistbox.h:36
DragListBox::dragMoveEvent
void dragMoveEvent(QDragMoveEvent *evt)
Definition: draglistbox.cpp:55
DragListBox::mousePressEvent
void mousePressEvent(QMouseEvent *evt)
Definition: draglistbox.cpp:97
DragListBox::DragListBox
DragListBox(QWidget *parent=0, const char *name=0)
Default constructor.
Definition: draglistbox.cpp:28
draglistbox.h
DragListBox::mouseMoveEvent
void mouseMoveEvent(QMouseEvent *)
Definition: draglistbox.cpp:113
DragListBox::dragEnterEvent
void dragEnterEvent(QDragEnterEvent *evt)
Definition: draglistbox.cpp:46
KListWidget
QList
DragListBox::~DragListBox
~DragListBox()
Default destructor.
Definition: draglistbox.cpp:38
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

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

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal