Debian Codegraph @

kysdk-qtwidgets/test/testkcolorcombobox/widget.cpp

raw
1 /*
2 *
3 *
4 * Copyright (C) 2023, KylinSoft Co., Ltd.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this library. If not, see <https://www.gnu.org/licenses/>.
18 *
19 * Authors: Zhen Sun <[email protected]>
20 *
21 */
22
23 #include "widget.h"
24 #include "kcolorcombobox.h"
25 #include <QColor>
26 #include <QDebug>
27 #include <QHBoxLayout>
28 #include <QList>
29 using namespace kdk;
30
31 Widget::Widget(QWidget *parent)
32 : QWidget(parent)
33 {
34 QHBoxLayout *hLayout = new QHBoxLayout(this);
35 KColorComboBox *comboBoxCircle = new KColorComboBox(this);
36 comboBoxCircle->setComboType(KColorComboBox::Circle);
37 connect(comboBoxCircle, &KColorComboBox::currentColorChanged, this, [=]() {
38 qDebug() << "currentColorChanged";
39 });
40 connect(comboBoxCircle, &KColorComboBox::activated, this, [=]() {
41 qDebug() << "activatedChanged";
42 });
43 connect(comboBoxCircle, &KColorComboBox::highlighted, this, [=]() {
44 qDebug() << "highlightChanged";
45 });
46 hLayout->addWidget(comboBoxCircle);
47 comboBoxCircle->setFixedSize(36, 36);
48 KColorComboBox *comboBoxRect = new KColorComboBox(this);
49 connect(comboBoxRect, &KColorComboBox::currentColorChanged, this, [=]() {
50 qDebug() << "currentColorChanged";
51 });
52 connect(comboBoxRect, &KColorComboBox::activated, this, [=]() {
53 qDebug() << "activatedChanged";
54 });
55 connect(comboBoxRect, &KColorComboBox::highlighted, this, [=]() {
56 qDebug() << "highlightChanged";
57 });
58 comboBoxRect->setComboType(KColorComboBox::RoundedRect);
59 hLayout->addWidget(comboBoxRect);
60 comboBoxRect->setFixedSize(36, 36);
61
62 // 1.列表插入
63 QList<QColor> list;
64 list.append(QColor(255, 0, 0));
65 list.append(QColor(0, 255, 0));
66 list.append(QColor(255, 255, 0));
67 comboBoxCircle->setColorList(list);
68 // 2.逐个插入
69 comboBoxRect->addColor(QColor(255, 0, 0));
70 comboBoxRect->addColor(QColor(0, 255, 0));
71 comboBoxRect->addColor(QColor(255, 255, 0));
72 setGeometry(400, 400, 400, 400);
73 comboBoxCircle->setCurrentIndex(1);
74 }
75
76 Widget::~Widget()
77 {
78 }