Changeset View
Changeset View
Standalone View
Standalone View
applets/kimpanel/backend/ibus/emojier/emojier.cpp
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | |||||
53 | 53 | | |||
54 | struct Emoji { | 54 | struct Emoji { | ||
55 | QString content; | 55 | QString content; | ||
56 | QString description; | 56 | QString description; | ||
57 | QString category; | 57 | QString category; | ||
58 | QStringList annotations; | 58 | QStringList annotations; | ||
59 | }; | 59 | }; | ||
60 | 60 | | |||
61 | class TextImageProvider : public QQuickImageProvider | | |||
62 | { | | |||
63 | public: | | |||
64 | TextImageProvider() | | |||
65 | : QQuickImageProvider(QQuickImageProvider::Pixmap) | | |||
66 | { | | |||
67 | } | | |||
68 | | ||||
69 | QPixmap requestPixmap(const QString &id, QSize *_size, const QSize &requestedSize) override | | |||
70 | { | | |||
71 | const QString renderString = id.mid(1); //drop initial / | | |||
72 | | ||||
73 | QSize size = requestedSize; | | |||
74 | QFont font; | | |||
75 | if (!size.isValid()) { | | |||
76 | QPixmap dummy; | | |||
77 | QFontMetrics fm(font, &dummy); | | |||
78 | size = { fm.horizontalAdvance(renderString), fm.height() }; | | |||
79 | } else { | | |||
80 | font.setPointSize((requestedSize.height() * 3) / 4); | | |||
81 | } | | |||
82 | if (_size) { | | |||
83 | *_size = size; | | |||
84 | } | | |||
85 | | ||||
86 | QPixmap pixmap(size.width(), size.height()); | | |||
87 | pixmap.fill(Qt::transparent); | | |||
88 | QPainter p; | | |||
89 | p.begin(&pixmap); | | |||
90 | p.setFont(font); | | |||
91 | p.drawText(QRect(0, 0, size.width(), size.height()), Qt::AlignCenter, renderString); | | |||
92 | p.end(); | | |||
93 | return pixmap; | | |||
94 | } | | |||
95 | }; | | |||
96 | | ||||
97 | class AbstractEmojiModel : public QAbstractListModel | 61 | class AbstractEmojiModel : public QAbstractListModel | ||
98 | { | 62 | { | ||
99 | Q_OBJECT | 63 | Q_OBJECT | ||
100 | public: | 64 | public: | ||
101 | enum EmojiRole { CategoryRole = Qt::UserRole + 1, AnnotationsRole }; | 65 | enum EmojiRole { CategoryRole = Qt::UserRole + 1, AnnotationsRole }; | ||
102 | 66 | | |||
103 | int rowCount(const QModelIndex & parent = {}) const override { return parent.isValid() ? 0 : m_emoji.count(); } | 67 | int rowCount(const QModelIndex & parent = {}) const override { return parent.isValid() ? 0 : m_emoji.count(); } | ||
104 | QVariant data(const QModelIndex & index, int role) const override { | 68 | QVariant data(const QModelIndex & index, int role) const override { | ||
▲ Show 20 Lines • Show All 295 Lines • ▼ Show 20 Line(s) | 336 | // about.setProductName(""); | |||
400 | qmlRegisterType<EmojiModel>("org.kde.plasma.emoji", 1, 0, "EmojiModel"); | 364 | qmlRegisterType<EmojiModel>("org.kde.plasma.emoji", 1, 0, "EmojiModel"); | ||
401 | qmlRegisterType<CategoryModelFilter>("org.kde.plasma.emoji", 1, 0, "CategoryModelFilter"); | 365 | qmlRegisterType<CategoryModelFilter>("org.kde.plasma.emoji", 1, 0, "CategoryModelFilter"); | ||
402 | qmlRegisterType<SearchModelFilter>("org.kde.plasma.emoji", 1, 0, "SearchModelFilter"); | 366 | qmlRegisterType<SearchModelFilter>("org.kde.plasma.emoji", 1, 0, "SearchModelFilter"); | ||
403 | qmlRegisterType<RecentEmojiModel>("org.kde.plasma.emoji", 1, 0, "RecentEmojiModel"); | 367 | qmlRegisterType<RecentEmojiModel>("org.kde.plasma.emoji", 1, 0, "RecentEmojiModel"); | ||
404 | qmlRegisterSingletonType<CopyHelperPrivate>("org.kde.plasma.emoji", 1, 0, "CopyHelper", [] (QQmlEngine*, QJSEngine*) -> QObject* { return new CopyHelperPrivate; }); | 368 | qmlRegisterSingletonType<CopyHelperPrivate>("org.kde.plasma.emoji", 1, 0, "CopyHelper", [] (QQmlEngine*, QJSEngine*) -> QObject* { return new CopyHelperPrivate; }); | ||
405 | 369 | | |||
406 | QQmlApplicationEngine engine; | 370 | QQmlApplicationEngine engine; | ||
407 | new EngineWatcher(&engine); | 371 | new EngineWatcher(&engine); | ||
408 | engine.addImageProvider(QLatin1String("text"), new TextImageProvider); | | |||
409 | engine.load(QUrl(QStringLiteral("qrc:/ui/emojier.qml"))); | 372 | engine.load(QUrl(QStringLiteral("qrc:/ui/emojier.qml"))); | ||
410 | 373 | | |||
411 | QObject::connect(service, &KDBusService::activateRequested, &engine, [&engine](const QStringList &/*arguments*/, const QString &/*workingDirectory*/) { | 374 | QObject::connect(service, &KDBusService::activateRequested, &engine, [&engine](const QStringList &/*arguments*/, const QString &/*workingDirectory*/) { | ||
412 | for (QObject* object : engine.rootObjects()) { | 375 | for (QObject* object : engine.rootObjects()) { | ||
413 | auto w = qobject_cast<QQuickWindow*>(object); | 376 | auto w = qobject_cast<QQuickWindow*>(object); | ||
414 | if (!w) | 377 | if (!w) | ||
415 | continue; | 378 | continue; | ||
416 | w->setVisible(true); | 379 | w->setVisible(true); | ||
417 | w->raise(); | 380 | w->raise(); | ||
418 | } | 381 | } | ||
419 | }); | 382 | }); | ||
420 | 383 | | |||
421 | return app.exec(); | 384 | return app.exec(); | ||
422 | } | 385 | } | ||
423 | 386 | | |||
424 | #include "emojier.moc" | 387 | #include "emojier.moc" |