From 0582c90a9ed4b965629267713f51c0da7c38b39d Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Wed, 4 Sep 2024 11:53:23 +0900 Subject: Rename remaining ntq[m-r]* related files to equivalent tq* (except ntqmodules.h) Signed-off-by: Michele Calgaro --- src/dialogs/ntqmessagebox.h | 223 ------ src/dialogs/ntqprintdialog.h | 103 --- src/dialogs/qmessagebox.cpp | 1664 --------------------------------------- src/dialogs/qprintdialog.cpp | 1677 ---------------------------------------- src/dialogs/qt_dialogs.pri | 8 +- src/dialogs/tqdialog.cpp | 4 +- src/dialogs/tqerrormessage.cpp | 2 +- src/dialogs/tqfiledialog.cpp | 2 +- src/dialogs/tqmessagebox.cpp | 1664 +++++++++++++++++++++++++++++++++++++++ src/dialogs/tqmessagebox.h | 223 ++++++ src/dialogs/tqprintdialog.cpp | 1677 ++++++++++++++++++++++++++++++++++++++++ src/dialogs/tqprintdialog.h | 103 +++ 12 files changed, 3675 insertions(+), 3675 deletions(-) delete mode 100644 src/dialogs/ntqmessagebox.h delete mode 100644 src/dialogs/ntqprintdialog.h delete mode 100644 src/dialogs/qmessagebox.cpp delete mode 100644 src/dialogs/qprintdialog.cpp create mode 100644 src/dialogs/tqmessagebox.cpp create mode 100644 src/dialogs/tqmessagebox.h create mode 100644 src/dialogs/tqprintdialog.cpp create mode 100644 src/dialogs/tqprintdialog.h (limited to 'src/dialogs') diff --git a/src/dialogs/ntqmessagebox.h b/src/dialogs/ntqmessagebox.h deleted file mode 100644 index abaf2576..00000000 --- a/src/dialogs/ntqmessagebox.h +++ /dev/null @@ -1,223 +0,0 @@ -/**************************************************************************** -** -** Definition of TQMessageBox class -** -** Created : 950503 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the dialogs module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQMESSAGEBOX_H -#define TQMESSAGEBOX_H - -#ifndef QT_H -#include "tqdialog.h" -#endif // QT_H - -#ifndef TQT_NO_MESSAGEBOX - -class TQLabel; -class TQPushButton; -struct TQMessageBoxData; - -class TQ_EXPORT TQMessageBox : public TQDialog -{ - TQ_OBJECT - TQ_ENUMS( Icon ) - TQ_PROPERTY( TQString text READ text WRITE setText ) - TQ_PROPERTY( Icon icon READ icon WRITE setIcon ) - TQ_PROPERTY( TQPixmap iconPixmap READ iconPixmap WRITE setIconPixmap ) - TQ_PROPERTY( TextFormat textFormat READ textFormat WRITE setTextFormat ) - -public: - enum Icon { NoIcon = 0, Information = 1, Warning = 2, Critical = 3, - Question = 4 }; - - TQMessageBox( TQWidget* parent=0, const char* name=0 ); - TQMessageBox( const TQString& caption, const TQString &text, Icon icon, - int button0, int button1, int button2, - TQWidget* parent=0, const char* name=0, bool modal=TRUE, - WFlags f=WStyle_DialogBorder ); - ~TQMessageBox(); - - enum { NoButton = 0, Ok = 1, Cancel = 2, Yes = 3, No = 4, Abort = 5, - Retry = 6, Ignore = 7, YesAll = 8, NoAll = 9, ButtonMask = 0xff, - Default = 0x100, Escape = 0x200, FlagMask = 0x300 }; - - static int information( TQWidget *parent, const TQString &caption, - const TQString& text, - int button0, int button1=0, int button2=0 ); - static int information( TQWidget *parent, const TQString &caption, - const TQString& text, - const TQString& button0Text = TQString::null, - const TQString& button1Text = TQString::null, - const TQString& button2Text = TQString::null, - int defaultButtonNumber = 0, - int escapeButtonNumber = -1 ); - - static int question( TQWidget *parent, const TQString &caption, - const TQString& text, - int button0, int button1=0, int button2=0 ); - static int question( TQWidget *parent, const TQString &caption, - const TQString& text, - const TQString& button0Text = TQString::null, - const TQString& button1Text = TQString::null, - const TQString& button2Text = TQString::null, - int defaultButtonNumber = 0, - int escapeButtonNumber = -1 ); - - static int warning( TQWidget *parent, const TQString &caption, - const TQString& text, - int button0, int button1, int button2=0 ); - static int warning( TQWidget *parent, const TQString &caption, - const TQString& text, - const TQString& button0Text = TQString::null, - const TQString& button1Text = TQString::null, - const TQString& button2Text = TQString::null, - int defaultButtonNumber = 0, - int escapeButtonNumber = -1 ); - - static int critical( TQWidget *parent, const TQString &caption, - const TQString& text, - int button0, int button1, int button2=0 ); - static int critical( TQWidget *parent, const TQString &caption, - const TQString& text, - const TQString& button0Text = TQString::null, - const TQString& button1Text = TQString::null, - const TQString& button2Text = TQString::null, - int defaultButtonNumber = 0, - int escapeButtonNumber = -1 ); - - static void about( TQWidget *parent, const TQString &caption, - const TQString& text ); - - static void aboutTQt( TQWidget *parent, - const TQString& caption=TQString::null ); - -/* OBSOLETE */ - static int message( const TQString &caption, - const TQString& text, - const TQString& buttonText=TQString::null, - TQWidget *parent=0, const char * =0 ) { - return TQMessageBox::information( parent, caption, text, - buttonText.isEmpty() - ? tr("OK") : buttonText ) == 0; - } - -/* OBSOLETE */ - static bool query( const TQString &caption, - const TQString& text, - const TQString& yesButtonText=TQString::null, - const TQString& noButtonText=TQString::null, - TQWidget *parent=0, const char * = 0 ) { - return TQMessageBox::information( parent, caption, text, - yesButtonText.isEmpty() - ? tr("OK") : yesButtonText, - noButtonText ) == 0; - } - - TQString text() const; - void setText( const TQString &); - - Icon icon() const; - - void setIcon( Icon ); - void setIcon( const TQPixmap & ); - - const TQPixmap *iconPixmap() const; - void setIconPixmap( const TQPixmap & ); - - TQString buttonText( int button ) const; - void setButtonText( int button, const TQString &); - - void adjustSize(); - -/* OBSOLETE */ - static TQPixmap standardIcon( Icon icon, GUIStyle ); - - static TQPixmap standardIcon( Icon icon ); - - TextFormat textFormat() const; - void setTextFormat( TextFormat ); - -protected: - void resizeEvent( TQResizeEvent * ); - void showEvent( TQShowEvent * ); - void closeEvent( TQCloseEvent * ); - void keyPressEvent( TQKeyEvent * ); - void styleChanged( TQStyle& ); - -private slots: - void buttonClicked(); - -private: - void init( int, int, int ); - int indexOf( int ) const; - void resizeButtons(); - TQLabel *label; - TQMessageBoxData *mbd; - void *reserved1; - void *reserved2; - -private: // Disabled copy constructor and operator= -#if defined(TQ_DISABLE_COPY) - TQMessageBox( const TQMessageBox & ); - TQMessageBox &operator=( const TQMessageBox & ); -#endif -}; - -/* -* Macro to be used at the beginning of main(), e.g. -* -* #include -* #include -* int main( int argc, char**argv ) -* { -* QT_REQUIRE_VERSION( argc, argv, "3.0.5" ) -* ... -* } -*/ -#define QT_REQUIRE_VERSION( argc, argv, str ) { TQString s=TQString::fromLatin1(str);\ -TQString sq=TQString::fromLatin1(tqVersion()); if ( (sq.section('.',0,0).toInt()<<16)+\ -(sq.section('.',1,1).toInt()<<8)+sq.section('.',2,2).toInt()<(s.section('.',0,0).toInt()<<16)+\ -(s.section('.',1,1).toInt()<<8)+s.section('.',2,2).toInt() ){if ( !tqApp){ int c=0; new \ -TQApplication(argc,argv);} TQString s = TQApplication::tr("Executable '%1' requires TQt "\ - "%2, found TQt %3.").arg(TQString::fromLatin1(tqAppName())).arg(TQString::fromLatin1(\ -str)).arg(TQString::fromLatin1(tqVersion()) ); TQMessageBox::critical( 0, TQApplication::tr(\ -"Incompatible TQt Library Error" ), s, TQMessageBox::Abort,0 ); tqFatal(s.ascii()); }} - - -#endif // TQT_NO_MESSAGEBOX - -#endif // TQMESSAGEBOX_H diff --git a/src/dialogs/ntqprintdialog.h b/src/dialogs/ntqprintdialog.h deleted file mode 100644 index 29824416..00000000 --- a/src/dialogs/ntqprintdialog.h +++ /dev/null @@ -1,103 +0,0 @@ -/**************************************************************************** -** -** Definition of print dialog. -** -** Created : 950829 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the dialogs module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQPRINTDIALOG_H -#define TQPRINTDIALOG_H - -#ifndef QT_H -#include "tqdialog.h" -#endif // QT_H - -#ifndef TQT_NO_PRINTDIALOG - -class TQGroupBox; -class TQPrintDialogPrivate; -class TQListView; - -class TQ_EXPORT TQPrintDialog : public TQDialog -{ - TQ_OBJECT -public: - TQPrintDialog( TQPrinter *, TQWidget* parent=0, const char* name=0 ); - ~TQPrintDialog(); - - static bool getPrinterSetup( TQPrinter *, TQWidget* = 0 ); - static void setGlobalPrintDialog( TQPrintDialog * ); - - void setPrinter( TQPrinter *, bool = FALSE ); - TQPrinter * printer() const; - - void addButton( TQPushButton *but ); - -private slots: - void browseClicked(); - void okClicked(); - - void printerOrFileSelected( int ); - void landscapeSelected( int ); - void paperSizeSelected( int ); - void orientSelected( int ); - void pageOrderSelected( int ); - void colorModeSelected( int ); - void setNumCopies( int ); - void printRangeSelected( int ); - void setFirstPage( int ); - void setLastPage( int ); - - void fileNameEditChanged( const TQString &text ); - -private: - TQPrintDialogPrivate *d; - - TQGroupBox * setupDestination(); - TQGroupBox * setupOptions(); - TQGroupBox * setupPaper(); - TQGroupBox * setupPrinterSettings(); - -private: // Disabled copy constructor and operator= -#if defined(TQ_DISABLE_COPY) - TQPrintDialog( const TQPrintDialog & ); - TQPrintDialog &operator=( const TQPrintDialog & ); -#endif -}; - -#endif - -#endif // TQPRINTDIALOG_H diff --git a/src/dialogs/qmessagebox.cpp b/src/dialogs/qmessagebox.cpp deleted file mode 100644 index 381a9f4f..00000000 --- a/src/dialogs/qmessagebox.cpp +++ /dev/null @@ -1,1664 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQMessageBox class -** -** Created : 950503 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the dialogs module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "ntqmessagebox.h" - -#ifndef TQT_NO_MESSAGEBOX - -#include "tqaccel.h" -#include "tqlabel.h" -#include "tqpushbutton.h" -#include "tqimage.h" -#include "ntqapplication.h" -#include "tqstyle.h" -#include "tqobjectlist.h" -#if defined(QT_ACCESSIBILITY_SUPPORT) -#include "tqaccessible.h" -#endif - -#ifdef TQ_WS_X11 -#include "private/tqttdeintegration_x11_p.h" -#endif - -extern bool tqt_use_native_dialogs; - -// Internal class - don't touch - -class TQMessageBoxLabel : public TQLabel -{ - TQ_OBJECT -public: - TQMessageBoxLabel( TQWidget* parent ) : TQLabel( parent, "messageBoxText") - { - setAlignment( AlignAuto|ExpandTabs ); - } -}; -#include "qmessagebox.moc" - - - -// the TQt logo, for aboutTQt -/* XPM */ -static const char * const qtlogo_xpm[] = { -/* width height ncolors chars_per_pixel */ -"50 50 17 1", -/* colors */ -" c #000000", -". c #495808", -"X c #2A3304", -"o c #242B04", -"O c #030401", -"+ c #9EC011", -"@ c #93B310", -"# c #748E0C", -"$ c #A2C511", -"% c #8BA90E", -"& c #99BA10", -"* c #060701", -"= c #181D02", -"- c #212804", -"; c #61770A", -": c #0B0D01", -"/ c None", -/* pixels */ -"/$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$/", -"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$", -"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$", -"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$", -"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$", -"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$", -"$$$$$$$$$$$$$$$$$$$$$$$+++$$$$$$$$$$$$$$$$$$$$$$$$", -"$$$$$$$$$$$$$$$$$$$@;.o=::=o.;@$$$$$$$$$$$$$$$$$$$", -"$$$$$$$$$$$$$$$$+#X* **X#+$$$$$$$$$$$$$$$$", -"$$$$$$$$$$$$$$$#oO* O **o#+$$$$$$$$$$$$$$", -"$$$$$$$$$$$$$&.* OO O*.&$$$$$$$$$$$$$", -"$$$$$$$$$$$$@XOO * OO X&$$$$$$$$$$$$", -"$$$$$$$$$$$@XO OO O **:::OOO OOO X@$$$$$$$$$$$", -"$$$$$$$$$$&XO O-;#@++@%.oOO X&$$$$$$$$$$", -"$$$$$$$$$$.O : *-#+$$$$$$$$+#- : O O*.$$$$$$$$$$", -"$$$$$$$$$#*OO O*.&$$$$$$$$$$$$+.OOOO **#$$$$$$$$$", -"$$$$$$$$+-OO O *;$$$$$$$$$$$&$$$$;* o+$$$$$$$$", -"$$$$$$$$#O* O .+$$$$$$$$$$@X;$$$+.O *#$$$$$$$$", -"$$$$$$$$X* -&$$$$$$$$$$@- :;$$$&- OX$$$$$$$$", -"$$$$$$$@*O *O#$$$$$$$$$$@oOO**;$$$# O*%$$$$$$$", -"$$$$$$$; -+$$$$$$$$$@o O OO ;+$$-O *;$$$$$$$", -"$$$$$$$. ;$$$$$$$$$@-OO OO X&$$;O .$$$$$$$", -"$$$$$$$o *#$$$$$$$$@o O O O-@$$$#O *o$$$$$$$", -"$$$$$$+= *@$$$$$$$@o* OO -@$$$$&: =$$$$$$$", -"$$$$$$+: :+$$$$$$@- *-@$$$$$$: :+$$$$$$", -"$$$$$$+: :+$$$$$@o* O *-@$$$$$$: :+$$$$$$", -"$$$$$$$= :@$$$$@o*OOO -@$$$$@: =+$$$$$$", -"$$$$$$$- O%$$$@o* O O O O-@$$$#* OX$$$$$$$", -"$$$$$$$. O *O;$$&o O*O* *O -@$$; O.$$$$$$$", -"$$$$$$$;* Oo+$$;O*O:OO-- Oo@+= *;$$$$$$$", -"$$$$$$$@* O O#$$$;*OOOo@@-O Oo;O* **@$$$$$$$", -"$$$$$$$$X* OOO-+$$$;O o@$$@- O O OX$$$$$$$$", -"$$$$$$$$#* * O.$$$$;X@$$$$@-O O O#$$$$$$$$", -"$$$$$$$$+oO O OO.+$$+&$$$$$$@-O o+$$$$$$$$", -"$$$$$$$$$#* **.&$$$$$$$$$$@o OO:#$$$$$$$$$", -"$$$$$$$$$+. O* O-#+$$$$$$$$+;O OOO:@$$$$$$$$$", -"$$$$$$$$$$&X *O -;#@++@#;=O O -@$$$$$$$$", -"$$$$$$$$$$$&X O O*O::::O OO Oo@$$$$$$$", -"$$$$$$$$$$$$@XOO OO O*X+$$$$$$", -"$$$$$$$$$$$$$&.* ** O :: *:#$$$$$$$", -"$$$$$$$$$$$$$$$#o*OO O Oo#@-OOO=#$$$$$$$$", -"$$$$$$$$$$$$$$$$+#X:* * O**X#+$$@-*:#$$$$$$$$$", -"$$$$$$$$$$$$$$$$$$$%;.o=::=o.#@$$$$$$@X#$$$$$$$$$$", -"$$$$$$$$$$$$$$$$$$$$$$$$+++$$$$$$$$$$$+$$$$$$$$$$$", -"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$", -"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$", -"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$", -"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$", -"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$", -"/$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$/", -}; - - -/*! - \class TQMessageBox - \brief The TQMessageBox class provides a modal dialog with a short message, an icon, and some buttons. - \ingroup dialogs - \mainclass - - Message boxes are used to provide informative messages and to ask - simple questions. - - TQMessageBox provides a range of different messages, arranged - roughly along two axes: severity and complexity. - - Severity is - \table - \row - \i \img qmessagebox-quest.png - \i Question - \i For message boxes that ask a question as part of normal - operation. Some style guides recommend using Information for this - purpose. - \row - \i \img qmessagebox-info.png - \i Information - \i For message boxes that are part of normal operation. - \row - \i \img qmessagebox-warn.png - \i Warning - \i For message boxes that tell the user about unusual errors. - \row - \i \img qmessagebox-crit.png - \i Critical - \i For message boxes that tell the user about critical errors. - \endtable - - The message box has a different icon for each of the severity levels. - - Complexity is one button (OK) for simple messages, or two or even - three buttons for questions. - - There are static functions for the most common cases. - - Examples: - - If a program is unable to find a supporting file, but can do perfectly - well without it: - - \code - TQMessageBox::information( this, "Application name", - "Unable to find the user preferences file.\n" - "The factory default will be used instead." ); - \endcode - - question() is useful for simple yes/no questions: - - \code - if ( TQFile::exists( filename ) && - TQMessageBox::question( - this, - tr("Overwrite File? -- Application Name"), - tr("A file called %1 already exists." - "Do you want to overwrite it?") - .arg( filename ), - tr("&Yes"), tr("&No"), - TQString::null, 0, 1 ) ) - return false; - \endcode - - warning() can be used to tell the user about unusual errors, or - errors which can't be easily fixed: - - \code - switch( TQMessageBox::warning( this, "Application name", - "Could not connect to the server.\n" - "This program can't function correctly " - "without the server.\n\n", - "Retry", - "Quit", 0, 0, 1 ) ) { - case 0: // The user clicked the Retry again button or pressed Enter - // try again - break; - case 1: // The user clicked the Quit or pressed Escape - // exit - break; - } - \endcode - - The text part of all message box messages can be either rich text - or plain text. If you specify a rich text formatted string, it - will be rendered using the default stylesheet. See - TQStyleSheet::defaultSheet() for details. With certain strings that - contain XML meta characters, the auto-rich text detection may - fail, interpreting plain text incorrectly as rich text. In these - rare cases, use TQStyleSheet::convertFromPlainText() to convert - your plain text string to a visually equivalent rich text string - or set the text format explicitly with setTextFormat(). - - Note that the Microsoft Windows User Interface Guidelines - recommend using the application name as the window's caption. - - Below are more examples of how to use the static member functions. - After these examples you will find an overview of the non-static - member functions. - - Exiting a program is part of its normal operation. If there is - unsaved data the user probably should be asked if they want to - save the data. For example: - - \code - switch( TQMessageBox::information( this, "Application name here", - "The document contains unsaved changes\n" - "Do you want to save the changes before exiting?", - "&Save", "&Discard", "Cancel", - 0, // Enter == button 0 - 2 ) ) { // Escape == button 2 - case 0: // Save clicked or Alt+S pressed or Enter pressed. - // save - break; - case 1: // Discard clicked or Alt+D pressed - // don't save but exit - break; - case 2: // Cancel clicked or Escape pressed - // don't exit - break; - } - \endcode - - The Escape button cancels the entire exit operation, and pressing - Enter causes the changes to be saved before the exit occurs. - - Disk full errors are unusual and they certainly can be hard to - correct. This example uses predefined buttons instead of - hard-coded button texts: - - \code - switch( TQMessageBox::warning( this, "Application name here", - "Could not save the user preferences,\n" - "because the disk is full. You can delete\n" - "some files and press Retry, or you can\n" - "abort the Save Preferences operation.", - TQMessageBox::Retry | TQMessageBox::Default, - TQMessageBox::Abort | TQMessageBox::Escape )) { - case TQMessageBox::Retry: // Retry clicked or Enter pressed - // try again - break; - case TQMessageBox::Abort: // Abort clicked or Escape pressed - // abort - break; - } - \endcode - - The critical() function should be reserved for critical errors. In - this example errorDetails is a TQString or const char*, and TQString - is used to concatenate several strings: - - \code - TQMessageBox::critical( 0, "Application name here", - TQString("An internal error occurred. Please ") + - "call technical support at 1234-56789 and report\n"+ - "these numbers:\n\n" + errorDetails + - "\n\nApplication will now exit." ); - \endcode - - In this example an OK button is displayed. - - TQMessageBox provides a very simple About box which displays an - appropriate icon and the string you provide: - - \code - TQMessageBox::about( this, "About ", - " is a \n\n" - "Copyright 1991-2003 Such-and-such. " - "\n\n" - "For technical support, call 1234-56789 or see\n" - "http://www.such-and-such.com/Application/\n" ); - \endcode - - See about() for more information. - - If you want your users to know that the application is built using - TQt (so they know that you use high quality tools) you might like - to add an "About TQt" menu option under the Help menu to invoke - aboutTQt(). - - If none of the standard message boxes is suitable, you can create a - TQMessageBox from scratch and use custom button texts: - - \code - TQMessageBox mb( "Application name here", - "Saving the file will overwrite the original file on the disk.\n" - "Do you really want to save?", - TQMessageBox::Information, - TQMessageBox::Yes | TQMessageBox::Default, - TQMessageBox::No, - TQMessageBox::Cancel | TQMessageBox::Escape ); - mb.setButtonText( TQMessageBox::Yes, "Save" ); - mb.setButtonText( TQMessageBox::No, "Discard" ); - switch( mb.exec() ) { - case TQMessageBox::Yes: - // save and exit - break; - case TQMessageBox::No: - // exit without saving - break; - case TQMessageBox::Cancel: - // don't save and don't exit - break; - } - \endcode - - TQMessageBox defines two enum types: Icon and an unnamed button type. - Icon defines the \c Question, \c Information, \c Warning, and \c - Critical icons for each GUI style. It is used by the constructor - and by the static member functions question(), information(), - warning() and critical(). A function called standardIcon() gives - you access to the various icons. - - The button types are: - \list - \i Ok - the default for single-button message boxes - \i Cancel - note that this is \e not automatically Escape - \i Yes - \i No - \i Abort - \i Retry - \i Ignore - \i YesAll - \i NoAll - \endlist - - Button types can be combined with two modifiers by using OR, '|': - \list - \i Default - makes pressing Enter equivalent to - clicking this button. Normally used with Ok, Yes or similar. - \i Escape - makes pressing Escape equivalent to clicking this button. - Normally used with Abort, Cancel or similar. - \endlist - - The text(), icon() and iconPixmap() functions provide access to the - current text and pixmap of the message box. The setText(), setIcon() - and setIconPixmap() let you change it. The difference between - setIcon() and setIconPixmap() is that the former accepts a - TQMessageBox::Icon and can be used to set standard icons, whereas the - latter accepts a TQPixmap and can be used to set custom icons. - - setButtonText() and buttonText() provide access to the buttons. - - TQMessageBox has no signals or slots. - - - - \sa TQDialog, - \link http://www.iarchitect.com/errormsg.htm - Isys on error messages \endlink, - \link guibooks.html#fowler GUI Design Handbook: Message Box \endlink -*/ - - -/*! - \enum TQMessageBox::Icon - - This enum has the following values: - - \value NoIcon the message box does not have any icon. - - \value Question an icon indicating that - the message is asking a question. - - \value Information an icon indicating that - the message is nothing out of the ordinary. - - \value Warning an icon indicating that the - message is a warning, but can be dealt with. - - \value Critical an icon indicating that - the message represents a critical problem. - -*/ - - -struct TQMessageBoxData { - TQMessageBoxData(TQMessageBox* parent) : - iconLabel( parent, "icon" ) - { - } - - int numButtons; // number of buttons - TQMessageBox::Icon icon; // message box icon - TQLabel iconLabel; // label holding any icon - int button[3]; // button types - int defButton; // default button (index) - int escButton; // escape button (index) - TQSize buttonSize; // button size - TQPushButton *pb[3]; // buttons -}; - -static const int LastButton = TQMessageBox::NoAll; - -/* - NOTE: The table of button texts correspond to the button enum. -*/ - -#ifndef Q_OS_TEMP -static const char * const mb_texts[] = { -#else -const char * mb_texts[] = { -#endif - 0, - TQT_TRANSLATE_NOOP("TQMessageBox","OK"), - TQT_TRANSLATE_NOOP("TQMessageBox","Cancel"), - TQT_TRANSLATE_NOOP("TQMessageBox","&Yes"), - TQT_TRANSLATE_NOOP("TQMessageBox","&No"), - TQT_TRANSLATE_NOOP("TQMessageBox","&Abort"), - TQT_TRANSLATE_NOOP("TQMessageBox","&Retry"), - TQT_TRANSLATE_NOOP("TQMessageBox","&Ignore"), - TQT_TRANSLATE_NOOP("TQMessageBox","Yes to &All"), - TQT_TRANSLATE_NOOP("TQMessageBox","N&o to All"), - 0 -}; - -/*! - Constructs a message box with no text and a button with the label - "OK". - - If \a parent is 0, the message box becomes an application-global - modal dialog box. If \a parent is a widget, the message box - becomes modal relative to \a parent. - - The \a parent and \a name arguments are passed to the TQDialog - constructor. -*/ - -TQMessageBox::TQMessageBox( TQWidget *parent, const char *name ) - : TQDialog( parent, name, TRUE, WStyle_Customize | WStyle_DialogBorder | WStyle_Title | WStyle_SysMenu ) -{ - init( Ok, 0, 0 ); -} - - -/*! - Constructs a message box with a \a caption, a \a text, an \a icon, - and up to three buttons. - - The \a icon must be one of the following: - \list - \i TQMessageBox::NoIcon - \i TQMessageBox::Question - \i TQMessageBox::Information - \i TQMessageBox::Warning - \i TQMessageBox::Critical - \endlist - - Each button, \a button0, \a button1 and \a button2, can have one - of the following values: - \list - \i TQMessageBox::NoButton - \i TQMessageBox::Ok - \i TQMessageBox::Cancel - \i TQMessageBox::Yes - \i TQMessageBox::No - \i TQMessageBox::Abort - \i TQMessageBox::Retry - \i TQMessageBox::Ignore - \i TQMessageBox::YesAll - \i TQMessageBox::NoAll - \endlist - - Use TQMessageBox::NoButton for the later parameters to have fewer - than three buttons in your message box. If you don't specify any - buttons at all, TQMessageBox will provide an Ok button. - - One of the buttons can be OR-ed with the \c TQMessageBox::Default - flag to make it the default button (clicked when Enter is - pressed). - - One of the buttons can be OR-ed with the \c TQMessageBox::Escape - flag to make it the cancel or close button (clicked when Escape is - pressed). - - Example: - \code - TQMessageBox mb( "Application Name", - "Hardware failure.\n\nDisk error detected\nDo you want to stop?", - TQMessageBox::Question, - TQMessageBox::Yes | TQMessageBox::Default, - TQMessageBox::No | TQMessageBox::Escape, - TQMessageBox::NoButton ); - if ( mb.exec() == TQMessageBox::No ) - // try again - \endcode - - If \a parent is 0, the message box becomes an application-global - modal dialog box. If \a parent is a widget, the message box - becomes modal relative to \a parent. - - If \a modal is TRUE the message box is modal; otherwise it - is modeless. - - The \a parent, \a name, \a modal, and \a f arguments are passed to - the TQDialog constructor. - - \sa setCaption(), setText(), setIcon() -*/ - -TQMessageBox::TQMessageBox( const TQString& caption, - const TQString &text, Icon icon, - int button0, int button1, int button2, - TQWidget *parent, const char *name, - bool modal, WFlags f ) - : TQDialog( parent, name, modal, f | WStyle_Customize | WStyle_DialogBorder | WStyle_Title | WStyle_SysMenu ) -{ - init( button0, button1, button2 ); -#ifndef TQT_NO_WIDGET_TOPEXTRA - setCaption( caption ); -#endif - setText( text ); - setIcon( icon ); -} - - -/*! - Destroys the message box. -*/ - -TQMessageBox::~TQMessageBox() -{ - delete mbd; -} - -static TQString * translatedTextAboutTQt = 0; - -void TQMessageBox::init( int button0, int button1, int button2 ) -{ - if ( !translatedTextAboutTQt ) { - translatedTextAboutTQt = new TQString; - - *translatedTextAboutTQt = tr( - "

About TQt

" - "

This program uses TQt version %1.

" - "

TQt is a C++ toolkit for multiplatform GUI & " - "application development.

" - "

TQt provides single-source " - "portability across MS Windows, Mac OS X, " - "Linux, and all major commercial Unix variants.

" - "

See https://trinitydesktop.org/docs/qt3/ " - "for more information.

" - ).arg( TQT_VERSION_STR ); - - } - label = new TQMessageBoxLabel( this ); - TQ_CHECK_PTR( label ); - - if ( (button2 && !button1) || (button1 && !button0) ) { -#if defined(QT_CHECK_RANGE) - tqWarning( "TQMessageBox: Inconsistent button parameters" ); -#endif - button0 = button1 = button2 = 0; - } - mbd = new TQMessageBoxData(this); - TQ_CHECK_PTR( mbd ); - mbd->icon = NoIcon; - mbd->iconLabel.setPixmap( TQPixmap() ); - mbd->numButtons = 0; - mbd->button[0] = button0; - mbd->button[1] = button1; - mbd->button[2] = button2; - mbd->defButton = -1; - mbd->escButton = -1; - int i; - for ( i=0; i<3; i++ ) { - int b = mbd->button[i]; - if ( (b & Default) ) { - if ( mbd->defButton >= 0 ) { -#if defined(QT_CHECK_RANGE) - tqWarning( "TQMessageBox: There can be at most one " - "default button" ); -#endif - } else { - mbd->defButton = i; - } - } - if ( (b & Escape) ) { - if ( mbd->escButton >= 0 ) { -#if defined(QT_CHECK_RANGE) - tqWarning( "TQMessageBox: There can be at most one " - "escape button" ); -#endif - } else { - mbd->escButton = i; - } - } - b &= ButtonMask; - if ( b == 0 ) { - if ( i == 0 ) // no buttons, add an Ok button - b = Ok; - } else if ( b < 0 || b > LastButton ) { -#if defined(QT_CHECK_RANGE) - tqWarning( "TQMessageBox: Invalid button specifier" ); -#endif - b = Ok; - } else { - if ( i > 0 && mbd->button[i-1] == 0 ) { -#if defined(QT_CHECK_RANGE) - tqWarning( "TQMessageBox: Inconsistent button parameters; " - "button %d defined but not button %d", - i+1, i ); -#endif - b = 0; - } - } - mbd->button[i] = b; - if ( b ) - mbd->numButtons++; - } - for ( i=0; i<3; i++ ) { - if ( i >= mbd->numButtons ) { - mbd->pb[i] = 0; - } else { - TQCString buttonName; - buttonName.sprintf( "button%d", i+1 ); - mbd->pb[i] = new TQPushButton( - tr(mb_texts[mbd->button[i]]), - this, buttonName ); - if ( mbd->defButton == i ) { - mbd->pb[i]->setDefault( TRUE ); - mbd->pb[i]->setFocus(); - } - mbd->pb[i]->setAutoDefault( TRUE ); - mbd->pb[i]->setFocusPolicy( TQWidget::StrongFocus ); - connect( mbd->pb[i], TQ_SIGNAL(clicked()), TQ_SLOT(buttonClicked()) ); - } - } - resizeButtons(); - reserved1 = reserved2 = 0; -} - - -int TQMessageBox::indexOf( int button ) const -{ - int index = -1; - for ( int i=0; inumButtons; i++ ) { - if ( mbd->button[i] == button ) { - index = i; - break; - } - } - return index; -} - - -void TQMessageBox::resizeButtons() -{ - int i; - TQSize maxSize; - for ( i=0; inumButtons; i++ ) { - TQSize s = mbd->pb[i]->sizeHint(); - maxSize.setWidth( TQMAX(maxSize.width(), s.width()) ); - maxSize.setHeight( TQMAX(maxSize.height(),s.height()) ); - } - mbd->buttonSize = maxSize; - for ( i=0; inumButtons; i++ ) - mbd->pb[i]->resize( maxSize ); -} - - -/*! - \property TQMessageBox::text - \brief the message box text to be displayed. - - The text will be interpreted either as a plain text or as rich - text, depending on the text format setting (\l - TQMessageBox::textFormat). The default setting is \c AutoText, i.e. - the message box will try to auto-detect the format of the text. - - The default value of this property is TQString::null. - - \sa textFormat -*/ -TQString TQMessageBox::text() const -{ - return label->text(); -} - - -void TQMessageBox::setText( const TQString &text ) -{ - label->setText( text ); -} - - -/*! - \property TQMessageBox::icon - \brief the message box's icon - - The icon of the message box can be one of the following predefined - icons: - \list - \i TQMessageBox::NoIcon - \i TQMessageBox::Question - \i TQMessageBox::Information - \i TQMessageBox::Warning - \i TQMessageBox::Critical - \endlist - - The actual pixmap used for displaying the icon depends on the - current \link TQWidget::style() GUI style\endlink. You can also set - a custom pixmap icon using the \l TQMessageBox::iconPixmap - property. The default icon is TQMessageBox::NoIcon. - - \sa iconPixmap -*/ - -TQMessageBox::Icon TQMessageBox::icon() const -{ - return mbd->icon; -} - -void TQMessageBox::setIcon( Icon icon ) -{ - setIconPixmap( standardIcon(icon) ); - mbd->icon = icon; -} - -/*! - \obsolete - - Returns the pixmap used for a standard icon. This - allows the pixmaps to be used in more complex message boxes. - \a icon specifies the required icon, e.g. TQMessageBox::Information, - TQMessageBox::Warning or TQMessageBox::Critical. - - \a style is unused. -*/ - -TQPixmap TQMessageBox::standardIcon( Icon icon, GUIStyle style) -{ - Q_UNUSED(style); - return TQMessageBox::standardIcon(icon); -} - - -/*! - Returns the pixmap used for a standard icon. This allows the - pixmaps to be used in more complex message boxes. \a icon - specifies the required icon, e.g. TQMessageBox::Question, - TQMessageBox::Information, TQMessageBox::Warning or - TQMessageBox::Critical. -*/ - -TQPixmap TQMessageBox::standardIcon( Icon icon ) -{ - TQPixmap pm; - switch ( icon ) { - case Information: - pm = TQApplication::style().stylePixmap( TQStyle::SP_MessageBoxInformation ); - break; - case Warning: - pm = TQApplication::style().stylePixmap( TQStyle::SP_MessageBoxWarning ); - break; - case Critical: - pm = TQApplication::style().stylePixmap( TQStyle::SP_MessageBoxCritical ); - break; - case Question: - pm = TQApplication::style().stylePixmap( TQStyle::SP_MessageBoxQuestion ); - default: - break; - } - return pm; -} - - -/*! - \property TQMessageBox::iconPixmap - \brief the current icon - - The icon currently used by the message box. Note that it's often - hard to draw one pixmap that looks appropriate in both Motif and - Windows GUI styles; you may want to draw two pixmaps. - - \sa icon -*/ - -const TQPixmap *TQMessageBox::iconPixmap() const -{ - return mbd->iconLabel.pixmap(); -} - - -void TQMessageBox::setIconPixmap( const TQPixmap &pixmap ) -{ - mbd->iconLabel.setPixmap(pixmap); - mbd->icon = NoIcon; -} - - -/*! - Returns the text of the message box button \a button, or - TQString::null if the message box does not contain the button. - - \sa setButtonText() -*/ - -TQString TQMessageBox::buttonText( int button ) const -{ - int index = indexOf(button); - return index >= 0 && mbd->pb[index] - ? mbd->pb[index]->text() - : TQString::null; -} - - -/*! - Sets the text of the message box button \a button to \a text. - Setting the text of a button that is not in the message box is - silently ignored. - - \sa buttonText() -*/ - -void TQMessageBox::setButtonText( int button, const TQString &text ) -{ - int index = indexOf(button); - if ( index >= 0 && mbd->pb[index] ) { - mbd->pb[index]->setText( text ); - resizeButtons(); - } -} - - -/*! - \internal - Internal slot to handle button clicks. -*/ - -void TQMessageBox::buttonClicked() -{ - int reply = 0; - const TQObject *s = sender(); - for ( int i=0; inumButtons; i++ ) { - if ( mbd->pb[i] == s ) - reply = mbd->button[i]; - } - done( reply ); -} - - -/*! - Adjusts the size of the message box to fit the contents just before - TQDialog::exec() or TQDialog::show() is called. - - This function will not be called if the message box has been explicitly - resized before showing it. -*/ -void TQMessageBox::adjustSize() -{ - if ( !testWState(WState_Polished) ) - polish(); - resizeButtons(); - label->adjustSize(); - TQSize labelSize( label->size() ); - int n = mbd->numButtons; - int bw = mbd->buttonSize.width(); - int bh = mbd->buttonSize.height(); - int border = bh / 2 - style().pixelMetric(TQStyle::PM_ButtonDefaultIndicator); - if ( border <= 0 ) - border = 10; - int btn_spacing = 7; - if ( style().styleHint(TQStyle::SH_GUIStyle) == MotifStyle ) - btn_spacing = border; -#ifndef Q_OS_TEMP - int buttons = mbd->numButtons * bw + (n-1) * btn_spacing; - int h = bh; -#else - int visibleButtons = 0; - for ( int i = 0; i < mbd->numButtons; ++i ) - visibleButtons += mbd->pb[i]->isVisible() ? 1 : 0; - int buttons = visibleButtons == 0 ? 0 : visibleButtons * bw + (visibleButtons-1) * btn_spacing; - int h = visibleButtons == 0 ? 0 : bh; - n = visibleButtons; -#endif - if ( labelSize.height() ) - h += labelSize.height() + 3*border; - else - h += 2*border; - int lmargin = 0; - if ( mbd->iconLabel.pixmap() && mbd->iconLabel.pixmap()->width() ) { - mbd->iconLabel.adjustSize(); - lmargin += mbd->iconLabel.width() + border; - if ( h < mbd->iconLabel.height() + 3*border + bh && n ) - h = mbd->iconLabel.height() + 3*border + bh; - } - int w = TQMAX( buttons, labelSize.width() + lmargin ) + 2*border; - TQRect screen = TQApplication::desktop()->screenGeometry( pos() ); - if ( w > screen.width() ) - w = screen.width(); - resize( w, h ); - setMinimumSize( size() ); -#ifdef TQ_WS_MAC - setMaximumSize(size()); -#endif -} - - -/*!\reimp -*/ -void TQMessageBox::resizeEvent( TQResizeEvent * ) -{ - int i; - int n = mbd->numButtons; - int bw = mbd->buttonSize.width(); - int bh = mbd->buttonSize.height(); -#ifdef Q_OS_TEMP - int visibleButtons = 0; - for ( i = 0; i < n; ++i ) - visibleButtons += mbd->pb[i]->isVisible() ? 1 : 0; - n = visibleButtons; - bw = visibleButtons == 0 ? 0 : bw; - bh = visibleButtons == 0 ? 0 : bh; -#endif - int border = bh / 2 - style().pixelMetric(TQStyle::PM_ButtonDefaultIndicator); - if ( border <= 0 ) - border = 10; - int btn_spacing = 7; - if ( style().styleHint(TQStyle::SH_GUIStyle) == MotifStyle ) - btn_spacing = border; - int lmargin = 0; - mbd->iconLabel.adjustSize(); - bool rtl = TQApplication::reverseLayout(); - if (rtl) - mbd->iconLabel.move(width() - border - mbd->iconLabel.width(), border); - else - mbd->iconLabel.move(border, border); - if ( mbd->iconLabel.pixmap() && mbd->iconLabel.pixmap()->width() ) - lmargin += mbd->iconLabel.width() + border; - label->setGeometry((rtl ? 0 : lmargin) + border, - border, - width() - lmargin -2*border, - height() - 3*border - bh); - int extra_space = (width() - bw*n - 2*border - (n-1)*btn_spacing); - if ( style().styleHint(TQStyle::SH_GUIStyle) == MotifStyle ) - for ( i=0; ipb[rtl ? n - i - 1 : i]->move(border + i*bw + i*btn_spacing + extra_space*(i+1)/(n+1), - height() - border - bh ); - else - for ( i=0; ipb[rtl ? n - i - 1 : i]->move(border + i*bw + extra_space/2 + i*btn_spacing, - height() - border - bh ); -} - - -/*!\reimp -*/ -void TQMessageBox::keyPressEvent( TQKeyEvent *e ) -{ - if ( e->key() == Key_Escape ) { - if ( mbd->escButton >= 0 ) { - TQPushButton *pb = mbd->pb[mbd->escButton]; - pb->animateClick(); - e->accept(); - return; - } - } -#ifndef TQT_NO_ACCEL - if ( !( e->state() & AltButton ) ) { - TQObjectList *list = queryList( "TQPushButton" ); - TQObjectListIt it( *list ); - TQPushButton *pb; - while ( (pb = (TQPushButton*)it.current()) ) { - int key = e->key() & ~(MODIFIER_MASK|UNICODE_ACCEL); - int acc = pb->accel() & ~(MODIFIER_MASK|UNICODE_ACCEL); - if ( key && acc && acc == key ) { - delete list; - emit pb->animateClick(); - return; - } - ++it; - } - delete list; - } -#endif - TQDialog::keyPressEvent( e ); -} - -/*!\reimp -*/ -void TQMessageBox::showEvent( TQShowEvent *e ) -{ -#if defined(QT_ACCESSIBILITY_SUPPORT) - TQAccessible::updateAccessibility( this, 0, TQAccessible::Alert ); -#endif - TQDialog::showEvent( e ); -} - -/*!\reimp -*/ -void TQMessageBox::closeEvent( TQCloseEvent *e ) -{ - TQDialog::closeEvent( e ); - if ( mbd->escButton != -1 ) - setResult( mbd->button[mbd->escButton] ); -} - -/***************************************************************************** - Static TQMessageBox functions - *****************************************************************************/ - -/*!\fn int TQMessageBox::message( const TQString &,const TQString&,const TQString&,TQWidget*,const char * ) - \obsolete - Opens a modal message box directly using the specified parameters. - - Please use information(), warning(), question(), or critical() instead. -*/ - -/*! \fn bool TQMessageBox::query( const TQString &,const TQString&,const TQString&,const TQString&,TQWidget *, const char * ) - \obsolete - Queries the user using a modal message box with two buttons. - Note that \a caption is not always shown, it depends on the window manager. - - Please use information(), question(), warning(), or critical() instead. -*/ - -/*! - Opens an information message box with the caption \a caption and - the text \a text. The dialog may have up to three buttons. Each of - the buttons, \a button0, \a button1 and \a button2 may be set to - one of the following values: - - \list - \i TQMessageBox::NoButton - \i TQMessageBox::Ok - \i TQMessageBox::Cancel - \i TQMessageBox::Yes - \i TQMessageBox::No - \i TQMessageBox::Abort - \i TQMessageBox::Retry - \i TQMessageBox::Ignore - \i TQMessageBox::YesAll - \i TQMessageBox::NoAll - \endlist - - If you don't want all three buttons, set the last button, or last - two buttons to TQMessageBox::NoButton. - - One button can be OR-ed with \c TQMessageBox::Default, and one - button can be OR-ed with \c TQMessageBox::Escape. - - Returns the identity (TQMessageBox::Ok, or TQMessageBox::No, etc.) - of the button that was clicked. - - If \a parent is 0, the message box becomes an application-global - modal dialog box. If \a parent is a widget, the message box - becomes modal relative to \a parent. - - \sa question(), warning(), critical() -*/ - -int TQMessageBox::information( TQWidget *parent, - const TQString& caption, const TQString& text, - int button0, int button1, int button2 ) -{ -#if defined(TQ_WS_X11) - if ( tqt_use_native_dialogs && TQTDEIntegration::enabled()) - return TQTDEIntegration::information( parent, caption, text, button0, button1, button2 ); -#endif - TQMessageBox *mb = new TQMessageBox( caption, text, Information, - button0, button1, button2, - parent, "qt_msgbox_information", TRUE, - WDestructiveClose); - TQ_CHECK_PTR( mb ); - return mb->exec(); -} - -/*! - Opens a question message box with the caption \a caption and the - text \a text. The dialog may have up to three buttons. Each of the - buttons, \a button0, \a button1 and \a button2 may be set to one - of the following values: - - \list - \i TQMessageBox::NoButton - \i TQMessageBox::Ok - \i TQMessageBox::Cancel - \i TQMessageBox::Yes - \i TQMessageBox::No - \i TQMessageBox::Abort - \i TQMessageBox::Retry - \i TQMessageBox::Ignore - \i TQMessageBox::YesAll - \i TQMessageBox::NoAll - \endlist - - If you don't want all three buttons, set the last button, or last - two buttons to TQMessageBox::NoButton. - - One button can be OR-ed with \c TQMessageBox::Default, and one - button can be OR-ed with \c TQMessageBox::Escape. - - Returns the identity (TQMessageBox::Yes, or TQMessageBox::No, etc.) - of the button that was clicked. - - If \a parent is 0, the message box becomes an application-global - modal dialog box. If \a parent is a widget, the message box - becomes modal relative to \a parent. - - \sa information(), warning(), critical() -*/ - -int TQMessageBox::question( TQWidget *parent, - const TQString& caption, const TQString& text, - int button0, int button1, int button2 ) -{ -#if defined(TQ_WS_X11) - if ( tqt_use_native_dialogs && TQTDEIntegration::enabled()) - return TQTDEIntegration::question( parent, caption, text, button0, button1, button2 ); -#endif - TQMessageBox *mb = new TQMessageBox( caption, text, Question, - button0, button1, button2, - parent, "qt_msgbox_information", TRUE, - WDestructiveClose); - TQ_CHECK_PTR( mb ); - return mb->exec(); -} - - -/*! - Opens a warning message box with the caption \a caption and the - text \a text. The dialog may have up to three buttons. Each of the - button parameters, \a button0, \a button1 and \a button2 may be - set to one of the following values: - - \list - \i TQMessageBox::NoButton - \i TQMessageBox::Ok - \i TQMessageBox::Cancel - \i TQMessageBox::Yes - \i TQMessageBox::No - \i TQMessageBox::Abort - \i TQMessageBox::Retry - \i TQMessageBox::Ignore - \i TQMessageBox::YesAll - \i TQMessageBox::NoAll - \endlist - - If you don't want all three buttons, set the last button, or last - two buttons to TQMessageBox::NoButton. - - One button can be OR-ed with \c TQMessageBox::Default, and one - button can be OR-ed with \c TQMessageBox::Escape. - - Returns the identity (TQMessageBox::Ok, or TQMessageBox::No, etc.) - of the button that was clicked. - - If \a parent is 0, the message box becomes an application-global - modal dialog box. If \a parent is a widget, the message box - becomes modal relative to \a parent. - - \sa information(), question(), critical() -*/ - -int TQMessageBox::warning( TQWidget *parent, - const TQString& caption, const TQString& text, - int button0, int button1, int button2 ) -{ -#if defined(TQ_WS_X11) - if ( tqt_use_native_dialogs && TQTDEIntegration::enabled()) - return TQTDEIntegration::warning( parent, caption, text, button0, button1, button2 ); -#endif - TQMessageBox *mb = new TQMessageBox( caption, text, Warning, - button0, button1, button2, - parent, "qt_msgbox_warning", TRUE, - WDestructiveClose); - TQ_CHECK_PTR( mb ); - return mb->exec(); -} - - -/*! - Opens a critical message box with the caption \a caption and the - text \a text. The dialog may have up to three buttons. Each of the - button parameters, \a button0, \a button1 and \a button2 may be - set to one of the following values: - - \list - \i TQMessageBox::NoButton - \i TQMessageBox::Ok - \i TQMessageBox::Cancel - \i TQMessageBox::Yes - \i TQMessageBox::No - \i TQMessageBox::Abort - \i TQMessageBox::Retry - \i TQMessageBox::Ignore - \i TQMessageBox::YesAll - \i TQMessageBox::NoAll - \endlist - - If you don't want all three buttons, set the last button, or last - two buttons to TQMessageBox::NoButton. - - One button can be OR-ed with \c TQMessageBox::Default, and one - button can be OR-ed with \c TQMessageBox::Escape. - - Returns the identity (TQMessageBox::Ok, or TQMessageBox::No, etc.) - of the button that was clicked. - - If \a parent is 0, the message box becomes an application-global - modal dialog box. If \a parent is a widget, the message box - becomes modal relative to \a parent. - - \sa information(), question(), warning() -*/ - -int TQMessageBox::critical( TQWidget *parent, - const TQString& caption, const TQString& text, - int button0, int button1, int button2 ) -{ -#if defined(TQ_WS_X11) - if ( tqt_use_native_dialogs && TQTDEIntegration::enabled()) - return TQTDEIntegration::critical( parent, caption, text, button0, button1, button2 ); -#endif - TQMessageBox *mb = new TQMessageBox( caption, text, Critical, - button0, button1, button2, - parent, "qt_msgbox_critical", TRUE, - WDestructiveClose); - TQ_CHECK_PTR( mb ); - return mb->exec(); -} - - -/*! - Displays a simple about box with caption \a caption and text \a - text. The about box's parent is \a parent. - - about() looks for a suitable icon in four locations: - \list 1 - \i It prefers \link TQWidget::icon() parent->icon() \endlink if that exists. - \i If not, it tries the top-level widget containing \a parent. - \i If that fails, it tries the \link - TQApplication::mainWidget() main widget. \endlink - \i As a last resort it uses the Information icon. - \endlist - - The about box has a single button labelled "OK". - - \sa TQWidget::icon() TQApplication::mainWidget() -*/ - -void TQMessageBox::about( TQWidget *parent, const TQString &caption, - const TQString& text ) -{ - TQMessageBox *mb = new TQMessageBox( caption, text, - Information, - Ok + Default, 0, 0, - parent, "qt_msgbox_simple_about_box", TRUE, - WDestructiveClose); - TQ_CHECK_PTR( mb ); -#ifndef TQT_NO_WIDGET_TOPEXTRA - const TQPixmap *pm = parent ? parent->icon() : 0; - if ( pm && !pm->isNull() ) - mb->setIconPixmap( *pm ); - else { - pm = parent ? parent->topLevelWidget()->icon() : 0; - if ( pm && !pm->isNull() ) - mb->setIconPixmap( *pm ); - else { - pm = tqApp && tqApp->mainWidget() ? tqApp->mainWidget()->icon() : 0; - if ( pm && !pm->isNull() ) - mb->setIconPixmap( *pm ); - } - } -#endif - mb->exec(); -} - - -/*! \reimp -*/ - -void TQMessageBox::styleChanged( TQStyle& ) -{ - if ( mbd->icon != NoIcon ) { - // Reload icon for new style - setIcon( mbd->icon ); - } -} - - -static int textBox( TQWidget *parent, TQMessageBox::Icon severity, - const TQString& caption, const TQString& text, - const TQString& button0Text, - const TQString& button1Text, - const TQString& button2Text, - int defaultButtonNumber, - int escapeButtonNumber ) -{ - int b[3]; - b[0] = 1; - b[1] = button1Text.isEmpty() ? 0 : 2; - b[2] = button2Text.isEmpty() ? 0 : 3; - - int i; - for( i=0; i<3; i++ ) { - if ( b[i] && defaultButtonNumber == i ) - b[i] += TQMessageBox::Default; - if ( b[i] && escapeButtonNumber == i ) - b[i] += TQMessageBox::Escape; - } - - TQMessageBox *mb = new TQMessageBox( caption, text, severity, - b[0], b[1], b[2], - parent, "qt_msgbox_information", TRUE, - TQt::WDestructiveClose); - TQ_CHECK_PTR( mb ); - if ( button0Text.isEmpty() ) - mb->setButtonText( 1, TQMessageBox::tr(mb_texts[TQMessageBox::Ok]) ); - else - mb->setButtonText( 1, button0Text ); - if ( b[1] ) - mb->setButtonText( 2, button1Text ); - if ( b[2] ) - mb->setButtonText( 3, button2Text ); - -#ifndef TQT_NO_CURSOR - mb->setCursor( TQt::arrowCursor ); -#endif - return mb->exec() - 1; -} - - -/*! - \overload - - Displays an information message box with caption \a caption, text - \a text and one, two or three buttons. Returns the index of the - button that was clicked (0, 1 or 2). - - \a button0Text is the text of the first button, and is optional. - If \a button0Text is not supplied, "OK" (translated) will be used. - \a button1Text is the text of the second button, and is optional. - \a button2Text is the text of the third button, and is optional. - \a defaultButtonNumber (0, 1 or 2) is the index of the default - button; pressing Return or Enter is the same as clicking the - default button. It defaults to 0 (the first button). \a - escapeButtonNumber is the index of the Escape button; pressing - Escape is the same as clicking this button. It defaults to -1; - supply 0, 1 or 2 to make pressing Escape equivalent to clicking - the relevant button. - - If \a parent is 0, the message box becomes an application-global - modal dialog box. If \a parent is a widget, the message box - becomes modal relative to \a parent. - - Note: If you do not specify an Escape button then if the Escape - button is pressed then -1 will be returned. It is suggested that - you specify an Escape button to prevent this from happening. - - \sa question(), warning(), critical() -*/ - -int TQMessageBox::information( TQWidget *parent, const TQString &caption, - const TQString& text, - const TQString& button0Text, - const TQString& button1Text, - const TQString& button2Text, - int defaultButtonNumber, - int escapeButtonNumber ) -{ -#if defined(TQ_WS_X11) - if ( tqt_use_native_dialogs && TQTDEIntegration::enabled()) - return TQTDEIntegration::information( parent, caption, text, - button0Text, button1Text, button2Text, defaultButtonNumber, escapeButtonNumber ); -#endif - return textBox( parent, Information, caption, text, - button0Text, button1Text, button2Text, - defaultButtonNumber, escapeButtonNumber ); -} - -/*! - \overload - - Displays a question message box with caption \a caption, text \a - text and one, two or three buttons. Returns the index of the - button that was clicked (0, 1 or 2). - - \a button0Text is the text of the first button, and is optional. - If \a button0Text is not supplied, "OK" (translated) will be used. - \a button1Text is the text of the second button, and is optional. - \a button2Text is the text of the third button, and is optional. - \a defaultButtonNumber (0, 1 or 2) is the index of the default - button; pressing Return or Enter is the same as clicking the - default button. It defaults to 0 (the first button). \a - escapeButtonNumber is the index of the Escape button; pressing - Escape is the same as clicking this button. It defaults to -1; - supply 0, 1 or 2 to make pressing Escape equivalent to clicking - the relevant button. - - If \a parent is 0, the message box becomes an application-global - modal dialog box. If \a parent is a widget, the message box - becomes modal relative to \a parent. - - Note: If you do not specify an Escape button then if the Escape - button is pressed then -1 will be returned. It is suggested that - you specify an Escape button to prevent this from happening. - - \sa information(), warning(), critical() -*/ -int TQMessageBox::question( TQWidget *parent, const TQString &caption, - const TQString& text, - const TQString& button0Text, - const TQString& button1Text, - const TQString& button2Text, - int defaultButtonNumber, - int escapeButtonNumber ) -{ -#if defined(TQ_WS_X11) - if ( tqt_use_native_dialogs && TQTDEIntegration::enabled()) - return TQTDEIntegration::question( parent, caption, text, - button0Text, button1Text, button2Text, defaultButtonNumber, escapeButtonNumber ); -#endif - return textBox( parent, Question, caption, text, - button0Text, button1Text, button2Text, - defaultButtonNumber, escapeButtonNumber ); -} - - -/*! - \overload - - Displays a warning message box with a caption, a text, and 1, 2 or - 3 buttons. Returns the number of the button that was clicked (0, - 1, or 2). - - \a button0Text is the text of the first button, and is optional. - If \a button0Text is not supplied, "OK" (translated) will be used. - \a button1Text is the text of the second button, and is optional, - and \a button2Text is the text of the third button, and is - optional. \a defaultButtonNumber (0, 1 or 2) is the index of the - default button; pressing Return or Enter is the same as clicking - the default button. It defaults to 0 (the first button). \a - escapeButtonNumber is the index of the Escape button; pressing - Escape is the same as clicking this button. It defaults to -1; - supply 0, 1, or 2 to make pressing Escape equivalent to clicking - the relevant button. - - If \a parent is 0, the message box becomes an application-global - modal dialog box. If \a parent is a widget, the message box - becomes modal relative to \a parent. - - Note: If you do not specify an Escape button then if the Escape - button is pressed then -1 will be returned. It is suggested that - you specify an Escape button to prevent this from happening. - - \sa information(), question(), critical() -*/ - -int TQMessageBox::warning( TQWidget *parent, const TQString &caption, - const TQString& text, - const TQString& button0Text, - const TQString& button1Text, - const TQString& button2Text, - int defaultButtonNumber, - int escapeButtonNumber ) -{ -#if defined(TQ_WS_X11) - if ( tqt_use_native_dialogs && TQTDEIntegration::enabled()) - return TQTDEIntegration::warning( parent, caption, text, - button0Text, button1Text, button2Text, defaultButtonNumber, escapeButtonNumber ); -#endif - return textBox( parent, Warning, caption, text, - button0Text, button1Text, button2Text, - defaultButtonNumber, escapeButtonNumber ); -} - - -/*! - \overload - - Displays a critical error message box with a caption, a text, and - 1, 2 or 3 buttons. Returns the number of the button that was - clicked (0, 1 or 2). - - \a button0Text is the text of the first button, and is optional. - If \a button0Text is not supplied, "OK" (translated) will be used. - \a button1Text is the text of the second button, and is optional, - and \a button2Text is the text of the third button, and is - optional. \a defaultButtonNumber (0, 1 or 2) is the index of the - default button; pressing Return or Enter is the same as clicking - the default button. It defaults to 0 (the first button). \a - escapeButtonNumber is the index of the Escape button; pressing - Escape is the same as clicking this button. It defaults to -1; - supply 0, 1, or 2 to make pressing Escape equivalent to clicking - the relevant button. - - If \a parent is 0, the message box becomes an application-global - modal dialog box. If \a parent is a widget, the message box - becomes modal relative to \a parent. - - \sa information(), question(), warning() -*/ - -int TQMessageBox::critical( TQWidget *parent, const TQString &caption, - const TQString& text, - const TQString& button0Text, - const TQString& button1Text, - const TQString& button2Text, - int defaultButtonNumber, - int escapeButtonNumber ) -{ -#if defined(TQ_WS_X11) - if ( tqt_use_native_dialogs && TQTDEIntegration::enabled()) - return TQTDEIntegration::critical( parent, caption, text, - button0Text, button1Text, button2Text, defaultButtonNumber, escapeButtonNumber ); -#endif - return textBox( parent, Critical, caption, text, - button0Text, button1Text, button2Text, - defaultButtonNumber, escapeButtonNumber ); -} - - -/*! - Displays a simple message box about TQt, with caption \a caption - and centered over \a parent (if \a parent is not 0). The message - includes the version number of TQt being used by the application. - - This is useful for inclusion in the Help menu of an application. - See the examples/menu/menu.cpp example. - - TQApplication provides this functionality as a slot. - - \sa TQApplication::aboutTQt() -*/ - -void TQMessageBox::aboutTQt( TQWidget *parent, const TQString &caption ) -{ - TQMessageBox *mb = new TQMessageBox( parent, "qt_msgbox_about_qt" ); - TQ_CHECK_PTR( mb ); - mb->setWFlags( WDestructiveClose ); - -#ifndef TQT_NO_WIDGET_TOPEXTRA - TQString c = caption; - if ( c.isNull() ) - c = tr( "About TQt" ); - mb->setCaption( c ); -#endif - mb->setText( *translatedTextAboutTQt ); -#ifndef TQT_NO_IMAGEIO - TQPixmap pm; - TQImage logo( (const char **)qtlogo_xpm); - if ( tqGray(mb->palette().active().text().rgb()) > - tqGray(mb->palette().active().base().rgb()) ) - { - // light on dark, adjust some colors (where's 10?) - logo.setColor( 0, 0xffffffff ); - logo.setColor( 1, 0xff666666 ); - logo.setColor( 2, 0xffcccc66 ); - logo.setColor( 4, 0xffcccccc ); - logo.setColor( 6, 0xffffff66 ); - logo.setColor( 7, 0xff999999 ); - logo.setColor( 8, 0xff3333ff ); - logo.setColor( 9, 0xffffff33 ); - logo.setColor( 11, 0xffcccc99 ); - } - if ( pm.convertFromImage( logo ) ) - mb->setIconPixmap( pm ); -#endif - mb->setButtonText( 0, tr("OK") ); - if ( mb->mbd && mb->mbd->pb[0] ) { - mb->mbd->pb[0]->setAutoDefault( TRUE ); - mb->mbd->pb[0]->setFocusPolicy( TQWidget::StrongFocus ); - mb->mbd->pb[0]->setDefault( TRUE ); - mb->mbd->pb[0]->setFocus(); - } - mb->exec(); -} - -/*! - \reimp -*/ - -void TQMessageBox::setIcon( const TQPixmap &pix ) -{ - //reimplemented to avoid compiler warning. -#ifndef TQT_NO_WIDGET_TOPEXTRA - TQDialog::setIcon( pix ); -#endif -} - - -/*! - \property TQMessageBox::textFormat - \brief the format of the text displayed by the message box - - The current text format used by the message box. See the \l - TQt::TextFormat enum for an explanation of the possible options. - - The default format is \c AutoText. - - \sa setText() -*/ - -TQt::TextFormat TQMessageBox::textFormat() const -{ - return label->textFormat(); -} - - -void TQMessageBox::setTextFormat( TQt::TextFormat format ) -{ - label->setTextFormat( format ); -} - - -#endif diff --git a/src/dialogs/qprintdialog.cpp b/src/dialogs/qprintdialog.cpp deleted file mode 100644 index 9096ff9f..00000000 --- a/src/dialogs/qprintdialog.cpp +++ /dev/null @@ -1,1677 +0,0 @@ -/**************************************************************************** -** -** Implementation of internal print dialog (X11) used by TQPrinter::select(). -** -** Created : 950829 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the dialogs module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "ntqprintdialog.h" - -#ifndef TQT_NO_PRINTDIALOG - -#include "tqfiledialog.h" -#include "tqfile.h" -#include "tqtextstream.h" -#include "tqcombobox.h" -#include "tqframe.h" -#include "tqlabel.h" -#include "tqlineedit.h" -#include "tqpushbutton.h" -#include "tqprinter.h" -#include "tqlistview.h" -#include "tqlayout.h" -#include "tqbuttongroup.h" -#include "tqradiobutton.h" -#include "tqspinbox.h" -#include "ntqapplication.h" -#include "tqheader.h" -#include "tqstyle.h" -#include "tqstring.h" -#include "tqregexp.h" -#if !defined(TQT_NO_CUPS) || !defined(TQT_NO_NIS) -#include "tqlibrary.h" -#endif - -#ifndef TQT_NO_NIS - -#ifndef BOOL_DEFINED -#define BOOL_DEFINED -#endif - -#include -#include - -// Solaris redefines connect -> __xnet_connect with _XOPEN_SOURCE_EXTENDED. -#if defined(connect) -# undef connect -#endif - -#endif // TQT_NO_NIS - -// UNIX Large File Support redefines open -> open64 -#if defined(open) -# undef open -#endif - -#include -#include - - -class TQPrintDialogSpinBox : public TQSpinBox -{ -public: - TQPrintDialogSpinBox(int min, int max, int steps, TQWidget *parent, const char *name) - : TQSpinBox(min, max, steps, parent, name) - {} - - void interpretText() - { - TQSpinBox::interpretText(); - } -}; - - - - -enum { Success = 's', Unavail = 'u', NotFound = 'n', TryAgain = 't' }; -enum { Continue = 'c', Return = 'r' }; - -class TQPrintDialogPrivate -{ -public: - TQPrinter * printer; - - TQButtonGroup * printerOrFile; - - bool outputToFile; - TQListView * printers; - TQLineEdit * fileName; - TQPushButton * browse, *ok; - - TQButtonGroup * printRange; - TQLabel * firstPageLabel; - TQPrintDialogSpinBox * firstPage; - TQLabel * lastPageLabel; - TQPrintDialogSpinBox * lastPage; - TQRadioButton * printAllButton; - TQRadioButton * printRangeButton; - TQRadioButton * printSelectionButton; - TQRadioButton * printToFileButton; - TQComboBox *orientationCombo, *sizeCombo; - - TQPrinter::PageSize pageSize; - TQPrinter::Orientation orientation; - - TQButtonGroup * pageOrder; - TQPrinter::PageOrder pageOrder2; - - TQButtonGroup * colorMode; - TQPrinter::ColorMode colorMode2; - - TQPrintDialogSpinBox * copies; - int numCopies; - - TQBoxLayout *customLayout; - - TQPrinter::PageSize indexToPageSize[TQPrinter::NPageSize]; -}; - - -typedef void (*Q_PrintDialogHook)(TQListView *); -static Q_PrintDialogHook addPrinterHook = 0; - -void qt_set_printdialog_hook( Q_PrintDialogHook hook ) -{ - addPrinterHook = hook; -} - -static void isc( TQPrintDialogPrivate * d, const TQString & text, - TQPrinter::PageSize ps ); - -class TQPrinterListViewItem : public TQListViewItem -{ -public: - TQPrinterListViewItem( TQListView * printers, const TQString& name, - const TQString& host, const TQString& comment, - const TQStringList& aliases ) - : TQListViewItem( printers, name, host, comment ), ali( aliases ) { } - - bool samePrinter( const TQString& name ) { - return text( 0 ) == name || ali.find( name ) != ali.end(); - } - - TQStringList ali; -}; - -static void perhapsAddPrinter( TQListView * printers, const TQString &name, - TQString host, TQString comment, - TQStringList aliases = TQStringList() ) -{ - const TQListViewItem * i = printers->firstChild(); - while ( i && !((TQPrinterListViewItem *) i)->samePrinter(name) ) - i = i->nextSibling(); - if ( i ) - return; - if ( host.isEmpty() ) - host = TQPrintDialog::tr( "locally connected" ); - (void)new TQPrinterListViewItem( printers, - name.simplifyWhiteSpace(), - host.simplifyWhiteSpace(), - comment.simplifyWhiteSpace(), aliases ); -} - -static void parsePrinterDesc( TQString printerDesc, TQListView * printers ) -{ - if ( printerDesc.length() < 1 ) - return; - - printerDesc = printerDesc.simplifyWhiteSpace(); - int i = printerDesc.find( ':' ); - TQString printerName, printerComment, printerHost; - TQStringList aliases; - - if ( i >= 0 ) { - // have ':' want '|' - int j = printerDesc.find( '|' ); - if ( j > 0 && j < i ) { - printerName = printerDesc.left( j ); - aliases = TQStringList::split( '|', - printerDesc.mid(j + 1, i - j - 1) ); - // try extracting a comment from the aliases - printerComment = TQPrintDialog::tr( "Aliases: %1" ) - .arg( aliases.join(", ") ); - } else { - printerName = printerDesc.left( i ); - } - // look for lprng pseudo all printers entry - i = printerDesc.find( TQRegExp(TQString::fromLatin1(": *all *=")) ); - if ( i >= 0 ) - printerName = ""; - // look for signs of this being a remote printer - i = printerDesc.find( TQRegExp(TQString::fromLatin1(": *rm *=")) ); - if ( i >= 0 ) { - // point k at the end of remote host name - while ( printerDesc[i] != '=' ) - i++; - while ( printerDesc[i] == '=' || printerDesc[i].isSpace() ) - i++; - j = i; - while ( j < (int)printerDesc.length() && printerDesc[j] != ':' ) - j++; - - // and stuff that into the string - printerHost = printerDesc.mid( i, j - i ); - } - } - if ( printerName.length() ) - perhapsAddPrinter( printers, printerName, printerHost, printerComment, - aliases ); -} - -static int parsePrintcap( TQListView * printers, const TQString& fileName ) -{ - TQFile printcap( fileName ); - if ( !printcap.open( IO_ReadOnly ) ) - return NotFound; - - char * line_ascii = new char[1025]; - line_ascii[1024] = '\0'; - - TQString printerDesc; - bool atEnd = FALSE; - - while ( !atEnd ) { - if ( printcap.atEnd() || printcap.readLine( line_ascii, 1024 ) <= 0 ) - atEnd = TRUE; - TQString line = line_ascii; - line = line.stripWhiteSpace(); - if ( line.length() >= 1 && line[int(line.length()) - 1] == '\\' ) - line.truncate( line.length() - 1 ); - if ( line[0] == '#' ) { - if ( !atEnd ) - continue; - } else if ( line[0] == '|' || line[0] == ':' ) { - printerDesc += line; - if ( !atEnd ) - continue; - } - - parsePrinterDesc( printerDesc, printers ); - - // add the first line of the new printer definition - printerDesc = line; - } - delete[] line_ascii; - return Success; -} - - -// solaris, not 2.6 -static void parseEtcLpPrinters( TQListView * printers ) -{ - TQDir lp( TQString::fromLatin1("/etc/lp/printers") ); - const TQFileInfoList * dirs = lp.entryInfoList(); - if ( !dirs ) - return; - - TQFileInfoListIterator it( *dirs ); - TQFileInfo *printer; - TQString tmp; - while ( (printer = it.current()) != 0 ) { - ++it; - if ( printer->isDir() ) { - tmp.sprintf( "/etc/lp/printers/%s/configuration", - printer->fileName().ascii() ); - TQFile configuration( tmp ); - char * line = new char[1025]; - TQString remote( TQString::fromLatin1("Remote:") ); - TQString contentType( TQString::fromLatin1("Content types:") ); - TQString printerHost; - bool canPrintPostscript = FALSE; - if ( configuration.open( IO_ReadOnly ) ) { - while ( !configuration.atEnd() && - configuration.readLine( line, 1024 ) > 0 ) { - if ( TQString::fromLatin1(line).startsWith( remote ) ) { - const char * p = line; - while ( *p != ':' ) - p++; - p++; - while ( isspace((uchar) *p) ) - p++; - printerHost = TQString::fromLocal8Bit(p); - printerHost = printerHost.simplifyWhiteSpace(); - } else if ( TQString::fromLatin1(line).startsWith( contentType ) ) { - char * p = line; - while ( *p != ':' ) - p++; - p++; - char * e; - while ( *p ) { - while ( isspace((uchar) *p) ) - p++; - if ( *p ) { - char s; - e = p; - while ( isalnum((uchar) *e) ) - e++; - s = *e; - *e = '\0'; - if ( !qstrcmp( p, "postscript" ) || - !qstrcmp( p, "any" ) ) - canPrintPostscript = TRUE; - *e = s; - if ( s == ',' ) - e++; - p = e; - } - } - } - } - if ( canPrintPostscript ) - perhapsAddPrinter( printers, printer->fileName(), - printerHost, TQString::fromLatin1("") ); - } - delete[] line; - } - } -} - - -// solaris 2.6 -static char * parsePrintersConf( TQListView * printers, bool *found = 0 ) -{ - TQFile pc( TQString::fromLatin1("/etc/printers.conf") ); - if ( !pc.open( IO_ReadOnly ) ) { - if ( found ) - *found = FALSE; - return 0; - } - if ( found ) - *found = TRUE; - - char * line = new char[1025]; - line[1024] = '\0'; - - TQString printerDesc; - int lineLength = 0; - - char * defaultPrinter = 0; - - while ( !pc.atEnd() && - (lineLength=pc.readLine( line, 1024 )) > 0 ) { - if ( *line == '#' ) { - *line = '\0'; - lineLength = 0; - } - if ( lineLength >= 2 && line[lineLength-2] == '\\' ) { - line[lineLength-2] = '\0'; - printerDesc += TQString::fromLocal8Bit(line); - } else { - printerDesc += TQString::fromLocal8Bit(line); - printerDesc = printerDesc.simplifyWhiteSpace(); - int i = printerDesc.find( ':' ); - TQString printerName, printerHost, printerComment; - TQStringList aliases; - if ( i >= 0 ) { - // have : want | - int j = printerDesc.find( '|', 0 ); - if ( j >= i ) - j = -1; - printerName = printerDesc.mid( 0, j < 0 ? i : j ); - if ( printerName == TQString::fromLatin1("_default") ) { - i = printerDesc.find( - TQRegExp( TQString::fromLatin1(": *use *=") ) ); - while ( printerDesc[i] != '=' ) - i++; - while ( printerDesc[i] == '=' || printerDesc[i].isSpace() ) - i++; - j = i; - while ( j < (int)printerDesc.length() && - printerDesc[j] != ':' && printerDesc[j] != ',' ) - j++; - // that's our default printer - defaultPrinter = - tqstrdup( printerDesc.mid( i, j-i ).ascii() ); - printerName = ""; - printerDesc = ""; - } else if ( printerName == TQString::fromLatin1("_all") ) { - // skip it.. any other cases we want to skip? - printerName = ""; - printerDesc = ""; - } - - if ( j > 0 ) { - // try extracting a comment from the aliases - aliases = TQStringList::split( '|', - printerDesc.mid(j + 1, i - j - 1) ); - printerComment = TQPrintDialog::tr( "Aliases: %1" ) - .arg( aliases.join(", ") ); - } - // look for signs of this being a remote printer - i = printerDesc.find( - TQRegExp( TQString::fromLatin1(": *bsdaddr *=") ) ); - if ( i >= 0 ) { - // point k at the end of remote host name - while ( printerDesc[i] != '=' ) - i++; - while ( printerDesc[i] == '=' || printerDesc[i].isSpace() ) - i++; - j = i; - while ( j < (int)printerDesc.length() && - printerDesc[j] != ':' && printerDesc[j] != ',' ) - j++; - // and stuff that into the string - printerHost = printerDesc.mid( i, j-i ); - // maybe stick the remote printer name into the comment - if ( printerDesc[j] == ',' ) { - i = ++j; - while ( printerDesc[i].isSpace() ) - i++; - j = i; - while ( j < (int)printerDesc.length() && - printerDesc[j] != ':' && printerDesc[j] != ',' ) - j++; - if ( printerName != printerDesc.mid( i, j-i ) ) { - printerComment = - TQString::fromLatin1("Remote name: "); - printerComment += printerDesc.mid( i, j-i ); - } - } - } - } - if ( printerComment == ":" ) - printerComment = ""; // for cups - if ( printerName.length() ) - perhapsAddPrinter( printers, printerName, printerHost, - printerComment, aliases ); - // chop away the line, for processing the next one - printerDesc = ""; - } - } - delete[] line; - return defaultPrinter; -} - -#ifndef TQT_NO_NIS - -#if defined(Q_C_CALLBACKS) -extern "C" { -#endif - -static int foreach( int /* status */, char * /* key */, int /* keyLen */, - char * val, int valLen, char * data ) -{ - parsePrinterDesc( TQString::fromLatin1(val, valLen), (TQListView *) data ); - return 0; -} - -#if defined(Q_C_CALLBACKS) -} -#endif - -static int retrieveNisPrinters( TQListView * printers ) -{ - typedef int (*WildCast)( int, char *, int, char *, int, char * ); - char printersConfByname[] = "printers.conf.byname"; - char *domain; - int err; - - TQLibrary lib( "nsl" ); - typedef int (*ypGetDefaultDomain)(char **); - ypGetDefaultDomain _ypGetDefaultDomain = (ypGetDefaultDomain)lib.resolve( "yp_get_default_domain" ); - typedef int (*ypAll)(const char *, const char *, const struct ypall_callback *); - ypAll _ypAll = (ypAll)lib.resolve( "yp_all" ); - - if ( _ypGetDefaultDomain && _ypAll ) { - err = _ypGetDefaultDomain( &domain ); - if ( err == 0 ) { - ypall_callback cb; - // wild cast to support K&R-style system headers - (WildCast &) cb.foreach = (WildCast) foreach; - cb.data = (char *) printers; - err = _ypAll( domain, printersConfByname, &cb ); - } - if ( !err ) - return Success; - } - return Unavail; -} - -#endif // TQT_NO_NIS - -static char *parseNsswitchPrintersEntry( TQListView * printers, char *line ) -{ -#define skipSpaces() \ - while ( isspace((uchar) line[k]) ) \ - k++ - - char *defaultPrinter = 0; - bool stop = FALSE; - int lastStatus = NotFound; - - int k = 8; - skipSpaces(); - if ( line[k] != ':' ) - return 0; - k++; - - char *cp = strchr( line, '#' ); - if ( cp != 0 ) - *cp = '\0'; - - while ( line[k] != '\0' ) { - if ( isspace((uchar) line[k]) ) { - k++; - } else if ( line[k] == '[' ) { - k++; - skipSpaces(); - while ( line[k] != '\0' ) { - char status = tolower( line[k] ); - char action = '?'; - - while ( line[k] != '=' && line[k] != ']' && - line[k] != '\0' ) - k++; - if ( line[k] == '=' ) { - k++; - skipSpaces(); - action = tolower( line[k] ); - while ( line[k] != '\0' && !isspace((uchar) line[k]) && line[k] != ']' ) - k++; - } else if ( line[k] == ']' ) { - k++; - break; - } - skipSpaces(); - - if ( lastStatus == status ) - stop = ( action == (char) Return ); - } - } else { - if ( stop ) - break; - - TQCString source; - while ( line[k] != '\0' && !isspace((uchar) line[k]) && line[k] != '[' ) { - source += line[k]; - k++; - } - - if ( source == "user" ) { - lastStatus = parsePrintcap( printers, - TQDir::homeDirPath() + "/.printers" ); - } else if ( source == "files" ) { - bool found; - defaultPrinter = parsePrintersConf( printers, &found ); - if ( found ) - lastStatus = Success; -#ifndef TQT_NO_NIS - } else if ( source == "nis" ) { - lastStatus = retrieveNisPrinters( printers ); -#endif - } else { - // nisplus, dns, etc., are not implemented yet - lastStatus = NotFound; - } - stop = ( lastStatus == Success ); - } - } - return defaultPrinter; -} - -static char *parseNsswitchConf( TQListView * printers ) -{ - TQFile nc( TQString::fromLatin1("/etc/nsswitch.conf") ); - if ( !nc.open(IO_ReadOnly) ) - return 0; - - char *defaultPrinter = 0; - - char *line = new char[1025]; - line[1024] = '\0'; - - while ( !nc.atEnd() && - nc.readLine(line, 1024) > 0 ) { - if ( strncmp(line, "printers", 8) == 0 ) { - defaultPrinter = parseNsswitchPrintersEntry( printers, line ); - delete[] line; - return defaultPrinter; - } - } - - strcpy( line, "printers: user files nis nisplus xfn" ); - defaultPrinter = parseNsswitchPrintersEntry( printers, line ); - delete[] line; - return defaultPrinter; -} - -// HP-UX -static void parseEtcLpMember( TQListView * printers ) -{ - TQDir lp( TQString::fromLatin1("/etc/lp/member") ); - if ( !lp.exists() ) - return; - const TQFileInfoList * dirs = lp.entryInfoList(); - if ( !dirs ) - return; - - TQFileInfoListIterator it( *dirs ); - TQFileInfo *printer; - TQString tmp; - while ( (printer = it.current()) != 0 ) { - ++it; - // I haven't found any real documentation, so I'm guessing that - // since lpstat uses /etc/lp/member rather than one of the - // other directories, it's the one to use. I did not find a - // decent way to locate aliases and remote printers. - if ( printer->isFile() ) - perhapsAddPrinter( printers, printer->fileName(), - TQPrintDialog::tr("unknown"), - TQString::fromLatin1("") ); - } -} - -// IRIX 6.x -static void parseSpoolInterface( TQListView * printers ) -{ - TQDir lp( TQString::fromLatin1("/usr/spool/lp/interface") ); - if ( !lp.exists() ) - return; - const TQFileInfoList * files = lp.entryInfoList(); - if( !files ) - return; - - TQFileInfoListIterator it( *files ); - TQFileInfo *printer; - while ( (printer = it.current()) != 0) { - ++it; - - if ( !printer->isFile() ) - continue; - - // parse out some information - TQFile configFile( printer->filePath() ); - if ( !configFile.open( IO_ReadOnly ) ) - continue; - - TQCString line( 1025 ); - TQString namePrinter; - TQString hostName; - TQString hostPrinter; - TQString printerType; - - TQString nameKey( TQString::fromLatin1("NAME=") ); - TQString typeKey( TQString::fromLatin1("TYPE=") ); - TQString hostKey( TQString::fromLatin1("HOSTNAME=") ); - TQString hostPrinterKey( TQString::fromLatin1("HOSTPRINTER=") ); - - while ( !configFile.atEnd() && - (configFile.readLine(line.data(), 1024)) > 0 ) { - TQString uline = line; - if ( uline.startsWith( typeKey ) ) { - printerType = line.mid( nameKey.length() ); - printerType = printerType.simplifyWhiteSpace(); - } else if ( uline.startsWith( hostKey ) ) { - hostName = line.mid( hostKey.length() ); - hostName = hostName.simplifyWhiteSpace(); - } else if ( uline.startsWith( hostPrinterKey ) ) { - hostPrinter = line.mid( hostPrinterKey.length() ); - hostPrinter = hostPrinter.simplifyWhiteSpace(); - } else if ( uline.startsWith( nameKey ) ) { - namePrinter = line.mid( nameKey.length() ); - namePrinter = namePrinter.simplifyWhiteSpace(); - } - } - configFile.close(); - - printerType = printerType.stripWhiteSpace(); - if ( printerType.find("postscript", 0, FALSE) < 0 ) - continue; - - int ii = 0; - while ( (ii = namePrinter.find('"', ii)) >= 0 ) - namePrinter.remove( ii, 1 ); - - if ( hostName.isEmpty() || hostPrinter.isEmpty() ) { - perhapsAddPrinter( printers, printer->fileName(), - TQString::fromLatin1(""), namePrinter ); - } else { - TQString comment; - comment = namePrinter; - comment += " ("; - comment += hostPrinter; - comment += ")"; - perhapsAddPrinter( printers, printer->fileName(), - hostName, comment ); - } - } -} - - -// Every unix must have its own. It's a standard. Here is AIX. -static void parseQconfig( TQListView * printers ) -{ - TQFile qconfig( TQString::fromLatin1("/etc/qconfig") ); - if ( !qconfig.open( IO_ReadOnly ) ) - return; - - TQTextStream ts( &qconfig ); - TQString line; - - TQString stanzaName; // either a queue or a device name - bool up = TRUE; // queue up? default TRUE, can be FALSE - TQString remoteHost; // null if local - TQString deviceName; // null if remote - - TQRegExp newStanza( TQString::fromLatin1("^[0-z\\-]+:$") ); - - // our basic strategy here is to process each line, detecting new - // stanzas. each time we see a new stanza, we check if the - // previous stanza was a valid queue for a) a remote printer or b) - // a local printer. if it wasn't, we assume that what we see is - // the start of the first stanza, or that the previous stanza was - // a device stanza, or that there is some syntax error (we don't - // report those). - - do { - line = ts.readLine(); - bool indented = line[0].isSpace(); - line = line.simplifyWhiteSpace(); - - int i = line.find('='); - if ( indented && i != -1 ) { // line in stanza - TQString variable = line.left( i ).simplifyWhiteSpace(); - TQString value=line.mid( i+1, line.length() ).simplifyWhiteSpace(); - if ( variable == TQString::fromLatin1("device") ) - deviceName = value; - else if ( variable == TQString::fromLatin1("host") ) - remoteHost = value; - else if ( variable == TQString::fromLatin1("up") ) - up = !(value.lower() == TQString::fromLatin1("false")); - } else if ( line[0] == '*' ) { // comment - // nothing to do - } else if ( ts.atEnd() || // end of file, or beginning of new stanza - ( !indented && line.find( newStanza ) != -1 ) ) { - if ( up && stanzaName.length() > 0 && stanzaName.length() < 21 ) { - if ( remoteHost.length() ) // remote printer - perhapsAddPrinter( printers, stanzaName, remoteHost, - TQString::null ); - else if ( deviceName.length() ) // local printer - perhapsAddPrinter( printers, stanzaName, TQString::null, - TQString::null ); - } - line.truncate( line.length()-1 ); - if ( line.length() >= 1 && line.length() <= 20 ) - stanzaName = line; - up = TRUE; - remoteHost = TQString::null; - deviceName = TQString::null; - } else { - // syntax error? ignore. - } - } while ( !ts.atEnd() ); -} - - -#ifndef TQT_NO_CUPS -#include - -static char * parseCupsOutput( TQListView * printers ) -{ - char * defaultPrinter = 0; - int nd; - cups_dest_t * d; - TQLibrary lib( "cups" ); - typedef int (*CupsGetDests)(cups_dest_t **dests); - typedef void (*CupsFreeDests)(int num_dents, cups_dest_t *dests); - CupsGetDests _cupsGetDests = (CupsGetDests)lib.resolve( "cupsGetDests" ); - CupsFreeDests _cupsFreeDests = (CupsFreeDests)lib.resolve( "cupsFreeDests" ); - if ( _cupsGetDests ) { - nd = _cupsGetDests( &d ); - if ( nd < 1 ) - return 0; - - int n = 0; - while ( n < nd ) { - perhapsAddPrinter( printers, d[n].name, - TQPrintDialog::tr("Unknown Location"), 0 ); - if ( d[n].is_default && !defaultPrinter ) - defaultPrinter = tqstrdup( d[n].instance ); - n++; - } - if ( _cupsFreeDests ) { - _cupsFreeDests(nd, d); - } - } - return defaultPrinter; -} -#endif - -static TQPrintDialog * globalPrintDialog = 0; - -static void qpd_cleanup_globaldialog() -{ - if ( globalPrintDialog != 0 ) - delete globalPrintDialog; - globalPrintDialog = 0; -} - -/*! - \class TQPrintDialog ntqprintdialog.h - - \brief The TQPrintDialog class provides a dialog for specifying - the printer's configuration. - - \internal - - \warning The use of this class is not recommended since it is not - present on all platforms; use TQPrinter::setup() instead. - - \omit - - (ingroup dialogs) - - THIS DOCUMENTATION IS Not Revised. It must be revised before - becoming public API. - - It encompasses both the sort of details needed for doing a simple - print-out and some print configuration setup. - - The easiest way to use the class is through the static - function getPrinterSetup(). You can also subclass the TQPrintDialog - and add some custom buttons with addButton() to extend the - functionality of the print dialog. - -
- The printer dialog, on a large screen, in Motif style. -*/ - - -/*! Constructs a new modal printer dialog that configures \a prn and is a - child of \a parent named \a name. -*/ - -TQPrintDialog::TQPrintDialog( TQPrinter *prn, TQWidget *parent, const char *name ) - : TQDialog( parent, name, TRUE ) -{ - d = new TQPrintDialogPrivate; - d->numCopies = 1; - - TQBoxLayout * tll = new TQBoxLayout( this, TQBoxLayout::Down, 12, 0 ); - - // destination - TQGroupBox * g; - g = setupDestination(); - tll->addWidget( g, 1 ); - - tll->addSpacing( 12 ); - - // printer and paper settings - TQBoxLayout * lay = new TQBoxLayout( TQBoxLayout::LeftToRight ); - tll->addLayout( lay ); - - g = setupPrinterSettings(); - lay->addWidget( g, 1 ); - - lay->addSpacing( 12 ); - - g = setupPaper(); - lay->addWidget( g ); - - tll->addSpacing( 12 ); - - // options - g = setupOptions(); - tll->addWidget( g ); - tll->addSpacing( 12 ); - - TQBoxLayout *l = new TQBoxLayout( TQBoxLayout::LeftToRight ); - d->customLayout = new TQBoxLayout( TQBoxLayout::LeftToRight ); - tll->addLayout( l ); - l->addLayout( d->customLayout ); - l->addStretch(); - tll->addSpacing( 12 ); - - // buttons - TQBoxLayout *horiz = new TQBoxLayout( TQBoxLayout::LeftToRight ); - tll->addLayout( horiz ); - - bool rightalign = - bool(style().styleHint(TQStyle::SH_PrintDialog_RightAlignButtons, this)); - - if (rightalign) - horiz->addStretch( 1 ); - - d->ok = new TQPushButton( this, "ok" ); - d->ok->setText( tr("OK") ); - d->ok->setDefault( TRUE ); - horiz->addWidget( d->ok ); - if (! rightalign) - horiz->addStretch( 1 ); - horiz->addSpacing( 6 ); - - TQPushButton * cancel = new TQPushButton( this, "cancel" ); - cancel->setText( tr("Cancel") ); - horiz->addWidget( cancel ); - - TQSize s1 = d->ok->sizeHint(); - TQSize s2 = cancel->sizeHint(); - s1 = TQSize( TQMAX(s1.width(), s2.width()), - TQMAX(s1.height(), s2.height()) ); - - d->ok->setFixedSize( s1 ); - cancel->setFixedSize( s1 ); - - tll->activate(); - - connect( d->ok, TQ_SIGNAL(clicked()), TQ_SLOT(okClicked()) ); - connect( cancel, TQ_SIGNAL(clicked()), TQ_SLOT(reject()) ); - - TQSize ms( minimumSize() ); - TQSize ss( TQApplication::desktop()->screenGeometry( pos() ).size() ); - if ( ms.height() < 512 && ss.height() >= 600 ) - ms.setHeight( 512 ); - else if ( ms.height() < 460 && ss.height() >= 480 ) - ms.setHeight( 460 ); - resize( ms ); - - setPrinter( prn, TRUE ); - d->printers->setFocus(); -} - - -/*! Destroys the object and frees any allocated resources. Does not - delete the associated TQPrinter object. -*/ - -TQPrintDialog::~TQPrintDialog() -{ - if ( this == globalPrintDialog ) - globalPrintDialog = 0; - delete d; -} - -/*! - This method allows you to specify a global print dialog, given in \a - pd, that will be used instead of the default dialog provided by TQt. - - This is useful, since there are many different printing systems on - Unix, and we cannot support all of them. Calling this method before - using a printer for the first time allows you to set up your own - print dialog. - - \sa setupPrinters() -*/ -void TQPrintDialog::setGlobalPrintDialog( TQPrintDialog *pd ) -{ - TQPrintDialog *oldPd = globalPrintDialog; - globalPrintDialog = pd; - if ( oldPd ) - delete oldPd; - else - tqAddPostRoutine( qpd_cleanup_globaldialog ); - globalPrintDialog->adjustSize(); -} - -TQGroupBox * TQPrintDialog::setupPrinterSettings() -{ - TQGroupBox * g = new TQGroupBox( 1, Horizontal, tr( "Printer settings"), - this, "settings group box" ); - - d->colorMode = new TQButtonGroup( this ); - d->colorMode->hide(); - connect( d->colorMode, TQ_SIGNAL(clicked(int)), - this, TQ_SLOT(colorModeSelected(int)) ); - - TQRadioButton *rb; - rb = new TQRadioButton( tr( "Print in color if available" ), - g, "color" ); - d->colorMode->insert( rb, TQPrinter::Color ); - rb->setChecked( TRUE ); - - rb = new TQRadioButton( tr("Print in grayscale"), - g, "graysacle" ); - d->colorMode->insert( rb, TQPrinter::GrayScale ); - - return g; -} - -TQGroupBox * TQPrintDialog::setupDestination() -{ - TQGroupBox * g = new TQGroupBox( 0, Horizontal, tr( "Print destination"), - this, "destination group box" ); - - TQBoxLayout * tll = new TQBoxLayout( g->layout(), TQBoxLayout::Down ); - - d->printerOrFile = new TQButtonGroup( this ); - d->printerOrFile->hide(); - connect( d->printerOrFile, TQ_SIGNAL(clicked(int)), - this, TQ_SLOT(printerOrFileSelected(int)) ); - - // printer radio button, list - TQRadioButton * rb = new TQRadioButton( tr( "Print to printer:" ), g, - "printer" ); - tll->addWidget( rb ); - d->printerOrFile->insert( rb, 0 ); - rb->setChecked( TRUE ); - d->outputToFile = FALSE; - - TQBoxLayout * horiz = new TQBoxLayout( TQBoxLayout::LeftToRight ); - tll->addLayout( horiz, 3 ); - horiz->addSpacing( 19 ); - - d->printers = new TQListView( g, "list of printers" ); - d->printers->setAllColumnsShowFocus( TRUE ); - d->printers->addColumn( tr("Printer"), 125 ); - d->printers->addColumn( tr("Host"), 125 ); - d->printers->addColumn( tr("Comment"), 150 ); - -#if defined(Q_OS_UNIX) - char * etcLpDefault = 0; - -#ifndef TQT_NO_CUPS - etcLpDefault = parseCupsOutput( d->printers ); -#endif - if ( d->printers->childCount() == 0 ) { - // we only use other schemes when cups fails. - - parsePrintcap( d->printers, TQString::fromLatin1("/etc/printcap") ); - parseEtcLpMember( d->printers ); - parseSpoolInterface( d->printers ); - parseQconfig( d->printers ); - if ( addPrinterHook ) - (*addPrinterHook)( d->printers ); - - TQFileInfo f; - f.setFile( TQString::fromLatin1("/etc/lp/printers") ); - if ( f.isDir() ) { - parseEtcLpPrinters( d->printers ); - TQFile def( TQString::fromLatin1("/etc/lp/default") ); - if ( def.open( IO_ReadOnly ) ) { - if ( etcLpDefault ) - delete[] etcLpDefault; - etcLpDefault = new char[1025]; - def.readLine( etcLpDefault, 1024 ); - char * p = etcLpDefault; - while ( p && *p ) { - if ( !isprint((uchar) *p) || isspace((uchar) *p) ) - *p = 0; - else - p++; - } - } - } - - char * def = 0; - f.setFile( TQString::fromLatin1("/etc/nsswitch.conf") ); - if ( f.isFile() ) { - def = parseNsswitchConf( d->printers ); - } else { - f.setFile( TQString::fromLatin1("/etc/printers.conf") ); - if ( f.isFile() ) - def = parsePrintersConf( d->printers ); - } - - if ( def ) { - if ( etcLpDefault ) - delete[] etcLpDefault; - etcLpDefault = def; - } - } - - // all printers hopefully known. try to find a good default - TQString dollarPrinter; - { - const char * t = getenv( "PRINTER" ); - if ( !t || !*t ) - t = getenv( "LPDEST" ); - dollarPrinter = TQString::fromLatin1( t ); - if ( !dollarPrinter.isEmpty() ) - perhapsAddPrinter( d->printers, dollarPrinter, - TQPrintDialog::tr("unknown"), - TQString::fromLatin1("") ); - } - int quality = 0; - - // bang the best default into the listview - const TQListViewItem * lvi = d->printers->firstChild(); - d->printers->setCurrentItem( (TQListViewItem *)lvi ); - while ( lvi ) { - TQRegExp ps( TQString::fromLatin1("[^a-z]ps(?:[^a-z]|$)") ); - TQRegExp lp( TQString::fromLatin1("[^a-z]lp(?:[^a-z]|$)") ); - - if ( quality < 4 && lvi->text(0) == dollarPrinter ) { - d->printers->setCurrentItem( (TQListViewItem *)lvi ); - quality = 4; - } else if ( quality < 3 && etcLpDefault && - lvi->text(0) == TQString::fromLatin1(etcLpDefault) ) { - d->printers->setCurrentItem( (TQListViewItem *)lvi ); - quality = 3; - } else if ( quality < 2 && - ( lvi->text(0) == TQString::fromLatin1("ps") || - ps.search(lvi->text(2)) != -1 ) ) { - d->printers->setCurrentItem( (TQListViewItem *)lvi ); - quality = 2; - } else if ( quality < 1 && - ( lvi->text(0) == TQString::fromLatin1("lp") || - lp.search(lvi->text(2)) > -1 ) ) { - d->printers->setCurrentItem( (TQListViewItem *)lvi ); - quality = 1; - } - lvi = lvi->nextSibling(); - } - - if ( d->printers->currentItem() ) - d->printers->setSelected( d->printers->currentItem(), TRUE ); - - if ( etcLpDefault ) // Avoid purify complaint - delete[] etcLpDefault; -#endif - - int h = fontMetrics().height(); - if ( d->printers->firstChild() ) - h = d->printers->firstChild()->height(); - d->printers->setMinimumSize( d->printers->sizeHint().width(), - d->printers->header()->height() + - 3 * h ); - horiz->addWidget( d->printers, 3 ); - - tll->addSpacing( 6 ); - - // file radio button, edit/browse - d->printToFileButton = new TQRadioButton( tr( "Print to file:" ), g, "file" ); - tll->addWidget( d->printToFileButton ); - d->printerOrFile->insert( d->printToFileButton, 1 ); - - horiz = new TQBoxLayout( TQBoxLayout::LeftToRight ); - tll->addLayout( horiz ); - horiz->addSpacing( 19 ); - - d->fileName = new TQLineEdit( g, "file name" ); - connect( d->fileName, TQ_SIGNAL( textChanged(const TQString&) ), - this, TQ_SLOT( fileNameEditChanged(const TQString&) ) ); - horiz->addWidget( d->fileName, 1 ); - horiz->addSpacing( 6 ); - d->browse = new TQPushButton( tr("Browse..."), g, "browse files" ); - d->browse->setAutoDefault( FALSE ); -#ifdef TQT_NO_FILEDIALOG - d->browse->setEnabled( FALSE ); -#endif - connect( d->browse, TQ_SIGNAL(clicked()), - this, TQ_SLOT(browseClicked()) ); - horiz->addWidget( d->browse ); - - d->fileName->setEnabled( FALSE ); - d->browse->setEnabled( FALSE ); - - tll->activate(); - - return g; -} - - -TQGroupBox * TQPrintDialog::setupOptions() -{ - TQGroupBox * g = new TQGroupBox( 0, Horizontal, tr( "Options"), - this, "options group box" ); - - TQBoxLayout * tll = new TQBoxLayout( g->layout(), TQBoxLayout::Down ); - - TQBoxLayout *lay = new TQBoxLayout( TQBoxLayout::LeftToRight ); - tll->addLayout( lay ); - - tll = new TQBoxLayout( lay, TQBoxLayout::Down ); - - d->printRange = new TQButtonGroup( this ); - d->printRange->hide(); - connect( d->printRange, TQ_SIGNAL(clicked(int)), - this, TQ_SLOT(printRangeSelected(int)) ); - - d->pageOrder = new TQButtonGroup( this ); - d->pageOrder->hide(); - connect( d->pageOrder, TQ_SIGNAL(clicked(int)), - this, TQ_SLOT(pageOrderSelected(int)) ); - - d->printAllButton = new TQRadioButton( tr("Print all"), g, "print all" ); - d->printRange->insert( d->printAllButton, 0 ); - tll->addWidget( d->printAllButton ); - - d->printSelectionButton = new TQRadioButton( tr("Print selection"), - g, "print selection" ); - d->printRange->insert( d->printSelectionButton, 1 ); - tll->addWidget( d->printSelectionButton ); - - d->printRangeButton = new TQRadioButton( tr("Print range"), - g, "print range" ); - d->printRange->insert( d->printRangeButton, 2 ); - tll->addWidget( d->printRangeButton ); - - TQBoxLayout * horiz = new TQBoxLayout( TQBoxLayout::LeftToRight ); - tll->addLayout( horiz ); - - d->firstPageLabel = new TQLabel( tr("From page:"), g, "first page" ); - horiz->addSpacing( 19 ); - horiz->addWidget( d->firstPageLabel ); - - d->firstPage = new TQPrintDialogSpinBox( 1, 9999, 1, g, "first page" ); - d->firstPage->setValue( 1 ); - horiz->addWidget( d->firstPage, 1 ); - connect( d->firstPage, TQ_SIGNAL(valueChanged(int)), - this, TQ_SLOT(setFirstPage(int)) ); - - horiz = new TQBoxLayout( TQBoxLayout::LeftToRight ); - tll->addLayout( horiz ); - - d->lastPageLabel = new TQLabel( tr("To page:"), g, "last page" ); - horiz->addSpacing( 19 ); - horiz->addWidget( d->lastPageLabel ); - - d->lastPage = new TQPrintDialogSpinBox( 1, 9999, 1, g, "last page" ); - d->lastPage->setValue( 9999 ); - horiz->addWidget( d->lastPage, 1 ); - connect( d->lastPage, TQ_SIGNAL(valueChanged(int)), - this, TQ_SLOT(setLastPage(int)) ); - - lay->addSpacing( 25 ); - tll = new TQBoxLayout( lay, TQBoxLayout::Down ); - - // print order - TQRadioButton * rb = new TQRadioButton( tr("Print first page first"), - g, "first page first" ); - tll->addWidget( rb ); - d->pageOrder->insert( rb, TQPrinter::FirstPageFirst ); - rb->setChecked( TRUE ); - - rb = new TQRadioButton( tr("Print last page first"), - g, "last page first" ); - tll->addWidget( rb ); - d->pageOrder->insert( rb, TQPrinter::LastPageFirst ); - - tll->addStretch(); - - // copies - - horiz = new TQBoxLayout( TQBoxLayout::LeftToRight ); - tll->addLayout( horiz ); - - TQLabel * l = new TQLabel( tr("Number of copies:"), g, "Number of copies" ); - horiz->addWidget( l ); - - d->copies = new TQPrintDialogSpinBox( 1, 99, 1, g, "copies" ); - d->copies->setValue( 1 ); - horiz->addWidget( d->copies, 1 ); - connect( d->copies, TQ_SIGNAL(valueChanged(int)), - this, TQ_SLOT(setNumCopies(int)) ); - - TQSize s = d->firstPageLabel->sizeHint() - .expandedTo( d->lastPageLabel->sizeHint() ) - .expandedTo( l->sizeHint() ); - d->firstPageLabel->setMinimumSize( s ); - d->lastPageLabel->setMinimumSize( s ); - l->setMinimumSize( s.width() + 19, s.height() ); - - tll->activate(); - - return g; -} - - -void isc( TQPrintDialogPrivate * d, - const TQString & text, - TQPrinter::PageSize ps ) -{ - if ( d && text && ps < TQPrinter::NPageSize ) { - d->sizeCombo->insertItem( text, -1 ); - int index = d->sizeCombo->count()-1; - if ( index >= 0 && index < TQPrinter::NPageSize ) - d->indexToPageSize[index] = ps; - } -} - -TQGroupBox * TQPrintDialog::setupPaper() -{ - TQGroupBox * g = new TQGroupBox( 1, Horizontal, tr( "Paper format"), - this, "Paper format" ); - d->pageSize = TQPrinter::A4; - - // page orientation - d->orientationCombo = new TQComboBox( FALSE, g ); - d->orientationCombo->insertItem( tr( "Portrait" ), -1 ); - d->orientationCombo->insertItem( tr( "Landscape" ), -1 ); - - d->orientation = TQPrinter::Portrait; - - g->addSpace( 8 ); - - connect( d->orientationCombo, TQ_SIGNAL( activated(int) ), - this, TQ_SLOT( orientSelected(int) ) ); - - // paper size - d->sizeCombo = new TQComboBox( FALSE, g ); - - int n; - for( n=0; nindexToPageSize[n] = TQPrinter::A4; - - isc( d, tr( "A0 (841 x 1189 mm)" ), TQPrinter::A0 ); - isc( d, tr( "A1 (594 x 841 mm)" ), TQPrinter::A1 ); - isc( d, tr( "A2 (420 x 594 mm)" ), TQPrinter::A2 ); - isc( d, tr( "A3 (297 x 420 mm)" ), TQPrinter::A3 ); - isc( d, tr( "A4 (210x297 mm, 8.26x11.7 inches)" ), TQPrinter::A4 ); - isc( d, tr( "A5 (148 x 210 mm)" ), TQPrinter::A5 ); - isc( d, tr( "A6 (105 x 148 mm)" ), TQPrinter::A6 ); - isc( d, tr( "A7 (74 x 105 mm)" ), TQPrinter::A7 ); - isc( d, tr( "A8 (52 x 74 mm)" ), TQPrinter::A8 ); - isc( d, tr( "A9 (37 x 52 mm)" ), TQPrinter::A9 ); - isc( d, tr( "B0 (1000 x 1414 mm)" ), TQPrinter::B0 ); - isc( d, tr( "B1 (707 x 1000 mm)" ), TQPrinter::B1 ); - isc( d, tr( "B2 (500 x 707 mm)" ), TQPrinter::B2 ); - isc( d, tr( "B3 (353 x 500 mm)" ), TQPrinter::B3 ); - isc( d, tr( "B4 (250 x 353 mm)" ), TQPrinter::B4 ); - isc( d, tr( "B5 (176 x 250 mm, 6.93x9.84 inches)" ), TQPrinter::B5 ); - isc( d, tr( "B6 (125 x 176 mm)" ), TQPrinter::B6 ); - isc( d, tr( "B7 (88 x 125 mm)" ), TQPrinter::B7 ); - isc( d, tr( "B8 (62 x 88 mm)" ), TQPrinter::B8 ); - isc( d, tr( "B9 (44 x 62 mm)" ), TQPrinter::B9 ); - isc( d, tr( "B10 (31 x 44 mm)" ), TQPrinter::B10 ); - isc( d, tr( "C5E (163 x 229 mm)" ), TQPrinter::C5E ); - isc( d, tr( "DLE (110 x 220 mm)" ), TQPrinter::DLE ); - isc( d, tr( "Executive (7.5x10 inches, 191x254 mm)" ), TQPrinter::Executive ); - isc( d, tr( "Folio (210 x 330 mm)" ), TQPrinter::Folio ); - isc( d, tr( "Ledger (432 x 279 mm)" ), TQPrinter::Ledger ); - isc( d, tr( "Legal (8.5x14 inches, 216x356 mm)" ), TQPrinter::Legal ); - isc( d, tr( "Letter (8.5x11 inches, 216x279 mm)" ), TQPrinter::Letter ); - isc( d, tr( "Tabloid (279 x 432 mm)" ), TQPrinter::Tabloid ); - isc( d, tr( "US Common #10 Envelope (105 x 241 mm)" ), TQPrinter::Comm10E ); - - connect( d->sizeCombo, TQ_SIGNAL( activated(int) ), - this, TQ_SLOT( paperSizeSelected(int) ) ); - - return g; -} - - -/*! - Display a dialog and allow the user to configure the TQPrinter \a - p for an optional widget \a w. Returns TRUE if the user clicks OK or - presses Enter, FALSE if the user clicks Cancel or presses Esc. - - getPrinterSetup() remembers the settings and provides the same - settings the next time the dialog is shown. -*/ - -bool TQPrintDialog::getPrinterSetup( TQPrinter * p, TQWidget* w ) -{ - if ( !globalPrintDialog ) { - globalPrintDialog = new TQPrintDialog( 0, 0, "global print dialog" ); -#ifndef TQT_NO_WIDGET_TOPEXTRA - globalPrintDialog->setCaption( TQPrintDialog::tr( "Setup Printer" ) ); -#endif - tqAddPostRoutine( qpd_cleanup_globaldialog ); - globalPrintDialog->setPrinter( p, TRUE ); - globalPrintDialog->adjustSize(); - } else { - globalPrintDialog->setPrinter( p, TRUE ); - } - globalPrintDialog->adjustPosition( w ); - #ifndef TQT_NO_WIDGET_TOPEXTRA - if ( w ) { - const TQPixmap *pm = w->icon(); - if ( pm && !pm->isNull() ) - globalPrintDialog->setIcon( *pm ); - else { - w = w ? w->topLevelWidget() : 0; - pm = w ? w->icon() : 0; - if ( pm && !pm->isNull() ) - globalPrintDialog->setIcon( *pm ); - } - } -#endif - bool r = globalPrintDialog->exec() == TQDialog::Accepted; - globalPrintDialog->setPrinter( 0 ); - return r; -} - - -void TQPrintDialog::printerOrFileSelected( int id ) -{ - d->outputToFile = id ? TRUE : FALSE; - if ( d->outputToFile ) { - d->ok->setEnabled( TRUE ); - fileNameEditChanged( d->fileName->text() ); - if ( !d->fileName->edited() && d->fileName->text().isEmpty() ) { - TQString home = TQString::fromLatin1( ::getenv( "HOME" ) ); - TQString cur = TQDir::currentDirPath(); - if ( home.at(home.length()-1) != '/' ) - home += '/'; - if ( cur.at(cur.length()-1) != '/' ) - cur += '/'; - if ( cur.left( home.length() ) != home ) - cur = home; -#ifdef TQ_WS_X11 - cur += "print.ps"; -#endif - d->fileName->setText( cur ); - d->fileName->setCursorPosition( cur.length() ); - d->fileName->selectAll(); - } - d->browse->setEnabled( TRUE ); - d->fileName->setEnabled( TRUE ); - d->fileName->setFocus(); - d->printers->setEnabled( FALSE ); - } else { - d->ok->setEnabled( d->printers->childCount() != 0 ); - d->printers->setEnabled( TRUE ); - if ( d->fileName->hasFocus() || d->browse->hasFocus() ) - d->printers->setFocus(); - d->browse->setEnabled( FALSE ); - d->fileName->setEnabled( FALSE ); - } -} - - -void TQPrintDialog::landscapeSelected( int id ) -{ - d->orientation = (TQPrinter::Orientation)id; -} - - -void TQPrintDialog::paperSizeSelected( int id ) -{ - if ( id < TQPrinter::NPageSize ) - d->pageSize = TQPrinter::PageSize( d->indexToPageSize[id] ); -} - - -void TQPrintDialog::orientSelected( int id ) -{ - d->orientation = (TQPrinter::Orientation)id; -} - - -void TQPrintDialog::pageOrderSelected( int id ) -{ - d->pageOrder2 = (TQPrinter::PageOrder)id; -} - - -void TQPrintDialog::setNumCopies( int copies ) -{ - d->numCopies = copies; -} - - -void TQPrintDialog::browseClicked() -{ -#ifndef TQT_NO_FILEDIALOG - TQString fn = TQFileDialog::getSaveFileName( d->fileName->text(), tr( "PostScript Files (*.ps);;All Files (*)" ), this ); - if ( !fn.isNull() ) - d->fileName->setText( fn ); -#endif -} - - -void TQPrintDialog::okClicked() -{ - d->lastPage->interpretText(); - d->firstPage->interpretText(); - d->copies->interpretText(); - if ( d->outputToFile ) { - d->printer->setOutputToFile( TRUE ); - d->printer->setOutputFileName( d->fileName->text() ); - } else { - d->printer->setOutputToFile( FALSE ); - TQListViewItem * l = d->printers->currentItem(); - if ( l ) - d->printer->setPrinterName( l->text( 0 ) ); - } - - d->printer->setOrientation( d->orientation ); - d->printer->setPageSize( d->pageSize ); - d->printer->setPageOrder( d->pageOrder2 ); - d->printer->setColorMode( d->colorMode2 ); - d->printer->setNumCopies( d->numCopies ); - if ( d->printAllButton->isChecked() ) { - d->printer->setPrintRange(TQPrinter::AllPages); - d->printer->setFromTo( d->printer->minPage(), d->printer->maxPage() ); - } else { - if (d->printSelectionButton->isChecked()) - d->printer->setPrintRange(TQPrinter::Selection); - else - d->printer->setPrintRange(TQPrinter::PageRange); - d->printer->setFromTo( d->firstPage->value(), d->lastPage->value() ); - } - - accept(); -} - - -void TQPrintDialog::printRangeSelected( int id ) -{ - bool enable = id == 2 ? TRUE : FALSE; - d->firstPage->setEnabled( enable ); - d->lastPage->setEnabled( enable ); - d->firstPageLabel->setEnabled( enable ); - d->lastPageLabel->setEnabled( enable ); -} - - -void TQPrintDialog::setFirstPage( int fp ) -{ - if ( d->printer ) - d->lastPage->setRange( fp, TQMAX(fp, TQPrintDialog::d->printer->maxPage()) ); -} - - -void TQPrintDialog::setLastPage( int lp ) -{ - if ( d->printer ) - d->firstPage->setRange( TQMIN(lp, TQPrintDialog::d->printer->minPage()), lp ); -} - - -/*! - Sets this dialog to configure printer \a p, or no printer if \a p - is null. If \a pickUpSettings is TRUE, the dialog reads most of - its settings from \a p. If \a pickUpSettings is FALSE (the - default) the dialog keeps its old settings. -*/ - -void TQPrintDialog::setPrinter( TQPrinter * p, bool pickUpSettings ) -{ - d->printer = p; - - if ( p && pickUpSettings ) { - // top to botton in the old dialog. - // printer or file - d->printerOrFile->setButton( p->outputToFile() ); - printerOrFileSelected( p->outputToFile() ); - - // printer name - if ( !!p->printerName() ) { - TQListViewItem * i = d->printers->firstChild(); - while ( i && i->text( 0 ) != p->printerName() ) - i = i->nextSibling(); - if ( i ) { - d->printers->setSelected( i, TRUE ); - d->ok->setEnabled( TRUE ); - } else if ( d->fileName->text().isEmpty() ) { - d->ok->setEnabled( d->printers->childCount() != 0 ); - } - } - - // print command does not exist any more - - // file name - d->printToFileButton->setEnabled( d->printer->isOptionEnabled( TQPrinter::PrintToFile ) ); - d->fileName->setText( p->outputFileName() ); - - // orientation - d->orientationCombo->setCurrentItem( (int)p->orientation() ); - orientSelected( p->orientation() ); - - // page size - int n = 0; - while ( n < TQPrinter::NPageSize && - d->indexToPageSize[n] != p->pageSize() ) - n++; - d->sizeCombo->setCurrentItem( n ); - paperSizeSelected( n ); - - // New stuff (Options) - - // page order - d->pageOrder->setButton( (int)p->pageOrder() ); - pageOrderSelected( p->pageOrder() ); - - // color mode - d->colorMode->setButton( (int)p->colorMode() ); - colorModeSelected( p->colorMode() ); - - // number of copies - d->copies->setValue( p->numCopies() ); - setNumCopies( p->numCopies() ); - } - - if( p ) { - d->printAllButton->setEnabled( TRUE ); - d->printSelectionButton - ->setEnabled( d->printer->isOptionEnabled( TQPrinter::PrintSelection ) ); - d->printRangeButton - ->setEnabled( d->printer->isOptionEnabled( TQPrinter::PrintPageRange ) ); - - TQPrinter::PrintRange range = p->printRange(); - switch ( range ) { - case TQPrinter::AllPages: - d->printAllButton->setChecked(TRUE); - printRangeSelected( d->printRange->id( d->printAllButton ) ); - break; - case TQPrinter::Selection: - d->printSelectionButton->setChecked(TRUE); - printRangeSelected( d->printRange->id( d->printSelectionButton ) ); - break; - case TQPrinter::PageRange: - d->printRangeButton->setChecked(TRUE); - printRangeSelected( d->printRange->id( d->printRangeButton ) ); - break; - } - } - - if ( p && p->maxPage() ) { - d->firstPage->setRange( p->minPage(), p->maxPage() ); - d->lastPage->setRange( p->minPage(), p->maxPage() ); - if ( p->fromPage() || p->toPage() ) { - setFirstPage( p->fromPage() ); - setLastPage( p->toPage() ); - d->firstPage->setValue(p->fromPage()); - d->lastPage->setValue(p->toPage()); - } - } -} - - -/*! Returns a pointer to the printer this dialog configures, or 0 if - this dialog does not operate on any printer. */ - -TQPrinter * TQPrintDialog::printer() const -{ - return d->printer; -} - - -void TQPrintDialog::colorModeSelected( int id ) -{ - d->colorMode2 = (TQPrinter::ColorMode)id; -} - -/*! - Adds the button \a but to the layout of the print dialog. The added - buttons are arranged from the left to the right below the - last groupbox of the printdialog. -*/ - -void TQPrintDialog::addButton( TQPushButton *but ) -{ - d->customLayout->addWidget( but ); -} - -void TQPrintDialog::fileNameEditChanged( const TQString &text ) -{ - if ( d->fileName->isEnabled() ) - d->ok->setEnabled( !text.isEmpty() ); -} - -#endif diff --git a/src/dialogs/qt_dialogs.pri b/src/dialogs/qt_dialogs.pri index 9702afad..555633b8 100644 --- a/src/dialogs/qt_dialogs.pri +++ b/src/dialogs/qt_dialogs.pri @@ -8,7 +8,7 @@ dialogs { $$DIALOGS_H/tqerrormessage.h \ $$DIALOGS_H/tqfiledialog.h \ $$DIALOGS_H/tqfontdialog.h \ - $$DIALOGS_H/ntqmessagebox.h \ + $$DIALOGS_H/tqmessagebox.h \ $$DIALOGS_H/tqprogressdialog.h \ $$DIALOGS_H/tqtabdialog.h \ $$DIALOGS_H/tqwizard.h \ @@ -16,15 +16,15 @@ dialogs { !embedded:mac:SOURCES += $$DIALOGS_CPP/tqfiledialog_mac.cpp $$DIALOGS_CPP/tqcolordialog_mac.cpp win32:SOURCES += $$DIALOGS_CPP/tqfiledialog_win.cpp - unix:SOURCES += $$DIALOGS_CPP/qprintdialog.cpp - unix:HEADERS += $$DIALOGS_H/ntqprintdialog.h + unix:SOURCES += $$DIALOGS_CPP/tqprintdialog.cpp + unix:HEADERS += $$DIALOGS_H/tqprintdialog.h SOURCES += $$DIALOGS_CPP/tqcolordialog.cpp \ $$DIALOGS_CPP/tqdialog.cpp \ $$DIALOGS_CPP/tqerrormessage.cpp \ $$DIALOGS_CPP/tqfiledialog.cpp \ $$DIALOGS_CPP/tqfontdialog.cpp \ - $$DIALOGS_CPP/qmessagebox.cpp \ + $$DIALOGS_CPP/tqmessagebox.cpp \ $$DIALOGS_CPP/tqprogressdialog.cpp \ $$DIALOGS_CPP/tqtabdialog.cpp \ $$DIALOGS_CPP/tqwizard.cpp \ diff --git a/src/dialogs/tqdialog.cpp b/src/dialogs/tqdialog.cpp index 1f620cb6..42853e00 100644 --- a/src/dialogs/tqdialog.cpp +++ b/src/dialogs/tqdialog.cpp @@ -344,8 +344,8 @@ void TQDialog::hideDefault() Hides special buttons which are rather shown in the titlebar on WinCE, to conserve screen space. */ -# include "ntqmessagebox.h" -extern const char * mb_texts[]; // Defined in qmessagebox.cpp +# include "tqmessagebox.h" +extern const char * mb_texts[]; // Defined in tqmessagebox.cpp void TQDialog::hideSpecial() { // "OK" buttons are hidden, and (Ok) shown on titlebar diff --git a/src/dialogs/tqerrormessage.cpp b/src/dialogs/tqerrormessage.cpp index 2caa0949..f99db2c7 100644 --- a/src/dialogs/tqerrormessage.cpp +++ b/src/dialogs/tqerrormessage.cpp @@ -47,7 +47,7 @@ #include "tqdict.h" #include "tqlabel.h" #include "tqlayout.h" -#include "ntqmessagebox.h" +#include "tqmessagebox.h" #include "tqpushbutton.h" #include "tqstringlist.h" #include "tqstylesheet.h" diff --git a/src/dialogs/tqfiledialog.cpp b/src/dialogs/tqfiledialog.cpp index 77de59b6..9937f69a 100644 --- a/src/dialogs/tqfiledialog.cpp +++ b/src/dialogs/tqfiledialog.cpp @@ -75,7 +75,7 @@ #include "tqlistbox.h" #include "tqlistview.h" #include "tqmap.h" -#include "ntqmessagebox.h" +#include "tqmessagebox.h" #include "tqmime.h" #include "tqnetworkprotocol.h" #include "tqobjectlist.h" diff --git a/src/dialogs/tqmessagebox.cpp b/src/dialogs/tqmessagebox.cpp new file mode 100644 index 00000000..2a717826 --- /dev/null +++ b/src/dialogs/tqmessagebox.cpp @@ -0,0 +1,1664 @@ +/**************************************************************************** +** +** Implementation of TQMessageBox class +** +** Created : 950503 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the dialogs module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "tqmessagebox.h" + +#ifndef TQT_NO_MESSAGEBOX + +#include "tqaccel.h" +#include "tqlabel.h" +#include "tqpushbutton.h" +#include "tqimage.h" +#include "ntqapplication.h" +#include "tqstyle.h" +#include "tqobjectlist.h" +#if defined(QT_ACCESSIBILITY_SUPPORT) +#include "tqaccessible.h" +#endif + +#ifdef TQ_WS_X11 +#include "private/tqttdeintegration_x11_p.h" +#endif + +extern bool tqt_use_native_dialogs; + +// Internal class - don't touch + +class TQMessageBoxLabel : public TQLabel +{ + TQ_OBJECT +public: + TQMessageBoxLabel( TQWidget* parent ) : TQLabel( parent, "messageBoxText") + { + setAlignment( AlignAuto|ExpandTabs ); + } +}; +#include "tqmessagebox.moc" + + + +// the TQt logo, for aboutTQt +/* XPM */ +static const char * const qtlogo_xpm[] = { +/* width height ncolors chars_per_pixel */ +"50 50 17 1", +/* colors */ +" c #000000", +". c #495808", +"X c #2A3304", +"o c #242B04", +"O c #030401", +"+ c #9EC011", +"@ c #93B310", +"# c #748E0C", +"$ c #A2C511", +"% c #8BA90E", +"& c #99BA10", +"* c #060701", +"= c #181D02", +"- c #212804", +"; c #61770A", +": c #0B0D01", +"/ c None", +/* pixels */ +"/$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$/", +"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$", +"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$", +"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$", +"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$", +"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$", +"$$$$$$$$$$$$$$$$$$$$$$$+++$$$$$$$$$$$$$$$$$$$$$$$$", +"$$$$$$$$$$$$$$$$$$$@;.o=::=o.;@$$$$$$$$$$$$$$$$$$$", +"$$$$$$$$$$$$$$$$+#X* **X#+$$$$$$$$$$$$$$$$", +"$$$$$$$$$$$$$$$#oO* O **o#+$$$$$$$$$$$$$$", +"$$$$$$$$$$$$$&.* OO O*.&$$$$$$$$$$$$$", +"$$$$$$$$$$$$@XOO * OO X&$$$$$$$$$$$$", +"$$$$$$$$$$$@XO OO O **:::OOO OOO X@$$$$$$$$$$$", +"$$$$$$$$$$&XO O-;#@++@%.oOO X&$$$$$$$$$$", +"$$$$$$$$$$.O : *-#+$$$$$$$$+#- : O O*.$$$$$$$$$$", +"$$$$$$$$$#*OO O*.&$$$$$$$$$$$$+.OOOO **#$$$$$$$$$", +"$$$$$$$$+-OO O *;$$$$$$$$$$$&$$$$;* o+$$$$$$$$", +"$$$$$$$$#O* O .+$$$$$$$$$$@X;$$$+.O *#$$$$$$$$", +"$$$$$$$$X* -&$$$$$$$$$$@- :;$$$&- OX$$$$$$$$", +"$$$$$$$@*O *O#$$$$$$$$$$@oOO**;$$$# O*%$$$$$$$", +"$$$$$$$; -+$$$$$$$$$@o O OO ;+$$-O *;$$$$$$$", +"$$$$$$$. ;$$$$$$$$$@-OO OO X&$$;O .$$$$$$$", +"$$$$$$$o *#$$$$$$$$@o O O O-@$$$#O *o$$$$$$$", +"$$$$$$+= *@$$$$$$$@o* OO -@$$$$&: =$$$$$$$", +"$$$$$$+: :+$$$$$$@- *-@$$$$$$: :+$$$$$$", +"$$$$$$+: :+$$$$$@o* O *-@$$$$$$: :+$$$$$$", +"$$$$$$$= :@$$$$@o*OOO -@$$$$@: =+$$$$$$", +"$$$$$$$- O%$$$@o* O O O O-@$$$#* OX$$$$$$$", +"$$$$$$$. O *O;$$&o O*O* *O -@$$; O.$$$$$$$", +"$$$$$$$;* Oo+$$;O*O:OO-- Oo@+= *;$$$$$$$", +"$$$$$$$@* O O#$$$;*OOOo@@-O Oo;O* **@$$$$$$$", +"$$$$$$$$X* OOO-+$$$;O o@$$@- O O OX$$$$$$$$", +"$$$$$$$$#* * O.$$$$;X@$$$$@-O O O#$$$$$$$$", +"$$$$$$$$+oO O OO.+$$+&$$$$$$@-O o+$$$$$$$$", +"$$$$$$$$$#* **.&$$$$$$$$$$@o OO:#$$$$$$$$$", +"$$$$$$$$$+. O* O-#+$$$$$$$$+;O OOO:@$$$$$$$$$", +"$$$$$$$$$$&X *O -;#@++@#;=O O -@$$$$$$$$", +"$$$$$$$$$$$&X O O*O::::O OO Oo@$$$$$$$", +"$$$$$$$$$$$$@XOO OO O*X+$$$$$$", +"$$$$$$$$$$$$$&.* ** O :: *:#$$$$$$$", +"$$$$$$$$$$$$$$$#o*OO O Oo#@-OOO=#$$$$$$$$", +"$$$$$$$$$$$$$$$$+#X:* * O**X#+$$@-*:#$$$$$$$$$", +"$$$$$$$$$$$$$$$$$$$%;.o=::=o.#@$$$$$$@X#$$$$$$$$$$", +"$$$$$$$$$$$$$$$$$$$$$$$$+++$$$$$$$$$$$+$$$$$$$$$$$", +"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$", +"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$", +"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$", +"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$", +"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$", +"/$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$/", +}; + + +/*! + \class TQMessageBox + \brief The TQMessageBox class provides a modal dialog with a short message, an icon, and some buttons. + \ingroup dialogs + \mainclass + + Message boxes are used to provide informative messages and to ask + simple questions. + + TQMessageBox provides a range of different messages, arranged + roughly along two axes: severity and complexity. + + Severity is + \table + \row + \i \img tqmessagebox-quest.png + \i Question + \i For message boxes that ask a question as part of normal + operation. Some style guides recommend using Information for this + purpose. + \row + \i \img tqmessagebox-info.png + \i Information + \i For message boxes that are part of normal operation. + \row + \i \img tqmessagebox-warn.png + \i Warning + \i For message boxes that tell the user about unusual errors. + \row + \i \img tqmessagebox-crit.png + \i Critical + \i For message boxes that tell the user about critical errors. + \endtable + + The message box has a different icon for each of the severity levels. + + Complexity is one button (OK) for simple messages, or two or even + three buttons for questions. + + There are static functions for the most common cases. + + Examples: + + If a program is unable to find a supporting file, but can do perfectly + well without it: + + \code + TQMessageBox::information( this, "Application name", + "Unable to find the user preferences file.\n" + "The factory default will be used instead." ); + \endcode + + question() is useful for simple yes/no questions: + + \code + if ( TQFile::exists( filename ) && + TQMessageBox::question( + this, + tr("Overwrite File? -- Application Name"), + tr("A file called %1 already exists." + "Do you want to overwrite it?") + .arg( filename ), + tr("&Yes"), tr("&No"), + TQString::null, 0, 1 ) ) + return false; + \endcode + + warning() can be used to tell the user about unusual errors, or + errors which can't be easily fixed: + + \code + switch( TQMessageBox::warning( this, "Application name", + "Could not connect to the server.\n" + "This program can't function correctly " + "without the server.\n\n", + "Retry", + "Quit", 0, 0, 1 ) ) { + case 0: // The user clicked the Retry again button or pressed Enter + // try again + break; + case 1: // The user clicked the Quit or pressed Escape + // exit + break; + } + \endcode + + The text part of all message box messages can be either rich text + or plain text. If you specify a rich text formatted string, it + will be rendered using the default stylesheet. See + TQStyleSheet::defaultSheet() for details. With certain strings that + contain XML meta characters, the auto-rich text detection may + fail, interpreting plain text incorrectly as rich text. In these + rare cases, use TQStyleSheet::convertFromPlainText() to convert + your plain text string to a visually equivalent rich text string + or set the text format explicitly with setTextFormat(). + + Note that the Microsoft Windows User Interface Guidelines + recommend using the application name as the window's caption. + + Below are more examples of how to use the static member functions. + After these examples you will find an overview of the non-static + member functions. + + Exiting a program is part of its normal operation. If there is + unsaved data the user probably should be asked if they want to + save the data. For example: + + \code + switch( TQMessageBox::information( this, "Application name here", + "The document contains unsaved changes\n" + "Do you want to save the changes before exiting?", + "&Save", "&Discard", "Cancel", + 0, // Enter == button 0 + 2 ) ) { // Escape == button 2 + case 0: // Save clicked or Alt+S pressed or Enter pressed. + // save + break; + case 1: // Discard clicked or Alt+D pressed + // don't save but exit + break; + case 2: // Cancel clicked or Escape pressed + // don't exit + break; + } + \endcode + + The Escape button cancels the entire exit operation, and pressing + Enter causes the changes to be saved before the exit occurs. + + Disk full errors are unusual and they certainly can be hard to + correct. This example uses predefined buttons instead of + hard-coded button texts: + + \code + switch( TQMessageBox::warning( this, "Application name here", + "Could not save the user preferences,\n" + "because the disk is full. You can delete\n" + "some files and press Retry, or you can\n" + "abort the Save Preferences operation.", + TQMessageBox::Retry | TQMessageBox::Default, + TQMessageBox::Abort | TQMessageBox::Escape )) { + case TQMessageBox::Retry: // Retry clicked or Enter pressed + // try again + break; + case TQMessageBox::Abort: // Abort clicked or Escape pressed + // abort + break; + } + \endcode + + The critical() function should be reserved for critical errors. In + this example errorDetails is a TQString or const char*, and TQString + is used to concatenate several strings: + + \code + TQMessageBox::critical( 0, "Application name here", + TQString("An internal error occurred. Please ") + + "call technical support at 1234-56789 and report\n"+ + "these numbers:\n\n" + errorDetails + + "\n\nApplication will now exit." ); + \endcode + + In this example an OK button is displayed. + + TQMessageBox provides a very simple About box which displays an + appropriate icon and the string you provide: + + \code + TQMessageBox::about( this, "About ", + " is a \n\n" + "Copyright 1991-2003 Such-and-such. " + "\n\n" + "For technical support, call 1234-56789 or see\n" + "http://www.such-and-such.com/Application/\n" ); + \endcode + + See about() for more information. + + If you want your users to know that the application is built using + TQt (so they know that you use high quality tools) you might like + to add an "About TQt" menu option under the Help menu to invoke + aboutTQt(). + + If none of the standard message boxes is suitable, you can create a + TQMessageBox from scratch and use custom button texts: + + \code + TQMessageBox mb( "Application name here", + "Saving the file will overwrite the original file on the disk.\n" + "Do you really want to save?", + TQMessageBox::Information, + TQMessageBox::Yes | TQMessageBox::Default, + TQMessageBox::No, + TQMessageBox::Cancel | TQMessageBox::Escape ); + mb.setButtonText( TQMessageBox::Yes, "Save" ); + mb.setButtonText( TQMessageBox::No, "Discard" ); + switch( mb.exec() ) { + case TQMessageBox::Yes: + // save and exit + break; + case TQMessageBox::No: + // exit without saving + break; + case TQMessageBox::Cancel: + // don't save and don't exit + break; + } + \endcode + + TQMessageBox defines two enum types: Icon and an unnamed button type. + Icon defines the \c Question, \c Information, \c Warning, and \c + Critical icons for each GUI style. It is used by the constructor + and by the static member functions question(), information(), + warning() and critical(). A function called standardIcon() gives + you access to the various icons. + + The button types are: + \list + \i Ok - the default for single-button message boxes + \i Cancel - note that this is \e not automatically Escape + \i Yes + \i No + \i Abort + \i Retry + \i Ignore + \i YesAll + \i NoAll + \endlist + + Button types can be combined with two modifiers by using OR, '|': + \list + \i Default - makes pressing Enter equivalent to + clicking this button. Normally used with Ok, Yes or similar. + \i Escape - makes pressing Escape equivalent to clicking this button. + Normally used with Abort, Cancel or similar. + \endlist + + The text(), icon() and iconPixmap() functions provide access to the + current text and pixmap of the message box. The setText(), setIcon() + and setIconPixmap() let you change it. The difference between + setIcon() and setIconPixmap() is that the former accepts a + TQMessageBox::Icon and can be used to set standard icons, whereas the + latter accepts a TQPixmap and can be used to set custom icons. + + setButtonText() and buttonText() provide access to the buttons. + + TQMessageBox has no signals or slots. + + + + \sa TQDialog, + \link http://www.iarchitect.com/errormsg.htm + Isys on error messages \endlink, + \link guibooks.html#fowler GUI Design Handbook: Message Box \endlink +*/ + + +/*! + \enum TQMessageBox::Icon + + This enum has the following values: + + \value NoIcon the message box does not have any icon. + + \value Question an icon indicating that + the message is asking a question. + + \value Information an icon indicating that + the message is nothing out of the ordinary. + + \value Warning an icon indicating that the + message is a warning, but can be dealt with. + + \value Critical an icon indicating that + the message represents a critical problem. + +*/ + + +struct TQMessageBoxData { + TQMessageBoxData(TQMessageBox* parent) : + iconLabel( parent, "icon" ) + { + } + + int numButtons; // number of buttons + TQMessageBox::Icon icon; // message box icon + TQLabel iconLabel; // label holding any icon + int button[3]; // button types + int defButton; // default button (index) + int escButton; // escape button (index) + TQSize buttonSize; // button size + TQPushButton *pb[3]; // buttons +}; + +static const int LastButton = TQMessageBox::NoAll; + +/* + NOTE: The table of button texts correspond to the button enum. +*/ + +#ifndef Q_OS_TEMP +static const char * const mb_texts[] = { +#else +const char * mb_texts[] = { +#endif + 0, + TQT_TRANSLATE_NOOP("TQMessageBox","OK"), + TQT_TRANSLATE_NOOP("TQMessageBox","Cancel"), + TQT_TRANSLATE_NOOP("TQMessageBox","&Yes"), + TQT_TRANSLATE_NOOP("TQMessageBox","&No"), + TQT_TRANSLATE_NOOP("TQMessageBox","&Abort"), + TQT_TRANSLATE_NOOP("TQMessageBox","&Retry"), + TQT_TRANSLATE_NOOP("TQMessageBox","&Ignore"), + TQT_TRANSLATE_NOOP("TQMessageBox","Yes to &All"), + TQT_TRANSLATE_NOOP("TQMessageBox","N&o to All"), + 0 +}; + +/*! + Constructs a message box with no text and a button with the label + "OK". + + If \a parent is 0, the message box becomes an application-global + modal dialog box. If \a parent is a widget, the message box + becomes modal relative to \a parent. + + The \a parent and \a name arguments are passed to the TQDialog + constructor. +*/ + +TQMessageBox::TQMessageBox( TQWidget *parent, const char *name ) + : TQDialog( parent, name, TRUE, WStyle_Customize | WStyle_DialogBorder | WStyle_Title | WStyle_SysMenu ) +{ + init( Ok, 0, 0 ); +} + + +/*! + Constructs a message box with a \a caption, a \a text, an \a icon, + and up to three buttons. + + The \a icon must be one of the following: + \list + \i TQMessageBox::NoIcon + \i TQMessageBox::Question + \i TQMessageBox::Information + \i TQMessageBox::Warning + \i TQMessageBox::Critical + \endlist + + Each button, \a button0, \a button1 and \a button2, can have one + of the following values: + \list + \i TQMessageBox::NoButton + \i TQMessageBox::Ok + \i TQMessageBox::Cancel + \i TQMessageBox::Yes + \i TQMessageBox::No + \i TQMessageBox::Abort + \i TQMessageBox::Retry + \i TQMessageBox::Ignore + \i TQMessageBox::YesAll + \i TQMessageBox::NoAll + \endlist + + Use TQMessageBox::NoButton for the later parameters to have fewer + than three buttons in your message box. If you don't specify any + buttons at all, TQMessageBox will provide an Ok button. + + One of the buttons can be OR-ed with the \c TQMessageBox::Default + flag to make it the default button (clicked when Enter is + pressed). + + One of the buttons can be OR-ed with the \c TQMessageBox::Escape + flag to make it the cancel or close button (clicked when Escape is + pressed). + + Example: + \code + TQMessageBox mb( "Application Name", + "Hardware failure.\n\nDisk error detected\nDo you want to stop?", + TQMessageBox::Question, + TQMessageBox::Yes | TQMessageBox::Default, + TQMessageBox::No | TQMessageBox::Escape, + TQMessageBox::NoButton ); + if ( mb.exec() == TQMessageBox::No ) + // try again + \endcode + + If \a parent is 0, the message box becomes an application-global + modal dialog box. If \a parent is a widget, the message box + becomes modal relative to \a parent. + + If \a modal is TRUE the message box is modal; otherwise it + is modeless. + + The \a parent, \a name, \a modal, and \a f arguments are passed to + the TQDialog constructor. + + \sa setCaption(), setText(), setIcon() +*/ + +TQMessageBox::TQMessageBox( const TQString& caption, + const TQString &text, Icon icon, + int button0, int button1, int button2, + TQWidget *parent, const char *name, + bool modal, WFlags f ) + : TQDialog( parent, name, modal, f | WStyle_Customize | WStyle_DialogBorder | WStyle_Title | WStyle_SysMenu ) +{ + init( button0, button1, button2 ); +#ifndef TQT_NO_WIDGET_TOPEXTRA + setCaption( caption ); +#endif + setText( text ); + setIcon( icon ); +} + + +/*! + Destroys the message box. +*/ + +TQMessageBox::~TQMessageBox() +{ + delete mbd; +} + +static TQString * translatedTextAboutTQt = 0; + +void TQMessageBox::init( int button0, int button1, int button2 ) +{ + if ( !translatedTextAboutTQt ) { + translatedTextAboutTQt = new TQString; + + *translatedTextAboutTQt = tr( + "

About TQt

" + "

This program uses TQt version %1.

" + "

TQt is a C++ toolkit for multiplatform GUI & " + "application development.

" + "

TQt provides single-source " + "portability across MS Windows, Mac OS X, " + "Linux, and all major commercial Unix variants.

" + "

See https://trinitydesktop.org/docs/qt3/ " + "for more information.

" + ).arg( TQT_VERSION_STR ); + + } + label = new TQMessageBoxLabel( this ); + TQ_CHECK_PTR( label ); + + if ( (button2 && !button1) || (button1 && !button0) ) { +#if defined(QT_CHECK_RANGE) + tqWarning( "TQMessageBox: Inconsistent button parameters" ); +#endif + button0 = button1 = button2 = 0; + } + mbd = new TQMessageBoxData(this); + TQ_CHECK_PTR( mbd ); + mbd->icon = NoIcon; + mbd->iconLabel.setPixmap( TQPixmap() ); + mbd->numButtons = 0; + mbd->button[0] = button0; + mbd->button[1] = button1; + mbd->button[2] = button2; + mbd->defButton = -1; + mbd->escButton = -1; + int i; + for ( i=0; i<3; i++ ) { + int b = mbd->button[i]; + if ( (b & Default) ) { + if ( mbd->defButton >= 0 ) { +#if defined(QT_CHECK_RANGE) + tqWarning( "TQMessageBox: There can be at most one " + "default button" ); +#endif + } else { + mbd->defButton = i; + } + } + if ( (b & Escape) ) { + if ( mbd->escButton >= 0 ) { +#if defined(QT_CHECK_RANGE) + tqWarning( "TQMessageBox: There can be at most one " + "escape button" ); +#endif + } else { + mbd->escButton = i; + } + } + b &= ButtonMask; + if ( b == 0 ) { + if ( i == 0 ) // no buttons, add an Ok button + b = Ok; + } else if ( b < 0 || b > LastButton ) { +#if defined(QT_CHECK_RANGE) + tqWarning( "TQMessageBox: Invalid button specifier" ); +#endif + b = Ok; + } else { + if ( i > 0 && mbd->button[i-1] == 0 ) { +#if defined(QT_CHECK_RANGE) + tqWarning( "TQMessageBox: Inconsistent button parameters; " + "button %d defined but not button %d", + i+1, i ); +#endif + b = 0; + } + } + mbd->button[i] = b; + if ( b ) + mbd->numButtons++; + } + for ( i=0; i<3; i++ ) { + if ( i >= mbd->numButtons ) { + mbd->pb[i] = 0; + } else { + TQCString buttonName; + buttonName.sprintf( "button%d", i+1 ); + mbd->pb[i] = new TQPushButton( + tr(mb_texts[mbd->button[i]]), + this, buttonName ); + if ( mbd->defButton == i ) { + mbd->pb[i]->setDefault( TRUE ); + mbd->pb[i]->setFocus(); + } + mbd->pb[i]->setAutoDefault( TRUE ); + mbd->pb[i]->setFocusPolicy( TQWidget::StrongFocus ); + connect( mbd->pb[i], TQ_SIGNAL(clicked()), TQ_SLOT(buttonClicked()) ); + } + } + resizeButtons(); + reserved1 = reserved2 = 0; +} + + +int TQMessageBox::indexOf( int button ) const +{ + int index = -1; + for ( int i=0; inumButtons; i++ ) { + if ( mbd->button[i] == button ) { + index = i; + break; + } + } + return index; +} + + +void TQMessageBox::resizeButtons() +{ + int i; + TQSize maxSize; + for ( i=0; inumButtons; i++ ) { + TQSize s = mbd->pb[i]->sizeHint(); + maxSize.setWidth( TQMAX(maxSize.width(), s.width()) ); + maxSize.setHeight( TQMAX(maxSize.height(),s.height()) ); + } + mbd->buttonSize = maxSize; + for ( i=0; inumButtons; i++ ) + mbd->pb[i]->resize( maxSize ); +} + + +/*! + \property TQMessageBox::text + \brief the message box text to be displayed. + + The text will be interpreted either as a plain text or as rich + text, depending on the text format setting (\l + TQMessageBox::textFormat). The default setting is \c AutoText, i.e. + the message box will try to auto-detect the format of the text. + + The default value of this property is TQString::null. + + \sa textFormat +*/ +TQString TQMessageBox::text() const +{ + return label->text(); +} + + +void TQMessageBox::setText( const TQString &text ) +{ + label->setText( text ); +} + + +/*! + \property TQMessageBox::icon + \brief the message box's icon + + The icon of the message box can be one of the following predefined + icons: + \list + \i TQMessageBox::NoIcon + \i TQMessageBox::Question + \i TQMessageBox::Information + \i TQMessageBox::Warning + \i TQMessageBox::Critical + \endlist + + The actual pixmap used for displaying the icon depends on the + current \link TQWidget::style() GUI style\endlink. You can also set + a custom pixmap icon using the \l TQMessageBox::iconPixmap + property. The default icon is TQMessageBox::NoIcon. + + \sa iconPixmap +*/ + +TQMessageBox::Icon TQMessageBox::icon() const +{ + return mbd->icon; +} + +void TQMessageBox::setIcon( Icon icon ) +{ + setIconPixmap( standardIcon(icon) ); + mbd->icon = icon; +} + +/*! + \obsolete + + Returns the pixmap used for a standard icon. This + allows the pixmaps to be used in more complex message boxes. + \a icon specifies the required icon, e.g. TQMessageBox::Information, + TQMessageBox::Warning or TQMessageBox::Critical. + + \a style is unused. +*/ + +TQPixmap TQMessageBox::standardIcon( Icon icon, GUIStyle style) +{ + Q_UNUSED(style); + return TQMessageBox::standardIcon(icon); +} + + +/*! + Returns the pixmap used for a standard icon. This allows the + pixmaps to be used in more complex message boxes. \a icon + specifies the required icon, e.g. TQMessageBox::Question, + TQMessageBox::Information, TQMessageBox::Warning or + TQMessageBox::Critical. +*/ + +TQPixmap TQMessageBox::standardIcon( Icon icon ) +{ + TQPixmap pm; + switch ( icon ) { + case Information: + pm = TQApplication::style().stylePixmap( TQStyle::SP_MessageBoxInformation ); + break; + case Warning: + pm = TQApplication::style().stylePixmap( TQStyle::SP_MessageBoxWarning ); + break; + case Critical: + pm = TQApplication::style().stylePixmap( TQStyle::SP_MessageBoxCritical ); + break; + case Question: + pm = TQApplication::style().stylePixmap( TQStyle::SP_MessageBoxQuestion ); + default: + break; + } + return pm; +} + + +/*! + \property TQMessageBox::iconPixmap + \brief the current icon + + The icon currently used by the message box. Note that it's often + hard to draw one pixmap that looks appropriate in both Motif and + Windows GUI styles; you may want to draw two pixmaps. + + \sa icon +*/ + +const TQPixmap *TQMessageBox::iconPixmap() const +{ + return mbd->iconLabel.pixmap(); +} + + +void TQMessageBox::setIconPixmap( const TQPixmap &pixmap ) +{ + mbd->iconLabel.setPixmap(pixmap); + mbd->icon = NoIcon; +} + + +/*! + Returns the text of the message box button \a button, or + TQString::null if the message box does not contain the button. + + \sa setButtonText() +*/ + +TQString TQMessageBox::buttonText( int button ) const +{ + int index = indexOf(button); + return index >= 0 && mbd->pb[index] + ? mbd->pb[index]->text() + : TQString::null; +} + + +/*! + Sets the text of the message box button \a button to \a text. + Setting the text of a button that is not in the message box is + silently ignored. + + \sa buttonText() +*/ + +void TQMessageBox::setButtonText( int button, const TQString &text ) +{ + int index = indexOf(button); + if ( index >= 0 && mbd->pb[index] ) { + mbd->pb[index]->setText( text ); + resizeButtons(); + } +} + + +/*! + \internal + Internal slot to handle button clicks. +*/ + +void TQMessageBox::buttonClicked() +{ + int reply = 0; + const TQObject *s = sender(); + for ( int i=0; inumButtons; i++ ) { + if ( mbd->pb[i] == s ) + reply = mbd->button[i]; + } + done( reply ); +} + + +/*! + Adjusts the size of the message box to fit the contents just before + TQDialog::exec() or TQDialog::show() is called. + + This function will not be called if the message box has been explicitly + resized before showing it. +*/ +void TQMessageBox::adjustSize() +{ + if ( !testWState(WState_Polished) ) + polish(); + resizeButtons(); + label->adjustSize(); + TQSize labelSize( label->size() ); + int n = mbd->numButtons; + int bw = mbd->buttonSize.width(); + int bh = mbd->buttonSize.height(); + int border = bh / 2 - style().pixelMetric(TQStyle::PM_ButtonDefaultIndicator); + if ( border <= 0 ) + border = 10; + int btn_spacing = 7; + if ( style().styleHint(TQStyle::SH_GUIStyle) == MotifStyle ) + btn_spacing = border; +#ifndef Q_OS_TEMP + int buttons = mbd->numButtons * bw + (n-1) * btn_spacing; + int h = bh; +#else + int visibleButtons = 0; + for ( int i = 0; i < mbd->numButtons; ++i ) + visibleButtons += mbd->pb[i]->isVisible() ? 1 : 0; + int buttons = visibleButtons == 0 ? 0 : visibleButtons * bw + (visibleButtons-1) * btn_spacing; + int h = visibleButtons == 0 ? 0 : bh; + n = visibleButtons; +#endif + if ( labelSize.height() ) + h += labelSize.height() + 3*border; + else + h += 2*border; + int lmargin = 0; + if ( mbd->iconLabel.pixmap() && mbd->iconLabel.pixmap()->width() ) { + mbd->iconLabel.adjustSize(); + lmargin += mbd->iconLabel.width() + border; + if ( h < mbd->iconLabel.height() + 3*border + bh && n ) + h = mbd->iconLabel.height() + 3*border + bh; + } + int w = TQMAX( buttons, labelSize.width() + lmargin ) + 2*border; + TQRect screen = TQApplication::desktop()->screenGeometry( pos() ); + if ( w > screen.width() ) + w = screen.width(); + resize( w, h ); + setMinimumSize( size() ); +#ifdef TQ_WS_MAC + setMaximumSize(size()); +#endif +} + + +/*!\reimp +*/ +void TQMessageBox::resizeEvent( TQResizeEvent * ) +{ + int i; + int n = mbd->numButtons; + int bw = mbd->buttonSize.width(); + int bh = mbd->buttonSize.height(); +#ifdef Q_OS_TEMP + int visibleButtons = 0; + for ( i = 0; i < n; ++i ) + visibleButtons += mbd->pb[i]->isVisible() ? 1 : 0; + n = visibleButtons; + bw = visibleButtons == 0 ? 0 : bw; + bh = visibleButtons == 0 ? 0 : bh; +#endif + int border = bh / 2 - style().pixelMetric(TQStyle::PM_ButtonDefaultIndicator); + if ( border <= 0 ) + border = 10; + int btn_spacing = 7; + if ( style().styleHint(TQStyle::SH_GUIStyle) == MotifStyle ) + btn_spacing = border; + int lmargin = 0; + mbd->iconLabel.adjustSize(); + bool rtl = TQApplication::reverseLayout(); + if (rtl) + mbd->iconLabel.move(width() - border - mbd->iconLabel.width(), border); + else + mbd->iconLabel.move(border, border); + if ( mbd->iconLabel.pixmap() && mbd->iconLabel.pixmap()->width() ) + lmargin += mbd->iconLabel.width() + border; + label->setGeometry((rtl ? 0 : lmargin) + border, + border, + width() - lmargin -2*border, + height() - 3*border - bh); + int extra_space = (width() - bw*n - 2*border - (n-1)*btn_spacing); + if ( style().styleHint(TQStyle::SH_GUIStyle) == MotifStyle ) + for ( i=0; ipb[rtl ? n - i - 1 : i]->move(border + i*bw + i*btn_spacing + extra_space*(i+1)/(n+1), + height() - border - bh ); + else + for ( i=0; ipb[rtl ? n - i - 1 : i]->move(border + i*bw + extra_space/2 + i*btn_spacing, + height() - border - bh ); +} + + +/*!\reimp +*/ +void TQMessageBox::keyPressEvent( TQKeyEvent *e ) +{ + if ( e->key() == Key_Escape ) { + if ( mbd->escButton >= 0 ) { + TQPushButton *pb = mbd->pb[mbd->escButton]; + pb->animateClick(); + e->accept(); + return; + } + } +#ifndef TQT_NO_ACCEL + if ( !( e->state() & AltButton ) ) { + TQObjectList *list = queryList( "TQPushButton" ); + TQObjectListIt it( *list ); + TQPushButton *pb; + while ( (pb = (TQPushButton*)it.current()) ) { + int key = e->key() & ~(MODIFIER_MASK|UNICODE_ACCEL); + int acc = pb->accel() & ~(MODIFIER_MASK|UNICODE_ACCEL); + if ( key && acc && acc == key ) { + delete list; + emit pb->animateClick(); + return; + } + ++it; + } + delete list; + } +#endif + TQDialog::keyPressEvent( e ); +} + +/*!\reimp +*/ +void TQMessageBox::showEvent( TQShowEvent *e ) +{ +#if defined(QT_ACCESSIBILITY_SUPPORT) + TQAccessible::updateAccessibility( this, 0, TQAccessible::Alert ); +#endif + TQDialog::showEvent( e ); +} + +/*!\reimp +*/ +void TQMessageBox::closeEvent( TQCloseEvent *e ) +{ + TQDialog::closeEvent( e ); + if ( mbd->escButton != -1 ) + setResult( mbd->button[mbd->escButton] ); +} + +/***************************************************************************** + Static TQMessageBox functions + *****************************************************************************/ + +/*!\fn int TQMessageBox::message( const TQString &,const TQString&,const TQString&,TQWidget*,const char * ) + \obsolete + Opens a modal message box directly using the specified parameters. + + Please use information(), warning(), question(), or critical() instead. +*/ + +/*! \fn bool TQMessageBox::query( const TQString &,const TQString&,const TQString&,const TQString&,TQWidget *, const char * ) + \obsolete + Queries the user using a modal message box with two buttons. + Note that \a caption is not always shown, it depends on the window manager. + + Please use information(), question(), warning(), or critical() instead. +*/ + +/*! + Opens an information message box with the caption \a caption and + the text \a text. The dialog may have up to three buttons. Each of + the buttons, \a button0, \a button1 and \a button2 may be set to + one of the following values: + + \list + \i TQMessageBox::NoButton + \i TQMessageBox::Ok + \i TQMessageBox::Cancel + \i TQMessageBox::Yes + \i TQMessageBox::No + \i TQMessageBox::Abort + \i TQMessageBox::Retry + \i TQMessageBox::Ignore + \i TQMessageBox::YesAll + \i TQMessageBox::NoAll + \endlist + + If you don't want all three buttons, set the last button, or last + two buttons to TQMessageBox::NoButton. + + One button can be OR-ed with \c TQMessageBox::Default, and one + button can be OR-ed with \c TQMessageBox::Escape. + + Returns the identity (TQMessageBox::Ok, or TQMessageBox::No, etc.) + of the button that was clicked. + + If \a parent is 0, the message box becomes an application-global + modal dialog box. If \a parent is a widget, the message box + becomes modal relative to \a parent. + + \sa question(), warning(), critical() +*/ + +int TQMessageBox::information( TQWidget *parent, + const TQString& caption, const TQString& text, + int button0, int button1, int button2 ) +{ +#if defined(TQ_WS_X11) + if ( tqt_use_native_dialogs && TQTDEIntegration::enabled()) + return TQTDEIntegration::information( parent, caption, text, button0, button1, button2 ); +#endif + TQMessageBox *mb = new TQMessageBox( caption, text, Information, + button0, button1, button2, + parent, "qt_msgbox_information", TRUE, + WDestructiveClose); + TQ_CHECK_PTR( mb ); + return mb->exec(); +} + +/*! + Opens a question message box with the caption \a caption and the + text \a text. The dialog may have up to three buttons. Each of the + buttons, \a button0, \a button1 and \a button2 may be set to one + of the following values: + + \list + \i TQMessageBox::NoButton + \i TQMessageBox::Ok + \i TQMessageBox::Cancel + \i TQMessageBox::Yes + \i TQMessageBox::No + \i TQMessageBox::Abort + \i TQMessageBox::Retry + \i TQMessageBox::Ignore + \i TQMessageBox::YesAll + \i TQMessageBox::NoAll + \endlist + + If you don't want all three buttons, set the last button, or last + two buttons to TQMessageBox::NoButton. + + One button can be OR-ed with \c TQMessageBox::Default, and one + button can be OR-ed with \c TQMessageBox::Escape. + + Returns the identity (TQMessageBox::Yes, or TQMessageBox::No, etc.) + of the button that was clicked. + + If \a parent is 0, the message box becomes an application-global + modal dialog box. If \a parent is a widget, the message box + becomes modal relative to \a parent. + + \sa information(), warning(), critical() +*/ + +int TQMessageBox::question( TQWidget *parent, + const TQString& caption, const TQString& text, + int button0, int button1, int button2 ) +{ +#if defined(TQ_WS_X11) + if ( tqt_use_native_dialogs && TQTDEIntegration::enabled()) + return TQTDEIntegration::question( parent, caption, text, button0, button1, button2 ); +#endif + TQMessageBox *mb = new TQMessageBox( caption, text, Question, + button0, button1, button2, + parent, "qt_msgbox_information", TRUE, + WDestructiveClose); + TQ_CHECK_PTR( mb ); + return mb->exec(); +} + + +/*! + Opens a warning message box with the caption \a caption and the + text \a text. The dialog may have up to three buttons. Each of the + button parameters, \a button0, \a button1 and \a button2 may be + set to one of the following values: + + \list + \i TQMessageBox::NoButton + \i TQMessageBox::Ok + \i TQMessageBox::Cancel + \i TQMessageBox::Yes + \i TQMessageBox::No + \i TQMessageBox::Abort + \i TQMessageBox::Retry + \i TQMessageBox::Ignore + \i TQMessageBox::YesAll + \i TQMessageBox::NoAll + \endlist + + If you don't want all three buttons, set the last button, or last + two buttons to TQMessageBox::NoButton. + + One button can be OR-ed with \c TQMessageBox::Default, and one + button can be OR-ed with \c TQMessageBox::Escape. + + Returns the identity (TQMessageBox::Ok, or TQMessageBox::No, etc.) + of the button that was clicked. + + If \a parent is 0, the message box becomes an application-global + modal dialog box. If \a parent is a widget, the message box + becomes modal relative to \a parent. + + \sa information(), question(), critical() +*/ + +int TQMessageBox::warning( TQWidget *parent, + const TQString& caption, const TQString& text, + int button0, int button1, int button2 ) +{ +#if defined(TQ_WS_X11) + if ( tqt_use_native_dialogs && TQTDEIntegration::enabled()) + return TQTDEIntegration::warning( parent, caption, text, button0, button1, button2 ); +#endif + TQMessageBox *mb = new TQMessageBox( caption, text, Warning, + button0, button1, button2, + parent, "qt_msgbox_warning", TRUE, + WDestructiveClose); + TQ_CHECK_PTR( mb ); + return mb->exec(); +} + + +/*! + Opens a critical message box with the caption \a caption and the + text \a text. The dialog may have up to three buttons. Each of the + button parameters, \a button0, \a button1 and \a button2 may be + set to one of the following values: + + \list + \i TQMessageBox::NoButton + \i TQMessageBox::Ok + \i TQMessageBox::Cancel + \i TQMessageBox::Yes + \i TQMessageBox::No + \i TQMessageBox::Abort + \i TQMessageBox::Retry + \i TQMessageBox::Ignore + \i TQMessageBox::YesAll + \i TQMessageBox::NoAll + \endlist + + If you don't want all three buttons, set the last button, or last + two buttons to TQMessageBox::NoButton. + + One button can be OR-ed with \c TQMessageBox::Default, and one + button can be OR-ed with \c TQMessageBox::Escape. + + Returns the identity (TQMessageBox::Ok, or TQMessageBox::No, etc.) + of the button that was clicked. + + If \a parent is 0, the message box becomes an application-global + modal dialog box. If \a parent is a widget, the message box + becomes modal relative to \a parent. + + \sa information(), question(), warning() +*/ + +int TQMessageBox::critical( TQWidget *parent, + const TQString& caption, const TQString& text, + int button0, int button1, int button2 ) +{ +#if defined(TQ_WS_X11) + if ( tqt_use_native_dialogs && TQTDEIntegration::enabled()) + return TQTDEIntegration::critical( parent, caption, text, button0, button1, button2 ); +#endif + TQMessageBox *mb = new TQMessageBox( caption, text, Critical, + button0, button1, button2, + parent, "qt_msgbox_critical", TRUE, + WDestructiveClose); + TQ_CHECK_PTR( mb ); + return mb->exec(); +} + + +/*! + Displays a simple about box with caption \a caption and text \a + text. The about box's parent is \a parent. + + about() looks for a suitable icon in four locations: + \list 1 + \i It prefers \link TQWidget::icon() parent->icon() \endlink if that exists. + \i If not, it tries the top-level widget containing \a parent. + \i If that fails, it tries the \link + TQApplication::mainWidget() main widget. \endlink + \i As a last resort it uses the Information icon. + \endlist + + The about box has a single button labelled "OK". + + \sa TQWidget::icon() TQApplication::mainWidget() +*/ + +void TQMessageBox::about( TQWidget *parent, const TQString &caption, + const TQString& text ) +{ + TQMessageBox *mb = new TQMessageBox( caption, text, + Information, + Ok + Default, 0, 0, + parent, "qt_msgbox_simple_about_box", TRUE, + WDestructiveClose); + TQ_CHECK_PTR( mb ); +#ifndef TQT_NO_WIDGET_TOPEXTRA + const TQPixmap *pm = parent ? parent->icon() : 0; + if ( pm && !pm->isNull() ) + mb->setIconPixmap( *pm ); + else { + pm = parent ? parent->topLevelWidget()->icon() : 0; + if ( pm && !pm->isNull() ) + mb->setIconPixmap( *pm ); + else { + pm = tqApp && tqApp->mainWidget() ? tqApp->mainWidget()->icon() : 0; + if ( pm && !pm->isNull() ) + mb->setIconPixmap( *pm ); + } + } +#endif + mb->exec(); +} + + +/*! \reimp +*/ + +void TQMessageBox::styleChanged( TQStyle& ) +{ + if ( mbd->icon != NoIcon ) { + // Reload icon for new style + setIcon( mbd->icon ); + } +} + + +static int textBox( TQWidget *parent, TQMessageBox::Icon severity, + const TQString& caption, const TQString& text, + const TQString& button0Text, + const TQString& button1Text, + const TQString& button2Text, + int defaultButtonNumber, + int escapeButtonNumber ) +{ + int b[3]; + b[0] = 1; + b[1] = button1Text.isEmpty() ? 0 : 2; + b[2] = button2Text.isEmpty() ? 0 : 3; + + int i; + for( i=0; i<3; i++ ) { + if ( b[i] && defaultButtonNumber == i ) + b[i] += TQMessageBox::Default; + if ( b[i] && escapeButtonNumber == i ) + b[i] += TQMessageBox::Escape; + } + + TQMessageBox *mb = new TQMessageBox( caption, text, severity, + b[0], b[1], b[2], + parent, "qt_msgbox_information", TRUE, + TQt::WDestructiveClose); + TQ_CHECK_PTR( mb ); + if ( button0Text.isEmpty() ) + mb->setButtonText( 1, TQMessageBox::tr(mb_texts[TQMessageBox::Ok]) ); + else + mb->setButtonText( 1, button0Text ); + if ( b[1] ) + mb->setButtonText( 2, button1Text ); + if ( b[2] ) + mb->setButtonText( 3, button2Text ); + +#ifndef TQT_NO_CURSOR + mb->setCursor( TQt::arrowCursor ); +#endif + return mb->exec() - 1; +} + + +/*! + \overload + + Displays an information message box with caption \a caption, text + \a text and one, two or three buttons. Returns the index of the + button that was clicked (0, 1 or 2). + + \a button0Text is the text of the first button, and is optional. + If \a button0Text is not supplied, "OK" (translated) will be used. + \a button1Text is the text of the second button, and is optional. + \a button2Text is the text of the third button, and is optional. + \a defaultButtonNumber (0, 1 or 2) is the index of the default + button; pressing Return or Enter is the same as clicking the + default button. It defaults to 0 (the first button). \a + escapeButtonNumber is the index of the Escape button; pressing + Escape is the same as clicking this button. It defaults to -1; + supply 0, 1 or 2 to make pressing Escape equivalent to clicking + the relevant button. + + If \a parent is 0, the message box becomes an application-global + modal dialog box. If \a parent is a widget, the message box + becomes modal relative to \a parent. + + Note: If you do not specify an Escape button then if the Escape + button is pressed then -1 will be returned. It is suggested that + you specify an Escape button to prevent this from happening. + + \sa question(), warning(), critical() +*/ + +int TQMessageBox::information( TQWidget *parent, const TQString &caption, + const TQString& text, + const TQString& button0Text, + const TQString& button1Text, + const TQString& button2Text, + int defaultButtonNumber, + int escapeButtonNumber ) +{ +#if defined(TQ_WS_X11) + if ( tqt_use_native_dialogs && TQTDEIntegration::enabled()) + return TQTDEIntegration::information( parent, caption, text, + button0Text, button1Text, button2Text, defaultButtonNumber, escapeButtonNumber ); +#endif + return textBox( parent, Information, caption, text, + button0Text, button1Text, button2Text, + defaultButtonNumber, escapeButtonNumber ); +} + +/*! + \overload + + Displays a question message box with caption \a caption, text \a + text and one, two or three buttons. Returns the index of the + button that was clicked (0, 1 or 2). + + \a button0Text is the text of the first button, and is optional. + If \a button0Text is not supplied, "OK" (translated) will be used. + \a button1Text is the text of the second button, and is optional. + \a button2Text is the text of the third button, and is optional. + \a defaultButtonNumber (0, 1 or 2) is the index of the default + button; pressing Return or Enter is the same as clicking the + default button. It defaults to 0 (the first button). \a + escapeButtonNumber is the index of the Escape button; pressing + Escape is the same as clicking this button. It defaults to -1; + supply 0, 1 or 2 to make pressing Escape equivalent to clicking + the relevant button. + + If \a parent is 0, the message box becomes an application-global + modal dialog box. If \a parent is a widget, the message box + becomes modal relative to \a parent. + + Note: If you do not specify an Escape button then if the Escape + button is pressed then -1 will be returned. It is suggested that + you specify an Escape button to prevent this from happening. + + \sa information(), warning(), critical() +*/ +int TQMessageBox::question( TQWidget *parent, const TQString &caption, + const TQString& text, + const TQString& button0Text, + const TQString& button1Text, + const TQString& button2Text, + int defaultButtonNumber, + int escapeButtonNumber ) +{ +#if defined(TQ_WS_X11) + if ( tqt_use_native_dialogs && TQTDEIntegration::enabled()) + return TQTDEIntegration::question( parent, caption, text, + button0Text, button1Text, button2Text, defaultButtonNumber, escapeButtonNumber ); +#endif + return textBox( parent, Question, caption, text, + button0Text, button1Text, button2Text, + defaultButtonNumber, escapeButtonNumber ); +} + + +/*! + \overload + + Displays a warning message box with a caption, a text, and 1, 2 or + 3 buttons. Returns the number of the button that was clicked (0, + 1, or 2). + + \a button0Text is the text of the first button, and is optional. + If \a button0Text is not supplied, "OK" (translated) will be used. + \a button1Text is the text of the second button, and is optional, + and \a button2Text is the text of the third button, and is + optional. \a defaultButtonNumber (0, 1 or 2) is the index of the + default button; pressing Return or Enter is the same as clicking + the default button. It defaults to 0 (the first button). \a + escapeButtonNumber is the index of the Escape button; pressing + Escape is the same as clicking this button. It defaults to -1; + supply 0, 1, or 2 to make pressing Escape equivalent to clicking + the relevant button. + + If \a parent is 0, the message box becomes an application-global + modal dialog box. If \a parent is a widget, the message box + becomes modal relative to \a parent. + + Note: If you do not specify an Escape button then if the Escape + button is pressed then -1 will be returned. It is suggested that + you specify an Escape button to prevent this from happening. + + \sa information(), question(), critical() +*/ + +int TQMessageBox::warning( TQWidget *parent, const TQString &caption, + const TQString& text, + const TQString& button0Text, + const TQString& button1Text, + const TQString& button2Text, + int defaultButtonNumber, + int escapeButtonNumber ) +{ +#if defined(TQ_WS_X11) + if ( tqt_use_native_dialogs && TQTDEIntegration::enabled()) + return TQTDEIntegration::warning( parent, caption, text, + button0Text, button1Text, button2Text, defaultButtonNumber, escapeButtonNumber ); +#endif + return textBox( parent, Warning, caption, text, + button0Text, button1Text, button2Text, + defaultButtonNumber, escapeButtonNumber ); +} + + +/*! + \overload + + Displays a critical error message box with a caption, a text, and + 1, 2 or 3 buttons. Returns the number of the button that was + clicked (0, 1 or 2). + + \a button0Text is the text of the first button, and is optional. + If \a button0Text is not supplied, "OK" (translated) will be used. + \a button1Text is the text of the second button, and is optional, + and \a button2Text is the text of the third button, and is + optional. \a defaultButtonNumber (0, 1 or 2) is the index of the + default button; pressing Return or Enter is the same as clicking + the default button. It defaults to 0 (the first button). \a + escapeButtonNumber is the index of the Escape button; pressing + Escape is the same as clicking this button. It defaults to -1; + supply 0, 1, or 2 to make pressing Escape equivalent to clicking + the relevant button. + + If \a parent is 0, the message box becomes an application-global + modal dialog box. If \a parent is a widget, the message box + becomes modal relative to \a parent. + + \sa information(), question(), warning() +*/ + +int TQMessageBox::critical( TQWidget *parent, const TQString &caption, + const TQString& text, + const TQString& button0Text, + const TQString& button1Text, + const TQString& button2Text, + int defaultButtonNumber, + int escapeButtonNumber ) +{ +#if defined(TQ_WS_X11) + if ( tqt_use_native_dialogs && TQTDEIntegration::enabled()) + return TQTDEIntegration::critical( parent, caption, text, + button0Text, button1Text, button2Text, defaultButtonNumber, escapeButtonNumber ); +#endif + return textBox( parent, Critical, caption, text, + button0Text, button1Text, button2Text, + defaultButtonNumber, escapeButtonNumber ); +} + + +/*! + Displays a simple message box about TQt, with caption \a caption + and centered over \a parent (if \a parent is not 0). The message + includes the version number of TQt being used by the application. + + This is useful for inclusion in the Help menu of an application. + See the examples/menu/menu.cpp example. + + TQApplication provides this functionality as a slot. + + \sa TQApplication::aboutTQt() +*/ + +void TQMessageBox::aboutTQt( TQWidget *parent, const TQString &caption ) +{ + TQMessageBox *mb = new TQMessageBox( parent, "qt_msgbox_about_qt" ); + TQ_CHECK_PTR( mb ); + mb->setWFlags( WDestructiveClose ); + +#ifndef TQT_NO_WIDGET_TOPEXTRA + TQString c = caption; + if ( c.isNull() ) + c = tr( "About TQt" ); + mb->setCaption( c ); +#endif + mb->setText( *translatedTextAboutTQt ); +#ifndef TQT_NO_IMAGEIO + TQPixmap pm; + TQImage logo( (const char **)qtlogo_xpm); + if ( tqGray(mb->palette().active().text().rgb()) > + tqGray(mb->palette().active().base().rgb()) ) + { + // light on dark, adjust some colors (where's 10?) + logo.setColor( 0, 0xffffffff ); + logo.setColor( 1, 0xff666666 ); + logo.setColor( 2, 0xffcccc66 ); + logo.setColor( 4, 0xffcccccc ); + logo.setColor( 6, 0xffffff66 ); + logo.setColor( 7, 0xff999999 ); + logo.setColor( 8, 0xff3333ff ); + logo.setColor( 9, 0xffffff33 ); + logo.setColor( 11, 0xffcccc99 ); + } + if ( pm.convertFromImage( logo ) ) + mb->setIconPixmap( pm ); +#endif + mb->setButtonText( 0, tr("OK") ); + if ( mb->mbd && mb->mbd->pb[0] ) { + mb->mbd->pb[0]->setAutoDefault( TRUE ); + mb->mbd->pb[0]->setFocusPolicy( TQWidget::StrongFocus ); + mb->mbd->pb[0]->setDefault( TRUE ); + mb->mbd->pb[0]->setFocus(); + } + mb->exec(); +} + +/*! + \reimp +*/ + +void TQMessageBox::setIcon( const TQPixmap &pix ) +{ + //reimplemented to avoid compiler warning. +#ifndef TQT_NO_WIDGET_TOPEXTRA + TQDialog::setIcon( pix ); +#endif +} + + +/*! + \property TQMessageBox::textFormat + \brief the format of the text displayed by the message box + + The current text format used by the message box. See the \l + TQt::TextFormat enum for an explanation of the possible options. + + The default format is \c AutoText. + + \sa setText() +*/ + +TQt::TextFormat TQMessageBox::textFormat() const +{ + return label->textFormat(); +} + + +void TQMessageBox::setTextFormat( TQt::TextFormat format ) +{ + label->setTextFormat( format ); +} + + +#endif diff --git a/src/dialogs/tqmessagebox.h b/src/dialogs/tqmessagebox.h new file mode 100644 index 00000000..a8b56383 --- /dev/null +++ b/src/dialogs/tqmessagebox.h @@ -0,0 +1,223 @@ +/**************************************************************************** +** +** Definition of TQMessageBox class +** +** Created : 950503 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the dialogs module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQMESSAGEBOX_H +#define TQMESSAGEBOX_H + +#ifndef QT_H +#include "tqdialog.h" +#endif // QT_H + +#ifndef TQT_NO_MESSAGEBOX + +class TQLabel; +class TQPushButton; +struct TQMessageBoxData; + +class TQ_EXPORT TQMessageBox : public TQDialog +{ + TQ_OBJECT + TQ_ENUMS( Icon ) + TQ_PROPERTY( TQString text READ text WRITE setText ) + TQ_PROPERTY( Icon icon READ icon WRITE setIcon ) + TQ_PROPERTY( TQPixmap iconPixmap READ iconPixmap WRITE setIconPixmap ) + TQ_PROPERTY( TextFormat textFormat READ textFormat WRITE setTextFormat ) + +public: + enum Icon { NoIcon = 0, Information = 1, Warning = 2, Critical = 3, + Question = 4 }; + + TQMessageBox( TQWidget* parent=0, const char* name=0 ); + TQMessageBox( const TQString& caption, const TQString &text, Icon icon, + int button0, int button1, int button2, + TQWidget* parent=0, const char* name=0, bool modal=TRUE, + WFlags f=WStyle_DialogBorder ); + ~TQMessageBox(); + + enum { NoButton = 0, Ok = 1, Cancel = 2, Yes = 3, No = 4, Abort = 5, + Retry = 6, Ignore = 7, YesAll = 8, NoAll = 9, ButtonMask = 0xff, + Default = 0x100, Escape = 0x200, FlagMask = 0x300 }; + + static int information( TQWidget *parent, const TQString &caption, + const TQString& text, + int button0, int button1=0, int button2=0 ); + static int information( TQWidget *parent, const TQString &caption, + const TQString& text, + const TQString& button0Text = TQString::null, + const TQString& button1Text = TQString::null, + const TQString& button2Text = TQString::null, + int defaultButtonNumber = 0, + int escapeButtonNumber = -1 ); + + static int question( TQWidget *parent, const TQString &caption, + const TQString& text, + int button0, int button1=0, int button2=0 ); + static int question( TQWidget *parent, const TQString &caption, + const TQString& text, + const TQString& button0Text = TQString::null, + const TQString& button1Text = TQString::null, + const TQString& button2Text = TQString::null, + int defaultButtonNumber = 0, + int escapeButtonNumber = -1 ); + + static int warning( TQWidget *parent, const TQString &caption, + const TQString& text, + int button0, int button1, int button2=0 ); + static int warning( TQWidget *parent, const TQString &caption, + const TQString& text, + const TQString& button0Text = TQString::null, + const TQString& button1Text = TQString::null, + const TQString& button2Text = TQString::null, + int defaultButtonNumber = 0, + int escapeButtonNumber = -1 ); + + static int critical( TQWidget *parent, const TQString &caption, + const TQString& text, + int button0, int button1, int button2=0 ); + static int critical( TQWidget *parent, const TQString &caption, + const TQString& text, + const TQString& button0Text = TQString::null, + const TQString& button1Text = TQString::null, + const TQString& button2Text = TQString::null, + int defaultButtonNumber = 0, + int escapeButtonNumber = -1 ); + + static void about( TQWidget *parent, const TQString &caption, + const TQString& text ); + + static void aboutTQt( TQWidget *parent, + const TQString& caption=TQString::null ); + +/* OBSOLETE */ + static int message( const TQString &caption, + const TQString& text, + const TQString& buttonText=TQString::null, + TQWidget *parent=0, const char * =0 ) { + return TQMessageBox::information( parent, caption, text, + buttonText.isEmpty() + ? tr("OK") : buttonText ) == 0; + } + +/* OBSOLETE */ + static bool query( const TQString &caption, + const TQString& text, + const TQString& yesButtonText=TQString::null, + const TQString& noButtonText=TQString::null, + TQWidget *parent=0, const char * = 0 ) { + return TQMessageBox::information( parent, caption, text, + yesButtonText.isEmpty() + ? tr("OK") : yesButtonText, + noButtonText ) == 0; + } + + TQString text() const; + void setText( const TQString &); + + Icon icon() const; + + void setIcon( Icon ); + void setIcon( const TQPixmap & ); + + const TQPixmap *iconPixmap() const; + void setIconPixmap( const TQPixmap & ); + + TQString buttonText( int button ) const; + void setButtonText( int button, const TQString &); + + void adjustSize(); + +/* OBSOLETE */ + static TQPixmap standardIcon( Icon icon, GUIStyle ); + + static TQPixmap standardIcon( Icon icon ); + + TextFormat textFormat() const; + void setTextFormat( TextFormat ); + +protected: + void resizeEvent( TQResizeEvent * ); + void showEvent( TQShowEvent * ); + void closeEvent( TQCloseEvent * ); + void keyPressEvent( TQKeyEvent * ); + void styleChanged( TQStyle& ); + +private slots: + void buttonClicked(); + +private: + void init( int, int, int ); + int indexOf( int ) const; + void resizeButtons(); + TQLabel *label; + TQMessageBoxData *mbd; + void *reserved1; + void *reserved2; + +private: // Disabled copy constructor and operator= +#if defined(TQ_DISABLE_COPY) + TQMessageBox( const TQMessageBox & ); + TQMessageBox &operator=( const TQMessageBox & ); +#endif +}; + +/* +* Macro to be used at the beginning of main(), e.g. +* +* #include +* #include +* int main( int argc, char**argv ) +* { +* QT_REQUIRE_VERSION( argc, argv, "3.0.5" ) +* ... +* } +*/ +#define QT_REQUIRE_VERSION( argc, argv, str ) { TQString s=TQString::fromLatin1(str);\ +TQString sq=TQString::fromLatin1(tqVersion()); if ( (sq.section('.',0,0).toInt()<<16)+\ +(sq.section('.',1,1).toInt()<<8)+sq.section('.',2,2).toInt()<(s.section('.',0,0).toInt()<<16)+\ +(s.section('.',1,1).toInt()<<8)+s.section('.',2,2).toInt() ){if ( !tqApp){ int c=0; new \ +TQApplication(argc,argv);} TQString s = TQApplication::tr("Executable '%1' requires TQt "\ + "%2, found TQt %3.").arg(TQString::fromLatin1(tqAppName())).arg(TQString::fromLatin1(\ +str)).arg(TQString::fromLatin1(tqVersion()) ); TQMessageBox::critical( 0, TQApplication::tr(\ +"Incompatible TQt Library Error" ), s, TQMessageBox::Abort,0 ); tqFatal(s.ascii()); }} + + +#endif // TQT_NO_MESSAGEBOX + +#endif // TQMESSAGEBOX_H diff --git a/src/dialogs/tqprintdialog.cpp b/src/dialogs/tqprintdialog.cpp new file mode 100644 index 00000000..a82ae4ee --- /dev/null +++ b/src/dialogs/tqprintdialog.cpp @@ -0,0 +1,1677 @@ +/**************************************************************************** +** +** Implementation of internal print dialog (X11) used by TQPrinter::select(). +** +** Created : 950829 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the dialogs module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "tqprintdialog.h" + +#ifndef TQT_NO_PRINTDIALOG + +#include "tqfiledialog.h" +#include "tqfile.h" +#include "tqtextstream.h" +#include "tqcombobox.h" +#include "tqframe.h" +#include "tqlabel.h" +#include "tqlineedit.h" +#include "tqpushbutton.h" +#include "tqprinter.h" +#include "tqlistview.h" +#include "tqlayout.h" +#include "tqbuttongroup.h" +#include "tqradiobutton.h" +#include "tqspinbox.h" +#include "ntqapplication.h" +#include "tqheader.h" +#include "tqstyle.h" +#include "tqstring.h" +#include "tqregexp.h" +#if !defined(TQT_NO_CUPS) || !defined(TQT_NO_NIS) +#include "tqlibrary.h" +#endif + +#ifndef TQT_NO_NIS + +#ifndef BOOL_DEFINED +#define BOOL_DEFINED +#endif + +#include +#include + +// Solaris redefines connect -> __xnet_connect with _XOPEN_SOURCE_EXTENDED. +#if defined(connect) +# undef connect +#endif + +#endif // TQT_NO_NIS + +// UNIX Large File Support redefines open -> open64 +#if defined(open) +# undef open +#endif + +#include +#include + + +class TQPrintDialogSpinBox : public TQSpinBox +{ +public: + TQPrintDialogSpinBox(int min, int max, int steps, TQWidget *parent, const char *name) + : TQSpinBox(min, max, steps, parent, name) + {} + + void interpretText() + { + TQSpinBox::interpretText(); + } +}; + + + + +enum { Success = 's', Unavail = 'u', NotFound = 'n', TryAgain = 't' }; +enum { Continue = 'c', Return = 'r' }; + +class TQPrintDialogPrivate +{ +public: + TQPrinter * printer; + + TQButtonGroup * printerOrFile; + + bool outputToFile; + TQListView * printers; + TQLineEdit * fileName; + TQPushButton * browse, *ok; + + TQButtonGroup * printRange; + TQLabel * firstPageLabel; + TQPrintDialogSpinBox * firstPage; + TQLabel * lastPageLabel; + TQPrintDialogSpinBox * lastPage; + TQRadioButton * printAllButton; + TQRadioButton * printRangeButton; + TQRadioButton * printSelectionButton; + TQRadioButton * printToFileButton; + TQComboBox *orientationCombo, *sizeCombo; + + TQPrinter::PageSize pageSize; + TQPrinter::Orientation orientation; + + TQButtonGroup * pageOrder; + TQPrinter::PageOrder pageOrder2; + + TQButtonGroup * colorMode; + TQPrinter::ColorMode colorMode2; + + TQPrintDialogSpinBox * copies; + int numCopies; + + TQBoxLayout *customLayout; + + TQPrinter::PageSize indexToPageSize[TQPrinter::NPageSize]; +}; + + +typedef void (*Q_PrintDialogHook)(TQListView *); +static Q_PrintDialogHook addPrinterHook = 0; + +void qt_set_printdialog_hook( Q_PrintDialogHook hook ) +{ + addPrinterHook = hook; +} + +static void isc( TQPrintDialogPrivate * d, const TQString & text, + TQPrinter::PageSize ps ); + +class TQPrinterListViewItem : public TQListViewItem +{ +public: + TQPrinterListViewItem( TQListView * printers, const TQString& name, + const TQString& host, const TQString& comment, + const TQStringList& aliases ) + : TQListViewItem( printers, name, host, comment ), ali( aliases ) { } + + bool samePrinter( const TQString& name ) { + return text( 0 ) == name || ali.find( name ) != ali.end(); + } + + TQStringList ali; +}; + +static void perhapsAddPrinter( TQListView * printers, const TQString &name, + TQString host, TQString comment, + TQStringList aliases = TQStringList() ) +{ + const TQListViewItem * i = printers->firstChild(); + while ( i && !((TQPrinterListViewItem *) i)->samePrinter(name) ) + i = i->nextSibling(); + if ( i ) + return; + if ( host.isEmpty() ) + host = TQPrintDialog::tr( "locally connected" ); + (void)new TQPrinterListViewItem( printers, + name.simplifyWhiteSpace(), + host.simplifyWhiteSpace(), + comment.simplifyWhiteSpace(), aliases ); +} + +static void parsePrinterDesc( TQString printerDesc, TQListView * printers ) +{ + if ( printerDesc.length() < 1 ) + return; + + printerDesc = printerDesc.simplifyWhiteSpace(); + int i = printerDesc.find( ':' ); + TQString printerName, printerComment, printerHost; + TQStringList aliases; + + if ( i >= 0 ) { + // have ':' want '|' + int j = printerDesc.find( '|' ); + if ( j > 0 && j < i ) { + printerName = printerDesc.left( j ); + aliases = TQStringList::split( '|', + printerDesc.mid(j + 1, i - j - 1) ); + // try extracting a comment from the aliases + printerComment = TQPrintDialog::tr( "Aliases: %1" ) + .arg( aliases.join(", ") ); + } else { + printerName = printerDesc.left( i ); + } + // look for lprng pseudo all printers entry + i = printerDesc.find( TQRegExp(TQString::fromLatin1(": *all *=")) ); + if ( i >= 0 ) + printerName = ""; + // look for signs of this being a remote printer + i = printerDesc.find( TQRegExp(TQString::fromLatin1(": *rm *=")) ); + if ( i >= 0 ) { + // point k at the end of remote host name + while ( printerDesc[i] != '=' ) + i++; + while ( printerDesc[i] == '=' || printerDesc[i].isSpace() ) + i++; + j = i; + while ( j < (int)printerDesc.length() && printerDesc[j] != ':' ) + j++; + + // and stuff that into the string + printerHost = printerDesc.mid( i, j - i ); + } + } + if ( printerName.length() ) + perhapsAddPrinter( printers, printerName, printerHost, printerComment, + aliases ); +} + +static int parsePrintcap( TQListView * printers, const TQString& fileName ) +{ + TQFile printcap( fileName ); + if ( !printcap.open( IO_ReadOnly ) ) + return NotFound; + + char * line_ascii = new char[1025]; + line_ascii[1024] = '\0'; + + TQString printerDesc; + bool atEnd = FALSE; + + while ( !atEnd ) { + if ( printcap.atEnd() || printcap.readLine( line_ascii, 1024 ) <= 0 ) + atEnd = TRUE; + TQString line = line_ascii; + line = line.stripWhiteSpace(); + if ( line.length() >= 1 && line[int(line.length()) - 1] == '\\' ) + line.truncate( line.length() - 1 ); + if ( line[0] == '#' ) { + if ( !atEnd ) + continue; + } else if ( line[0] == '|' || line[0] == ':' ) { + printerDesc += line; + if ( !atEnd ) + continue; + } + + parsePrinterDesc( printerDesc, printers ); + + // add the first line of the new printer definition + printerDesc = line; + } + delete[] line_ascii; + return Success; +} + + +// solaris, not 2.6 +static void parseEtcLpPrinters( TQListView * printers ) +{ + TQDir lp( TQString::fromLatin1("/etc/lp/printers") ); + const TQFileInfoList * dirs = lp.entryInfoList(); + if ( !dirs ) + return; + + TQFileInfoListIterator it( *dirs ); + TQFileInfo *printer; + TQString tmp; + while ( (printer = it.current()) != 0 ) { + ++it; + if ( printer->isDir() ) { + tmp.sprintf( "/etc/lp/printers/%s/configuration", + printer->fileName().ascii() ); + TQFile configuration( tmp ); + char * line = new char[1025]; + TQString remote( TQString::fromLatin1("Remote:") ); + TQString contentType( TQString::fromLatin1("Content types:") ); + TQString printerHost; + bool canPrintPostscript = FALSE; + if ( configuration.open( IO_ReadOnly ) ) { + while ( !configuration.atEnd() && + configuration.readLine( line, 1024 ) > 0 ) { + if ( TQString::fromLatin1(line).startsWith( remote ) ) { + const char * p = line; + while ( *p != ':' ) + p++; + p++; + while ( isspace((uchar) *p) ) + p++; + printerHost = TQString::fromLocal8Bit(p); + printerHost = printerHost.simplifyWhiteSpace(); + } else if ( TQString::fromLatin1(line).startsWith( contentType ) ) { + char * p = line; + while ( *p != ':' ) + p++; + p++; + char * e; + while ( *p ) { + while ( isspace((uchar) *p) ) + p++; + if ( *p ) { + char s; + e = p; + while ( isalnum((uchar) *e) ) + e++; + s = *e; + *e = '\0'; + if ( !qstrcmp( p, "postscript" ) || + !qstrcmp( p, "any" ) ) + canPrintPostscript = TRUE; + *e = s; + if ( s == ',' ) + e++; + p = e; + } + } + } + } + if ( canPrintPostscript ) + perhapsAddPrinter( printers, printer->fileName(), + printerHost, TQString::fromLatin1("") ); + } + delete[] line; + } + } +} + + +// solaris 2.6 +static char * parsePrintersConf( TQListView * printers, bool *found = 0 ) +{ + TQFile pc( TQString::fromLatin1("/etc/printers.conf") ); + if ( !pc.open( IO_ReadOnly ) ) { + if ( found ) + *found = FALSE; + return 0; + } + if ( found ) + *found = TRUE; + + char * line = new char[1025]; + line[1024] = '\0'; + + TQString printerDesc; + int lineLength = 0; + + char * defaultPrinter = 0; + + while ( !pc.atEnd() && + (lineLength=pc.readLine( line, 1024 )) > 0 ) { + if ( *line == '#' ) { + *line = '\0'; + lineLength = 0; + } + if ( lineLength >= 2 && line[lineLength-2] == '\\' ) { + line[lineLength-2] = '\0'; + printerDesc += TQString::fromLocal8Bit(line); + } else { + printerDesc += TQString::fromLocal8Bit(line); + printerDesc = printerDesc.simplifyWhiteSpace(); + int i = printerDesc.find( ':' ); + TQString printerName, printerHost, printerComment; + TQStringList aliases; + if ( i >= 0 ) { + // have : want | + int j = printerDesc.find( '|', 0 ); + if ( j >= i ) + j = -1; + printerName = printerDesc.mid( 0, j < 0 ? i : j ); + if ( printerName == TQString::fromLatin1("_default") ) { + i = printerDesc.find( + TQRegExp( TQString::fromLatin1(": *use *=") ) ); + while ( printerDesc[i] != '=' ) + i++; + while ( printerDesc[i] == '=' || printerDesc[i].isSpace() ) + i++; + j = i; + while ( j < (int)printerDesc.length() && + printerDesc[j] != ':' && printerDesc[j] != ',' ) + j++; + // that's our default printer + defaultPrinter = + tqstrdup( printerDesc.mid( i, j-i ).ascii() ); + printerName = ""; + printerDesc = ""; + } else if ( printerName == TQString::fromLatin1("_all") ) { + // skip it.. any other cases we want to skip? + printerName = ""; + printerDesc = ""; + } + + if ( j > 0 ) { + // try extracting a comment from the aliases + aliases = TQStringList::split( '|', + printerDesc.mid(j + 1, i - j - 1) ); + printerComment = TQPrintDialog::tr( "Aliases: %1" ) + .arg( aliases.join(", ") ); + } + // look for signs of this being a remote printer + i = printerDesc.find( + TQRegExp( TQString::fromLatin1(": *bsdaddr *=") ) ); + if ( i >= 0 ) { + // point k at the end of remote host name + while ( printerDesc[i] != '=' ) + i++; + while ( printerDesc[i] == '=' || printerDesc[i].isSpace() ) + i++; + j = i; + while ( j < (int)printerDesc.length() && + printerDesc[j] != ':' && printerDesc[j] != ',' ) + j++; + // and stuff that into the string + printerHost = printerDesc.mid( i, j-i ); + // maybe stick the remote printer name into the comment + if ( printerDesc[j] == ',' ) { + i = ++j; + while ( printerDesc[i].isSpace() ) + i++; + j = i; + while ( j < (int)printerDesc.length() && + printerDesc[j] != ':' && printerDesc[j] != ',' ) + j++; + if ( printerName != printerDesc.mid( i, j-i ) ) { + printerComment = + TQString::fromLatin1("Remote name: "); + printerComment += printerDesc.mid( i, j-i ); + } + } + } + } + if ( printerComment == ":" ) + printerComment = ""; // for cups + if ( printerName.length() ) + perhapsAddPrinter( printers, printerName, printerHost, + printerComment, aliases ); + // chop away the line, for processing the next one + printerDesc = ""; + } + } + delete[] line; + return defaultPrinter; +} + +#ifndef TQT_NO_NIS + +#if defined(Q_C_CALLBACKS) +extern "C" { +#endif + +static int foreach( int /* status */, char * /* key */, int /* keyLen */, + char * val, int valLen, char * data ) +{ + parsePrinterDesc( TQString::fromLatin1(val, valLen), (TQListView *) data ); + return 0; +} + +#if defined(Q_C_CALLBACKS) +} +#endif + +static int retrieveNisPrinters( TQListView * printers ) +{ + typedef int (*WildCast)( int, char *, int, char *, int, char * ); + char printersConfByname[] = "printers.conf.byname"; + char *domain; + int err; + + TQLibrary lib( "nsl" ); + typedef int (*ypGetDefaultDomain)(char **); + ypGetDefaultDomain _ypGetDefaultDomain = (ypGetDefaultDomain)lib.resolve( "yp_get_default_domain" ); + typedef int (*ypAll)(const char *, const char *, const struct ypall_callback *); + ypAll _ypAll = (ypAll)lib.resolve( "yp_all" ); + + if ( _ypGetDefaultDomain && _ypAll ) { + err = _ypGetDefaultDomain( &domain ); + if ( err == 0 ) { + ypall_callback cb; + // wild cast to support K&R-style system headers + (WildCast &) cb.foreach = (WildCast) foreach; + cb.data = (char *) printers; + err = _ypAll( domain, printersConfByname, &cb ); + } + if ( !err ) + return Success; + } + return Unavail; +} + +#endif // TQT_NO_NIS + +static char *parseNsswitchPrintersEntry( TQListView * printers, char *line ) +{ +#define skipSpaces() \ + while ( isspace((uchar) line[k]) ) \ + k++ + + char *defaultPrinter = 0; + bool stop = FALSE; + int lastStatus = NotFound; + + int k = 8; + skipSpaces(); + if ( line[k] != ':' ) + return 0; + k++; + + char *cp = strchr( line, '#' ); + if ( cp != 0 ) + *cp = '\0'; + + while ( line[k] != '\0' ) { + if ( isspace((uchar) line[k]) ) { + k++; + } else if ( line[k] == '[' ) { + k++; + skipSpaces(); + while ( line[k] != '\0' ) { + char status = tolower( line[k] ); + char action = '?'; + + while ( line[k] != '=' && line[k] != ']' && + line[k] != '\0' ) + k++; + if ( line[k] == '=' ) { + k++; + skipSpaces(); + action = tolower( line[k] ); + while ( line[k] != '\0' && !isspace((uchar) line[k]) && line[k] != ']' ) + k++; + } else if ( line[k] == ']' ) { + k++; + break; + } + skipSpaces(); + + if ( lastStatus == status ) + stop = ( action == (char) Return ); + } + } else { + if ( stop ) + break; + + TQCString source; + while ( line[k] != '\0' && !isspace((uchar) line[k]) && line[k] != '[' ) { + source += line[k]; + k++; + } + + if ( source == "user" ) { + lastStatus = parsePrintcap( printers, + TQDir::homeDirPath() + "/.printers" ); + } else if ( source == "files" ) { + bool found; + defaultPrinter = parsePrintersConf( printers, &found ); + if ( found ) + lastStatus = Success; +#ifndef TQT_NO_NIS + } else if ( source == "nis" ) { + lastStatus = retrieveNisPrinters( printers ); +#endif + } else { + // nisplus, dns, etc., are not implemented yet + lastStatus = NotFound; + } + stop = ( lastStatus == Success ); + } + } + return defaultPrinter; +} + +static char *parseNsswitchConf( TQListView * printers ) +{ + TQFile nc( TQString::fromLatin1("/etc/nsswitch.conf") ); + if ( !nc.open(IO_ReadOnly) ) + return 0; + + char *defaultPrinter = 0; + + char *line = new char[1025]; + line[1024] = '\0'; + + while ( !nc.atEnd() && + nc.readLine(line, 1024) > 0 ) { + if ( strncmp(line, "printers", 8) == 0 ) { + defaultPrinter = parseNsswitchPrintersEntry( printers, line ); + delete[] line; + return defaultPrinter; + } + } + + strcpy( line, "printers: user files nis nisplus xfn" ); + defaultPrinter = parseNsswitchPrintersEntry( printers, line ); + delete[] line; + return defaultPrinter; +} + +// HP-UX +static void parseEtcLpMember( TQListView * printers ) +{ + TQDir lp( TQString::fromLatin1("/etc/lp/member") ); + if ( !lp.exists() ) + return; + const TQFileInfoList * dirs = lp.entryInfoList(); + if ( !dirs ) + return; + + TQFileInfoListIterator it( *dirs ); + TQFileInfo *printer; + TQString tmp; + while ( (printer = it.current()) != 0 ) { + ++it; + // I haven't found any real documentation, so I'm guessing that + // since lpstat uses /etc/lp/member rather than one of the + // other directories, it's the one to use. I did not find a + // decent way to locate aliases and remote printers. + if ( printer->isFile() ) + perhapsAddPrinter( printers, printer->fileName(), + TQPrintDialog::tr("unknown"), + TQString::fromLatin1("") ); + } +} + +// IRIX 6.x +static void parseSpoolInterface( TQListView * printers ) +{ + TQDir lp( TQString::fromLatin1("/usr/spool/lp/interface") ); + if ( !lp.exists() ) + return; + const TQFileInfoList * files = lp.entryInfoList(); + if( !files ) + return; + + TQFileInfoListIterator it( *files ); + TQFileInfo *printer; + while ( (printer = it.current()) != 0) { + ++it; + + if ( !printer->isFile() ) + continue; + + // parse out some information + TQFile configFile( printer->filePath() ); + if ( !configFile.open( IO_ReadOnly ) ) + continue; + + TQCString line( 1025 ); + TQString namePrinter; + TQString hostName; + TQString hostPrinter; + TQString printerType; + + TQString nameKey( TQString::fromLatin1("NAME=") ); + TQString typeKey( TQString::fromLatin1("TYPE=") ); + TQString hostKey( TQString::fromLatin1("HOSTNAME=") ); + TQString hostPrinterKey( TQString::fromLatin1("HOSTPRINTER=") ); + + while ( !configFile.atEnd() && + (configFile.readLine(line.data(), 1024)) > 0 ) { + TQString uline = line; + if ( uline.startsWith( typeKey ) ) { + printerType = line.mid( nameKey.length() ); + printerType = printerType.simplifyWhiteSpace(); + } else if ( uline.startsWith( hostKey ) ) { + hostName = line.mid( hostKey.length() ); + hostName = hostName.simplifyWhiteSpace(); + } else if ( uline.startsWith( hostPrinterKey ) ) { + hostPrinter = line.mid( hostPrinterKey.length() ); + hostPrinter = hostPrinter.simplifyWhiteSpace(); + } else if ( uline.startsWith( nameKey ) ) { + namePrinter = line.mid( nameKey.length() ); + namePrinter = namePrinter.simplifyWhiteSpace(); + } + } + configFile.close(); + + printerType = printerType.stripWhiteSpace(); + if ( printerType.find("postscript", 0, FALSE) < 0 ) + continue; + + int ii = 0; + while ( (ii = namePrinter.find('"', ii)) >= 0 ) + namePrinter.remove( ii, 1 ); + + if ( hostName.isEmpty() || hostPrinter.isEmpty() ) { + perhapsAddPrinter( printers, printer->fileName(), + TQString::fromLatin1(""), namePrinter ); + } else { + TQString comment; + comment = namePrinter; + comment += " ("; + comment += hostPrinter; + comment += ")"; + perhapsAddPrinter( printers, printer->fileName(), + hostName, comment ); + } + } +} + + +// Every unix must have its own. It's a standard. Here is AIX. +static void parseQconfig( TQListView * printers ) +{ + TQFile qconfig( TQString::fromLatin1("/etc/qconfig") ); + if ( !qconfig.open( IO_ReadOnly ) ) + return; + + TQTextStream ts( &qconfig ); + TQString line; + + TQString stanzaName; // either a queue or a device name + bool up = TRUE; // queue up? default TRUE, can be FALSE + TQString remoteHost; // null if local + TQString deviceName; // null if remote + + TQRegExp newStanza( TQString::fromLatin1("^[0-z\\-]+:$") ); + + // our basic strategy here is to process each line, detecting new + // stanzas. each time we see a new stanza, we check if the + // previous stanza was a valid queue for a) a remote printer or b) + // a local printer. if it wasn't, we assume that what we see is + // the start of the first stanza, or that the previous stanza was + // a device stanza, or that there is some syntax error (we don't + // report those). + + do { + line = ts.readLine(); + bool indented = line[0].isSpace(); + line = line.simplifyWhiteSpace(); + + int i = line.find('='); + if ( indented && i != -1 ) { // line in stanza + TQString variable = line.left( i ).simplifyWhiteSpace(); + TQString value=line.mid( i+1, line.length() ).simplifyWhiteSpace(); + if ( variable == TQString::fromLatin1("device") ) + deviceName = value; + else if ( variable == TQString::fromLatin1("host") ) + remoteHost = value; + else if ( variable == TQString::fromLatin1("up") ) + up = !(value.lower() == TQString::fromLatin1("false")); + } else if ( line[0] == '*' ) { // comment + // nothing to do + } else if ( ts.atEnd() || // end of file, or beginning of new stanza + ( !indented && line.find( newStanza ) != -1 ) ) { + if ( up && stanzaName.length() > 0 && stanzaName.length() < 21 ) { + if ( remoteHost.length() ) // remote printer + perhapsAddPrinter( printers, stanzaName, remoteHost, + TQString::null ); + else if ( deviceName.length() ) // local printer + perhapsAddPrinter( printers, stanzaName, TQString::null, + TQString::null ); + } + line.truncate( line.length()-1 ); + if ( line.length() >= 1 && line.length() <= 20 ) + stanzaName = line; + up = TRUE; + remoteHost = TQString::null; + deviceName = TQString::null; + } else { + // syntax error? ignore. + } + } while ( !ts.atEnd() ); +} + + +#ifndef TQT_NO_CUPS +#include + +static char * parseCupsOutput( TQListView * printers ) +{ + char * defaultPrinter = 0; + int nd; + cups_dest_t * d; + TQLibrary lib( "cups" ); + typedef int (*CupsGetDests)(cups_dest_t **dests); + typedef void (*CupsFreeDests)(int num_dents, cups_dest_t *dests); + CupsGetDests _cupsGetDests = (CupsGetDests)lib.resolve( "cupsGetDests" ); + CupsFreeDests _cupsFreeDests = (CupsFreeDests)lib.resolve( "cupsFreeDests" ); + if ( _cupsGetDests ) { + nd = _cupsGetDests( &d ); + if ( nd < 1 ) + return 0; + + int n = 0; + while ( n < nd ) { + perhapsAddPrinter( printers, d[n].name, + TQPrintDialog::tr("Unknown Location"), 0 ); + if ( d[n].is_default && !defaultPrinter ) + defaultPrinter = tqstrdup( d[n].instance ); + n++; + } + if ( _cupsFreeDests ) { + _cupsFreeDests(nd, d); + } + } + return defaultPrinter; +} +#endif + +static TQPrintDialog * globalPrintDialog = 0; + +static void qpd_cleanup_globaldialog() +{ + if ( globalPrintDialog != 0 ) + delete globalPrintDialog; + globalPrintDialog = 0; +} + +/*! + \class TQPrintDialog tqprintdialog.h + + \brief The TQPrintDialog class provides a dialog for specifying + the printer's configuration. + + \internal + + \warning The use of this class is not recommended since it is not + present on all platforms; use TQPrinter::setup() instead. + + \omit + + (ingroup dialogs) + + THIS DOCUMENTATION IS Not Revised. It must be revised before + becoming public API. + + It encompasses both the sort of details needed for doing a simple + print-out and some print configuration setup. + + The easiest way to use the class is through the static + function getPrinterSetup(). You can also subclass the TQPrintDialog + and add some custom buttons with addButton() to extend the + functionality of the print dialog. + +
+ The printer dialog, on a large screen, in Motif style. +*/ + + +/*! Constructs a new modal printer dialog that configures \a prn and is a + child of \a parent named \a name. +*/ + +TQPrintDialog::TQPrintDialog( TQPrinter *prn, TQWidget *parent, const char *name ) + : TQDialog( parent, name, TRUE ) +{ + d = new TQPrintDialogPrivate; + d->numCopies = 1; + + TQBoxLayout * tll = new TQBoxLayout( this, TQBoxLayout::Down, 12, 0 ); + + // destination + TQGroupBox * g; + g = setupDestination(); + tll->addWidget( g, 1 ); + + tll->addSpacing( 12 ); + + // printer and paper settings + TQBoxLayout * lay = new TQBoxLayout( TQBoxLayout::LeftToRight ); + tll->addLayout( lay ); + + g = setupPrinterSettings(); + lay->addWidget( g, 1 ); + + lay->addSpacing( 12 ); + + g = setupPaper(); + lay->addWidget( g ); + + tll->addSpacing( 12 ); + + // options + g = setupOptions(); + tll->addWidget( g ); + tll->addSpacing( 12 ); + + TQBoxLayout *l = new TQBoxLayout( TQBoxLayout::LeftToRight ); + d->customLayout = new TQBoxLayout( TQBoxLayout::LeftToRight ); + tll->addLayout( l ); + l->addLayout( d->customLayout ); + l->addStretch(); + tll->addSpacing( 12 ); + + // buttons + TQBoxLayout *horiz = new TQBoxLayout( TQBoxLayout::LeftToRight ); + tll->addLayout( horiz ); + + bool rightalign = + bool(style().styleHint(TQStyle::SH_PrintDialog_RightAlignButtons, this)); + + if (rightalign) + horiz->addStretch( 1 ); + + d->ok = new TQPushButton( this, "ok" ); + d->ok->setText( tr("OK") ); + d->ok->setDefault( TRUE ); + horiz->addWidget( d->ok ); + if (! rightalign) + horiz->addStretch( 1 ); + horiz->addSpacing( 6 ); + + TQPushButton * cancel = new TQPushButton( this, "cancel" ); + cancel->setText( tr("Cancel") ); + horiz->addWidget( cancel ); + + TQSize s1 = d->ok->sizeHint(); + TQSize s2 = cancel->sizeHint(); + s1 = TQSize( TQMAX(s1.width(), s2.width()), + TQMAX(s1.height(), s2.height()) ); + + d->ok->setFixedSize( s1 ); + cancel->setFixedSize( s1 ); + + tll->activate(); + + connect( d->ok, TQ_SIGNAL(clicked()), TQ_SLOT(okClicked()) ); + connect( cancel, TQ_SIGNAL(clicked()), TQ_SLOT(reject()) ); + + TQSize ms( minimumSize() ); + TQSize ss( TQApplication::desktop()->screenGeometry( pos() ).size() ); + if ( ms.height() < 512 && ss.height() >= 600 ) + ms.setHeight( 512 ); + else if ( ms.height() < 460 && ss.height() >= 480 ) + ms.setHeight( 460 ); + resize( ms ); + + setPrinter( prn, TRUE ); + d->printers->setFocus(); +} + + +/*! Destroys the object and frees any allocated resources. Does not + delete the associated TQPrinter object. +*/ + +TQPrintDialog::~TQPrintDialog() +{ + if ( this == globalPrintDialog ) + globalPrintDialog = 0; + delete d; +} + +/*! + This method allows you to specify a global print dialog, given in \a + pd, that will be used instead of the default dialog provided by TQt. + + This is useful, since there are many different printing systems on + Unix, and we cannot support all of them. Calling this method before + using a printer for the first time allows you to set up your own + print dialog. + + \sa setupPrinters() +*/ +void TQPrintDialog::setGlobalPrintDialog( TQPrintDialog *pd ) +{ + TQPrintDialog *oldPd = globalPrintDialog; + globalPrintDialog = pd; + if ( oldPd ) + delete oldPd; + else + tqAddPostRoutine( qpd_cleanup_globaldialog ); + globalPrintDialog->adjustSize(); +} + +TQGroupBox * TQPrintDialog::setupPrinterSettings() +{ + TQGroupBox * g = new TQGroupBox( 1, Horizontal, tr( "Printer settings"), + this, "settings group box" ); + + d->colorMode = new TQButtonGroup( this ); + d->colorMode->hide(); + connect( d->colorMode, TQ_SIGNAL(clicked(int)), + this, TQ_SLOT(colorModeSelected(int)) ); + + TQRadioButton *rb; + rb = new TQRadioButton( tr( "Print in color if available" ), + g, "color" ); + d->colorMode->insert( rb, TQPrinter::Color ); + rb->setChecked( TRUE ); + + rb = new TQRadioButton( tr("Print in grayscale"), + g, "graysacle" ); + d->colorMode->insert( rb, TQPrinter::GrayScale ); + + return g; +} + +TQGroupBox * TQPrintDialog::setupDestination() +{ + TQGroupBox * g = new TQGroupBox( 0, Horizontal, tr( "Print destination"), + this, "destination group box" ); + + TQBoxLayout * tll = new TQBoxLayout( g->layout(), TQBoxLayout::Down ); + + d->printerOrFile = new TQButtonGroup( this ); + d->printerOrFile->hide(); + connect( d->printerOrFile, TQ_SIGNAL(clicked(int)), + this, TQ_SLOT(printerOrFileSelected(int)) ); + + // printer radio button, list + TQRadioButton * rb = new TQRadioButton( tr( "Print to printer:" ), g, + "printer" ); + tll->addWidget( rb ); + d->printerOrFile->insert( rb, 0 ); + rb->setChecked( TRUE ); + d->outputToFile = FALSE; + + TQBoxLayout * horiz = new TQBoxLayout( TQBoxLayout::LeftToRight ); + tll->addLayout( horiz, 3 ); + horiz->addSpacing( 19 ); + + d->printers = new TQListView( g, "list of printers" ); + d->printers->setAllColumnsShowFocus( TRUE ); + d->printers->addColumn( tr("Printer"), 125 ); + d->printers->addColumn( tr("Host"), 125 ); + d->printers->addColumn( tr("Comment"), 150 ); + +#if defined(Q_OS_UNIX) + char * etcLpDefault = 0; + +#ifndef TQT_NO_CUPS + etcLpDefault = parseCupsOutput( d->printers ); +#endif + if ( d->printers->childCount() == 0 ) { + // we only use other schemes when cups fails. + + parsePrintcap( d->printers, TQString::fromLatin1("/etc/printcap") ); + parseEtcLpMember( d->printers ); + parseSpoolInterface( d->printers ); + parseQconfig( d->printers ); + if ( addPrinterHook ) + (*addPrinterHook)( d->printers ); + + TQFileInfo f; + f.setFile( TQString::fromLatin1("/etc/lp/printers") ); + if ( f.isDir() ) { + parseEtcLpPrinters( d->printers ); + TQFile def( TQString::fromLatin1("/etc/lp/default") ); + if ( def.open( IO_ReadOnly ) ) { + if ( etcLpDefault ) + delete[] etcLpDefault; + etcLpDefault = new char[1025]; + def.readLine( etcLpDefault, 1024 ); + char * p = etcLpDefault; + while ( p && *p ) { + if ( !isprint((uchar) *p) || isspace((uchar) *p) ) + *p = 0; + else + p++; + } + } + } + + char * def = 0; + f.setFile( TQString::fromLatin1("/etc/nsswitch.conf") ); + if ( f.isFile() ) { + def = parseNsswitchConf( d->printers ); + } else { + f.setFile( TQString::fromLatin1("/etc/printers.conf") ); + if ( f.isFile() ) + def = parsePrintersConf( d->printers ); + } + + if ( def ) { + if ( etcLpDefault ) + delete[] etcLpDefault; + etcLpDefault = def; + } + } + + // all printers hopefully known. try to find a good default + TQString dollarPrinter; + { + const char * t = getenv( "PRINTER" ); + if ( !t || !*t ) + t = getenv( "LPDEST" ); + dollarPrinter = TQString::fromLatin1( t ); + if ( !dollarPrinter.isEmpty() ) + perhapsAddPrinter( d->printers, dollarPrinter, + TQPrintDialog::tr("unknown"), + TQString::fromLatin1("") ); + } + int quality = 0; + + // bang the best default into the listview + const TQListViewItem * lvi = d->printers->firstChild(); + d->printers->setCurrentItem( (TQListViewItem *)lvi ); + while ( lvi ) { + TQRegExp ps( TQString::fromLatin1("[^a-z]ps(?:[^a-z]|$)") ); + TQRegExp lp( TQString::fromLatin1("[^a-z]lp(?:[^a-z]|$)") ); + + if ( quality < 4 && lvi->text(0) == dollarPrinter ) { + d->printers->setCurrentItem( (TQListViewItem *)lvi ); + quality = 4; + } else if ( quality < 3 && etcLpDefault && + lvi->text(0) == TQString::fromLatin1(etcLpDefault) ) { + d->printers->setCurrentItem( (TQListViewItem *)lvi ); + quality = 3; + } else if ( quality < 2 && + ( lvi->text(0) == TQString::fromLatin1("ps") || + ps.search(lvi->text(2)) != -1 ) ) { + d->printers->setCurrentItem( (TQListViewItem *)lvi ); + quality = 2; + } else if ( quality < 1 && + ( lvi->text(0) == TQString::fromLatin1("lp") || + lp.search(lvi->text(2)) > -1 ) ) { + d->printers->setCurrentItem( (TQListViewItem *)lvi ); + quality = 1; + } + lvi = lvi->nextSibling(); + } + + if ( d->printers->currentItem() ) + d->printers->setSelected( d->printers->currentItem(), TRUE ); + + if ( etcLpDefault ) // Avoid purify complaint + delete[] etcLpDefault; +#endif + + int h = fontMetrics().height(); + if ( d->printers->firstChild() ) + h = d->printers->firstChild()->height(); + d->printers->setMinimumSize( d->printers->sizeHint().width(), + d->printers->header()->height() + + 3 * h ); + horiz->addWidget( d->printers, 3 ); + + tll->addSpacing( 6 ); + + // file radio button, edit/browse + d->printToFileButton = new TQRadioButton( tr( "Print to file:" ), g, "file" ); + tll->addWidget( d->printToFileButton ); + d->printerOrFile->insert( d->printToFileButton, 1 ); + + horiz = new TQBoxLayout( TQBoxLayout::LeftToRight ); + tll->addLayout( horiz ); + horiz->addSpacing( 19 ); + + d->fileName = new TQLineEdit( g, "file name" ); + connect( d->fileName, TQ_SIGNAL( textChanged(const TQString&) ), + this, TQ_SLOT( fileNameEditChanged(const TQString&) ) ); + horiz->addWidget( d->fileName, 1 ); + horiz->addSpacing( 6 ); + d->browse = new TQPushButton( tr("Browse..."), g, "browse files" ); + d->browse->setAutoDefault( FALSE ); +#ifdef TQT_NO_FILEDIALOG + d->browse->setEnabled( FALSE ); +#endif + connect( d->browse, TQ_SIGNAL(clicked()), + this, TQ_SLOT(browseClicked()) ); + horiz->addWidget( d->browse ); + + d->fileName->setEnabled( FALSE ); + d->browse->setEnabled( FALSE ); + + tll->activate(); + + return g; +} + + +TQGroupBox * TQPrintDialog::setupOptions() +{ + TQGroupBox * g = new TQGroupBox( 0, Horizontal, tr( "Options"), + this, "options group box" ); + + TQBoxLayout * tll = new TQBoxLayout( g->layout(), TQBoxLayout::Down ); + + TQBoxLayout *lay = new TQBoxLayout( TQBoxLayout::LeftToRight ); + tll->addLayout( lay ); + + tll = new TQBoxLayout( lay, TQBoxLayout::Down ); + + d->printRange = new TQButtonGroup( this ); + d->printRange->hide(); + connect( d->printRange, TQ_SIGNAL(clicked(int)), + this, TQ_SLOT(printRangeSelected(int)) ); + + d->pageOrder = new TQButtonGroup( this ); + d->pageOrder->hide(); + connect( d->pageOrder, TQ_SIGNAL(clicked(int)), + this, TQ_SLOT(pageOrderSelected(int)) ); + + d->printAllButton = new TQRadioButton( tr("Print all"), g, "print all" ); + d->printRange->insert( d->printAllButton, 0 ); + tll->addWidget( d->printAllButton ); + + d->printSelectionButton = new TQRadioButton( tr("Print selection"), + g, "print selection" ); + d->printRange->insert( d->printSelectionButton, 1 ); + tll->addWidget( d->printSelectionButton ); + + d->printRangeButton = new TQRadioButton( tr("Print range"), + g, "print range" ); + d->printRange->insert( d->printRangeButton, 2 ); + tll->addWidget( d->printRangeButton ); + + TQBoxLayout * horiz = new TQBoxLayout( TQBoxLayout::LeftToRight ); + tll->addLayout( horiz ); + + d->firstPageLabel = new TQLabel( tr("From page:"), g, "first page" ); + horiz->addSpacing( 19 ); + horiz->addWidget( d->firstPageLabel ); + + d->firstPage = new TQPrintDialogSpinBox( 1, 9999, 1, g, "first page" ); + d->firstPage->setValue( 1 ); + horiz->addWidget( d->firstPage, 1 ); + connect( d->firstPage, TQ_SIGNAL(valueChanged(int)), + this, TQ_SLOT(setFirstPage(int)) ); + + horiz = new TQBoxLayout( TQBoxLayout::LeftToRight ); + tll->addLayout( horiz ); + + d->lastPageLabel = new TQLabel( tr("To page:"), g, "last page" ); + horiz->addSpacing( 19 ); + horiz->addWidget( d->lastPageLabel ); + + d->lastPage = new TQPrintDialogSpinBox( 1, 9999, 1, g, "last page" ); + d->lastPage->setValue( 9999 ); + horiz->addWidget( d->lastPage, 1 ); + connect( d->lastPage, TQ_SIGNAL(valueChanged(int)), + this, TQ_SLOT(setLastPage(int)) ); + + lay->addSpacing( 25 ); + tll = new TQBoxLayout( lay, TQBoxLayout::Down ); + + // print order + TQRadioButton * rb = new TQRadioButton( tr("Print first page first"), + g, "first page first" ); + tll->addWidget( rb ); + d->pageOrder->insert( rb, TQPrinter::FirstPageFirst ); + rb->setChecked( TRUE ); + + rb = new TQRadioButton( tr("Print last page first"), + g, "last page first" ); + tll->addWidget( rb ); + d->pageOrder->insert( rb, TQPrinter::LastPageFirst ); + + tll->addStretch(); + + // copies + + horiz = new TQBoxLayout( TQBoxLayout::LeftToRight ); + tll->addLayout( horiz ); + + TQLabel * l = new TQLabel( tr("Number of copies:"), g, "Number of copies" ); + horiz->addWidget( l ); + + d->copies = new TQPrintDialogSpinBox( 1, 99, 1, g, "copies" ); + d->copies->setValue( 1 ); + horiz->addWidget( d->copies, 1 ); + connect( d->copies, TQ_SIGNAL(valueChanged(int)), + this, TQ_SLOT(setNumCopies(int)) ); + + TQSize s = d->firstPageLabel->sizeHint() + .expandedTo( d->lastPageLabel->sizeHint() ) + .expandedTo( l->sizeHint() ); + d->firstPageLabel->setMinimumSize( s ); + d->lastPageLabel->setMinimumSize( s ); + l->setMinimumSize( s.width() + 19, s.height() ); + + tll->activate(); + + return g; +} + + +void isc( TQPrintDialogPrivate * d, + const TQString & text, + TQPrinter::PageSize ps ) +{ + if ( d && text && ps < TQPrinter::NPageSize ) { + d->sizeCombo->insertItem( text, -1 ); + int index = d->sizeCombo->count()-1; + if ( index >= 0 && index < TQPrinter::NPageSize ) + d->indexToPageSize[index] = ps; + } +} + +TQGroupBox * TQPrintDialog::setupPaper() +{ + TQGroupBox * g = new TQGroupBox( 1, Horizontal, tr( "Paper format"), + this, "Paper format" ); + d->pageSize = TQPrinter::A4; + + // page orientation + d->orientationCombo = new TQComboBox( FALSE, g ); + d->orientationCombo->insertItem( tr( "Portrait" ), -1 ); + d->orientationCombo->insertItem( tr( "Landscape" ), -1 ); + + d->orientation = TQPrinter::Portrait; + + g->addSpace( 8 ); + + connect( d->orientationCombo, TQ_SIGNAL( activated(int) ), + this, TQ_SLOT( orientSelected(int) ) ); + + // paper size + d->sizeCombo = new TQComboBox( FALSE, g ); + + int n; + for( n=0; nindexToPageSize[n] = TQPrinter::A4; + + isc( d, tr( "A0 (841 x 1189 mm)" ), TQPrinter::A0 ); + isc( d, tr( "A1 (594 x 841 mm)" ), TQPrinter::A1 ); + isc( d, tr( "A2 (420 x 594 mm)" ), TQPrinter::A2 ); + isc( d, tr( "A3 (297 x 420 mm)" ), TQPrinter::A3 ); + isc( d, tr( "A4 (210x297 mm, 8.26x11.7 inches)" ), TQPrinter::A4 ); + isc( d, tr( "A5 (148 x 210 mm)" ), TQPrinter::A5 ); + isc( d, tr( "A6 (105 x 148 mm)" ), TQPrinter::A6 ); + isc( d, tr( "A7 (74 x 105 mm)" ), TQPrinter::A7 ); + isc( d, tr( "A8 (52 x 74 mm)" ), TQPrinter::A8 ); + isc( d, tr( "A9 (37 x 52 mm)" ), TQPrinter::A9 ); + isc( d, tr( "B0 (1000 x 1414 mm)" ), TQPrinter::B0 ); + isc( d, tr( "B1 (707 x 1000 mm)" ), TQPrinter::B1 ); + isc( d, tr( "B2 (500 x 707 mm)" ), TQPrinter::B2 ); + isc( d, tr( "B3 (353 x 500 mm)" ), TQPrinter::B3 ); + isc( d, tr( "B4 (250 x 353 mm)" ), TQPrinter::B4 ); + isc( d, tr( "B5 (176 x 250 mm, 6.93x9.84 inches)" ), TQPrinter::B5 ); + isc( d, tr( "B6 (125 x 176 mm)" ), TQPrinter::B6 ); + isc( d, tr( "B7 (88 x 125 mm)" ), TQPrinter::B7 ); + isc( d, tr( "B8 (62 x 88 mm)" ), TQPrinter::B8 ); + isc( d, tr( "B9 (44 x 62 mm)" ), TQPrinter::B9 ); + isc( d, tr( "B10 (31 x 44 mm)" ), TQPrinter::B10 ); + isc( d, tr( "C5E (163 x 229 mm)" ), TQPrinter::C5E ); + isc( d, tr( "DLE (110 x 220 mm)" ), TQPrinter::DLE ); + isc( d, tr( "Executive (7.5x10 inches, 191x254 mm)" ), TQPrinter::Executive ); + isc( d, tr( "Folio (210 x 330 mm)" ), TQPrinter::Folio ); + isc( d, tr( "Ledger (432 x 279 mm)" ), TQPrinter::Ledger ); + isc( d, tr( "Legal (8.5x14 inches, 216x356 mm)" ), TQPrinter::Legal ); + isc( d, tr( "Letter (8.5x11 inches, 216x279 mm)" ), TQPrinter::Letter ); + isc( d, tr( "Tabloid (279 x 432 mm)" ), TQPrinter::Tabloid ); + isc( d, tr( "US Common #10 Envelope (105 x 241 mm)" ), TQPrinter::Comm10E ); + + connect( d->sizeCombo, TQ_SIGNAL( activated(int) ), + this, TQ_SLOT( paperSizeSelected(int) ) ); + + return g; +} + + +/*! + Display a dialog and allow the user to configure the TQPrinter \a + p for an optional widget \a w. Returns TRUE if the user clicks OK or + presses Enter, FALSE if the user clicks Cancel or presses Esc. + + getPrinterSetup() remembers the settings and provides the same + settings the next time the dialog is shown. +*/ + +bool TQPrintDialog::getPrinterSetup( TQPrinter * p, TQWidget* w ) +{ + if ( !globalPrintDialog ) { + globalPrintDialog = new TQPrintDialog( 0, 0, "global print dialog" ); +#ifndef TQT_NO_WIDGET_TOPEXTRA + globalPrintDialog->setCaption( TQPrintDialog::tr( "Setup Printer" ) ); +#endif + tqAddPostRoutine( qpd_cleanup_globaldialog ); + globalPrintDialog->setPrinter( p, TRUE ); + globalPrintDialog->adjustSize(); + } else { + globalPrintDialog->setPrinter( p, TRUE ); + } + globalPrintDialog->adjustPosition( w ); + #ifndef TQT_NO_WIDGET_TOPEXTRA + if ( w ) { + const TQPixmap *pm = w->icon(); + if ( pm && !pm->isNull() ) + globalPrintDialog->setIcon( *pm ); + else { + w = w ? w->topLevelWidget() : 0; + pm = w ? w->icon() : 0; + if ( pm && !pm->isNull() ) + globalPrintDialog->setIcon( *pm ); + } + } +#endif + bool r = globalPrintDialog->exec() == TQDialog::Accepted; + globalPrintDialog->setPrinter( 0 ); + return r; +} + + +void TQPrintDialog::printerOrFileSelected( int id ) +{ + d->outputToFile = id ? TRUE : FALSE; + if ( d->outputToFile ) { + d->ok->setEnabled( TRUE ); + fileNameEditChanged( d->fileName->text() ); + if ( !d->fileName->edited() && d->fileName->text().isEmpty() ) { + TQString home = TQString::fromLatin1( ::getenv( "HOME" ) ); + TQString cur = TQDir::currentDirPath(); + if ( home.at(home.length()-1) != '/' ) + home += '/'; + if ( cur.at(cur.length()-1) != '/' ) + cur += '/'; + if ( cur.left( home.length() ) != home ) + cur = home; +#ifdef TQ_WS_X11 + cur += "print.ps"; +#endif + d->fileName->setText( cur ); + d->fileName->setCursorPosition( cur.length() ); + d->fileName->selectAll(); + } + d->browse->setEnabled( TRUE ); + d->fileName->setEnabled( TRUE ); + d->fileName->setFocus(); + d->printers->setEnabled( FALSE ); + } else { + d->ok->setEnabled( d->printers->childCount() != 0 ); + d->printers->setEnabled( TRUE ); + if ( d->fileName->hasFocus() || d->browse->hasFocus() ) + d->printers->setFocus(); + d->browse->setEnabled( FALSE ); + d->fileName->setEnabled( FALSE ); + } +} + + +void TQPrintDialog::landscapeSelected( int id ) +{ + d->orientation = (TQPrinter::Orientation)id; +} + + +void TQPrintDialog::paperSizeSelected( int id ) +{ + if ( id < TQPrinter::NPageSize ) + d->pageSize = TQPrinter::PageSize( d->indexToPageSize[id] ); +} + + +void TQPrintDialog::orientSelected( int id ) +{ + d->orientation = (TQPrinter::Orientation)id; +} + + +void TQPrintDialog::pageOrderSelected( int id ) +{ + d->pageOrder2 = (TQPrinter::PageOrder)id; +} + + +void TQPrintDialog::setNumCopies( int copies ) +{ + d->numCopies = copies; +} + + +void TQPrintDialog::browseClicked() +{ +#ifndef TQT_NO_FILEDIALOG + TQString fn = TQFileDialog::getSaveFileName( d->fileName->text(), tr( "PostScript Files (*.ps);;All Files (*)" ), this ); + if ( !fn.isNull() ) + d->fileName->setText( fn ); +#endif +} + + +void TQPrintDialog::okClicked() +{ + d->lastPage->interpretText(); + d->firstPage->interpretText(); + d->copies->interpretText(); + if ( d->outputToFile ) { + d->printer->setOutputToFile( TRUE ); + d->printer->setOutputFileName( d->fileName->text() ); + } else { + d->printer->setOutputToFile( FALSE ); + TQListViewItem * l = d->printers->currentItem(); + if ( l ) + d->printer->setPrinterName( l->text( 0 ) ); + } + + d->printer->setOrientation( d->orientation ); + d->printer->setPageSize( d->pageSize ); + d->printer->setPageOrder( d->pageOrder2 ); + d->printer->setColorMode( d->colorMode2 ); + d->printer->setNumCopies( d->numCopies ); + if ( d->printAllButton->isChecked() ) { + d->printer->setPrintRange(TQPrinter::AllPages); + d->printer->setFromTo( d->printer->minPage(), d->printer->maxPage() ); + } else { + if (d->printSelectionButton->isChecked()) + d->printer->setPrintRange(TQPrinter::Selection); + else + d->printer->setPrintRange(TQPrinter::PageRange); + d->printer->setFromTo( d->firstPage->value(), d->lastPage->value() ); + } + + accept(); +} + + +void TQPrintDialog::printRangeSelected( int id ) +{ + bool enable = id == 2 ? TRUE : FALSE; + d->firstPage->setEnabled( enable ); + d->lastPage->setEnabled( enable ); + d->firstPageLabel->setEnabled( enable ); + d->lastPageLabel->setEnabled( enable ); +} + + +void TQPrintDialog::setFirstPage( int fp ) +{ + if ( d->printer ) + d->lastPage->setRange( fp, TQMAX(fp, TQPrintDialog::d->printer->maxPage()) ); +} + + +void TQPrintDialog::setLastPage( int lp ) +{ + if ( d->printer ) + d->firstPage->setRange( TQMIN(lp, TQPrintDialog::d->printer->minPage()), lp ); +} + + +/*! + Sets this dialog to configure printer \a p, or no printer if \a p + is null. If \a pickUpSettings is TRUE, the dialog reads most of + its settings from \a p. If \a pickUpSettings is FALSE (the + default) the dialog keeps its old settings. +*/ + +void TQPrintDialog::setPrinter( TQPrinter * p, bool pickUpSettings ) +{ + d->printer = p; + + if ( p && pickUpSettings ) { + // top to botton in the old dialog. + // printer or file + d->printerOrFile->setButton( p->outputToFile() ); + printerOrFileSelected( p->outputToFile() ); + + // printer name + if ( !!p->printerName() ) { + TQListViewItem * i = d->printers->firstChild(); + while ( i && i->text( 0 ) != p->printerName() ) + i = i->nextSibling(); + if ( i ) { + d->printers->setSelected( i, TRUE ); + d->ok->setEnabled( TRUE ); + } else if ( d->fileName->text().isEmpty() ) { + d->ok->setEnabled( d->printers->childCount() != 0 ); + } + } + + // print command does not exist any more + + // file name + d->printToFileButton->setEnabled( d->printer->isOptionEnabled( TQPrinter::PrintToFile ) ); + d->fileName->setText( p->outputFileName() ); + + // orientation + d->orientationCombo->setCurrentItem( (int)p->orientation() ); + orientSelected( p->orientation() ); + + // page size + int n = 0; + while ( n < TQPrinter::NPageSize && + d->indexToPageSize[n] != p->pageSize() ) + n++; + d->sizeCombo->setCurrentItem( n ); + paperSizeSelected( n ); + + // New stuff (Options) + + // page order + d->pageOrder->setButton( (int)p->pageOrder() ); + pageOrderSelected( p->pageOrder() ); + + // color mode + d->colorMode->setButton( (int)p->colorMode() ); + colorModeSelected( p->colorMode() ); + + // number of copies + d->copies->setValue( p->numCopies() ); + setNumCopies( p->numCopies() ); + } + + if( p ) { + d->printAllButton->setEnabled( TRUE ); + d->printSelectionButton + ->setEnabled( d->printer->isOptionEnabled( TQPrinter::PrintSelection ) ); + d->printRangeButton + ->setEnabled( d->printer->isOptionEnabled( TQPrinter::PrintPageRange ) ); + + TQPrinter::PrintRange range = p->printRange(); + switch ( range ) { + case TQPrinter::AllPages: + d->printAllButton->setChecked(TRUE); + printRangeSelected( d->printRange->id( d->printAllButton ) ); + break; + case TQPrinter::Selection: + d->printSelectionButton->setChecked(TRUE); + printRangeSelected( d->printRange->id( d->printSelectionButton ) ); + break; + case TQPrinter::PageRange: + d->printRangeButton->setChecked(TRUE); + printRangeSelected( d->printRange->id( d->printRangeButton ) ); + break; + } + } + + if ( p && p->maxPage() ) { + d->firstPage->setRange( p->minPage(), p->maxPage() ); + d->lastPage->setRange( p->minPage(), p->maxPage() ); + if ( p->fromPage() || p->toPage() ) { + setFirstPage( p->fromPage() ); + setLastPage( p->toPage() ); + d->firstPage->setValue(p->fromPage()); + d->lastPage->setValue(p->toPage()); + } + } +} + + +/*! Returns a pointer to the printer this dialog configures, or 0 if + this dialog does not operate on any printer. */ + +TQPrinter * TQPrintDialog::printer() const +{ + return d->printer; +} + + +void TQPrintDialog::colorModeSelected( int id ) +{ + d->colorMode2 = (TQPrinter::ColorMode)id; +} + +/*! + Adds the button \a but to the layout of the print dialog. The added + buttons are arranged from the left to the right below the + last groupbox of the printdialog. +*/ + +void TQPrintDialog::addButton( TQPushButton *but ) +{ + d->customLayout->addWidget( but ); +} + +void TQPrintDialog::fileNameEditChanged( const TQString &text ) +{ + if ( d->fileName->isEnabled() ) + d->ok->setEnabled( !text.isEmpty() ); +} + +#endif diff --git a/src/dialogs/tqprintdialog.h b/src/dialogs/tqprintdialog.h new file mode 100644 index 00000000..29824416 --- /dev/null +++ b/src/dialogs/tqprintdialog.h @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Definition of print dialog. +** +** Created : 950829 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the dialogs module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQPRINTDIALOG_H +#define TQPRINTDIALOG_H + +#ifndef QT_H +#include "tqdialog.h" +#endif // QT_H + +#ifndef TQT_NO_PRINTDIALOG + +class TQGroupBox; +class TQPrintDialogPrivate; +class TQListView; + +class TQ_EXPORT TQPrintDialog : public TQDialog +{ + TQ_OBJECT +public: + TQPrintDialog( TQPrinter *, TQWidget* parent=0, const char* name=0 ); + ~TQPrintDialog(); + + static bool getPrinterSetup( TQPrinter *, TQWidget* = 0 ); + static void setGlobalPrintDialog( TQPrintDialog * ); + + void setPrinter( TQPrinter *, bool = FALSE ); + TQPrinter * printer() const; + + void addButton( TQPushButton *but ); + +private slots: + void browseClicked(); + void okClicked(); + + void printerOrFileSelected( int ); + void landscapeSelected( int ); + void paperSizeSelected( int ); + void orientSelected( int ); + void pageOrderSelected( int ); + void colorModeSelected( int ); + void setNumCopies( int ); + void printRangeSelected( int ); + void setFirstPage( int ); + void setLastPage( int ); + + void fileNameEditChanged( const TQString &text ); + +private: + TQPrintDialogPrivate *d; + + TQGroupBox * setupDestination(); + TQGroupBox * setupOptions(); + TQGroupBox * setupPaper(); + TQGroupBox * setupPrinterSettings(); + +private: // Disabled copy constructor and operator= +#if defined(TQ_DISABLE_COPY) + TQPrintDialog( const TQPrintDialog & ); + TQPrintDialog &operator=( const TQPrintDialog & ); +#endif +}; + +#endif + +#endif // TQPRINTDIALOG_H -- cgit v1.2.1