home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kfinddialog.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-05-22  |  9.3 KB  |  316 lines

  1. /*
  2.     Copyright (C) 2001, S.R.Haque <srhaque@iee.org>.
  3.     Copyright (C) 2002, David Faure <david@mandrakesoft.com>
  4.     This file is part of the KDE project
  5.  
  6.     This library is free software; you can redistribute it and/or
  7.     modify it under the terms of the GNU Library General Public
  8.     License version 2, as published by the Free Software Foundation.
  9.  
  10.     This library is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.     Library General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU Library General Public License
  16.     along with this library; see the file COPYING.LIB.  If not, write to
  17.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18.     Boston, MA 02110-1301, USA.
  19. */
  20.  
  21. #ifndef KFINDDIALOG_H
  22. #define KFINDDIALOG_H
  23.  
  24. #include <kdialogbase.h>
  25. class KHistoryCombo;
  26. class QPushButton;
  27. class QPopupMenu;
  28. class QGridLayout;
  29. class QLabel;
  30. class QGroupBox;
  31. class QCheckBox;
  32.  
  33. /**
  34.  * @ingroup main
  35.  * @ingroup findreplace
  36.  * @brief A generic "find" dialog.
  37.  *
  38.  * @author S.R.Haque <srhaque@iee.org>
  39.  *
  40.  * \b Detail:
  41.  *
  42.  * This widget inherits from KDialogBase and implements
  43.  * the following additional functionalities:  a find string
  44.  * object and an area for a user-defined widget to extend the dialog.
  45.  *
  46.  * \b Example:
  47.  *
  48.  * To use the basic modal find dialog, and then run the search:
  49.  *
  50.  * \code
  51.  *  KFindDialog dlg(....)
  52.  *  if ( dlg.exec() != QDialog::Accepted )
  53.  *      return;
  54.  *
  55.  *  // proceed with KFind from here
  56.  * \endcode
  57.  *
  58.  * To create a non-modal find dialog:
  59.  * \code
  60.  *   if ( m_findDia )
  61.  *     KWin::setActiveWindow( m_findDia->winId() );
  62.  *   else
  63.  *   {
  64.  *     m_findDia = new KFindDialog(false,...);
  65.  *     connect( m_findDia, SIGNAL(okClicked()), this, SLOT(findTextNext()) );
  66.  *   }
  67.  * \endcode
  68.  * Don't forget to delete and reset m_findDia when closed.
  69.  * (But do NOT delete your KFind object at that point, it's needed for "Find Next")
  70.  *
  71.  * To use your own extensions: see findExtension().
  72.  *
  73.  */
  74. class KUTILS_EXPORT KFindDialog:
  75.     public KDialogBase
  76. {
  77.     Q_OBJECT
  78.  
  79. public:
  80.  
  81.     // Options.
  82.  
  83.     // KDE4: move to KFind
  84.     /**
  85.      * Options for the search
  86.      */
  87.     enum Options
  88.     {
  89.         WholeWordsOnly = 1,     ///< Match whole words only.
  90.         FromCursor = 2,         ///< Start from current cursor position.
  91.         SelectedText = 4,       ///< Only search selected area.
  92.         CaseSensitive = 8,      ///< Consider case when matching.
  93.         FindBackwards = 16,     ///< Go backwards.
  94.         RegularExpression = 32, ///< Interpret the pattern as a regular expression.
  95.         FindIncremental = 64,   ///< Find incremental.
  96.         // Note that KReplaceDialog uses 256 and 512
  97.         // User extensions can use boolean options above this value.
  98.         MinimumUserOption = 65536 ///< The first flag which can be used by extensions.
  99.     };
  100.  
  101.     /**
  102.      * Construct a modal find dialog
  103.      *
  104.      * @param parent The parent object of this widget.
  105.      * @param name The name of this widget.
  106.      * @param options A bitfield of the Options to be checked.
  107.      * @param findStrings The find history, see findHistory()
  108.      * @param hasSelection Whether a selection exists
  109.      */
  110.     KFindDialog( QWidget *parent = 0, const char *name = 0, long options = 0,
  111.                  const QStringList &findStrings = QStringList(), bool hasSelection = false );
  112.     // KDE4: fix ambiguity with private constructor
  113.     // Maybe remove options (there's setOptions) and findStrings (setFindHistory) and hasSelection (setHasSelection)
  114.  
  115.     /**
  116.      * Construct a non-modal find dialog
  117.      *
  118.      * @param modal set to @c false to get a non-modal dialog
  119.      * @param parent The parent object of this widget.
  120.      * @param name The name of this widget.
  121.      * @param options A bitfield of the Options to be checked.
  122.      * @param findStrings The find history, see findHistory()
  123.      * @param hasSelection Whether a selection exists
  124.      */
  125.     KFindDialog( bool modal, QWidget *parent = 0, const char *name = 0, long options = 0,
  126.                  const QStringList &findStrings = QStringList(), bool hasSelection = false );
  127.     // KDE4: consider simplifying
  128.  
  129.     /**
  130.      * Destructor.
  131.      */
  132.     virtual ~KFindDialog();
  133.  
  134.     /**
  135.      * Provide the list of @p strings to be displayed as the history
  136.      * of find strings. @p strings might get truncated if it is
  137.      * too long.
  138.      *
  139.      * @param history The find history.
  140.      * @see findHistory
  141.      */
  142.     void setFindHistory( const QStringList &history );
  143.  
  144.     /**
  145.      * Returns the list of history items.
  146.      *
  147.      * @return The find history.
  148.      * @see setFindHistory
  149.      */
  150.     QStringList findHistory() const;
  151.  
  152.     /**
  153.      * Enable/disable the 'search in selection' option, depending
  154.      * on whether there actually is a selection.
  155.      *
  156.      * @param hasSelection @c true if a selection exists
  157.      */
  158.     void setHasSelection( bool hasSelection );
  159.  
  160.     /**
  161.      * Hide/show the 'from cursor' option, depending
  162.      * on whether the application implements a cursor.
  163.      *
  164.      * @param hasCursor @c true if the application features a cursor
  165.      * This is assumed to be the case by default.
  166.      */
  167.     void setHasCursor( bool hasCursor );
  168.  
  169.      /**
  170.      * Enable/disable the 'Find backwards' option, depending
  171.      * on whether the application supports it.
  172.      *
  173.      * @param supports @c true if the application supports backwards find
  174.      * This is assumed to be the case by default.
  175.      * @since 3.4
  176.      */
  177.     void setSupportsBackwardsFind( bool supports );
  178.  
  179.      /**
  180.      * Enable/disable the 'Case sensitive' option, depending
  181.      * on whether the application supports it.
  182.      *
  183.      * @param supports @c true if the application supports case sensitive find
  184.      * This is assumed to be the case by default.
  185.      * @since 3.4
  186.      */
  187.     void setSupportsCaseSensitiveFind( bool supports );
  188.  
  189.      /**
  190.      * Enable/disable the 'Whole words only' option, depending
  191.      * on whether the application supports it.
  192.      *
  193.      * @param supports @c true if the application supports whole words only find
  194.      * This is assumed to be the case by default.
  195.      * @since 3.4
  196.      */
  197.     void setSupportsWholeWordsFind( bool supports );
  198.  
  199.      /**
  200.      * Enable/disable the 'Regular expression' option, depending
  201.      * on whether the application supports it.
  202.      *
  203.      * @param supports @c true if the application supports regular expression find
  204.      * This is assumed to be the case by default.
  205.      * @since 3.4
  206.      */
  207.     void setSupportsRegularExpressionFind( bool supports );
  208.  
  209.     /**
  210.      * Set the options which are checked.
  211.      *
  212.      * @param options The setting of the Options.
  213.      * @see Options
  214.      */
  215.     void setOptions( long options );
  216.  
  217.     /**
  218.      * Returns the state of the options. Disabled options may be returned in
  219.      * an indeterminate state.
  220.      *
  221.      * @return The options.
  222.      * @see Options, setOptions
  223.      */
  224.     long options() const;
  225.  
  226.     /**
  227.      * Returns the pattern to find.
  228.      * @return The search text.
  229.      */
  230.     QString pattern() const;
  231.  
  232.     /**
  233.      * Sets the pattern to find.
  234.      * @param pattern The new search pattern.
  235.      */
  236.     void setPattern ( const QString &pattern );
  237.  
  238.     /**
  239.      * Returns an empty widget which the user may fill with additional UI
  240.      * elements as required. The widget occupies the width of the dialog,
  241.      * and is positioned immediately below the regular expression support
  242.      * widgets for the pattern string.
  243.      * @return An extensible QWidget.
  244.      */
  245.     QWidget *findExtension();
  246.  
  247. protected slots:
  248.  
  249.     void slotOk();
  250.     void slotSelectedTextToggled(bool);
  251.     void showPatterns();
  252.     void showPlaceholders();
  253.     void textSearchChanged( const QString &);
  254.  
  255. protected:
  256.     virtual void showEvent ( QShowEvent * );
  257.  
  258. private slots:
  259.     /**
  260.      * connected to the aboutToShow of the placeholders menu,
  261.      * updates it according to the text in the pattern.
  262.      */
  263.     void slotPlaceholdersAboutToShow();
  264.  
  265. private:
  266.  
  267.     QGroupBox *m_findGrp;
  268.     QLabel *m_findLabel;
  269.     KHistoryCombo *m_find;
  270.     QCheckBox *m_regExp;
  271.     QPushButton *m_regExpItem;
  272.     QGridLayout *m_findLayout;
  273.     QWidget *m_findExtension;
  274.  
  275.     QGroupBox *m_optionGrp;
  276.     QCheckBox *m_wholeWordsOnly;
  277.     QCheckBox *m_fromCursor;
  278.     QCheckBox *m_selectedText;
  279.     QCheckBox *m_caseSensitive;
  280.     QCheckBox *m_findBackwards;
  281.  
  282.     QPopupMenu *m_patterns;
  283.  
  284.     // Our dirty little secret is that we also implement the "replace" dialog. But we
  285.     // keep that fact hidden from all but our friends.
  286.  
  287.     friend class KReplaceDialog;
  288.  
  289.     /**
  290.      * Construct a find dialog with a parent object and a name. This version of the
  291.      * constructor is for use by friends only!
  292.      *
  293.      * @param forReplace Is this a replace dialog?
  294.      */
  295.     KFindDialog( QWidget *parent, const char *name, bool forReplace );
  296.     void init( bool forReplace, const QStringList &findStrings, bool hasSelection );
  297.  
  298.     QGroupBox *m_replaceGrp;
  299.     QLabel *m_replaceLabel;
  300.     KHistoryCombo *m_replace;
  301.     QCheckBox* m_backRef;
  302.     QPushButton* m_backRefItem;
  303.     QGridLayout *m_replaceLayout;
  304.     QWidget *m_replaceExtension;
  305.  
  306.     QCheckBox* m_promptOnReplace;
  307.  
  308.     QPopupMenu *m_placeholders;
  309.  
  310.     // Binary compatible extensibility.
  311.     class KFindDialogPrivate;
  312.     KFindDialogPrivate *d;
  313. };
  314.  
  315. #endif // KFINDDIALOG_H
  316.