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/linbostartactions.cpp

160 lines
5.9 KiB
C++
Raw Normal View History

#include "../headers/linbostartactions.h"
LinboStartActions::LinboStartActions(LinboBackend* backend, LinboOsSelectionRow* osSelectionRow, QWidget *parent) : QWidget(parent)
{
this->backend = backend;
this->osSelectionRow = osSelectionRow;
stackView = new QModernStackedWidget(this);
// Action Buttons
this->buttonWidget = new QWidget();
startOsButton = new QModernPushButton(":/svgIcons/startAction.svg", this->buttonWidget);
connect(startOsButton, SIGNAL(clicked()), this, SLOT(executeStartAction()));
syncOsButton = new QModernPushButton(":/svgIcons/syncAction.svg", this->buttonWidget);
reinstallOsButton = new QModernPushButton(":/svgIcons/resetAction.svg", this->buttonWidget);
this->stackView->addWidget(this->buttonWidget);
actionButtons.append(startOsButton);
actionButtons.append(syncOsButton);
actionButtons.append(reinstallOsButton);
// Progress bar
this->progressBarWidget = new QWidget();
progressBar = new QModernProgressBar(this->progressBarWidget);
progressBar->setIndeterminate(true);
this->stackView->addWidget(this->progressBarWidget);
this->stackView->setCurrentWidget(this->buttonWidget);
}
void LinboStartActions::resizeAndPositionAllItems() {
// stack view
this->stackView->setFixedSize(this->size());
// Action buttons
// bring buttons in correct order:
LinboOs* selectedOs = this->osSelectionRow->getSelectedOs();
LinboOs::LinboOsStartAction defaultAction = selectedOs->getDefaultAction();
int startOsPosition = 0;
int syncOsPosition = 1;
int reinstallOsPosition = 2;
qDebug() << "Default action is: " << defaultAction;
switch (defaultAction) {
case LinboOs::StartOs:
break;
case LinboOs::SyncOs:
syncOsPosition = 0;
startOsPosition = 1;
reinstallOsPosition = 2;
break;
case LinboOs::ReinstallOs:
reinstallOsPosition = 0;
syncOsPosition = 1;
startOsPosition = 2;
break;
default:
break;
}
//this->actionButtons.move(this->actionButtons.indexOf(this->startOsButton), startOsPosition);
//this->actionButtons.move(this->actionButtons.indexOf(this->syncOsButton), syncOsPosition);
//this->actionButtons.move(this->actionButtons.indexOf(this->reinstallOsButton), reinstallOsPosition);
while (this->actionButtons.length() < 3) {
this->actionButtons.append(nullptr);
}
this->actionButtons[startOsPosition] = this->startOsButton;
this->actionButtons[syncOsPosition] = this->syncOsButton;
this->actionButtons[reinstallOsPosition] = this->reinstallOsButton;
// check for disabled actions
QList<bool> positionsEnabled;
positionsEnabled.append(true);
positionsEnabled.append(true);
positionsEnabled.append(true);
positionsEnabled[startOsPosition] = selectedOs->getStartbutton();
positionsEnabled[syncOsPosition] = selectedOs->getSyncbutton();
positionsEnabled[reinstallOsPosition] = selectedOs->getNewbutton();
// move buttons into place
this->buttonWidget->setFixedSize(this->size());
int buttonSpacing = this->height() * 0.1;
int defaultButtonHeight = this->height() * 0.6;
this->actionButtons[0]->setGeometry((this->width() - defaultButtonHeight) / 2, 0,defaultButtonHeight, defaultButtonHeight);
int secondaryButtonHeight = this->height() * 0.3;
if(positionsEnabled[1] && positionsEnabled[2]) {
this->actionButtons[1]->setGeometry(
this->width() / 2 - secondaryButtonHeight - buttonSpacing / 2,
defaultButtonHeight + buttonSpacing,
secondaryButtonHeight,
secondaryButtonHeight
);
this->actionButtons[2]->setGeometry(
this->width() / 2 + buttonSpacing / 2,
defaultButtonHeight + buttonSpacing,
secondaryButtonHeight,
secondaryButtonHeight
);
}
else if(!positionsEnabled[1]) {
this->actionButtons[1]->hide();
this->actionButtons[2]->setGeometry(
this->width() / 2 - secondaryButtonHeight / 2,
defaultButtonHeight + buttonSpacing,
secondaryButtonHeight,
secondaryButtonHeight
);
}
else if(!positionsEnabled[2]) {
this->actionButtons[1]->setGeometry(
this->width() / 2 - secondaryButtonHeight / 2,
defaultButtonHeight + buttonSpacing,
secondaryButtonHeight,
secondaryButtonHeight
);
this->actionButtons[2]->hide();
}
// Progress bar
this->progressBarWidget->setFixedSize(this->size());
int progressBarHeight = this->height() * 0.1;
int progressBarWidth = this->width() * 0.5;
progressBar->setGeometry((this->width() - progressBarWidth) / 2, (this->height() - progressBarHeight) / 2, progressBarWidth, progressBarHeight);
}
void LinboStartActions::resizeEvent(QResizeEvent *event) {
this->resizeAndPositionAllItems();
QWidget::resizeEvent(event);
}
void LinboStartActions::executeStartAction() {
this->stackView->setCurrentWidgetAnimated(this->progressBarWidget);
this->osSelectionRow->setShowOnlySelectedButton(true);
this->backend->startOs(this->osSelectionRow->getSelectedOs());
//this->progressBar->show();
}
void LinboStartActions::executeSyncAction() {
this->stackView->setCurrentWidgetAnimated(this->progressBarWidget);
this->osSelectionRow->setShowOnlySelectedButton(true);
this->backend->startOs(this->osSelectionRow->getSelectedOs());
//this->progressBar->show();
}
void LinboStartActions::executeReinstallAction() {
this->stackView->setCurrentWidgetAnimated(this->progressBarWidget);
this->osSelectionRow->setShowOnlySelectedButton(true);
this->backend->startOs(this->osSelectionRow->getSelectedOs());
//this->progressBar->show();
}