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