File indexing completed on 2025-04-27 03:58:36
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2009-06-15 0007 * Description : multi-languages string editor 0008 * 0009 * SPDX-FileCopyrightText: 2009-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #ifndef DIGIKAM_ALT_LANG_STR_EDIT_H 0016 #define DIGIKAM_ALT_LANG_STR_EDIT_H 0017 0018 // Qt includes 0019 0020 #include <QWidget> 0021 #include <QString> 0022 #include <QStringList> 0023 #include <QMap> 0024 0025 // Local includes 0026 0027 #include "digikam_export.h" 0028 #include "dmetadata.h" 0029 #include "dtextedit.h" 0030 0031 namespace Digikam 0032 { 0033 0034 class DIGIKAM_EXPORT AltLangStrEdit : public QWidget 0035 { 0036 Q_OBJECT 0037 0038 public: 0039 0040 /** 0041 * Default contructor. Use lines to use a specific number of lines with text editor. 0042 */ 0043 explicit AltLangStrEdit(QWidget* const parent, unsigned int lines = 3); 0044 ~AltLangStrEdit() override; 0045 0046 /** 0047 * Create a title widget with a QLabel and relevant text. 0048 * If a title widget already exists, it's remplaced. 0049 */ 0050 void setTitle(const QString& title); 0051 0052 /** 0053 * Create a title with a specific widget instance (aka a QCheckBox for ex). 0054 * If a title widget already exists, it's remplaced. 0055 */ 0056 void setTitleWidget(QWidget* const twdg); 0057 0058 /** 0059 * Return the current title widget instance. 0060 * If no previous call of setTitle() or setWidgetTitle(), this function will return nullptr. 0061 */ 0062 QWidget* titleWidget() const; 0063 0064 void setPlaceholderText(const QString& msg); 0065 0066 void setCurrentLanguageCode(const QString& lang); 0067 QString currentLanguageCode() const; 0068 0069 QString languageCode(int index) const; 0070 0071 /** 0072 * Fix lines visibile in text editor to lines. If zero, do not fix layout to number of lines visible. 0073 */ 0074 void setLinesVisible(uint lines); 0075 uint linesVisible() const; 0076 0077 QString defaultAltLang() const; 0078 bool asDefaultAltLang() const; 0079 0080 /** 0081 * Reset widget, clear all entries 0082 */ 0083 void reset(); 0084 0085 /** 0086 * Ensure that the current language is added to the list of entries, 0087 * even if the text is empty. 0088 * signalValueAdded() will be emitted. 0089 */ 0090 void addCurrent(); 0091 0092 DTextEdit* textEdit() const; 0093 0094 MetaEngine::AltLangMap& values() const; 0095 0096 virtual void setValues(const MetaEngine::AltLangMap& values); 0097 0098 /** 0099 * Return the literal name of RFC 3066 language code (format FR-fr for ex). 0100 */ 0101 static QString languageNameRFC3066(const QString& code); 0102 0103 /** 0104 * Return all language codes available following the RFC 3066. 0105 */ 0106 static QStringList allLanguagesRFC3066(); 0107 0108 Q_SIGNALS: 0109 0110 /** 0111 * Emitted when the user changes the text for the current language. 0112 */ 0113 void signalModified(const QString& lang, const QString& text); 0114 0115 /** 0116 * Emitted when the current language changed. 0117 */ 0118 void signalSelectionChanged(const QString& lang); 0119 0120 /** 0121 * Emitted when an entry for a new language is added. 0122 */ 0123 void signalValueAdded(const QString& lang, const QString& text); 0124 0125 /** 0126 * Emitted when the entry for a language is removed. 0127 */ 0128 void signalValueDeleted(const QString& lang); 0129 0130 public Q_SLOTS: 0131 0132 /** 0133 * Can be used to turn on/off visibility of internal widgets. 0134 * This do not includes the title widget. 0135 */ 0136 void slotEnabledInternalWidgets(bool); 0137 0138 protected Q_SLOTS: 0139 0140 void slotTextChanged(); 0141 void slotSelectionChanged(); 0142 void slotDeleteValue(); 0143 0144 private Q_SLOTS: 0145 0146 /** 0147 * Perform text translation with Web-service. 0148 */ 0149 void slotTranslate(const QString& lang); 0150 0151 void slotTranslationFinished(); 0152 0153 protected: 0154 0155 void populateLangAltListEntries(); 0156 0157 void changeEvent(QEvent* e) override; 0158 0159 private: 0160 0161 class Private; 0162 Private* const d; 0163 0164 friend class Private; 0165 }; 0166 0167 } // namespace Digikam 0168 0169 #endif // DIGIKAM_ALT_LANG_STR_EDIT_H