Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2021 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 :
23 : #include "radiobuttongroupbox.h"
24 :
25 : #include <QStyle>
26 : #include <QStyleOption>
27 : #include <QStylePainter>
28 :
29 : using namespace muse::uicomponents;
30 :
31 0 : RadioButtonGroupBox::RadioButtonGroupBox(QWidget* parent)
32 0 : : QGroupBox(parent)
33 : {
34 0 : }
35 :
36 0 : RadioButtonGroupBox::RadioButtonGroupBox(const QString& title, QWidget* parent)
37 0 : : QGroupBox(title, parent)
38 : {
39 0 : }
40 :
41 0 : void RadioButtonGroupBox::paintEvent(QPaintEvent*)
42 : {
43 0 : QStylePainter painter(this);
44 0 : QStyleOptionGroupBox styleOption;
45 0 : initStyleOption(&styleOption);
46 :
47 : // Paint the default QGroupBox-style control, which includes an unwanted checkbox that we'll cover up afterwards.
48 0 : painter.drawComplexControl(QStyle::CC_GroupBox, styleOption);
49 :
50 : // Calculate the background color that is the same to the background window color.
51 0 : QColor bgColor = styleOption.palette.window().color();
52 :
53 : // Adjust the style options to use the checkbox's rectangle.
54 0 : styleOption.rect = style()->subControlRect(QStyle::CC_GroupBox, &styleOption, QStyle::SC_GroupBoxCheckBox, this);
55 :
56 : // Cover up the checkbox, making sure to enlarge the rectangle a bit to cover up any anti-aliasing around the edges.
57 0 : painter.fillRect(styleOption.rect.adjusted(-2, -2, 2, 2), bgColor);
58 :
59 : // Paint the radio button.
60 0 : painter.drawPrimitive(QStyle::PE_IndicatorRadioButton, styleOption);
61 0 : }
|