[Kstars-devel] KDE/kdeedu/kstars/kstars

Jason Harris kstars at 30doradus.org
Sat Feb 17 04:29:20 CET 2007


SVN commit 634384 by harris:

Fix DragListBox, a custom widget used in the Add Catalog tool.  
It is now derived from KListWidget, rather than K3ListBox.

CCMAIL: kstars-devel at kde.org



 M  +12 -12    addcatdialog.cpp  
 M  +4 -4      addcatdialog.ui  
 M  +39 -27    widgets/draglistbox.cpp  
 M  +6 -5      widgets/draglistbox.h  


--- trunk/KDE/kdeedu/kstars/kstars/addcatdialog.cpp #634383:634384
@@ -54,17 +54,17 @@
 	connect( acd->PreviewButton, SIGNAL( clicked() ), this, SLOT( slotPreviewCatalog() ) );
 	connect( this, SIGNAL( okClicked() ), this, SLOT( slotCreateCatalog() ) );
 
-	acd->FieldList->insertItem( i18n( "ID Number" ) );
-	acd->FieldList->insertItem( i18n( "Right Ascension" ) );
-	acd->FieldList->insertItem( i18n( "Declination" ) );
-	acd->FieldList->insertItem( i18n( "Object Type" ) );
+	acd->FieldList->addItem( i18n( "ID Number" ) );
+	acd->FieldList->addItem( i18n( "Right Ascension" ) );
+	acd->FieldList->addItem( i18n( "Declination" ) );
+	acd->FieldList->addItem( i18n( "Object Type" ) );
 
-	acd->FieldPool->insertItem( i18n( "Common Name" ) );
-	acd->FieldPool->insertItem( i18n( "Magnitude" ) );
-	acd->FieldPool->insertItem( i18n( "Major Axis" ) );
-	acd->FieldPool->insertItem( i18n( "Minor Axis" ) );
-	acd->FieldPool->insertItem( i18n( "Position Angle" ) );
-	acd->FieldPool->insertItem( i18n( "Ignore" ) );
+	acd->FieldPool->addItem( i18n( "Common Name" ) );
+	acd->FieldPool->addItem( i18n( "Magnitude" ) );
+	acd->FieldPool->addItem( i18n( "Major Axis" ) );
+	acd->FieldPool->addItem( i18n( "Minor Axis" ) );
+	acd->FieldPool->addItem( i18n( "Position Angle" ) );
+	acd->FieldPool->addItem( i18n( "Ignore" ) );
 	connect(this,SIGNAL(okClicked()),this,SLOT(slotOk()));
 	connect(this,SIGNAL(cancelClicked()),this,SLOT(slotCancel()));
 	connect(this,SIGNAL(helpClicked()),this,SLOT(slotHelp()));
@@ -156,7 +156,7 @@
 	h += QString("# ");
 
 	for ( uint i=0; i < acd->FieldList->count(); ++i ) {
-		QString f = acd->FieldList->text( i );
+		QString f = acd->FieldList->item( i )->text();
 
 		if ( f == i18n( "ID Number" ) ) {
 			h += "ID  ";
@@ -191,7 +191,7 @@
 	if ( ! acd->DataURL->url().isEmpty() && dataFile.open( QIODevice::ReadOnly ) ) {
 		acd->DataFileBox->clear();
 		QTextStream dataStream( &dataFile );
-		acd->DataFileBox->insertStringList( dataStream.readAll().split( "\n" ) );
+		acd->DataFileBox->addItems( dataStream.readAll().split( "\n" ) );
 		dataFile.close();
 	}
 }
--- trunk/KDE/kdeedu/kstars/kstars/addcatdialog.ui #634383:634384
@@ -45,7 +45,7 @@
        </widget>
       </item>
       <item>
-       <widget class="K3ListBox" name="DataFileBox" >
+       <widget class="KListWidget" name="DataFileBox" >
         <property name="enabled" >
          <bool>true</bool>
         </property>
@@ -297,7 +297,7 @@
  <customwidgets>
   <customwidget>
    <class>DragListBox</class>
-   <extends>K3ListBox</extends>
+   <extends>KListWidget</extends>
    <header>widgets/draglistbox.h</header>
    <container>0</container>
    <pixmap></pixmap>
@@ -338,9 +338,9 @@
    <pixmap></pixmap>
   </customwidget>
   <customwidget>
-   <class>K3ListBox</class>
+   <class>KListWidget</class>
    <extends></extends>
-   <header>k3listbox.h</header>
+   <header>klistwidget.h</header>
    <container>0</container>
    <pixmap></pixmap>
   </customwidget>
--- trunk/KDE/kdeedu/kstars/kstars/widgets/draglistbox.cpp #634383:634384
@@ -25,12 +25,13 @@
 
 #include "draglistbox.h"
 
-DragListBox::DragListBox( QWidget *parent, const char *name, Qt::WFlags f )
-		: K3ListBox( parent, name, f ) {
+DragListBox::DragListBox( QWidget *parent, const char *name )
+		: KListWidget( parent ) {
 
+	if ( name ) 
     setObjectName( name );
 	setAcceptDrops( true );
-	dragging = false;
+	leftButtonDown = false;
 }
 
 DragListBox::~DragListBox() {}
@@ -42,56 +43,67 @@
 }
 
 bool DragListBox::contains( const QString &s ) const {
-	for ( uint i=0; i<count(); ++i )
-		if ( text(i) == s ) return true;
-
-	return false;
+	QList<QListWidgetItem*> foundList = findItems( s, Qt::MatchExactly );
+	if ( foundList.isEmpty() ) return false;
+	else return true;
 }
 
 void DragListBox::dropEvent( QDropEvent *evt ) {
 	QString text;
 
-	int i = int( float(evt->pos().y())/float(itemHeight()) + 0.5 ) + topItem();
-	if ( i > int( count() ) + 1 ) i = count() + 1;
+	if ( evt->mimeData()->hasText() ) {
+		text = evt->mimeData()->text();
 
-	if ( Q3TextDrag::decode( evt, text ) ) {
-		//If we dragged an "Ignore" item from the FieldList to the FieldPool, then we don't
+		//Copy an item dragged from FieldPool to FieldList 
+		//If we dragged an "Ignore" item from the FieldPool to the FieldList, then we don't
 		//need to insert the item, because FieldPool already has a persistent Ignore item.
 		if ( !( text == i18n("Ignore" ) && QString(evt->source()->objectName()) == "FieldList" &&
 				evt->source() != this )) {
-			insertItem( text, i );
+			int i = indexAt( evt->pos() ).row();
+			insertItem( i, text );
 		}
 
-		//If we dragged the "Ignore" item from FieldPool to FieldList, then we don't
+		//Remove an item dragged from FieldList to FieldPool.
+		//If we dragged the "Ignore" item from FieldList to FieldPool, then we don't
 		//want to remove the item from the FieldPool
 		if ( !( text == i18n("Ignore" ) && QString(evt->source()->objectName()) == "FieldPool" &&
 				evt->source() != this ) ) {
 			DragListBox *fp = (DragListBox*)evt->source();
-			fp->removeItem( fp->currentItem() );
+			delete fp->takeItem( fp->currentRow() );
 		}
 	}
 }
 
 
 void DragListBox::mousePressEvent( QMouseEvent *evt ) {
-	Q3ListBox::mousePressEvent( evt );
-	dragging = true;
+	QListWidget::mousePressEvent( evt );
 
-	//Record position of the Ignore item; we may have to restore it.
-	if ( currentText() == i18n("Ignore") )
-		IgnoreIndex = currentItem();
-	else
-		IgnoreIndex = -1;
+	if ( evt->button() == Qt::LeftButton ) {
+		leftButtonDown = true;
+	}
 }
 
+void DragListBox::mouseReleaseEvent( QMouseEvent *evt ) {
+	QListWidget::mouseReleaseEvent( evt );
 
-void DragListBox::mouseMoveEvent( QMouseEvent * )
-{
-	if ( dragging ) {
-		Q3DragObject *drag = new Q3TextDrag( currentText(), this );
-		drag->dragMove();
-		dragging = false;
+	if ( evt->button() == Qt::LeftButton ) {
+		leftButtonDown = false;
 	}
 }
 
+void DragListBox::mouseMoveEvent( QMouseEvent *evt ) {
+
+	if ( leftButtonDown ) {
+		leftButtonDown = false; //Don't create multiple QDrag objects!
+
+		QDrag *drag = new QDrag( this );
+		QMimeData *mimeData = new QMimeData;
+		mimeData->setText( currentItem()->text() );
+		drag->setMimeData( mimeData );
+		
+		Qt::DropAction dropAction = drag->start();
+		evt->accept();
+	}
+}
+
 #include "draglistbox.moc"
--- trunk/KDE/kdeedu/kstars/kstars/widgets/draglistbox.h #634383:634384
@@ -18,7 +18,7 @@
 #ifndef DRAGLISTBOX_H
 #define DRAGLISTBOX_H
 
-#include <k3listbox.h>
+#include <klistwidget.h>
 //Added by qt3to4:
 #include <QDragEnterEvent>
 #include <QMouseEvent>
@@ -28,18 +28,18 @@
 class QDragDropEvent;
 
 /**@class DragListBox
-	*@short Extension of KListBox that allows Drag-and-Drop 
+	*@short Extension of KListWidget that allows Drag-and-Drop 
 	*with other DragListBoxes
 	*@author Jason Harris
 	*@version 1.0
 	*/
 
-class DragListBox : public K3ListBox {
+class DragListBox : public KListWidget {
 	Q_OBJECT
 public:
 /**@short Default constructor
  */
-	DragListBox( QWidget *parent = 0, const char *name = 0, Qt::WFlags = 0 );
+	DragListBox( QWidget *parent = 0, const char* name = 0 );
 
 /**@short Default destructor
  */
@@ -52,8 +52,9 @@
 	void dropEvent( QDropEvent *evt );
 	void mousePressEvent( QMouseEvent *evt );
 	void mouseMoveEvent( QMouseEvent * );
+	void mouseReleaseEvent( QMouseEvent * );
 private:
-	bool dragging;
+	bool leftButtonDown;
 	int IgnoreIndex;
 
 };


More information about the Kstars-devel mailing list