| 1 |
/* |
| 2 |
* SPDX-FileCopyrightText: 2021~2021 CSSlayer <[email protected]> |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: BSD-3-Clause |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
#ifndef _PLATFORMINPUTCONTEXT_FCITXCANDIDATEWINDOW_H_ |
| 9 |
#define _PLATFORMINPUTCONTEXT_FCITXCANDIDATEWINDOW_H_ |
| 10 |
|
| 11 |
#include "fcitxflags.h" |
| 12 |
#include "fcitxqtdbustypes.h" |
| 13 |
#include <QGuiApplication> |
| 14 |
#include <QPainter> |
| 15 |
#include <QPointer> |
| 16 |
#include <QRasterWindow> |
| 17 |
#include <QTextLayout> |
| 18 |
#include <memory> |
| 19 |
#include <qscopedpointer.h> |
| 20 |
#include <vector> |
| 21 |
|
| 22 |
#if defined(FCITX_ENABLE_QT6_WAYLAND_WORKAROUND) && \ |
| 23 |
QT_VERSION >= QT_VERSION_CHECK(6, 6, 0) |
| 24 |
#include <QtWaylandClient/private/qwayland-xdg-shell.h> |
| 25 |
#endif |
| 26 |
|
| 27 |
namespace fcitx { |
| 28 |
|
| 29 |
class FcitxTheme; |
| 30 |
class MultilineText; |
| 31 |
class QFcitxPlatformInputContext; |
| 32 |
|
| 33 |
class FcitxCandidateWindow : public QRasterWindow { |
| 34 |
Q_OBJECT |
| 35 |
public: |
| 36 |
explicit FcitxCandidateWindow(QWindow *window, |
| 37 |
QFcitxPlatformInputContext *context); |
| 38 |
~FcitxCandidateWindow(); |
| 39 |
|
| 40 |
void render(QPainter *painter); |
| 41 |
|
| 42 |
public Q_SLOTS: |
| 43 |
void updateClientSideUI(const FcitxQtFormattedPreeditList &preedit, |
| 44 |
int cursorpos, |
| 45 |
const FcitxQtFormattedPreeditList &auxUp, |
| 46 |
const FcitxQtFormattedPreeditList &auxDown, |
| 47 |
const FcitxQtStringKeyValueList &candidates, |
| 48 |
int candidateIndex, int layoutHint, bool hasPrev, |
| 49 |
bool hasNext); |
| 50 |
void updatePosition(); |
| 51 |
|
| 52 |
QSize sizeHint(); |
| 53 |
|
| 54 |
Q_SIGNALS: |
| 55 |
void candidateSelected(int i); |
| 56 |
void prevClicked(); |
| 57 |
void nextClicked(); |
| 58 |
|
| 59 |
protected: |
| 60 |
bool event(QEvent *event) override; |
| 61 |
|
| 62 |
void paintEvent(QPaintEvent *event) override; |
| 63 |
void mouseMoveEvent(QMouseEvent *) override; |
| 64 |
void mouseReleaseEvent(QMouseEvent *) override; |
| 65 |
void wheelEvent(QWheelEvent *) override; |
| 66 |
|
| 67 |
int highlight() const { |
| 68 |
int highlightIndex = (hoverIndex_ >= 0) ? hoverIndex_ : highlight_; |
| 69 |
return highlightIndex; |
| 70 |
} |
| 71 |
|
| 72 |
private: |
| 73 |
const bool isWayland_ = |
| 74 |
QGuiApplication::platformName().startsWith("wayland"); |
| 75 |
uint32_t repositionToken_ = 0; |
| 76 |
QSize actualSize_; |
| 77 |
QPointer<QFcitxPlatformInputContext> context_; |
| 78 |
QPointer<FcitxTheme> theme_; |
| 79 |
QTextLayout upperLayout_; |
| 80 |
QTextLayout lowerLayout_; |
| 81 |
std::vector<std::unique_ptr<MultilineText>> candidateLayouts_; |
| 82 |
std::vector<std::unique_ptr<MultilineText>> labelLayouts_; |
| 83 |
int cursor_ = -1; |
| 84 |
int highlight_ = -1; |
| 85 |
int hoverIndex_ = -1; |
| 86 |
int accAngle_ = 0; |
| 87 |
bool prevHovered_ = false; |
| 88 |
bool nextHovered_ = false; |
| 89 |
bool hasPrev_ = false; |
| 90 |
bool hasNext_ = false; |
| 91 |
FcitxCandidateLayoutHint layoutHint_ = FcitxCandidateLayoutHint::NotSet; |
| 92 |
int candidatesHeight_ = 0; |
| 93 |
QRect prevRegion_; |
| 94 |
QRect nextRegion_; |
| 95 |
std::vector<QRect> candidateRegions_; |
| 96 |
QPointer<QWindow> parent_; |
| 97 |
|
| 98 |
#if defined(FCITX_ENABLE_QT6_WAYLAND_WORKAROUND) && \ |
| 99 |
QT_VERSION >= QT_VERSION_CHECK(6, 6, 0) && \ |
| 100 |
QT_VERSION < QT_VERSION_CHECK(6, 10, 0) |
| 101 |
QScopedPointer<QtWayland::xdg_wm_base> xdgWmBase_; |
| 102 |
#endif |
| 103 |
}; |
| 104 |
|
| 105 |
} // namespace fcitx |
| 106 |
|
| 107 |
#endif // _PLATFORMINPUTCONTEXT_FCITXCANDIDATEWINDOW_H_ |