KConfigWidgets

klanguagebutton.h
1/*
2 klangbutton.h - Button with language selection drop down menu.
3 Derived from the KLangCombo class by Hans Petter Bieker.
4
5 SPDX-FileCopyrightText: 1999-2003 Hans Petter Bieker <bieker@kde.org>
6 SPDX-FileCopyrightText: 2001 Martijn Klingens <klingens@kde.org>
7 SPDX-FileCopyrightText: 2007 David Jarvie <djarvie@kde.org>
8
9 SPDX-License-Identifier: LGPL-2.0-or-later
10*/
11
12#ifndef KLANGUAGEBUTTON_H
13#define KLANGUAGEBUTTON_H
14
15#include "kconfigwidgets_export.h"
16#include <QWidget>
17#include <memory>
18
19class QAction;
20class KLanguageButtonPrivate;
21
22/**
23 * @class KLanguageButton klanguagebutton.h KLanguageButton
24 *
25 * KLanguageButton is a pushbutton which allows a language to be selected from
26 * a popup list.
27 *
28 * Languages are identified by their ISO 639-1 codes, e.g. en, pt_BR.
29 *
30 * \image html klanguagebutton.png "KDE Language Selection Widget"
31 *
32 * @author Hans Petter Bieker <bieker@kde.org>, Martijn Klingens <klingens@kde.org>,
33 * David Jarvie <djarvie@kde.org>
34 */
35class KCONFIGWIDGETS_EXPORT KLanguageButton : public QWidget
36{
37 Q_OBJECT
38
39public:
40 /**
41 * Constructs a button whose text is determined by the current language
42 * in the popup list.
43 *
44 * @param parent the parent of the button
45 */
46 explicit KLanguageButton(QWidget *parent = nullptr);
47
48 /**
49 * Constructs a button with static text.
50 *
51 * @param text the text of the button
52 * @param parent the parent of the button
53 */
54 explicit KLanguageButton(const QString &text, QWidget *parent = nullptr);
55
56 /**
57 * Deconstructor
58 */
59 ~KLanguageButton() override;
60
61 /**
62 * Sets the locale to display language names. By default, QLocale::system().name() is used.
63 *
64 * @param locale locale to use
65 */
66 void setLocale(const QString &locale);
67
68 /**
69 * Sets a static button text.
70 *
71 * @param text button text
72 */
73 void setText(const QString &text);
74
75 /**
76 * Specifies whether language codes should be shown alongside language names
77 * in the popup. Calling this method does not affect any previously
78 * inserted language texts, so it should normally be called before
79 * populating the list.
80 *
81 * @param show true to show codes, false to hide codes
82 */
83 void showLanguageCodes(bool show);
84
85 /**
86 * Load all known languages into the popup list.
87 * The current language in the list is set to the default language for the
88 * current locale (as modified by setLocale()).
89 */
90 void loadAllLanguages();
91
92 /**
93 * Inserts a language into the combo box.
94 * Normally the display name of the language is obtained automatically, but
95 * if either the language code does not exist, or there are special display
96 * requirements, the name of the language can be specified in @p name.
97 *
98 * @param languageCode the code for the language
99 * @param name language name. If empty, the name is obtained automatically.
100 * @param index the insertion position, or -1 to insert in alphabetical order
101 */
102 void insertLanguage(const QString &languageCode, const QString &name = QString(), int index = -1);
103
104 /**
105 * Inserts a separator item into the combo box. A negative index will append the item.
106 *
107 * @param index the insertion position
108 */
109 void insertSeparator(int index = -1);
110
111 /**
112 * Returns the number of items in the combo box.
113 */
114 int count() const;
115
116 /**
117 * Removes all combobox items.
118 */
119 void clear();
120
121 /**
122 * Returns the language code of the combobox's current item.
123 *
124 * @return the current item's language code
125 */
126 QString current() const;
127
128 /**
129 * Checks whether the specified language is in the popup list.
130 *
131 * @param languageCode the language's code
132 * @return true if in the list
133 */
134 bool contains(const QString &languageCode) const;
135
136 /**
137 * Sets a given language to be the current item.
138 *
139 * @param languageCode the language's code
140 */
141 void setCurrentItem(const QString &languageCode);
142
144 /**
145 * This signal is emitted when a new item is activated.
146 *
147 * @param languageCode code of the activated language
148 */
149 void activated(const QString &languageCode);
150 /**
151 * This signal is emitted when a new item is highlighted.
152 *
153 * @param languageCode code of the highlighted language
154 */
155 void highlighted(const QString &languageCode);
156
157private Q_SLOTS:
158 KCONFIGWIDGETS_NO_EXPORT void slotTriggered(QAction *action);
159 KCONFIGWIDGETS_NO_EXPORT void slotHovered(QAction *action);
160
161private:
162 friend class KLanguageButtonPrivate;
163 std::unique_ptr<KLanguageButtonPrivate> const d;
164};
165
166#endif
KLanguageButton is a pushbutton which allows a language to be selected from a popup list.
void highlighted(const QString &languageCode)
This signal is emitted when a new item is highlighted.
void activated(const QString &languageCode)
This signal is emitted when a new item is activated.
~KLanguageButton() override
Deconstructor.
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
void setLocale(const QLocale &locale)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:13:01 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.