Files
o3de/Code/Framework/AzQtComponents/AzQtComponents/Components/ButtonStripe.cpp
T
Steve Pham 38261d0800 Shorten copyright headers by splitting into 2 lines (#2213)
* Updated all copyright headers to split the longer original copyright line into 2 shorter lines

Signed-off-by: Steve Pham <spham@amazon.com>
2021-07-16 15:25:48 -07:00

70 lines
1.9 KiB
C++

/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include <AzQtComponents/Components/ButtonStripe.h>
#include <QGridLayout>
#include <QButtonGroup>
#include <QPushButton>
#include <QVariant>
namespace AzQtComponents
{
ButtonStripe::ButtonStripe(QWidget* parent)
: QWidget(parent)
, m_gridLayout(new QGridLayout(this))
, m_buttonGroup(new QButtonGroup(this))
{
m_gridLayout->setSpacing(0);
}
void ButtonStripe::addButtons(const QStringList& buttonNames, int current)
{
const auto buttonsCount = buttonNames.size();
for (int i = 0; i < buttonsCount; ++i)
{
auto pushButton = new QPushButton(buttonNames.at(i));
pushButton->setCheckable(true);
if (i == 0)
{
pushButton->setProperty("class", "ButtonStripeButtonFirst");
}
else if (i == buttonsCount - 1)
{
pushButton->setProperty("class", "ButtonStripeButtonLast");
}
else
{
pushButton->setProperty("class", "ButtonStripeButtonCenter");
}
m_buttonGroup->addButton(pushButton, i);
m_gridLayout->addWidget(pushButton, 0, m_gridLayout->columnCount());
m_buttons.append(pushButton);
connect(pushButton, &QPushButton::clicked, this, [this, pushButton] {
emit buttonClicked(m_buttons.indexOf(pushButton));
});
}
setCurrent(current);
}
void ButtonStripe::setCurrent(int index)
{
const int numButtons = m_buttons.size();
if (index < numButtons && index >= 0)
{
m_buttons.at(index)->setChecked(true);
}
}
}
#include "Components/moc_ButtonStripe.cpp"