[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdelibs/kdeprint/management
From:       Albert Astals Cid <tsdgeos () terra ! es>
Date:       2007-09-02 21:47:48
Message-ID: 1188769668.408080.27915.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 707776 by aacid:

Fix dropping items in jobs view prints them
Fix right click on job items shows menu
Fix connect


 M  +49 -31    kmjobviewer.cpp  
 M  +4 -3      kmjobviewer.h  


--- trunk/KDE/kdelibs/kdeprint/management/kmjobviewer.cpp #707775:707776
@@ -65,24 +65,54 @@
 class KJobListView : public QTreeWidget
 {
 public:
-	KJobListView( QWidget *parent = 0 );
+	KJobListView( KMJobViewer *parent );
 
 protected:
 	virtual void dragEnterEvent( QDragEnterEvent* );
+	virtual void dragMoveEvent( QDragMoveEvent* );
+	virtual bool dropMimeData ( QTreeWidgetItem * parent, int index, const QMimeData * \
data, Qt::DropAction action );  };
 
-KJobListView::KJobListView( QWidget *parent)
+KJobListView::KJobListView(KMJobViewer *parent)
 	: QTreeWidget( parent )
 {
 	setAcceptDrops( true );
+	setItemsExpandable( false );
+	setRootIsDecorated( false );
 }
 
 void KJobListView::dragEnterEvent( QDragEnterEvent *event )
 {
 	if ( KUrl::List::canDecode( event->mimeData() ) )
+	{
 		event->acceptProposedAction();
+	}
 }
 
+void KJobListView::dragMoveEvent ( QDragMoveEvent * event ) 
+{
+	if ( KUrl::List::canDecode( event->mimeData() ) )
+	{
+		event->acceptProposedAction();
+	}
+}
+
+bool KJobListView::dropMimeData ( QTreeWidgetItem *, int, const QMimeData * data, \
Qt::DropAction ) +{
+	QStringList files;
+	QString target;
+	
+	KUrl::List uris = KUrl::List::fromMimeData( data );
+	for ( KUrl::List::ConstIterator it = uris.begin();
+		it != uris.end(); ++it)
+	{
+		if ( KIO::NetAccess::download( *it, target, 0 ) )
+			files << target;
+	}
+	if (!files.isEmpty()) \
static_cast<KMJobViewer*>(parentWidget())->tryToPrintFiles(files); +	return true;
+}
+
 KMJobViewer::KMJobViewer(QWidget *parent)
 : KXmlGuiWindow(parent)
 {
@@ -240,16 +270,17 @@
 	if (!m_view)
 	{
 		m_view = new KJobListView(this);
-    QStringList headerLabels;
-    headerLabels << i18n("Job ID") << i18n("Owner") << i18n("Name")
-                 << i18nc("Status", "State") << i18n("Size (KB)") << \
                i18n("Page(s)");
-    m_view->setHeaderLabels(headerLabels);
-		connect( m_view, SIGNAL( dropped( QDropEvent*, QTreeWidgetItem* ) ), SLOT( \
slotDropped( QDropEvent*, QTreeWidgetItem* ) ) ); +		QStringList headerLabels;
+		headerLabels << i18n("Job ID") << i18n("Owner") << i18n("Name")
+		             << i18nc("Status", "State") << i18n("Size (KB)") << i18n("Page(s)");
+		m_view->setHeaderLabels(headerLabels);
+		m_view->installEventFilter(this);
 		KMFactory::self()->uiManager()->setupJobViewer(m_view);
 		m_view->setFrameStyle(QFrame::WinPanel|QFrame::Sunken);
 		m_view->setLineWidth(1);
+		m_view->setContextMenuPolicy(Qt::CustomContextMenu);
 		connect(m_view,SIGNAL(itemSelectionChanged ()),SLOT(slotSelectionChanged()));
-		connect(m_view,SIGNAL(rightButtonPressed(QTreeWidgetItem*,const \
QPoint&,int)),SLOT(slotRightClicked(QTreeWidgetItem*,const QPoint&,int))); \
+		connect(m_view,SIGNAL(customContextMenuRequested(const QPoint \
&)),SLOT(slotContextMenu(const QPoint&)));  setCentralWidget(m_view);
 	}
 
@@ -559,9 +590,9 @@
 	}
 }
 
-void KMJobViewer::slotRightClicked(QTreeWidgetItem*,const QPoint& p,int)
+void KMJobViewer::slotContextMenu(const QPoint& p)
 {
-	if (m_pop) m_pop->popup(p);
+	if (m_pop) m_pop->popup(m_view->viewport()->mapToGlobal(p));
 }
 
 void KMJobViewer::loadPrinters()
@@ -646,7 +677,7 @@
 	foreach (KAction* action, acts)
 	{
 		// connect the action to this
-		connect(action, SIGNAL(triggered(QAction*)), \
SLOT(pluginActionActivated(QAction*))); +		connect(action, SIGNAL(triggered()), \
SLOT(pluginActionActivated()));  
 		// should add it to the toolbar and menubar
 // 		action->plug(toolBar(), toolbarindex++);
@@ -711,9 +742,10 @@
 		e->accept();
 }
 
-void KMJobViewer::pluginActionActivated(QAction *action)
+void KMJobViewer::pluginActionActivated()
 {
-  const int ID = action->data().toInt();
+	QAction *action = qobject_cast<QAction *>(sender());
+	const int ID = action->data().toInt();
 
 	KMTimer::self()->hold();
 
@@ -768,25 +800,11 @@
 	return ( m_stickybox ? m_stickybox->isChecked() : false );
 }
 
-void KMJobViewer::slotDropped( QDropEvent *e, QTreeWidgetItem* )
+void KMJobViewer::tryToPrintFiles(const QStringList &files)
 {
-	QStringList files;
-	QString target;
-
-        KUrl::List uris = KUrl::List::fromMimeData( e->mimeData() );
-	for ( KUrl::List::ConstIterator it = uris.begin();
-	      it != uris.end(); ++it)
-	{
-		if ( KIO::NetAccess::download( *it, target, 0 ) )
-			files << target;
-	}
-
-	if ( files.count() > 0 )
-	{
-		KPrinter prt;
-		if ( prt.autoConfigure( m_prname, this ) )
-			prt.printFiles( files, false, false );
-	}
+	KPrinter prt;
+	if ( prt.autoConfigure( m_prname, this ) )
+		prt.printFiles( files, false, false );
 }
 
 #include "kmjobviewer.moc"
--- trunk/KDE/kdelibs/kdeprint/management/kmjobviewer.h #707775:707776
@@ -58,6 +58,8 @@
 	void refresh(bool reload = false);
 	QString printer() const;
 	bool isSticky() const;
+	
+	void tryToPrintFiles(const QStringList &files);
 
 Q_SIGNALS:
 	void jobsShown(KMJobViewer*, bool hasJobs);
@@ -66,7 +68,7 @@
 	void viewerDestroyed(KMJobViewer*);
 
 public Q_SLOTS:
-	void pluginActionActivated(QAction*);
+	void pluginActionActivated();
 
 protected Q_SLOTS:
 	void slotSelectionChanged();
@@ -74,7 +76,7 @@
 	void slotResume();
 	void slotRemove();
 	void slotRestart();
-	void slotRightClicked(QTreeWidgetItem*,const QPoint&,int);
+	void slotContextMenu(const QPoint&);
 	void slotMove(QAction*);
 	void slotPrinterSelected(QAction*);
 	void slotShowCompleted(bool);
@@ -85,7 +87,6 @@
 	void slotUserOnly(bool);
 	void slotUserChanged();
 	void slotConfigure();
-	void slotDropped( QDropEvent*, QTreeWidgetItem* );
 
 protected:
 	void init();


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic