Using Existing Dialogs with QMotifDialog[ Previous: Using Custom QDialogs ] [ Home ] [ Next: Using Qt Main Window Classes ]As mentioned earlier, the Print dialog cannot be replaced until we have converted the View widget. The Print dialog will be removed once we have finished our migration, since we will use QPrinter instead. Based on this information, we decide that it is not worth replacing the Print dialog with a custom QDialog replacement. Instead, we will keep the Motif based dialog and use QMotifDialog to integrate the dialog with the application.
Modality RequirementsModality with QDialog is different from Motif. The QDialog::exec() function does not return until the dialog is finished. In Motif, modality is simply a property of the shell, and the application programmer must write QDialog::exec() style functionality if they want that behavior. Since we will be using QMotifDialog (which is a QDialog subclass), we will need to have an accept and a reject callback for each dialog we integrate with QMotifDialog. The predefined Motif dialogs have these already: the XmNokCallback and XmNcancelCallback callbacks. However, the Print dialog only has an accept callback (the XmdNprintCallback), but it does not have a reject callback. We need to add this. This is easily done. We add an XtCallbackList for the XmNcancelCallback callback in Xmd/PrintP.h:
XtCallbackList print_callback; XtCallbackList cancel_callback; We add the XmNcancelCallback callback to the list of resources for the XmdPrint widget class in Xmd/Print.c:
{ XmdNprintCallback, XmCCallback, XmRCallback, sizeof(XtCallbackList), XtOffsetOf( XmdPrintRec, print.print_callback ), XmRPointer, (XtPointer) NULL }, { XmNcancelCallback, XmCCallback, XmRCallback, sizeof(XtCallbackList), XtOffsetOf( XmdPrintRec, print.cancel_callback ), XmRPointer, (XtPointer) NULL } We need to activate this callback whenever we unmanage the widget and do not activate the print callback, which is in the do_help_cb() function:
do_help_cb(Widget button, Widget pw, XtPointer ignore) { XmdPrintWidget print = (XmdPrintWidget) pw; XmAnyCallbackStruct cb; cb.reason = XmCR_HELP; cb.event = NULL; XtCallCallbackList(pw, print -> manager.help_callback, (XtPointer) &cb); cb.reason = XmCR_CANCEL; XtCallCallbackList( pw, print->print.cancel_callback, (XtPointer) &cb ); XtUnmanageChild(pw); } ... and in the unmanage_cb() function:
unmanage_cb(Widget button, Widget pw, XtPointer ignore) { XmdPrintWidget print = (XmdPrintWidget) pw; XmAnyCallbackStruct cb; cb.reason = XmCR_CANCEL; cb.event = NULL; XtCallCallbackList( pw, print->print.cancel_callback, (XtPointer) &cb ); XtUnmanageChild(pw); }
Integrating the Print DialogNow that the Print dialog has the appropriate accept and reject callbacks, we can use QMotifDialog. First we need to include the QMotifDialog header in todo.cpp.
#include <qmotifdialog.h> We add a ShowPrintDialog() function which will create and execute the print dialog.
void ShowPrintDialog(Widget, XtPointer, XmPushButtonCallbackStruct *); We change the Print menu item callback to call the new ShowPrintDialog() function. We pass the top-level QMotifWidget, which we will use as the parent for the dialog.
XtAddCallback(file_menu[FILE_PRINT], XmNactivateCallback, (XtCallbackProc) ShowPrintDialog, (XtPointer) &toplevel); The ShowPrintDialog() function creates the Print dialog and executes it. We use the XmdNprintCallback callback to accept the dialog and the XmNcancelCallback callback to reject the dialog. We can do this easily by using the QMotifDialog::acceptCallback() and QMotifDialog::rejectCallback() functions, respectively. We also ensure that the print callback continues to call the Print() function as before.
void ShowPrintDialog(Widget, XtPointer client_data, XmPushButtonCallbackStruct *) { QMotifDialog dialog( (QWidget *) client_data ); (void) XtCreateWidget( "print dialog", xmdPrintWidgetClass, dialog.shell(), NULL, 0 ); // the print callback calls QMotifDialog::acceptCallback() XtAddCallback( dialog.dialog(), XmdNprintCallback, (XtCallbackProc) QMotifDialog::acceptCallback, &dialog ); // the cancel callback calls QMotifDialog::rejectCallback() XtAddCallback( dialog.dialog(), XmNcancelCallback, (XtCallbackProc) QMotifDialog::rejectCallback, &dialog ); // the print callback also calls the original Print() function XtAddCallback( dialog.dialog(), XmdNprintCallback, (XtCallbackProc) Print, NULL ); dialog.exec(); } After we build the project, the application runs and operates as expected. There is no visual or behavioral difference, even though the Print dialog is using QMotifDialog. [ Previous: Using Custom QDialogs ] [ Home ] [ Next: Using Qt Main Window Classes ]
|
Publicité
Best OfActualités les plus luesSemaine
Mois
Année
Le Qt Quarterly au hasardConserver la réactivité de l'IHMQt Quarterly est la revue trimestrielle proposée par Nokia et à destination des développeurs Qt. Ces articles d'une grande qualité technique sont rédigés par des experts Qt. Lire l'article.
CommunautéRessources
Liens utilesContact
Qt dans le magazine |
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 3.2 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com