ctkFontButton.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. #ifndef __ctkFontButton_h
  15. #define __ctkFontButton_h
  16. // Qt includes
  17. #include <QFont>
  18. #include <QPushButton>
  19. // CTK includes
  20. #include "ctkWidgetsExport.h"
  21. class ctkFontButtonPrivate;
  22. /// \ingroup Widgets
  23. class CTK_WIDGETS_EXPORT ctkFontButton: public QPushButton
  24. {
  25. Q_OBJECT
  26. /// Application QFont by default
  27. Q_PROPERTY(QFont currentFont READ currentFont WRITE setCurrentFont NOTIFY currentFontChanged USER true)
  28. /// This property holds the format of the text of the pushbutton. These
  29. /// expressions may be used in place of the current font:
  30. /// * fff family
  31. /// * sss pointSize with suffix "pt". e.g. "9pt"
  32. /// * ss pointSize with no suffix. e.g. "9"
  33. /// * www full name weight e.g. Bold (if font is bold)
  34. /// * ww weight. e.g. 50 (if font is normal)
  35. /// * biu 3 character string where the first character is 'b' if bold or - otherwise,
  36. /// the second character is 'i' if the font italic or - otherwise and the third
  37. /// characis is 'u' if the font is underline or '-' otherwise. e.g. "bi-" if the font
  38. /// is bold and italic but not underline
  39. /// * bbb 'bold' if bold, nothing otherwise
  40. /// * bb 'b' if bold, nothing otherwise
  41. /// * iii 'italic' if italic, nothing otherwise
  42. /// * ii 'i' if italic, nothing otherwise
  43. /// * uuu 'underline' if underline, nothing otherwise
  44. /// * uu 'u' if underline, nothing otherwise
  45. /// Note that the listing order matches the replacement order.
  46. /// fff-sss by default.
  47. Q_PROPERTY(QString fontTextFormat READ fontTextFormat WRITE setFontTextFormat)
  48. public:
  49. /// Constructor
  50. /// Creates a default ctkFontButton initialized with QApplication font
  51. ctkFontButton(QWidget * parent = 0);
  52. /// Constructor
  53. /// Creates a ctkFontButton with a given font
  54. ctkFontButton(const QFont& currentFont, QWidget * parent = 0);
  55. /// Destructor
  56. virtual ~ctkFontButton();
  57. /// Set/get the current font
  58. void setCurrentFont(const QFont& newFont);
  59. QFont currentFont()const;
  60. /// Set the font text format
  61. /// \sa fontTextFormat, fontTextFormat()
  62. void setFontTextFormat(const QString& fontTextFormat);
  63. /// Get the font text format
  64. /// \sa fontTextFormat, setFontTextFormat()
  65. QString fontTextFormat()const;
  66. public Q_SLOTS:
  67. /// browse() opens a pop up where the user can select a new font.
  68. /// browse() is automatically called when the button is clicked.
  69. void browseFont();
  70. Q_SIGNALS:
  71. /// Fired anytime the current font changed.
  72. /// Programatically or by the user via the file dialog that pop up when
  73. /// clicking on the button.
  74. void currentFontChanged(const QFont&);
  75. protected:
  76. QScopedPointer<ctkFontButtonPrivate> d_ptr;
  77. private:
  78. Q_DECLARE_PRIVATE(ctkFontButton);
  79. Q_DISABLE_COPY(ctkFontButton);
  80. };
  81. #endif