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

List:       kde-core-devel
Subject:    PATCH: KView
From:       Matthias Kretz <kretz () kde ! org>
Date:       2001-02-17 14:32:24
[Download RAW message or body]

Hi,

I never tested the "Desktop" functions in KView and they didn't work for 
KDE2.x. They rely on writing to the root window.

Therefore I changed the methods to us DCOP and tell KDesktop to use some 
other Background. The DCOP-code is copied from kcmbackground and adjusted to 
KView's needs.

Since the new documentation for KView says, that those functions do work, I'd 
say it should be commited!

-- 
        Matthias Kretz

---------------------------------------------------------------------
Matthias Kretz                                    Tel: +49 2771 35291
Nassaustr. 40                            Email: MatthiasKretz@gmx.net
35683 Dillenburg                                        kretz@kde.org
Germany                         http://www.Kretz.dyn.ns1.net/~mkretz/
---------------------------------------------------------------------

["kview.diff" (text/x-c)]

? .viewer.cpp.swp
Index: canvas.cpp
===================================================================
RCS file: /home/kde/kdegraphics/kview/canvas.cpp,v
retrieving revision 1.25
diff -u -3 -p -r1.25 canvas.cpp
--- canvas.cpp	2001/01/31 21:50:40	1.25
+++ canvas.cpp	2001/02/17 13:57:09
@@ -22,7 +22,12 @@
 #include <qbitmap.h>
 
 #include <kdebug.h>
+#include <dcopclient.h>
+#include <kapp.h>
+#include <kstddirs.h>
 
+#include <X11/Xlib.h>
+
 #include "canvas.h"
 
 static QString loadStdin();
@@ -190,47 +195,48 @@ void KImageCanvas::transformImage( const
 
 void KImageCanvas::tileToDesktop() const
 {
-
-  const QPixmap *image = _client->imagePix();
-
-  if( image == 0 ) {
-    return;
-  }
-
-  qApp->desktop()->setBackgroundPixmap( *image );
+  setDesktopBackground( 2 );
 }
 
 void KImageCanvas::maxToDesktop() const
 {
-  if( _client->imagePix() == 0 )
-    return;
-  
-  QPixmap image = *( _client->imagePix() );
-
-  int h = qApp->desktop()->height();
-  int w = qApp->desktop()->width();
-
-  image.convertFromImage( image.convertToImage().smoothScale( w, h ) );
-
-  qApp->desktop()->setBackgroundPixmap( image );
-
+  setDesktopBackground( 5 );
 }
 
 void KImageCanvas::maxpectToDesktop() const
 {
+  setDesktopBackground( 4 );
+}
+
+void KImageCanvas::setDesktopBackground( int mode ) const
+{
   if( _client->imagePix() == 0 )
     return;
   
   QPixmap image = *( _client->imagePix() );
 
-  double dh = (double)qApp->desktop()->height() / (double)image.height();
-  double dw = (double)qApp->desktop()->width() / (double)image.width();
-  double d = ( dh < dw ? dh : dw );
-  
-  image.convertFromImage( image.convertToImage().smoothScale(
-    int( d*image.width() ), int( d*image.height() ) ) );
+  QString filename = kapp->dirs()->saveLocation( "data", "kview/" ) + "wallpaper.jpg";
+  image.save( filename, "JPEG" );
+
+  DCOPClient *client = kapp->dcopClient();
+  if( ! client->isAttached() )
+    client->attach();
+
+  int screen_number = 0;
+  if ( qt_xdisplay() )
+    screen_number = DefaultScreen( qt_xdisplay() );
+  QCString appname;
+  if ( screen_number == 0 )
+    appname = "kdesktop";
+  else
+    appname.sprintf( "kdesktop-screen-%d", screen_number );
+
+  QByteArray data;
+  QDataStream arg( data, IO_WriteOnly );
+  arg << filename;
+  arg << mode;
 
-  qApp->desktop()->setBackgroundPixmap( image );
+  client->send( appname, "KBackgroundIface", "setWallpaper(QString,int)", data );
 }
 
 static void maxpect( QWidget *dest, QPixmap *image )
Index: canvas.h
===================================================================
RCS file: /home/kde/kdegraphics/kview/canvas.h,v
retrieving revision 1.18
diff -u -3 -p -r1.18 canvas.h
--- canvas.h	2000/12/10 22:59:27	1.18
+++ canvas.h	2001/02/17 13:57:09
@@ -140,6 +140,12 @@ protected:
   */
   void setStatus( Error );
 
+  /**
+   * calls KDesktop via DCOP and tells it to
+   * use some other Background
+   */
+  void setDesktopBackground( int ) const;
+
 signals:
   /**
   *


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

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