| 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 "kradiobuttonframe.h" |
| 23 |
|
| 24 |
#include <QDebug> |
| 25 |
namespace kdk |
| 26 |
{ |
| 27 |
|
| 28 |
class KRadioButtonFramePrivate : public QObject |
| 29 |
{ |
| 30 |
Q_OBJECT |
| 31 |
Q_DECLARE_PUBLIC(KRadioButtonFrame) |
| 32 |
public: |
| 33 |
KRadioButtonFramePrivate(KRadioButtonFrame *parent); |
| 34 |
|
| 35 |
private: |
| 36 |
KRadioButtonFrame *q_ptr; |
| 37 |
|
| 38 |
QButtonGroup *m_pButtonGroup; |
| 39 |
QHBoxLayout *m_pRadioLayout; |
| 40 |
KLabel *m_pSettingName; |
| 41 |
QHBoxLayout *m_pMainLayout; |
| 42 |
}; |
| 43 |
|
| 44 |
KRadioButtonFramePrivate::KRadioButtonFramePrivate(KRadioButtonFrame *parent) |
| 45 |
: q_ptr(parent) |
| 46 |
{ |
| 47 |
Q_Q(KRadioButtonFrame); |
| 48 |
m_pMainLayout = new QHBoxLayout(q); |
| 49 |
m_pMainLayout->setContentsMargins(16, 0, 16, 0); |
| 50 |
m_pMainLayout->setSpacing(16); |
| 51 |
m_pSettingName = new KLabel(q); |
| 52 |
m_pSettingName->setFixedWidth(SETTING_LABEL_WIDTH); |
| 53 |
|
| 54 |
m_pButtonGroup = new QButtonGroup(q); |
| 55 |
m_pRadioLayout = new QHBoxLayout(); |
| 56 |
m_pRadioLayout->setContentsMargins(0, 0, 0, 0); |
| 57 |
m_pRadioLayout->setSpacing(80); |
| 58 |
m_pMainLayout->addWidget(m_pSettingName); |
| 59 |
m_pMainLayout->addLayout(m_pRadioLayout); |
| 60 |
m_pMainLayout->addStretch(); |
| 61 |
q->setLayout(m_pMainLayout); |
| 62 |
} |
| 63 |
|
| 64 |
KRadioButtonFrame::KRadioButtonFrame(const QString title, QWidget *parent, BorderRadiusStyle style) |
| 65 |
: KBaseFrame(parent, style, true) |
| 66 |
, d_ptr(new KRadioButtonFramePrivate(this)) |
| 67 |
{ |
| 68 |
Q_D(KRadioButtonFrame); |
| 69 |
setObjectName("KRadioButtonFrame"); |
| 70 |
|
| 71 |
d->m_pSettingName->setText(title); |
| 72 |
} |
| 73 |
|
| 74 |
KRadioButtonFrame::~KRadioButtonFrame() |
| 75 |
{ |
| 76 |
} |
| 77 |
|
| 78 |
void KRadioButtonFrame::addButton(QRadioButton *button, int id, bool addStretch) |
| 79 |
{ |
| 80 |
Q_D(KRadioButtonFrame); |
| 81 |
d->m_pButtonGroup->addButton(button, id); |
| 82 |
d->m_pRadioLayout->addWidget(button, 0, Qt::AlignLeft | Qt::AlignVCenter); |
| 83 |
if (addStretch) { |
| 84 |
d->m_pRadioLayout->addStretch(); |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
QHBoxLayout *KRadioButtonFrame::radioHLayout() |
| 89 |
{ |
| 90 |
Q_D(KRadioButtonFrame); |
| 91 |
return d->m_pRadioLayout; |
| 92 |
} |
| 93 |
|
| 94 |
QButtonGroup *KRadioButtonFrame::buttonGroup() |
| 95 |
{ |
| 96 |
Q_D(KRadioButtonFrame); |
| 97 |
return d->m_pButtonGroup; |
| 98 |
} |
| 99 |
|
| 100 |
QHBoxLayout *KRadioButtonFrame::mainHLayout() |
| 101 |
{ |
| 102 |
Q_D(KRadioButtonFrame); |
| 103 |
return d->m_pMainLayout; |
| 104 |
} |
| 105 |
|
| 106 |
KLabel *KRadioButtonFrame::titleLabel() |
| 107 |
{ |
| 108 |
Q_D(KRadioButtonFrame); |
| 109 |
return d->m_pSettingName; |
| 110 |
} |
| 111 |
|
| 112 |
} |
| 113 |
|
| 114 |
#include "kradiobuttonframe.moc" |
| 115 |
#include "moc_kradiobuttonframe.cpp" |