| 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 "kintrowidget.h" |
| 24 |
#include <QBoxLayout> |
| 25 |
#include <QMenu> |
| 26 |
|
| 27 |
using namespace kdk; |
| 28 |
|
| 29 |
Widget::Widget(QWidget *parent) |
| 30 |
: QWidget(parent) |
| 31 |
{ |
| 32 |
QVBoxLayout *layout = new QVBoxLayout(this); |
| 33 |
KIntroWidget *widget1 = new KIntroWidget(this); |
| 34 |
widget1->setMainLabel("我是一段测试文本,测试显示不全是否可以换行(单行测试文本)"); |
| 35 |
widget1->setSubLabel("2024216161"); |
| 36 |
widget1->setFixedHeight(76); |
| 37 |
widget1->setBorderRadius(15); |
| 38 |
KIntroWidget *widget2 = new KIntroWidget(this); |
| 39 |
widget2->setMainLabel("我是一段测试文本,测试换行符号\n('\\n'不显示只换行)是否可以正常换行以及显示不全是否可以换行"); |
| 40 |
widget2->setSubLabel("2024216161"); |
| 41 |
widget2->setViewType(ViewType::IconView); |
| 42 |
widget2->setFixedSize(218, 200); |
| 43 |
widget2->setTitleColor(Qt::red); |
| 44 |
widget2->setBorderRadius(0, 20, 20, 30); |
| 45 |
layout->addWidget(widget1); |
| 46 |
layout->addWidget(widget2); |
| 47 |
|
| 48 |
QMenu *menu = new QMenu(); |
| 49 |
QAction *action1 = new QAction("action1", menu); |
| 50 |
QAction *action2 = new QAction("action2", menu); |
| 51 |
QAction *action3 = new QAction("action3", menu); |
| 52 |
menu->addAction(action1); |
| 53 |
menu->addAction(action2); |
| 54 |
menu->addAction(action3); |
| 55 |
|
| 56 |
connect(widget1, &KIntroWidget::rightClick, this, [=](QPoint point) { |
| 57 |
menu->move(point); |
| 58 |
menu->show(); |
| 59 |
}); |
| 60 |
|
| 61 |
QMenu *menu1 = new QMenu(); |
| 62 |
QAction *action4 = new QAction("action4", menu); |
| 63 |
QAction *action5 = new QAction("action5", menu); |
| 64 |
QAction *action6 = new QAction("action6", menu); |
| 65 |
menu1->addAction(action4); |
| 66 |
menu1->addAction(action5); |
| 67 |
menu1->addAction(action6); |
| 68 |
|
| 69 |
connect(widget2, &KIntroWidget::rightClick, this, [=](QPoint point) { |
| 70 |
menu1->move(point); |
| 71 |
menu1->show(); |
| 72 |
}); |
| 73 |
} |
| 74 |
|
| 75 |
Widget::~Widget() |
| 76 |
{ |
| 77 |
} |