1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
|
/*
* ========================================================================== *
* *
* This file is part of the Openterface Mini KVM App QT version *
* *
* Copyright (C) 2024 <info@openterface.com> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation version 3. *
* *
* This program is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
* ========================================================================== *
*/
#include "settingdialog.h"
#include "ui_settingdialog.h"
#include "ui/logpage.h"
#include "ui/hardwarepage.h"
#include "host/cameramanager.h"
#include "ui/videopage.h"
#include <QCamera>
#include <QCameraDevice>
#include <QCameraFormat>
#include <QComboBox>
#include <QDialogButtonBox>
#include <QDir>
#include <QFileDialog>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QCheckBox>
#include <QRegularExpression>
#include <QToolButton>
#include <QTreeWidget>
#include <QTreeWidgetItem>
#include <QStackedWidget>
#include <QDebug>
#include <QLoggingCategory>
#include <QSettings>
#include <QElapsedTimer>
#include <qtimer.h>
#include <QList>
#include <QSerialPortInfo>
#include <QLineEdit>
#include <QByteArray>
SettingDialog::SettingDialog(CameraManager *cameraManager, QWidget *parent)
: QDialog(parent)
, ui(new Ui::SettingDialog)
, m_cameraManager(cameraManager)
, settingTree(new QTreeWidget(this))
, stackedWidget(new QStackedWidget(this))
, logPage(new LogPage(this))
, audioPage(new AudioPage(this))
, videoPage(new VideoPage(cameraManager, this))
, hardwarePage(new HardwarePage(this))
, buttonWidget(new QWidget(this))
{
ui->setupUi(this);
createSettingTree();
createPages();
createButtons();
createLayout();
setWindowTitle(tr("Preferences"));
// loadLogSettings();
logPage->initLogSettings();
videoPage->initVideoSettings();
hardwarePage->initHardwareSetting();
// Connect the tree widget's currentItemChanged signal to a slot
connect(settingTree, &QTreeWidget::currentItemChanged, this, &SettingDialog::changePage);
}
SettingDialog::~SettingDialog()
{
delete ui;
// Ensure all dynamically allocated memory is freed
qDeleteAll(settingTree->invisibleRootItem()->takeChildren());
delete this;
}
void SettingDialog::createSettingTree() {
// qDebug() << "creating setting Tree";
settingTree->setColumnCount(1);
// settingTree->setHeaderLabels(QStringList(tr("general")));
settingTree->setHeaderHidden(true);
settingTree->setSelectionMode(QAbstractItemView::SingleSelection);
settingTree->setMaximumSize(QSize(120, 1000));
settingTree->setRootIsDecorated(false);
// QStringList names = {"Log"};
QStringList names = {"General", "Video", "Audio", "Hardware"};
for (const QString &name : names) { // add item to setting tree
QTreeWidgetItem *item = new QTreeWidgetItem(settingTree);
item->setText(0, name);
}
}
void SettingDialog::createPages() {
// Add pages to the stacked widget
stackedWidget->addWidget(logPage);
stackedWidget->addWidget(videoPage);
stackedWidget->addWidget(audioPage);
stackedWidget->addWidget(hardwarePage);
}
void SettingDialog::createButtons(){
QPushButton *okButton = new QPushButton("OK");
QPushButton *applyButton = new QPushButton("Apply");
QPushButton *cancelButton = new QPushButton("Cancel");
okButton->setFixedSize(80, 30);
applyButton->setFixedSize(80, 30);
cancelButton->setFixedSize(80, 30);
QHBoxLayout *buttonLayout = new QHBoxLayout(buttonWidget);
buttonLayout->addStretch();
buttonLayout->addWidget(okButton);
buttonLayout->addWidget(applyButton);
buttonLayout->addWidget(cancelButton);
connect(okButton, &QPushButton::clicked, this, &SettingDialog::handleOkButton);
connect(cancelButton, &QPushButton::clicked, this, &QDialog::reject);
connect(applyButton, &QPushButton::clicked, this, &SettingDialog::applyAccrodingPage);
}
void SettingDialog::createLayout() {
qDebug() << "createLayout";
QHBoxLayout *selectLayout = new QHBoxLayout;
selectLayout->addWidget(settingTree);
selectLayout->addWidget(stackedWidget);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(selectLayout);
mainLayout->addWidget(buttonWidget);
setLayout(mainLayout);
}
void SettingDialog::changePage(QTreeWidgetItem *current, QTreeWidgetItem *previous) {
static bool isChanging = false;
if (isChanging)
return;
isChanging = true;
if (!current)
current = previous;
QString itemText = current->text(0);
qDebug() << "Selected item:" << itemText;
if (itemText == "General") {
stackedWidget->setCurrentIndex(0);
} else if (itemText == "Video") {
stackedWidget->setCurrentIndex(1);
} else if (itemText == "Audio") {
stackedWidget->setCurrentIndex(2);
} else if (itemText == "Hardware") {
stackedWidget->setCurrentIndex(3);
}
QTimer::singleShot(100, this, [this]() {
isChanging = false;
});
}
void SettingDialog::applyAccrodingPage(){
int currentPageIndex = stackedWidget->currentIndex();
switch (currentPageIndex)
{
// sequence Log Video Audio
case 0:
logPage->applyLogsettings();
break;
case 1:
videoPage->applyVideoSettings();
break;
case 2:
break;
case 3:
hardwarePage->applyHardwareSetting();
break;
default:
break;
}
}
void SettingDialog::handleOkButton() {
logPage->applyLogsettings();
videoPage->applyVideoSettings();
hardwarePage->applyHardwareSetting();
accept();
}
HardwarePage* SettingDialog::getHardwarePage() {
return hardwarePage;
}
VideoPage* SettingDialog::getVideoPage() {
return videoPage;
}
|