ctkLanguageComboBox.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 __ctkLanguageComboBox_h
  15. #define __ctkLanguageComboBox_h
  16. // QT includes
  17. #include <QComboBox>
  18. // CTK includes
  19. #include "ctkWidgetsExport.h"
  20. class ctkLanguageComboBoxPrivate;
  21. /// ctkLanguageComboBox is a simple QComboBox to select the language
  22. /// of your application.
  23. /// You have to set the default language of your application and then
  24. /// set the directory to allow the comboBox to find the translation files.
  25. /// ctkLanguageComboBox automatically recognizes the language of the
  26. /// translation file by the suffix "_en" or "_fr" and add the associated
  27. /// language to the comboBox.
  28. /// \note:
  29. /// Translation files names need to finish with the suffix of the
  30. /// country.
  31. /// Example: for a french traduction, xxxx_fr.ts
  32. /// \warning Please don't use QComboBox methods when using this class.
  33. class CTK_WIDGETS_EXPORT ctkLanguageComboBox : public QComboBox
  34. {
  35. Q_OBJECT
  36. /// \brief This property controls the default language of the application.
  37. ///
  38. /// The default language is the language in which all the texts in GUI
  39. /// elements are written.
  40. /// As the application doesn't have translation file for the default
  41. /// language, this property adds an item to the combobox.
  42. /// The language format is a lowercase, two-letter, ISO 639 language code.
  43. /// For example: "fr", "en" or "de_ch".
  44. /// If empty, there is no default language, and there is no entry added.
  45. /// By default, there is no default language.
  46. /// \sa defaultLanguage(), setDefaultLanguage(), QLocale::setDefault()
  47. Q_PROPERTY(QString defaultLanguage READ defaultLanguage WRITE setDefaultLanguage)
  48. /// This property controls the directory where the translation files are
  49. /// located.
  50. /// \sa directory(), setDirectory()
  51. Q_PROPERTY(QString directory READ directory WRITE setDirectory)
  52. /// This property controls the current language of the combobox.
  53. /// The \a defaultLanguage by default.
  54. /// \sa currentLanguage(), setCurrentLanguage()
  55. Q_PROPERTY(QString currentLanguage READ currentLanguage WRITE setCurrentLanguage NOTIFY currentLanguageNameChanged USER true)
  56. public:
  57. typedef QComboBox Superclass;
  58. /// Constructor of ctkLanguageComboBox
  59. ctkLanguageComboBox(QWidget *parent = 0);
  60. /// Constructor that specifies a default language.
  61. /// \sa defaultLanguage
  62. ctkLanguageComboBox(const QString& defaultLanguage, QWidget *parent = 0);
  63. virtual ~ctkLanguageComboBox();
  64. /// Return the default language.
  65. /// \sa defaultLanguage, setDefaultLanguage()
  66. QString defaultLanguage()const;
  67. /// Set the default language. The previous default language is removed and
  68. /// replaced with the new default language.
  69. /// \sa defaultLanguage, defaultLanguage()
  70. void setDefaultLanguage(const QString& language);
  71. /// Set the \a directory with all the translation files.
  72. /// The list of available languages will be populated based on
  73. /// the discovered translation files.
  74. /// The default language will still be the first item in the menu.
  75. /// Empty by default.
  76. QString directory()const;
  77. void setDirectory(const QString& dir);
  78. /// Return the currently selected language of the combobox.
  79. /// \sa currentLanguage, setCurrentLanguage()
  80. QString currentLanguage()const;
  81. public Q_SLOTS:
  82. /// Set the current language
  83. /// \sa currentLanguage, currentLanguage()
  84. void setCurrentLanguage(const QString& language);
  85. protected slots:
  86. void onLanguageChanged(int index);
  87. signals:
  88. /// Signals emitted when the current language changed.
  89. /// \sa QLocale::name()
  90. void currentLanguageNameChanged(const QString&);
  91. protected:
  92. QScopedPointer<ctkLanguageComboBoxPrivate> d_ptr;
  93. private:
  94. Q_DECLARE_PRIVATE(ctkLanguageComboBox);
  95. Q_DISABLE_COPY(ctkLanguageComboBox);
  96. };
  97. #endif // __ctkLanguageComboBox_h