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

List:       kde-core-devel
Subject:    [patch] KdePrint::createPrintDialog() on non-X11
From:       Jaroslaw Staniek <js () iidea ! pl>
Date:       2008-07-07 23:39:05
Message-ID: 4872A919.404 () iidea ! pl
[Download RAW message or body]

For review.

Based on the fact that only X11 supports custom setting tabs in the print 
dialog (http://doc.trolltech.com/4.4/qabstractprintdialog.html#setOptionTabs)

On non-X11 tagets:
- do not build kcupsoptions*.{cpp|ui} and do not instantiate KCupsOptions*
   objects
- reparent widgets from QList<QWidget*> customTabs to the dialog even if we
   don't use them, to avoid leaks

Also:
- simplify the code by calling one overload of createPrintDialog() from another
- add more docs for non-X11 systems and about object ownership

-- 
regards / pozdrawiam, Jaroslaw Staniek
  Sponsored by OpenOffice Polska (http://www.openoffice.com.pl/en) to work on
  Kexi & KOffice (http://www.kexi.pl/en, http://www.koffice.org/kexi)
  KDE Libraries for MS Windows (http://windows.kde.org)

["cups_only_on_x11.patch" (text/plain)]

Index: kdeui/CMakeLists.txt
===================================================================
--- kdeui/CMakeLists.txt	(wersja 829263)
+++ kdeui/CMakeLists.txt	(kopia robocza)
@@ -65,9 +65,6 @@
  dialogs/kassistantdialog.cpp
  dialogs/kconfigdialog.cpp
  dialogs/kconfigdialogmanager.cpp
- dialogs/kcupsoptionswidget_p.cpp
- dialogs/kcupsoptionsjobwidget_p.cpp
- dialogs/kcupsoptionspageswidget_p.cpp
  dialogs/kbugreport.cpp
  dialogs/kdeprintdialog.cpp
  dialogs/kdialog.cpp
@@ -236,7 +233,10 @@
 )
 
 if (Q_WS_X11)
-    set(kdeui_LIB_SRCS ${kdeui_LIB_SRCS} util/kkeyserver_x11.cpp )
+    set(kdeui_LIB_SRCS ${kdeui_LIB_SRCS} util/kkeyserver_x11.cpp
+                                         dialogs/kcupsoptionswidget_p.cpp
+                                         dialogs/kcupsoptionsjobwidget_p.cpp
+                                         dialogs/kcupsoptionspageswidget_p.cpp )
 endif (Q_WS_X11)
 if (Q_WS_MAC)
     set(kdeui_LIB_SRCS ${kdeui_LIB_SRCS} util/kkeyserver_mac.cpp )
@@ -267,8 +267,6 @@
 endif(MINGW)
 
 set( kdeui_UI
-   dialogs/kcupsoptionspageswidget.ui
-   dialogs/kcupsoptionsjobwidget.ui
    dialogs/kpassworddialog.ui
    dialogs/knewpassworddialog.ui
    dialogs/kshortcutsdialog.ui
@@ -277,6 +275,12 @@
    sonnet/configui.ui
    )
 
+if (Q_WS_X11)
+    set( kdeui_UI ${kdeui_UI} dialogs/kcupsoptionspageswidget.ui
+                              dialogs/kcupsoptionsjobwidget.ui
+    )
+endif (Q_WS_X11)
+
 kde4_add_ui_files(kdeui_LIB_SRCS ${kdeui_UI} )
 
 
Index: kdeui/dialogs/kdeprintdialog.cpp
===================================================================
--- kdeui/dialogs/kdeprintdialog.cpp	(wersja 829263)
+++ kdeui/dialogs/kdeprintdialog.cpp	(kopia robocza)
@@ -21,8 +21,11 @@
  **/
 
 #include "kdeprintdialog.h"
+#ifdef Q_WS_X11
 #include "kcupsoptionspageswidget_p.h"
 #include "kcupsoptionsjobwidget_p.h"
+#endif
+
 #include "kdebug.h"
 #include "kdialog.h"
 #include "klocale.h"
@@ -31,25 +34,25 @@
 #include <QPrintDialog>
 
 QPrintDialog *KdePrint::createPrintDialog(QPrinter *printer,
-                                               const QList<QWidget*> &customTabs,
-                                               QWidget *parent)
+                                          const QList<QWidget*> &customTabs,
+                                          QWidget *parent)
 {
     QPrintDialog *dialog = new QPrintDialog( printer, parent );
+#ifdef Q_WS_X11
     KCupsOptionsPagesWidget *cupsOptionsPagesTab = new KCupsOptionsPagesWidget( \
                dialog );
     KCupsOptionsJobWidget *cupsOptionsJobTab = new KCupsOptionsJobWidget( dialog );
     dialog->setOptionTabs( QList<QWidget*>() << cupsOptionsPagesTab << \
cupsOptionsJobTab << customTabs ); +#else
+    foreach( QWidget* w, customTabs ) // reparent to avoid leaks
+        w->setParent( dialog );
+#endif
     dialog->setWindowTitle( KDialog::makeStandardCaption( i18nc( "@title:window", \
"Print" ) ) );  return dialog;
 }
 
 
 QPrintDialog *KdePrint::createPrintDialog(QPrinter *printer,
-                                               QWidget *parent)
+                                          QWidget *parent)
 {
-    QPrintDialog *dialog = new QPrintDialog( printer, parent );
-    KCupsOptionsPagesWidget *cupsOptionsPagesTab = new KCupsOptionsPagesWidget( \
                dialog );
-    KCupsOptionsJobWidget *cupsOptionsJobTab = new KCupsOptionsJobWidget( dialog );
-    dialog->setOptionTabs( QList<QWidget*>() << cupsOptionsPagesTab << \
                cupsOptionsJobTab );
-    dialog->setWindowTitle( KDialog::makeStandardCaption( i18nc( "@title:window", \
                "Print" ) ) );
-    return dialog;
+    return KdePrint::createPrintDialog(printer, QList<QWidget*>(), parent);
 }
Index: kdeui/dialogs/kdeprintdialog.h
===================================================================
--- kdeui/dialogs/kdeprintdialog.h	(wersja 829263)
+++ kdeui/dialogs/kdeprintdialog.h	(kopia robocza)
@@ -37,9 +37,13 @@
     /**
      * Creates a printer dialog for a QPrinter with the given custom widgets.
      *
-     * Note that the custom widgets will @b not be shown on Qt versions prior to
-     * 4.3.2.
+     * Note that the custom widgets are only supported on X11
+     * and will @b not be shown on Qt versions prior to 4.3.2.
+     * On non-X11 systems it is prederred to provide the widgets 
+     * within configuration dialog of the application.
      *
+     * Setting the widgets will transfer their ownership to the print dialog
+     * even on non-X11 systems.
      * The caller takes ownership of the dialog and is responsible
      * for deleting it.
      *
@@ -48,10 +52,11 @@
      * @param customTabs a list of custom widgets to show as tabs, the name printed \
                on the tab will
      *      be taken from the widgets windowTitle().
      * @see QWidget::setWindowTitle()
+     * @see QAbstractPrintDialog::setOptionTabs()
      */
     KDEUI_EXPORT QPrintDialog *createPrintDialog(QPrinter *printer,
-                                                      const QList<QWidget*> \
                &customTabs,
-                                                      QWidget *parent = 0);
+                                                 const QList<QWidget*> &customTabs,
+                                                 QWidget *parent = 0);
 
     /**
      * Creates a printer dialog for a QPrinter
@@ -63,7 +68,7 @@
      * @param parent the parent for the dialog
      */
     KDEUI_EXPORT QPrintDialog *createPrintDialog(QPrinter *printer,
-                                                      QWidget *parent = 0);
+                                                 QWidget *parent = 0);
 }
 
 



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

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