2017-12-20 14:39:09 +01:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
2014-09-03 18:04:10 +02:00
|
|
|
*
|
|
|
|
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
|
|
|
*
|
|
|
|
* Calamares is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Calamares is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "PrettyRadioButton.h"
|
|
|
|
|
|
|
|
#include "utils/CalamaresUtilsGui.h"
|
|
|
|
#include "widgets/ClickableLabel.h"
|
|
|
|
|
2018-09-12 14:09:01 +02:00
|
|
|
#include <QComboBox>
|
|
|
|
#include <QGridLayout>
|
2018-09-12 15:20:44 +02:00
|
|
|
#include <QHBoxLayout>
|
2014-09-03 18:04:10 +02:00
|
|
|
#include <QLabel>
|
|
|
|
|
|
|
|
|
|
|
|
PrettyRadioButton::PrettyRadioButton( QWidget* parent )
|
|
|
|
: QWidget( parent )
|
2018-09-12 15:20:44 +02:00
|
|
|
, m_label( new ClickableLabel )
|
2018-09-12 16:05:14 +02:00
|
|
|
, m_radio( new QRadioButton )
|
2018-09-12 15:20:44 +02:00
|
|
|
, m_mainLayout( new QGridLayout )
|
|
|
|
, m_optionsLayout( nullptr )
|
2014-09-03 18:04:10 +02:00
|
|
|
{
|
2018-09-12 14:09:01 +02:00
|
|
|
setLayout( m_mainLayout );
|
2014-09-03 18:04:10 +02:00
|
|
|
|
|
|
|
m_label->setBuddy( m_radio );
|
|
|
|
|
|
|
|
m_label->setWordWrap( true );
|
|
|
|
m_label->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
|
|
|
|
|
2018-09-12 14:09:01 +02:00
|
|
|
m_mainLayout->addWidget( m_radio, 0, 0 );
|
2018-09-12 15:20:44 +02:00
|
|
|
m_mainLayout->addWidget( m_label, 0, 1 );
|
2018-09-12 14:09:01 +02:00
|
|
|
m_mainLayout->setContentsMargins( 0, 0, 0, 0 );
|
2018-09-12 15:20:44 +02:00
|
|
|
|
|
|
|
connect( m_label, &ClickableLabel::clicked,
|
|
|
|
m_radio, &QRadioButton::click );
|
|
|
|
connect( m_radio, &QRadioButton::toggled,
|
|
|
|
this, &PrettyRadioButton::toggleOptions );
|
2014-09-03 18:04:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
PrettyRadioButton::setText( const QString& text )
|
|
|
|
{
|
|
|
|
m_label->setText( text );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
PrettyRadioButton::setIconSize( const QSize& size )
|
|
|
|
{
|
|
|
|
m_radio->setIconSize( size );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
PrettyRadioButton::setIcon( const QIcon& icon )
|
|
|
|
{
|
|
|
|
m_radio->setIcon( icon );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QSize
|
2015-11-05 18:27:51 +01:00
|
|
|
PrettyRadioButton::iconSize() const
|
2014-09-03 18:04:10 +02:00
|
|
|
{
|
|
|
|
return m_radio->iconSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QRadioButton*
|
2015-11-05 18:27:51 +01:00
|
|
|
PrettyRadioButton::buttonWidget() const
|
2014-09-03 18:04:10 +02:00
|
|
|
{
|
|
|
|
return m_radio;
|
|
|
|
}
|
2018-09-12 14:09:01 +02:00
|
|
|
|
|
|
|
void
|
2018-09-12 14:42:21 +02:00
|
|
|
PrettyRadioButton::addOptionsComboBox( QComboBox* box )
|
2018-09-12 14:09:01 +02:00
|
|
|
{
|
2018-09-12 15:20:44 +02:00
|
|
|
if ( !box )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( !m_optionsLayout )
|
|
|
|
{
|
|
|
|
QWidget* w = new QWidget;
|
|
|
|
m_optionsLayout = new QHBoxLayout;
|
|
|
|
m_optionsLayout->setAlignment( Qt::AlignmentFlag::AlignLeft );
|
|
|
|
m_optionsLayout->addStretch( 1 );
|
|
|
|
|
|
|
|
w->setLayout( m_optionsLayout );
|
|
|
|
m_mainLayout->addWidget( w, 1, 1 );
|
|
|
|
|
|
|
|
toggleOptions( m_radio->isChecked() );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_optionsLayout->insertWidget( m_optionsLayout->count()-1, box );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PrettyRadioButton::toggleOptions( bool toggle )
|
|
|
|
{
|
|
|
|
if ( m_optionsLayout )
|
|
|
|
m_optionsLayout->parentWidget()->setVisible( toggle );
|
2018-09-12 14:09:01 +02:00
|
|
|
}
|