2020-11-19 14:39:32 +01:00
|
|
|
#include "../headers/linboosselectionrow.h"
|
|
|
|
|
|
|
|
LinboOsSelectionRow::LinboOsSelectionRow(LinboBackend* backend, QWidget *parent) : QWidget(parent)
|
|
|
|
{
|
|
|
|
this->backend = backend;
|
2020-11-23 11:57:51 +01:00
|
|
|
connect(this->backend, SIGNAL(stateChanged(LinboBackend::LinboState)), this, SLOT(handleLinboStateChanged(LinboBackend::LinboState)));
|
2020-11-19 14:39:32 +01:00
|
|
|
|
2020-11-23 11:57:51 +01:00
|
|
|
this->showOnlySelectedButton = false;
|
2020-11-19 14:39:32 +01:00
|
|
|
|
|
|
|
this->osButtonGroup = new QButtonGroup();
|
|
|
|
this->osButtonGroup->setExclusive(true);
|
|
|
|
|
|
|
|
for(LinboOs* os : backend->getOperatingSystems()) {
|
|
|
|
LinboOsSelectButton* osButton = new LinboOsSelectButton("/icons/" + os->getIconName(), os, this->osButtonGroup, this);
|
2020-11-23 11:57:51 +01:00
|
|
|
connect(osButton->button, SIGNAL(toggled(bool)), this, SLOT(handleButtonToggled(bool)));
|
|
|
|
|
|
|
|
// auto select current OS
|
|
|
|
if(this->backend->getCurrentOs() == os)
|
|
|
|
osButton->button->setChecked(true);
|
|
|
|
|
2020-11-19 14:39:32 +01:00
|
|
|
this->osButtons.append(osButton);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LinboOsSelectionRow::resizeAndPositionAllButtons() {
|
|
|
|
int buttonWidth = this->width() / this->osButtonGroup->buttons().length();
|
2020-11-20 15:09:36 +01:00
|
|
|
if(this->showOnlySelectedButton) {
|
|
|
|
for(int i = 0; i < this->osButtons.length(); i++) {
|
|
|
|
if(!this->osButtons[i]->button->isChecked())
|
|
|
|
this->osButtons[i]->hide();
|
|
|
|
else {
|
|
|
|
QPropertyAnimation* moveAnimation = new QPropertyAnimation(this->osButtons[i], "geometry");
|
|
|
|
moveAnimation->setEasingCurve(QEasingCurve::InOutQuad);
|
|
|
|
moveAnimation->setDuration(400);
|
|
|
|
moveAnimation->setStartValue(this->osButtons[i]->geometry());
|
|
|
|
moveAnimation->setEndValue(QRect((this->width() - buttonWidth) / 2, 0, buttonWidth, this->height()));
|
|
|
|
moveAnimation->start();
|
|
|
|
}
|
2020-11-19 14:39:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for(int i = 0; i < this->osButtons.length(); i++) {
|
|
|
|
this->osButtons[i]->setGeometry(buttonWidth * i, 0, buttonWidth, this->height());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-23 11:57:51 +01:00
|
|
|
void LinboOsSelectionRow::handleButtonToggled(bool checked) {
|
|
|
|
if(checked)
|
|
|
|
this->backend->setCurrentOs(this->getSelectedOs());
|
|
|
|
}
|
|
|
|
|
2020-11-19 14:39:32 +01:00
|
|
|
LinboOs* LinboOsSelectionRow::getSelectedOs() {
|
|
|
|
for(LinboOsSelectButton* button : this->osButtons) {
|
|
|
|
if(button->button->isChecked())
|
|
|
|
return button->getOs();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LinboOsSelectionRow::setShowOnlySelectedButton(bool value) {
|
|
|
|
// find selected button
|
|
|
|
// set its x so it is in the middle (animated)
|
|
|
|
// set Opacity of all other buttons to 0 (animated)
|
|
|
|
if(value == this->showOnlySelectedButton)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this->showOnlySelectedButton = value;
|
|
|
|
|
|
|
|
this->resizeAndPositionAllButtons();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LinboOsSelectionRow::resizeEvent(QResizeEvent *event) {
|
|
|
|
QWidget::resizeEvent(event);
|
2020-11-23 11:57:51 +01:00
|
|
|
//qDebug() << "RESIZE EVENT: width: " << width() << " height: " << height();
|
2020-11-19 14:39:32 +01:00
|
|
|
this->resizeAndPositionAllButtons();
|
|
|
|
}
|
2020-11-23 11:57:51 +01:00
|
|
|
|
|
|
|
void LinboOsSelectionRow::handleLinboStateChanged(LinboBackend::LinboState newState) {
|
|
|
|
switch (newState) {
|
|
|
|
case LinboBackend::Idle:
|
|
|
|
this->setShowOnlySelectedButton(false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LinboBackend::Starting:
|
|
|
|
case LinboBackend::Syncing:
|
|
|
|
case LinboBackend::Reinstalling:
|
|
|
|
this->setShowOnlySelectedButton(true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|