DtkWidget
DTK Widget module
载入中...
搜索中...
未找到
dcrumbedit.h
浏览该文件的文档.
1// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5#ifndef DCRUMBEDIT_H
6#define DCRUMBEDIT_H
7
8#include <QTextEdit>
9
10#include <DObject>
11#include <dtkwidget_global.h>
12
13DWIDGET_BEGIN_NAMESPACE
14
15class LIBDTKWIDGETSHARED_EXPORT DCrumbTextFormat : public QTextCharFormat
16{
17public:
19
20 QColor tagColor() const;
21 void setTagColor(const QColor &color);
22 QString text() const;
23 void setText(const QString &text);
24 QColor textColor() const;
25 void setTextColor(const QColor &color);
26 QBrush background() const;
27 void setBackground(const QBrush &background);
28 int backgroundRadius() const;
29 void setBackgroundRadius(int radius);
30
31protected:
32 DCrumbTextFormat(int objectType);
33 explicit DCrumbTextFormat(const QTextFormat &fmt);
34 friend class CrumbObjectInterface;
35 friend class DCrumbEdit;
36 friend class DCrumbEditPrivate;
37};
38
40class LIBDTKWIDGETSHARED_EXPORT DCrumbEdit : public QTextEdit, public DCORE_NAMESPACE::DObject
41{
42 Q_OBJECT
43
44 Q_PROPERTY(bool crumbReadOnly READ crumbReadOnly WRITE setCrumbReadOnly)
45 Q_PROPERTY(int crumbRadius READ crumbRadius WRITE setCrumbRadius)
46 Q_PROPERTY(QString splitter READ splitter WRITE setSplitter)
47 Q_PROPERTY(bool dualClickMakeCrumb READ dualClickMakeCrumb WRITE setDualClickMakeCrumb)
48
49public:
50 enum CrumbType {
51 black = Qt::black,
52 white = Qt::white,
53 darkGray = Qt::darkGray,
54 gray = Qt::gray,
55 lightGray = Qt::lightGray,
56 red = Qt::red,
57 green = Qt::green,
58 blue = Qt::blue,
59 cyan = Qt::cyan,
60 magenta = Qt::magenta,
61 yellow = Qt::yellow,
62 darkRed = Qt::darkRed,
63 darkGreen = Qt::darkGreen,
64 darkBlue = Qt::darkBlue,
65 darkCyan = Qt::darkCyan,
66 darkMagenta = Qt::darkMagenta,
67 darkYellow = Qt::darkYellow
68 };
69
70 explicit DCrumbEdit(QWidget *parent = 0);
71
72 bool insertCrumb(const DCrumbTextFormat &format, int pos = -1);
73 bool insertCrumb(const QString &text, int pos = -1);
74 bool appendCrumb(const DCrumbTextFormat &format);
75 bool appendCrumb(const QString &text);
76
77 bool containCrumb(const QString &text) const;
78 QStringList crumbList() const;
79
80 DCrumbTextFormat crumbTextFormat(const QString &text) const;
81 DCrumbTextFormat makeTextFormat() const;
82 DCrumbTextFormat makeTextFormat(CrumbType type) const;
83
84 bool dualClickMakeCrumb() const Q_DECL_NOEXCEPT;
85 bool crumbReadOnly() const;
86 int crumbRadius() const;
87 QString splitter() const;
88
89Q_SIGNALS:
90 void crumbAdded(const QString &text);
91 void crumbRemoved(const QString &text);
92 void crumbListChanged();
93
94public Q_SLOTS:
95 void setCrumbReadOnly(bool crumbReadOnly);
96 void setCrumbRadius(int crumbRadius);
97 void setSplitter(const QString &splitter);
98
99 void setDualClickMakeCrumb(bool flag) Q_DECL_NOEXCEPT;
100
101protected:
102 bool event(QEvent *e) override;
103 void paintEvent(QPaintEvent *event) override;
104 void keyPressEvent(QKeyEvent *event) override;
105 void mouseDoubleClickEvent(QMouseEvent *event) override;
106 void focusOutEvent(QFocusEvent *event) override;
107
108 QMimeData *createMimeDataFromSelection() const override;
109 bool canInsertFromMimeData(const QMimeData *source) const override;
110 void insertFromMimeData(const QMimeData *source) override;
111
112private:
113 using QTextEdit::setDocument;
114 using QTextEdit::document;
115 using QTextEdit::setText;
116 using QTextEdit::setHtml;
117 using QTextEdit::setPlaceholderText;
118 using QTextEdit::insertPlainText;
119 using QTextEdit::insertHtml;
120 using QTextEdit::append;
121
122 D_DECLARE_PRIVATE(DCrumbEdit)
123 Q_PRIVATE_SLOT(d_func(), void _q_onDocumentLayoutChanged())
124 Q_PRIVATE_SLOT(d_func(), void _q_onCurrentPositionChanged())
125 Q_PRIVATE_SLOT(d_func(), void _q_onTextChanged())
126};
127
128DWIDGET_END_NAMESPACE
129
130#endif // DCRUMBEDIT_H
Definition dcrumbedit.cpp:90
Definition dcrumbedit.cpp:284
标签输入控件.
Definition dcrumbedit.h:41
表示标签输入控件 DCrumbEdit类 所含标签的文字样式.
Definition dcrumbedit.h:16