ctkLanguageComboBox.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. /// ctkLanguageComboBox is a simple QComboBox to select the language
  21. /// of your application.
  22. /// You have to set the default language of your application and then
  23. /// set the directory to allow the comboBox to find the translation files.
  24. /// ctkLanguageComboBox automaically recognizes the language of the
  25. /// translation file by the suffix _en or _fr and add the associated
  26. /// language to the comboBox.
  27. /// \note:
  28. /// Translation files names need to finish with the suffix of the
  29. /// country.
  30. /// Example: for a french traduction, xxxx_fr.ts
  31. class ctkLanguageComboBoxPrivate;
  32. class CTK_WIDGETS_EXPORT ctkLanguageComboBox : public QComboBox
  33. {
  34. Q_OBJECT
  35. Q_PROPERTY(QString currentLanguage READ currentLanguage WRITE setCurrentLanguage)
  36. Q_PROPERTY(QString directory READ directory WRITE setDirectory)
  37. public:
  38. typedef QComboBox Superclass;
  39. ctkLanguageComboBox(QWidget *parent = 0);
  40. virtual ~ctkLanguageComboBox();
  41. /// Return the currentLanguage of the combobox.
  42. QString currentLanguage()const;
  43. void setCurrentLanguage(const QString& language);
  44. /// Set the default language of your application.
  45. /// As the application doesn't have translation file for the default
  46. /// language, it's very important to set this variable. Otherwise,
  47. /// the default language is not added to the ComboBox.
  48. QString defaultLanguage()const;
  49. void setDefaultLanguage(const QString& language);
  50. /// Set the \a directory with all the translation files.
  51. /// The list of available languages will be populated based on
  52. /// the discovered translation files.
  53. QString directory()const;
  54. void setDirectory(const QString& dir);
  55. protected slots:
  56. void onLanguageChanged(int index);
  57. signals:
  58. /// Signals emitted when the current language changed.
  59. void currentLanguageNameChanged(const QString&);
  60. protected:
  61. QScopedPointer<ctkLanguageComboBoxPrivate> d_ptr;
  62. private:
  63. Q_DECLARE_PRIVATE(ctkLanguageComboBox);
  64. Q_DISABLE_COPY(ctkLanguageComboBox);
  65. };
  66. #endif // __ctkLanguageComboBox_h