diff --git a/qt/OpenRGBDialog2.cpp b/qt/OpenRGBDialog2.cpp index 9f2231e3..1b427957 100644 --- a/qt/OpenRGBDialog2.cpp +++ b/qt/OpenRGBDialog2.cpp @@ -178,6 +178,15 @@ OpenRGBDialog2::OpenRGBDialog2(QWidget *parent) : QMainWindow(parent), ui(new Op ui->DetectionProgressBar->setFormat(""); ui->DetectionProgressBar->setAlignment(Qt::AlignCenter); + /*-----------------------------------------------------*\ + | Set up Save Profile button action and menu | + \*-----------------------------------------------------*/ + QMenu* saveProfileMenu = new QMenu(this); + saveProfileMenu->addAction(ui->ActionSaveProfileAs); + + ui->ButtonSaveProfile->setMenu(saveProfileMenu); + ui->ButtonSaveProfile->setDefaultAction(ui->ActionSaveProfile); + /*-----------------------------------------------------*\ | Set up tray icon menu | \*-----------------------------------------------------*/ @@ -991,28 +1000,8 @@ void Ui::OpenRGBDialog2::on_ProfileSelected() qobject_cast(ui->DevicesTabBar->widget(device))->UpdateDevice(); } } - } -} -void Ui::OpenRGBDialog2::on_ButtonSaveProfile_clicked() -{ - OpenRGBProfileSaveDialog dialog; - ProfileManager* profile_manager = ResourceManager::get()->GetProfileManager(); - - if(profile_manager != NULL) - { - /*---------------------------------------------------------*\ - | Open Profile Name Dialog | - \*---------------------------------------------------------*/ - std::string profile_name = dialog.show(); - - /*---------------------------------------------------------*\ - | Save the profile | - \*---------------------------------------------------------*/ - if(profile_manager->SaveProfile(profile_name)) - { - UpdateProfileList(); - } + ui->ProfileBox->setCurrentIndex(ui->ProfileBox->findText(QString::fromStdString(profile_name))); } } @@ -1142,9 +1131,77 @@ void Ui::OpenRGBDialog2::SetDetectionViewState(bool detection_showing) } } +void OpenRGBDialog2::SaveProfile() +{ + ProfileManager* profile_manager = ResourceManager::get()->GetProfileManager(); + + if(profile_manager != NULL) + { + /*---------------------------------------------------------*\ + | Get the profile filename from the profiles list | + \*---------------------------------------------------------*/ + std::string filename = ui->ProfileBox->currentText().toStdString(); + + /*---------------------------------------------------------*\ + | Save the profile | + \*---------------------------------------------------------*/ + profile_manager->SaveProfile(filename); + } +} + +void OpenRGBDialog2::SaveProfileAs() +{ + ProfileManager* profile_manager = ResourceManager::get()->GetProfileManager(); + + if(profile_manager != NULL) + { + OpenRGBProfileSaveDialog dialog; + + /*---------------------------------------------------------*\ + | Open Profile Name Dialog | + \*---------------------------------------------------------*/ + std::string profile_name = dialog.show(); + + if(!profile_name.empty()) + { + /*---------------------------------------------------------*\ + | Extension .orp - OpenRgb Profile | + \*---------------------------------------------------------*/ + std::string filename = profile_name; + + /*---------------------------------------------------------*\ + | Save the profile | + \*---------------------------------------------------------*/ + if(profile_manager->SaveProfile(filename)) + { + UpdateProfileList(); + + ui->ProfileBox->setCurrentIndex(ui->ProfileBox->findText(QString::fromStdString(profile_name))); + } + } + } +} + void Ui::OpenRGBDialog2::on_ButtonRescan_clicked() { SetDetectionViewState(true); ResourceManager::get()->DetectDevices(); } + +void Ui::OpenRGBDialog2::on_ActionSaveProfile_triggered() +{ + if(ui->ProfileBox->currentIndex() >= 0) + { + SaveProfile(); + } + else + { + SaveProfileAs(); + } +} + +void Ui::OpenRGBDialog2::on_ActionSaveProfileAs_triggered() +{ + SaveProfileAs(); +} diff --git a/qt/OpenRGBDialog2.h b/qt/OpenRGBDialog2.h index efdc5448..7eaf3ee1 100644 --- a/qt/OpenRGBDialog2.h +++ b/qt/OpenRGBDialog2.h @@ -76,6 +76,8 @@ private: void closeEvent(QCloseEvent *event); void SetDetectionViewState(bool detection_showing); + void SaveProfile(); + void SaveProfileAs(); bool device_view_showing = false; @@ -101,12 +103,13 @@ private slots: void on_ShowHide(); void on_ReShow(QSystemTrayIcon::ActivationReason reason); void on_ProfileSelected(); - void on_ButtonSaveProfile_clicked(); void on_ButtonLoadProfile_clicked(); void on_ButtonDeleteProfile_clicked(); void on_ButtonToggleDeviceView_clicked(); void on_ButtonStopDetection_clicked(); void on_ButtonRescan_clicked(); + void on_ActionSaveProfile_triggered(); + void on_ActionSaveProfileAs_triggered(); }; #endif // OPENRGBDIALOG2_H diff --git a/qt/OpenRGBDialog2.ui b/qt/OpenRGBDialog2.ui index 120d6b6e..d5bf4760 100644 --- a/qt/OpenRGBDialog2.ui +++ b/qt/OpenRGBDialog2.ui @@ -96,10 +96,19 @@ - + + + + 0 + 0 + + Save Profile + + QToolButton::MenuButtonPopup + @@ -151,6 +160,22 @@ + + + Save Profile + + + Save Profile + + + + + Save Profile As... + + + Save Profile with custom name + +