Debian Codegraph @

kysdk-qtwidgets/test/testKTextedit/widget.cpp

raw
1 /*
2 *
3 * Copyright (C) 2024, KylinSoft Co., Ltd.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 3 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this library. If not, see <https://www.gnu.org/licenses/>.
17 *
18 * Authors: Zhenyu Wang <[email protected]>
19 *
20 */
21
22 #include "widget.h"
23 #include "kbubblewidget.h"
24 #include "ktextedit.h"
25 #include <QBoxLayout>
26
27 using namespace kdk;
28
29 Widget::Widget(QWidget *parent)
30 : QWidget(parent)
31 {
32 QVBoxLayout *mainLayout = new QVBoxLayout(this);
33
34 QPushButton *btn1 = new QPushButton();
35 btn1->setText("无tag-正常背景");
36 QPushButton *btn2 = new QPushButton();
37 btn2->setText("无tag-高亮背景");
38 QPushButton *btn3 = new QPushButton();
39 btn3->setText("有tag-正常背景");
40 QPushButton *btn4 = new QPushButton();
41 btn4->setText("有tag-高亮背景");
42
43 KBubbleWidget *bubbleWidget1 = new KBubbleWidget();
44 bubbleWidget1->setTailPosition(TopDirection);
45 QVBoxLayout *layout1 = new QVBoxLayout(bubbleWidget1);
46 KTextEdit *edit1 = new KTextEdit();
47
48 QPushButton *button1 = new QPushButton();
49 button1->setText("关闭");
50 layout1->addWidget(edit1);
51 layout1->addWidget(button1);
52 connect(btn1, &QPushButton::clicked, this, [=] {
53 bubbleWidget1->show();
54 });
55 connect(button1, &QPushButton::clicked, this, [=] {
56 bubbleWidget1->hide();
57 });
58
59 KBubbleWidget *bubbleWidget2 = new KBubbleWidget();
60 bubbleWidget2->setTailPosition(RightDirection, TailLocation::LeftLocation);
61 bubbleWidget2->setHighlightBackground(true);
62 QVBoxLayout *layout2 = new QVBoxLayout(bubbleWidget2);
63 KTextEdit *edit2 = new KTextEdit();
64 edit2->setReadOnly(true);
65 edit2->setText("这是一段测试性文字,用来测试ktextedit在只读状态(不可编辑状态)下的背景色。");
66
67 QPushButton *button2 = new QPushButton();
68 button2->setText("关闭");
69 layout2->addWidget(edit2);
70 layout2->addWidget(button2);
71 connect(btn2, &QPushButton::clicked, this, [=] {
72 bubbleWidget2->show();
73 });
74 connect(button2, &QPushButton::clicked, this, [=] {
75 bubbleWidget2->hide();
76 });
77
78 KBubbleWidget *bubbleWidget3 = new KBubbleWidget();
79 bubbleWidget3->setTailPosition(BottomDirection, TailLocation::RightLocation);
80 QVBoxLayout *layout3 = new QVBoxLayout(bubbleWidget3);
81 KTextEdit *edit3 = new KTextEdit();
82
83 edit3->setLabelVisible(true);
84 edit3->setPixmap(QIcon("system-computer-symbolic").pixmap(16, 16));
85 edit3->setLabelText("翻译");
86
87 QPushButton *button3 = new QPushButton();
88 button3->setText("关闭");
89 layout3->addWidget(edit3);
90 layout3->addWidget(button3);
91 connect(btn3, &QPushButton::clicked, this, [=] {
92 bubbleWidget3->show();
93 });
94 connect(button3, &QPushButton::clicked, this, [=] {
95 bubbleWidget3->hide();
96 });
97
98 KBubbleWidget *bubbleWidget4 = new KBubbleWidget();
99 bubbleWidget4->setTailPosition(LeftDirection, TailLocation::RightLocation);
100 bubbleWidget4->setHighlightBackground(true);
101 QVBoxLayout *layout4 = new QVBoxLayout(bubbleWidget4);
102 KTextEdit *edit4 = new KTextEdit();
103 edit4->setLabelVisible(true);
104 edit4->setPixmap(QIcon("system-computer-symbolic").pixmap(16, 16));
105 edit4->setLabelText("翻译");
106 edit4->setText("这是一段测试性文字,用来测试ktextedit在只读状态(不可编辑状态)下的背景色。");
107 edit4->setReadOnly(true);
108
109 QPushButton *button4 = new QPushButton();
110 button4->setText("关闭");
111 QPushButton *button5 = new QPushButton();
112 button5->setText("切换是否可编辑状态");
113 layout4->addWidget(edit4);
114 layout4->addWidget(button4);
115 layout4->addWidget(button5);
116 connect(btn4, &QPushButton::clicked, this, [=] {
117 bubbleWidget4->show();
118 });
119 connect(button4, &QPushButton::clicked, this, [=] {
120 bubbleWidget4->hide();
121 });
122
123 connect(button5, &QPushButton::clicked, this, [=] {
124 if (edit4->isReadOnly()) {
125 edit4->setReadOnly(false);
126 bubbleWidget4->setHighlightBackground(false);
127 } else {
128 edit4->setReadOnly(true);
129 bubbleWidget4->setHighlightBackground(true);
130 }
131 });
132
133 QHBoxLayout *hlayout1 = new QHBoxLayout();
134 QHBoxLayout *hlayout2 = new QHBoxLayout();
135 hlayout1->addWidget(btn1);
136 hlayout1->addWidget(btn2);
137 hlayout2->addWidget(btn3);
138 hlayout2->addWidget(btn4);
139 mainLayout->addLayout(hlayout1);
140 mainLayout->addLayout(hlayout2);
141 }
142
143 Widget::~Widget()
144 {
145 }