Debian Codegraph @

kysdk-qtwidgets/src/kswitchbuttonframe.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: Sisheng He <[email protected]>
20 *
21 */
22 #include "kswitchbuttonframe.h"
23 #include "themeController.h"
24 #include <QDebug>
25 namespace kdk
26 {
27
28 class KSwitchButtonFramePrivate : public QObject
29 {
30 Q_OBJECT
31 Q_DECLARE_PUBLIC(KSwitchButtonFrame)
32 public:
33 KSwitchButtonFramePrivate(KSwitchButtonFrame *parent);
34
35 private:
36 KSwitchButtonFrame *q_ptr;
37
38 QVBoxLayout *m_pVLayout;
39 KLabel *m_pHintLabel;
40 KSwitchButton *m_pSwitchButton;
41 KLabel *m_pSettingName;
42 QHBoxLayout *m_pMainLayout;
43 };
44
45 KSwitchButtonFramePrivate::KSwitchButtonFramePrivate(KSwitchButtonFrame *parent)
46 : q_ptr(parent)
47 {
48 Q_Q(KSwitchButtonFrame);
49 setParent(parent);
50
51 m_pSettingName = new KLabel(q);
52
53 m_pHintLabel = new KLabel(q);
54 m_pHintLabel->setVisible(false);
55 m_pHintLabel->setFontColor(ThemeController::getCustomColorFromDT("placeholdertext-active"));
56 m_pVLayout = new QVBoxLayout();
57 m_pVLayout->addWidget(m_pSettingName);
58 m_pVLayout->addWidget(m_pHintLabel);
59
60 m_pSwitchButton = new KSwitchButton();
61
62 m_pMainLayout = new QHBoxLayout(q);
63 m_pMainLayout->setContentsMargins(16, 0, 16, 0);
64 m_pMainLayout->addLayout(m_pVLayout);
65 m_pMainLayout->addStretch();
66 m_pMainLayout->addWidget(m_pSwitchButton);
67
68 q->setLayout(m_pMainLayout);
69 }
70
71 KSwitchButtonFrame::KSwitchButtonFrame(const QString title, QWidget *parent, BorderRadiusStyle style)
72 : KBaseFrame(parent, style, true)
73 , d_ptr(new KSwitchButtonFramePrivate(this))
74 {
75 Q_D(KSwitchButtonFrame);
76 d->setObjectName("KSwitchButtonFrame");
77
78 d->m_pSettingName->setText(title);
79 }
80
81 KSwitchButtonFrame::~KSwitchButtonFrame()
82 {
83 }
84
85 void KSwitchButtonFrame::setHintText(QString &hintText)
86 {
87 Q_D(KSwitchButtonFrame);
88 d->m_pHintLabel->setText(hintText);
89 d->m_pHintLabel->setVisible(true);
90 }
91
92 KSwitchButton *KSwitchButtonFrame::switchButton()
93 {
94 Q_D(KSwitchButtonFrame);
95 return d->m_pSwitchButton;
96 }
97
98 QHBoxLayout *KSwitchButtonFrame::mainHLayout()
99 {
100 Q_D(KSwitchButtonFrame);
101 return d->m_pMainLayout;
102 }
103
104 KLabel *KSwitchButtonFrame::titleLabel()
105 {
106 Q_D(KSwitchButtonFrame);
107 return d->m_pSettingName;
108 }
109
110 }
111
112 #include "kswitchbuttonframe.moc"
113 #include "moc_kswitchbuttonframe.cpp"