2020-11-19 14:39:32 +01:00
|
|
|
#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();
|
2020-11-20 15:09:36 +01:00
|
|
|
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);
|
2020-11-19 14:39:32 +01:00
|
|
|
this->stackView->addWidget(this->buttonWidget);
|
|
|
|
|
2020-11-20 15:09:36 +01:00
|
|
|
actionButtons.append(startOsButton);
|
|
|
|
actionButtons.append(syncOsButton);
|
|
|
|
actionButtons.append(reinstallOsButton);
|
|
|
|
|
2020-11-19 14:39:32 +01:00
|
|
|
// 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
|
2020-11-20 15:09:36 +01:00
|
|
|
// 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
|
2020-11-19 14:39:32 +01:00
|
|
|
this->buttonWidget->setFixedSize(this->size());
|
2020-11-20 15:09:36 +01:00
|
|
|
|
2020-11-19 14:39:32 +01:00
|
|
|
int buttonSpacing = this->height() * 0.1;
|
|
|
|
int defaultButtonHeight = this->height() * 0.6;
|
2020-11-20 15:09:36 +01:00
|
|
|
this->actionButtons[0]->setGeometry((this->width() - defaultButtonHeight) / 2, 0,defaultButtonHeight, defaultButtonHeight);
|
|
|
|
|
2020-11-19 14:39:32 +01:00
|
|
|
int secondaryButtonHeight = this->height() * 0.3;
|
2020-11-20 15:09:36 +01:00
|
|
|
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();
|
|
|
|
}
|
2020-11-19 14:39:32 +01:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2020-11-20 15:09:36 +01:00
|
|
|
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() {
|
2020-11-19 14:39:32 +01:00
|
|
|
this->stackView->setCurrentWidgetAnimated(this->progressBarWidget);
|
|
|
|
this->osSelectionRow->setShowOnlySelectedButton(true);
|
|
|
|
this->backend->startOs(this->osSelectionRow->getSelectedOs());
|
|
|
|
//this->progressBar->show();
|
|
|
|
}
|