File indexing completed on 2024-04-28 15:22:11

0001 /*
0002     SPDX-FileCopyrightText: 2008 Carlo Segato <brandon.ml@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include <kemoticons.h>
0008 
0009 #include <QApplication>
0010 #include <QDebug>
0011 #include <QLineEdit>
0012 #include <QLabel>
0013 #include <QComboBox>
0014 #include <QVBoxLayout>
0015 #include <QString>
0016 
0017 class KEmoTest : public QWidget
0018 {
0019     Q_OBJECT
0020 public:
0021     KEmoTest();
0022 
0023 public Q_SLOTS:
0024     void updateEmoticons();
0025     void changeTheme(const QString &emoticonTheme);
0026 
0027 private:
0028     QLineEdit *lineEdit;
0029     QLabel *label;
0030     KEmoticons emoticons;
0031     KEmoticonsTheme emoticonTheme;
0032     QComboBox *comboBox;
0033 };
0034 
0035 KEmoTest::KEmoTest()
0036 {
0037     lineEdit = new QLineEdit;
0038     label = new QLabel;
0039     QLabel *explanation = new QLabel;
0040     explanation->setText(QStringLiteral("Please enter text with emoticons. They will be parsed, "
0041                          "except <b>:-)</b> and <b>:)</b> which are excluded. "
0042                          "Emoticon theme can be chosen from the combo box."));
0043     explanation->setWordWrap(true);
0044     comboBox = new QComboBox;
0045 
0046     emoticonTheme = emoticons.theme();
0047     // Theme list is repeating three times the same two themes: "Oxygen" and "Glass"
0048     qDebug() << "Theme list: " << emoticons.themeList();
0049     // Theme name is empty!!
0050     qDebug() << "Theme name: " << emoticonTheme.themeName();
0051 
0052     comboBox->addItems(emoticons.themeList());
0053     comboBox->setCurrentIndex(emoticons.themeList().indexOf(emoticonTheme.themeName()));
0054 
0055     QVBoxLayout *layout = new QVBoxLayout;
0056     layout->addWidget(explanation);
0057     layout->addWidget(lineEdit);
0058     layout->addWidget(comboBox);
0059     layout->addWidget(label);
0060     setLayout(layout);
0061 
0062     connect(lineEdit, &QLineEdit::textChanged, this, &KEmoTest::updateEmoticons);
0063     connect(comboBox, SIGNAL(activated(QString)), this, SLOT(changeTheme(QString)));
0064 }
0065 
0066 void KEmoTest::updateEmoticons()
0067 {
0068     QStringList excludedEmoticons;
0069     excludedEmoticons << QStringLiteral(":)") << QStringLiteral(":-)");
0070     label->setText(emoticonTheme.parseEmoticons(lineEdit->text().toHtmlEscaped(), KEmoticonsTheme::DefaultParse, excludedEmoticons));
0071 }
0072 
0073 void KEmoTest::changeTheme(const QString &theme)
0074 {
0075     emoticonTheme = emoticons.theme(theme);
0076     updateEmoticons();
0077 }
0078 
0079 int main(int argc, char **argv)
0080 {
0081     QApplication::setApplicationName(QStringLiteral("kemoticonstest"));
0082     QApplication app(argc, argv);
0083 
0084     KEmoTest kt;
0085 
0086     kt.show();
0087 
0088     return app.exec();
0089 }
0090 
0091 #include "main.moc"