TDE personal information management applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
3.7KB

  1. /*
  2. * dateedit.h - date entry widget
  3. * Program: kalarm
  4. * Copyright © 2002-2007 by David Jarvie <software@astrojar.org.uk>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. #ifndef DATEEDIT_H
  21. #define DATEEDIT_H
  22. #include <libtdepim/kdateedit.h>
  23. /**
  24. * @short Date edit widget with range limits.
  25. *
  26. * The DateEdit class provides a date editor with the ability to set limits on the
  27. * dates which can be entered.
  28. *
  29. * Minimum and/or maximum permissible dates may be set, together with corresponding
  30. * error messages. If the user tries to enter a date outside the allowed range, the
  31. * appropriate error message (if any) is output using KMessageBox::sorry().
  32. *
  33. * @author David Jarvie <software@astrojar.org.uk>
  34. */
  35. class DateEdit : public KDateEdit
  36. {
  37. Q_OBJECT
  38. TQ_OBJECT
  39. public:
  40. /** Constructor.
  41. * @param parent The parent object of this widget.
  42. * @param name The name of this widget.
  43. */
  44. explicit DateEdit(TQWidget* parent = 0, const char* name = 0);
  45. /** Returns true if the widget contains a valid date. */
  46. bool isValid() const { return date().isValid(); }
  47. /** Returns the earliest date which can be entered.
  48. * If there is no minimum date, returns an invalid date.
  49. */
  50. const TQDate& minDate() const { return mMinDate; }
  51. /** Returns the latest date which can be entered.
  52. * If there is no maximum date, returns an invalid date.
  53. */
  54. const TQDate& maxDate() const { return mMaxDate; }
  55. /** Sets the earliest date which can be entered.
  56. * @param date Earliest date allowed. If invalid, any minimum limit is removed.
  57. * @param errorDate Error message to be displayed when a date earlier than
  58. * @p date is entered. Set to TQString() to use the default error message.
  59. */
  60. void setMinDate(const TQDate& date, const TQString& errorDate = TQString());
  61. /** Sets the latest date which can be entered.
  62. * @param date Latest date allowed. If invalid, any maximum limit is removed.
  63. * @param errorDate Error message to be displayed when a date later than
  64. * @p date is entered. Set to TQString() to use the default error message.
  65. */
  66. void setMaxDate(const TQDate& date, const TQString& errorDate = TQString());
  67. /** Sets the date held in the widget to an invalid date. */
  68. void setInvalid();
  69. protected:
  70. virtual void mousePressEvent(TQMouseEvent*);
  71. virtual void mouseReleaseEvent(TQMouseEvent*);
  72. virtual void mouseMoveEvent(TQMouseEvent*);
  73. virtual void keyPressEvent(TQKeyEvent*);
  74. virtual void keyReleaseEvent(TQKeyEvent*);
  75. private slots:
  76. void newDateEntered(const TQDate&);
  77. private:
  78. void pastLimitMessage(const TQDate& limit, const TQString& error, const TQString& defaultError);
  79. TQDate mMinDate; // minimum allowed date, or invalid for no minimum
  80. TQDate mMaxDate; // maximum allowed date, or invalid for no maximum
  81. TQString mMinDateErrString; // error message when entered date < mMinDate
  82. TQString mMaxDateErrString; // error message when entered date > mMaxDate
  83. };
  84. #endif // DATEEDIT_H