diff options
author | Lars Knoll <lars.knoll@nokia.com> | 2009-03-23 10:18:55 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2009-03-23 10:18:55 +0100 |
commit | e5fcad302d86d316390c6b0f62759a067313e8a9 (patch) | |
tree | c2afbf6f1066b6ce261f14341cf6d310e5595bc1 /examples/widgets/validators | |
download | qt4-tools-e5fcad302d86d316390c6b0f62759a067313e8a9.tar.gz |
Long live Qt 4.5!
Diffstat (limited to 'examples/widgets/validators')
-rw-r--r-- | examples/widgets/validators/ledoff.png | bin | 0 -> 562 bytes | |||
-rw-r--r-- | examples/widgets/validators/ledon.png | bin | 0 -> 486 bytes | |||
-rw-r--r-- | examples/widgets/validators/ledwidget.cpp | 63 | ||||
-rw-r--r-- | examples/widgets/validators/ledwidget.h | 65 | ||||
-rw-r--r-- | examples/widgets/validators/localeselector.cpp | 313 | ||||
-rw-r--r-- | examples/widgets/validators/localeselector.h | 61 | ||||
-rw-r--r-- | examples/widgets/validators/main.cpp | 137 | ||||
-rw-r--r-- | examples/widgets/validators/validators.pro | 21 | ||||
-rw-r--r-- | examples/widgets/validators/validators.qrc | 6 | ||||
-rw-r--r-- | examples/widgets/validators/validators.ui | 467 |
10 files changed, 1133 insertions, 0 deletions
diff --git a/examples/widgets/validators/ledoff.png b/examples/widgets/validators/ledoff.png Binary files differnew file mode 100644 index 0000000000..8b1f2ed123 --- /dev/null +++ b/examples/widgets/validators/ledoff.png diff --git a/examples/widgets/validators/ledon.png b/examples/widgets/validators/ledon.png Binary files differnew file mode 100644 index 0000000000..601c34d5a8 --- /dev/null +++ b/examples/widgets/validators/ledon.png diff --git a/examples/widgets/validators/ledwidget.cpp b/examples/widgets/validators/ledwidget.cpp new file mode 100644 index 0000000000..9213755b3c --- /dev/null +++ b/examples/widgets/validators/ledwidget.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "ledwidget.h" + +LEDWidget::LEDWidget(QWidget *parent) + : QLabel(parent), onPixmap(":/ledon.png"), offPixmap(":/ledoff.png") +{ + setPixmap(offPixmap); + flashTimer.setInterval(200); + flashTimer.setSingleShot(true); + connect(&flashTimer, SIGNAL(timeout()), this, SLOT(extinguish())); +}; + +void LEDWidget::extinguish() +{ + setPixmap(offPixmap); +} + +void LEDWidget::flash() +{ + setPixmap(onPixmap); + flashTimer.start(); +} + diff --git a/examples/widgets/validators/ledwidget.h b/examples/widgets/validators/ledwidget.h new file mode 100644 index 0000000000..08992f97f2 --- /dev/null +++ b/examples/widgets/validators/ledwidget.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef LEDWIDGET_H +#define LEDWIDGET_H + +#include <QLabel> +#include <QPixmap> +#include <QTimer> + +class LEDWidget : public QLabel +{ + Q_OBJECT +public: + LEDWidget(QWidget *parent = 0); +public slots: + void flash(); + +private slots: + void extinguish(); + +private: + QPixmap onPixmap, offPixmap; + QTimer flashTimer; +}; + +#endif // LEDWIDGET_H diff --git a/examples/widgets/validators/localeselector.cpp b/examples/widgets/validators/localeselector.cpp new file mode 100644 index 0000000000..b725d2666d --- /dev/null +++ b/examples/widgets/validators/localeselector.cpp @@ -0,0 +1,313 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "localeselector.h" +#include <QLocale> + +struct SupportedLocale +{ + int lang, country; +}; + +const SupportedLocale SUPPORTED_LOCALES[] = { + { 1, 0 }, // C/AnyCountry + { 3, 69 }, // Afan/Ethiopia + { 3, 111 }, // Afan/Kenya + { 4, 59 }, // Afar/Djibouti + { 4, 67 }, // Afar/Eritrea + { 4, 69 }, // Afar/Ethiopia + { 5, 195 }, // Afrikaans/SouthAfrica + { 5, 148 }, // Afrikaans/Namibia + { 6, 2 }, // Albanian/Albania + { 7, 69 }, // Amharic/Ethiopia + { 8, 186 }, // Arabic/SaudiArabia + { 8, 3 }, // Arabic/Algeria + { 8, 17 }, // Arabic/Bahrain + { 8, 64 }, // Arabic/Egypt + { 8, 103 }, // Arabic/Iraq + { 8, 109 }, // Arabic/Jordan + { 8, 115 }, // Arabic/Kuwait + { 8, 119 }, // Arabic/Lebanon + { 8, 122 }, // Arabic/LibyanArabJamahiriya + { 8, 145 }, // Arabic/Morocco + { 8, 162 }, // Arabic/Oman + { 8, 175 }, // Arabic/Qatar + { 8, 201 }, // Arabic/Sudan + { 8, 207 }, // Arabic/SyrianArabRepublic + { 8, 216 }, // Arabic/Tunisia + { 8, 223 }, // Arabic/UnitedArabEmirates + { 8, 237 }, // Arabic/Yemen + { 9, 11 }, // Armenian/Armenia + { 10, 100 }, // Assamese/India + { 12, 15 }, // Azerbaijani/Azerbaijan + { 14, 197 }, // Basque/Spain + { 15, 18 }, // Bengali/Bangladesh + { 15, 100 }, // Bengali/India + { 16, 25 }, // Bhutani/Bhutan + { 20, 33 }, // Bulgarian/Bulgaria + { 22, 20 }, // Byelorussian/Belarus + { 23, 36 }, // Cambodian/Cambodia + { 24, 197 }, // Catalan/Spain + { 25, 44 }, // Chinese/China + { 25, 97 }, // Chinese/HongKong + { 25, 126 }, // Chinese/Macau + { 25, 190 }, // Chinese/Singapore + { 25, 208 }, // Chinese/Taiwan + { 27, 54 }, // Croatian/Croatia + { 28, 57 }, // Czech/CzechRepublic + { 29, 58 }, // Danish/Denmark + { 30, 151 }, // Dutch/Netherlands + { 30, 21 }, // Dutch/Belgium + { 31, 225 }, // English/UnitedStates + { 31, 4 }, // English/AmericanSamoa + { 31, 13 }, // English/Australia + { 31, 21 }, // English/Belgium + { 31, 22 }, // English/Belize + { 31, 28 }, // English/Botswana + { 31, 38 }, // English/Canada + { 31, 89 }, // English/Guam + { 31, 97 }, // English/HongKong + { 31, 100 }, // English/India + { 31, 104 }, // English/Ireland + { 31, 107 }, // English/Jamaica + { 31, 133 }, // English/Malta + { 31, 134 }, // English/MarshallIslands + { 31, 148 }, // English/Namibia + { 31, 154 }, // English/NewZealand + { 31, 160 }, // English/NorthernMarianaIslands + { 31, 163 }, // English/Pakistan + { 31, 170 }, // English/Philippines + { 31, 190 }, // English/Singapore + { 31, 195 }, // English/SouthAfrica + { 31, 215 }, // English/TrinidadAndTobago + { 31, 224 }, // English/UnitedKingdom + { 31, 226 }, // English/UnitedStatesMinorOutlyingIslands + { 31, 234 }, // English/USVirginIslands + { 31, 240 }, // English/Zimbabwe + { 33, 68 }, // Estonian/Estonia + { 34, 71 }, // Faroese/FaroeIslands + { 36, 73 }, // Finnish/Finland + { 37, 74 }, // French/France + { 37, 21 }, // French/Belgium + { 37, 38 }, // French/Canada + { 37, 125 }, // French/Luxembourg + { 37, 142 }, // French/Monaco + { 37, 206 }, // French/Switzerland + { 40, 197 }, // Galician/Spain + { 41, 81 }, // Georgian/Georgia + { 42, 82 }, // German/Germany + { 42, 14 }, // German/Austria + { 42, 21 }, // German/Belgium + { 42, 123 }, // German/Liechtenstein + { 42, 125 }, // German/Luxembourg + { 42, 206 }, // German/Switzerland + { 43, 85 }, // Greek/Greece + { 43, 56 }, // Greek/Cyprus + { 44, 86 }, // Greenlandic/Greenland + { 46, 100 }, // Gujarati/India + { 47, 83 }, // Hausa/Ghana + { 47, 156 }, // Hausa/Niger + { 47, 157 }, // Hausa/Nigeria + { 48, 105 }, // Hebrew/Israel + { 49, 100 }, // Hindi/India + { 50, 98 }, // Hungarian/Hungary + { 51, 99 }, // Icelandic/Iceland + { 52, 101 }, // Indonesian/Indonesia + { 57, 104 }, // Irish/Ireland + { 58, 106 }, // Italian/Italy + { 58, 206 }, // Italian/Switzerland + { 59, 108 }, // Japanese/Japan + { 61, 100 }, // Kannada/India + { 63, 110 }, // Kazakh/Kazakhstan + { 64, 179 }, // Kinyarwanda/Rwanda + { 65, 116 }, // Kirghiz/Kyrgyzstan + { 66, 114 }, // Korean/RepublicOfKorea + { 67, 102 }, // Kurdish/Iran + { 67, 103 }, // Kurdish/Iraq + { 67, 207 }, // Kurdish/SyrianArabRepublic + { 67, 217 }, // Kurdish/Turkey + { 69, 117 }, // Laothian/Lao + { 71, 118 }, // Latvian/Latvia + { 72, 49 }, // Lingala/DemocraticRepublicOfCongo + { 72, 50 }, // Lingala/PeoplesRepublicOfCongo + { 73, 124 }, // Lithuanian/Lithuania + { 74, 127 }, // Macedonian/Macedonia + { 76, 130 }, // Malay/Malaysia + { 76, 32 }, // Malay/BruneiDarussalam + { 77, 100 }, // Malayalam/India + { 78, 133 }, // Maltese/Malta + { 80, 100 }, // Marathi/India + { 82, 143 }, // Mongolian/Mongolia + { 84, 150 }, // Nepali/Nepal + { 85, 161 }, // Norwegian/Norway + { 87, 100 }, // Oriya/India + { 88, 1 }, // Pashto/Afghanistan + { 89, 102 }, // Persian/Iran + { 89, 1 }, // Persian/Afghanistan + { 90, 172 }, // Polish/Poland + { 91, 173 }, // Portuguese/Portugal + { 91, 30 }, // Portuguese/Brazil + { 92, 100 }, // Punjabi/India + { 92, 163 }, // Punjabi/Pakistan + { 95, 177 }, // Romanian/Romania + { 96, 178 }, // Russian/RussianFederation + { 96, 222 }, // Russian/Ukraine + { 99, 100 }, // Sanskrit/India + { 100, 241 }, // Serbian/SerbiaAndMontenegro + { 100, 27 }, // Serbian/BosniaAndHerzegowina + { 100, 238 }, // Serbian/Yugoslavia + { 101, 241 }, // SerboCroatian/SerbiaAndMontenegro + { 101, 27 }, // SerboCroatian/BosniaAndHerzegowina + { 101, 238 }, // SerboCroatian/Yugoslavia + { 102, 195 }, // Sesotho/SouthAfrica + { 103, 195 }, // Setswana/SouthAfrica + { 107, 195 }, // Siswati/SouthAfrica + { 108, 191 }, // Slovak/Slovakia + { 109, 192 }, // Slovenian/Slovenia + { 110, 194 }, // Somali/Somalia + { 110, 59 }, // Somali/Djibouti + { 110, 69 }, // Somali/Ethiopia + { 110, 111 }, // Somali/Kenya + { 111, 197 }, // Spanish/Spain + { 111, 10 }, // Spanish/Argentina + { 111, 26 }, // Spanish/Bolivia + { 111, 43 }, // Spanish/Chile + { 111, 47 }, // Spanish/Colombia + { 111, 52 }, // Spanish/CostaRica + { 111, 61 }, // Spanish/DominicanRepublic + { 111, 63 }, // Spanish/Ecuador + { 111, 65 }, // Spanish/ElSalvador + { 111, 90 }, // Spanish/Guatemala + { 111, 96 }, // Spanish/Honduras + { 111, 139 }, // Spanish/Mexico + { 111, 155 }, // Spanish/Nicaragua + { 111, 166 }, // Spanish/Panama + { 111, 168 }, // Spanish/Paraguay + { 111, 169 }, // Spanish/Peru + { 111, 174 }, // Spanish/PuertoRico + { 111, 225 }, // Spanish/UnitedStates + { 111, 227 }, // Spanish/Uruguay + { 111, 231 }, // Spanish/Venezuela + { 113, 111 }, // Swahili/Kenya + { 113, 210 }, // Swahili/Tanzania + { 114, 205 }, // Swedish/Sweden + { 114, 73 }, // Swedish/Finland + { 116, 209 }, // Tajik/Tajikistan + { 117, 100 }, // Tamil/India + { 118, 178 }, // Tatar/RussianFederation + { 119, 100 }, // Telugu/India + { 120, 211 }, // Thai/Thailand + { 122, 67 }, // Tigrinya/Eritrea + { 122, 69 }, // Tigrinya/Ethiopia + { 124, 195 }, // Tsonga/SouthAfrica + { 125, 217 }, // Turkish/Turkey + { 129, 222 }, // Ukrainian/Ukraine + { 130, 100 }, // Urdu/India + { 130, 163 }, // Urdu/Pakistan + { 131, 228 }, // Uzbek/Uzbekistan + { 131, 1 }, // Uzbek/Afghanistan + { 132, 232 }, // Vietnamese/VietNam + { 134, 224 }, // Welsh/UnitedKingdom + { 136, 195 }, // Xhosa/SouthAfrica + { 138, 157 }, // Yoruba/Nigeria + { 140, 195 }, // Zulu/SouthAfrica + { 141, 161 }, // Nynorsk/Norway + { 142, 27 }, // Bosnian/BosniaAndHerzegowina + { 143, 131 }, // Divehi/Maldives + { 144, 224 }, // Manx/UnitedKingdom + { 145, 224 }, // Cornish/UnitedKingdom + { 146, 83 }, // Akan/Ghana + { 147, 100 }, // Konkani/India + { 148, 83 }, // Ga/Ghana + { 149, 157 }, // Igbo/Nigeria + { 150, 111 }, // Kamba/Kenya + { 151, 207 }, // Syriac/SyrianArabRepublic + { 152, 67 }, // Blin/Eritrea + { 153, 67 }, // Geez/Eritrea + { 153, 69 }, // Geez/Ethiopia + { 154, 157 }, // Koro/Nigeria + { 155, 69 }, // Sidamo/Ethiopia + { 156, 157 }, // Atsam/Nigeria + { 157, 67 }, // Tigre/Eritrea + { 158, 157 }, // Jju/Nigeria + { 159, 106 }, // Friulian/Italy + { 160, 195 }, // Venda/SouthAfrica + { 161, 83 }, // Ewe/Ghana + { 161, 212 }, // Ewe/Togo + { 163, 225 }, // Hawaiian/UnitedStates + { 164, 157 }, // Tyap/Nigeria + { 165, 129 } // Chewa/Malawi +}; + +const int SUPPORTED_LOCALES_COUNT = sizeof(SUPPORTED_LOCALES)/sizeof(SupportedLocale); + +typedef QPair<int, int> IntPair; +Q_DECLARE_METATYPE(SupportedLocale) + +LocaleSelector::LocaleSelector(QWidget *parent) + : QComboBox(parent) +{ + int curIndex = -1; + QLocale curLocale; + + for (int i = 0; i < SUPPORTED_LOCALES_COUNT; ++i) { + const SupportedLocale &l = SUPPORTED_LOCALES[i]; + if (l.lang == curLocale.language() && l.country == curLocale.country()) + curIndex = i; + QString text = QLocale::languageToString(QLocale::Language(l.lang)) + + QLatin1Char('/') + + QLocale::countryToString(QLocale::Country(l.country)); + addItem(text, qVariantFromValue(l)); + } + + setCurrentIndex(curIndex); + + connect(this, SIGNAL(activated(int)), this, SLOT(emitLocaleSelected(int))); +} + +void LocaleSelector::emitLocaleSelected(int index) +{ + QVariant v = itemData(index); + if (!v.isValid()) + return; + SupportedLocale l = qVariantValue<SupportedLocale>(v); + emit localeSelected(QLocale(QLocale::Language(l.lang), QLocale::Country(l.country))); +} diff --git a/examples/widgets/validators/localeselector.h b/examples/widgets/validators/localeselector.h new file mode 100644 index 0000000000..763b58b4af --- /dev/null +++ b/examples/widgets/validators/localeselector.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef LOCALESELECTOR_H +#define LOCALESELECTOR_H + +#include <QComboBox> + +class LocaleSelector : public QComboBox +{ + Q_OBJECT + +public: + LocaleSelector(QWidget *parent = 0); + +signals: + void localeSelected(const QLocale &locale); + +private slots: + void emitLocaleSelected(int index); +}; + +#endif //LOCALESELECTOR_H diff --git a/examples/widgets/validators/main.cpp b/examples/widgets/validators/main.cpp new file mode 100644 index 0000000000..6822b62dc0 --- /dev/null +++ b/examples/widgets/validators/main.cpp @@ -0,0 +1,137 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <qdebug.h> +#include <QApplication> +#include <QLineEdit> +#include <QValidator> + +#include "ui_validators.h" + +class ValidatorWidget : public QWidget, public Ui::ValidatorsForm +{ + Q_OBJECT +public: + ValidatorWidget(QWidget *parent = 0); + +private slots: + void updateValidator(); + void updateDoubleValidator(); + void _setLocale(const QLocale &l) { setLocale(l); updateValidator(); updateDoubleValidator(); } + +private: + QIntValidator *validator; + QDoubleValidator *doubleValidator; +}; + +ValidatorWidget::ValidatorWidget(QWidget *parent) + : QWidget(parent) +{ + setupUi(this); + + connect(localeSelector, SIGNAL(localeSelected(QLocale)), this, SLOT(_setLocale(QLocale))); + + connect(minVal, SIGNAL(editingFinished()), this, SLOT(updateValidator())); + connect(maxVal, SIGNAL(editingFinished()), this, SLOT(updateValidator())); + connect(editor, SIGNAL(editingFinished()), ledWidget, SLOT(flash())); + + connect(doubleMaxVal, SIGNAL(editingFinished()), this, SLOT(updateDoubleValidator())); + connect(doubleMinVal, SIGNAL(editingFinished()), this, SLOT(updateDoubleValidator())); + connect(doubleDecimals, SIGNAL(valueChanged(int)), this, SLOT(updateDoubleValidator())); + connect(doubleFormat, SIGNAL(activated(int)), this, SLOT(updateDoubleValidator())); + connect(doubleEditor, SIGNAL(editingFinished()), doubleLedWidget, SLOT(flash())); + + validator = 0; + doubleValidator = 0; + updateValidator(); + updateDoubleValidator(); +}; + +void ValidatorWidget::updateValidator() +{ + QIntValidator *v = new QIntValidator(minVal->value(), maxVal->value(), this); + v->setLocale(locale()); + editor->setValidator(v); + delete validator; + validator = v; + + QString s = editor->text(); + int i = 0; + if (validator->validate(s, i) == QValidator::Invalid) { + editor->clear(); + } else { + editor->setText(s); + } +} + +void ValidatorWidget::updateDoubleValidator() +{ + QDoubleValidator *v + = new QDoubleValidator(doubleMinVal->value(), doubleMaxVal->value(), + doubleDecimals->value(), this); + v->setNotation(static_cast<QDoubleValidator::Notation>(doubleFormat->currentIndex())); + v->setLocale(locale()); + doubleEditor->setValidator(v); + delete doubleValidator; + doubleValidator = v; + + QString s = doubleEditor->text(); + int i = 0; + if (doubleValidator->validate(s, i) == QValidator::Invalid) { + doubleEditor->clear(); + } else { + doubleEditor->setText(s); + } +} + +int main(int argc, char **argv) +{ + Q_INIT_RESOURCE(validators); + + QApplication app(argc, argv); + + ValidatorWidget w; + w.show(); + + return app.exec(); +} + +#include "main.moc" diff --git a/examples/widgets/validators/validators.pro b/examples/widgets/validators/validators.pro new file mode 100644 index 0000000000..8e7884d56e --- /dev/null +++ b/examples/widgets/validators/validators.pro @@ -0,0 +1,21 @@ +###################################################################### +# Automatically generated by qmake (2.01a) Tue Nov 28 13:20:04 2006 +###################################################################### + +TEMPLATE = app +TARGET = validators +DEPENDPATH += . +INCLUDEPATH += . + +FORMS += validators.ui +RESOURCES += validators.qrc + +# Input +SOURCES += main.cpp ledwidget.cpp localeselector.cpp +HEADERS += ledwidget.h localeselector.h + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/widgets/validators +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro *.png +sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/validators +INSTALLS += target sources diff --git a/examples/widgets/validators/validators.qrc b/examples/widgets/validators/validators.qrc new file mode 100644 index 0000000000..94874317a8 --- /dev/null +++ b/examples/widgets/validators/validators.qrc @@ -0,0 +1,6 @@ +<RCC> + <qresource prefix="/" > + <file>ledoff.png</file> + <file>ledon.png</file> + </qresource> +</RCC> diff --git a/examples/widgets/validators/validators.ui b/examples/widgets/validators/validators.ui new file mode 100644 index 0000000000..f05b96fbe0 --- /dev/null +++ b/examples/widgets/validators/validators.ui @@ -0,0 +1,467 @@ +<ui version="4.0" > + <class>ValidatorsForm</class> + <widget class="QWidget" name="ValidatorsForm" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>526</width> + <height>668</height> + </rect> + </property> + <property name="windowTitle" > + <string>Form</string> + </property> + <layout class="QVBoxLayout" > + <property name="margin" > + <number>9</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <layout class="QHBoxLayout" > + <property name="margin" > + <number>0</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <widget class="LocaleSelector" name="localeSelector" /> + </item> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" > + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item> + <widget class="QGroupBox" name="groupBox" > + <property name="title" > + <string>QIntValidator</string> + </property> + <layout class="QVBoxLayout" > + <property name="margin" > + <number>9</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <layout class="QHBoxLayout" > + <property name="margin" > + <number>0</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <layout class="QGridLayout" > + <property name="margin" > + <number>0</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item row="0" column="0" > + <widget class="QLabel" name="label" > + <property name="text" > + <string>Min:</string> + </property> + <property name="alignment" > + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item row="0" column="1" > + <widget class="QSpinBox" name="minVal" > + <property name="sizePolicy" > + <sizepolicy vsizetype="Fixed" hsizetype="Minimum" > + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimum" > + <number>-1000000</number> + </property> + <property name="maximum" > + <number>1000000</number> + </property> + </widget> + </item> + <item row="1" column="0" > + <widget class="QLabel" name="label_2" > + <property name="text" > + <string>Max:</string> + </property> + <property name="alignment" > + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item row="1" column="1" > + <widget class="QSpinBox" name="maxVal" > + <property name="sizePolicy" > + <sizepolicy vsizetype="Fixed" hsizetype="Minimum" > + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimum" > + <number>-1000000</number> + </property> + <property name="maximum" > + <number>1000000</number> + </property> + <property name="value" > + <number>1000</number> + </property> + </widget> + </item> + </layout> + </item> + <item> + <widget class="QFrame" name="frame" > + <property name="frameShape" > + <enum>QFrame::StyledPanel</enum> + </property> + <property name="frameShadow" > + <enum>QFrame::Sunken</enum> + </property> + <layout class="QVBoxLayout" > + <property name="margin" > + <number>9</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <widget class="LEDWidget" name="ledWidget" > + <property name="sizePolicy" > + <sizepolicy vsizetype="Fixed" hsizetype="Preferred" > + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="pixmap" > + <pixmap resource="validators.qrc" >:/ledoff.png</pixmap> + </property> + <property name="alignment" > + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="label_7" > + <property name="text" > + <string>editingFinished()</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + </layout> + </item> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Vertical</enum> + </property> + <property name="sizeType" > + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" > + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLineEdit" name="editor" /> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QGroupBox" name="groupBox_2" > + <property name="title" > + <string>QDoubleValidator</string> + </property> + <layout class="QVBoxLayout" > + <property name="margin" > + <number>9</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <layout class="QHBoxLayout" > + <property name="margin" > + <number>0</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <layout class="QGridLayout" > + <property name="margin" > + <number>0</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item row="0" column="0" > + <widget class="QLabel" name="label_3" > + <property name="text" > + <string>Min:</string> + </property> + <property name="alignment" > + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item row="0" column="1" > + <widget class="QDoubleSpinBox" name="doubleMinVal" > + <property name="sizePolicy" > + <sizepolicy vsizetype="Fixed" hsizetype="Minimum" > + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimum" > + <double>-100000.000000000000000</double> + </property> + <property name="maximum" > + <double>100000.000000000000000</double> + </property> + <property name="value" > + <double>0.000000000000000</double> + </property> + </widget> + </item> + <item row="0" column="2" > + <widget class="QLabel" name="label_5" > + <property name="text" > + <string>Format:</string> + </property> + <property name="alignment" > + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item row="0" column="3" > + <widget class="QComboBox" name="doubleFormat" > + <item> + <property name="text" > + <string>Standard</string> + </property> + </item> + <item> + <property name="text" > + <string>Scientific</string> + </property> + </item> + </widget> + </item> + <item row="1" column="0" > + <widget class="QLabel" name="label_4" > + <property name="text" > + <string>Max:</string> + </property> + <property name="alignment" > + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item row="1" column="1" > + <widget class="QDoubleSpinBox" name="doubleMaxVal" > + <property name="sizePolicy" > + <sizepolicy vsizetype="Fixed" hsizetype="Minimum" > + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimum" > + <double>-100000.000000000000000</double> + </property> + <property name="maximum" > + <double>100000.000000000000000</double> + </property> + <property name="value" > + <double>1000.000000000000000</double> + </property> + </widget> + </item> + <item row="1" column="2" > + <widget class="QLabel" name="label_6" > + <property name="text" > + <string>Decimals:</string> + </property> + <property name="alignment" > + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item row="1" column="3" > + <widget class="QSpinBox" name="doubleDecimals" > + <property name="value" > + <number>2</number> + </property> + </widget> + </item> + </layout> + </item> + <item> + <widget class="QFrame" name="frame_2" > + <property name="frameShape" > + <enum>QFrame::StyledPanel</enum> + </property> + <property name="frameShadow" > + <enum>QFrame::Sunken</enum> + </property> + <layout class="QVBoxLayout" > + <property name="margin" > + <number>9</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <widget class="LEDWidget" name="doubleLedWidget" > + <property name="text" > + <string/> + </property> + <property name="pixmap" > + <pixmap resource="validators.qrc" >:/ledoff.png</pixmap> + </property> + <property name="alignment" > + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="label_8" > + <property name="text" > + <string>editingFinished()</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + </layout> + </item> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Vertical</enum> + </property> + <property name="sizeType" > + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" > + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLineEdit" name="doubleEditor" /> + </item> + </layout> + </widget> + </item> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" > + <size> + <width>20</width> + <height>111</height> + </size> + </property> + </spacer> + </item> + <item> + <layout class="QHBoxLayout" > + <property name="margin" > + <number>0</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" > + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="pushButton" > + <property name="text" > + <string>Quit</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <customwidgets> + <customwidget> + <class>LEDWidget</class> + <extends>QLabel</extends> + <header>ledwidget.h</header> + </customwidget> + <customwidget> + <class>LocaleSelector</class> + <extends>QComboBox</extends> + <header>localeselector.h</header> + </customwidget> + </customwidgets> + <resources> + <include location="validators.qrc" /> + </resources> + <connections> + <connection> + <sender>pushButton</sender> + <signal>clicked()</signal> + <receiver>ValidatorsForm</receiver> + <slot>close()</slot> + <hints> + <hint type="sourcelabel" > + <x>94</x> + <y>274</y> + </hint> + <hint type="destinationlabel" > + <x>131</x> + <y>260</y> + </hint> + </hints> + </connection> + </connections> +</ui> |