This repository has been archived on 2022-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
modern-linbo-gui/sources/linboosselectionrow.cpp
2020-11-19 14:39:32 +01:00

71 lines
2.5 KiB
C++

#include "../headers/linboosselectionrow.h"
LinboOsSelectionRow::LinboOsSelectionRow(LinboBackend* backend, QWidget *parent) : QWidget(parent)
{
this->backend = backend;
this->showOnlySelectedButton = false;
this->osButtonGroup = new QButtonGroup();
this->osButtonGroup->setExclusive(true);
for(LinboOs* os : backend->getOperatingSystems()) {
LinboOsSelectButton* osButton = new LinboOsSelectButton("/icons/" + os->getIconName(), os, this->osButtonGroup, this);
this->osButtons.append(osButton);
}
// TODO: figure out by autostart
this->osButtonGroup->buttons()[0]->setChecked(true);
}
void LinboOsSelectionRow::resizeAndPositionAllButtons() {
qDebug() << "Resizing all Buttons";
if(this->showOnlySelectedButton) {
int buttonWidth = this->width() / this->osButtonGroup->buttons().length();
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(buttonWidth / 2, 0, buttonWidth, this->height()));
moveAnimation->start();
}
}
}
else {
int buttonWidth = this->width() / this->osButtonGroup->buttons().length();
for(int i = 0; i < this->osButtons.length(); i++) {
this->osButtons[i]->setGeometry(buttonWidth * i, 0, buttonWidth, this->height());
}
}
}
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);
qDebug() << "RESIZE EVENT: width: " << width() << " height: " << height();
this->resizeAndPositionAllButtons();
}