#include "SettingsDialog.h"
#include <QVBoxLayout>
#include <QFormLayout>
#include <QTimer>
#include <QColorDialog>
#include <QHBoxLayout>
#include <QFrame>
#include <QLabel>
#include <QDesktopServices>
#include <QUrl>
#include <QFile>
QFrame* addDivider() {
QFrame *divider = new QFrame();
divider->setFrameShape(QFrame::HLine);
divider->setFrameShadow(QFrame::Sunken);
return divider;
}
SettingsDialog::SettingsDialog(const NoteData &data, QWidget *parent)
: QDialog(parent), originalData(data) {
// version
QString versionRemote = "68.026.1";
setWindowTitle("");
setFixedWidth(333);
auto *layout = new QVBoxLayout(this);
auto *form = new QFormLayout();
form->setVerticalSpacing(7);
form->setHorizontalSpacing(7);
phraseEdit = new QLineEdit();
phraseEdit->setEchoMode(QLineEdit::Password);
encryptBtn = new QPushButton("Encrypt");
decryptBtn = new QPushButton("Decrypt");
encryptBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
decryptBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
QHBoxLayout *cryptoLayout = new QHBoxLayout();
cryptoLayout->addWidget(encryptBtn);
cryptoLayout->addWidget(decryptBtn);
form->addRow("Pass Phrase", phraseEdit);
form->addRow("", cryptoLayout);
form->addRow(addDivider());
currentBg = data.bgColor;
currentText = data.textColor;
currentFocus = data.focusColor;
fontCombo = new QFontComboBox();
fontCombo->setCurrentFont(QFont(data.fontFamily));
sizeSpin = new QSpinBox();
sizeSpin->setRange(8, 47);
sizeSpin->setValue(data.fontSize);
bgColorBtn = new QPushButton("Ground Color");
textColorBtn = new QPushButton("Text Color");
focusColorBtn = new QPushButton("Focus Color");
QFrame *bgPreview = new QFrame();
bgPreview->setFixedSize(23, 23);
QFrame *textPreview = new QFrame();
textPreview->setFixedSize(23, 23);
QFrame *focusPreview = new QFrame();
focusPreview->setFixedSize(23, 23);
QFrame *highlightPreview = new QFrame();
highlightPreview->setFixedSize(23, 23);
auto updateButtonColors = [this, bgPreview, textPreview, focusPreview]() {
bgPreview->setStyleSheet(QString("background-color: %1; border: 1px solid gray;").arg(currentBg.name()));
textPreview->setStyleSheet(QString("background-color: %1; border: 1px solid gray;").arg(currentText.name()));
focusPreview->setStyleSheet(QString("background-color: %1; border: 1px solid gray;").arg(currentFocus.name()));
};
auto *bgLayout = new QHBoxLayout();
bgLayout->addWidget(bgPreview); bgLayout->addWidget(bgColorBtn);
auto *textLayout = new QHBoxLayout();
textLayout->addWidget(textPreview); textLayout->addWidget(textColorBtn);
updateButtonColors();
connect(bgColorBtn, &QPushButton::clicked, [this, updateButtonColors]() {
QColor c = QColorDialog::getColor(currentBg, this, "Select Ground Color");
if (c.isValid()) { currentBg = c; updateButtonColors(); }
});
connect(textColorBtn, &QPushButton::clicked, [this, updateButtonColors]() {
QColor c = QColorDialog::getColor(currentText, this, "Select Text Color");
if (c.isValid()) { currentText = c; updateButtonColors(); }
});
connect(focusColorBtn, &QPushButton::clicked, [this, updateButtonColors]() {
QColor c = QColorDialog::getColor(currentFocus, this, "Select Focus Color");
if (c.isValid()) { currentFocus = c; updateButtonColors(); }
});
auto *focusLayout = new QHBoxLayout();
focusLayout->addWidget(focusPreview);
focusLayout->addWidget(focusColorBtn);
autoStartCheck = new QCheckBox("");
autoStartCheck->setChecked(data.autoStart);
hideTaskbarCheck = new QCheckBox("");
hideTaskbarCheck->setChecked(data.hideTaskbar);
form->addRow("Font Family", fontCombo);
form->addRow("Font Size", sizeSpin);
form->addRow("Font Color", textLayout);
form->addRow("Focus Color", focusLayout);
form->addRow("Ground Color", bgLayout);
form->addRow(addDivider());
form->addRow("Auto Start", autoStartCheck);
form->addRow("Hide Task Bar", hideTaskbarCheck);
form->addRow(addDivider());
connect(encryptBtn, &QPushButton::clicked, [this]() {
if (!phraseEdit->text().isEmpty()) {
emit encryptRequested(phraseEdit->text());
}
});
connect(decryptBtn, &QPushButton::clicked, [this]() {
if (!phraseEdit->text().isEmpty()) {
emit decryptRequested(phraseEdit->text());
}
});
layout->addLayout(form);
auto *bottomLayout = new QHBoxLayout();
auto *saveBtn = new QPushButton("Save");
auto *cancelBtn = new QPushButton("Cancel");
saveBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
cancelBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
auto *actionLayout = new QHBoxLayout();
actionLayout->setContentsMargins(0, 0, 0, 0);
actionLayout->addWidget(saveBtn);
actionLayout->addWidget(cancelBtn);
form->addRow("", actionLayout);
form->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::Fixed));
auto *infoLayout = new QHBoxLayout();
infoLayout->setAlignment(Qt::AlignCenter);
infoLayout->setSpacing(6);
QLabel *dataLabel = new QLabel("<a style='color: gray; text-decoration: none;' href='conf'>data: wedge.conf</a>");
dataLabel->setOpenExternalLinks(false);
dataLabel->setStyleSheet("font-size: 11px;");
auto openFileLogic = [this](const QString &link) {
QString path = ConfigManager::getConfigPath();
if (link == "conf") {
QDesktopServices::openUrl(QUrl::fromLocalFile(path + "/wedge.conf"));
}
};
connect(dataLabel, &QLabel::linkActivated, openFileLogic);
QLabel *sep1 = new QLabel(" ");
sep1->setStyleSheet("color: gray; font-size: 11px;");
QLabel *versionLabel = new QLabel(versionRemote);
versionLabel->setStyleSheet("color: gray; font-size: 11px;");
QLabel *sep2 = new QLabel(" ");
sep2->setStyleSheet("color: gray; font-size: 11px;");
QLabel *supportLink = new QLabel("<a style='color: gray; text-decoration: none;' href='https://vgmlr.com/mlwrk'>vgmlr.com/mlwrk</a>");
supportLink->setOpenExternalLinks(true);
supportLink->setStyleSheet("font-size: 11px;");
infoLayout->addWidget(dataLabel);
infoLayout->addWidget(sep1);
infoLayout->addWidget(versionLabel);
infoLayout->addWidget(sep2);
infoLayout->addWidget(supportLink);
layout->addLayout(form);
layout->addLayout(infoLayout);
layout->addSpacing(6);
connect(saveBtn, &QPushButton::clicked, this, &QDialog::accept);
connect(cancelBtn, &QPushButton::clicked, this, &QDialog::reject);
}
NoteData SettingsDialog::getUpdatedData() const {
NoteData data = originalData;
data.fontFamily = fontCombo->currentFont().family();
data.fontSize = sizeSpin->value();
data.autoStart = autoStartCheck->isChecked();
data.hideTaskbar = hideTaskbarCheck->isChecked();
data.bgColor = currentBg;
data.textColor = currentText;
data.focusColor = currentFocus;
return data;
}