#include "WedgeSettings.h"
#include <QVBoxLayout>
#include <QFormLayout>
#include <QTimer>
#include <QColorDialog>
#include <QHBoxLayout>
#include <QFrame>
#include <QLabel>
static QSpacerItem* makeSpacer(int height) {
return new QSpacerItem(0, height, QSizePolicy::Minimum, QSizePolicy::Fixed);
}
static QWidget* makeSectionHeader(const QString &title) {
auto *w = new QWidget();
auto *h = new QHBoxLayout(w);
h->setContentsMargins(0, 0, 0, 0);
h->setSpacing(8);
auto *label = new QLabel(title);
label->setStyleSheet("color: #999999; font-size: 8pt;");
label->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
h->addWidget(label);
auto *hr = new QFrame();
hr->setFrameShape(QFrame::HLine);
hr->setFrameShadow(QFrame::Plain);
hr->setStyleSheet("color: #cccccc; background-color: #cccccc;");
hr->setFixedHeight(1);
hr->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
h->addWidget(hr, 1);
return w;
}
SettingsDialog::SettingsDialog(const NoteData &data, QWidget *parent)
: QDialog(parent), originalData(data) {
setWindowTitle("");
setFixedWidth(333);
auto *layout = new QVBoxLayout(this);
auto *form = new QFormLayout();
form->setVerticalSpacing(7);
form->setHorizontalSpacing(15);
form->addRow(makeSectionHeader("Aesthetics"));
form->addItem(makeSpacer(2));
currentBg = data.bgColor;
currentText = data.textColor;
currentFocus = data.focusColor;
currentHighlight = data.highlightColor;
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");
highlightColorBtn = new QPushButton("Next 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, highlightPreview]() {
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()));
highlightPreview->setStyleSheet(QString("background-color: %1; border: 1px solid gray;").arg(currentHighlight.name()));
};
QHBoxLayout *bgLayout = new QHBoxLayout(); bgLayout->setSpacing(8); bgLayout->addWidget(bgPreview); bgLayout->addWidget(bgColorBtn);
QHBoxLayout *textLayout = new QHBoxLayout(); textLayout->setSpacing(8); textLayout->addWidget(textPreview); textLayout->addWidget(textColorBtn);
QHBoxLayout *focusLayout = new QHBoxLayout(); focusLayout->setSpacing(8); focusLayout->addWidget(focusPreview); focusLayout->addWidget(focusColorBtn);
QHBoxLayout *highlightLayout = new QHBoxLayout(); highlightLayout->setSpacing(8); highlightLayout->addWidget(highlightPreview); highlightLayout->addWidget(highlightColorBtn);
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(); }
});
connect(highlightColorBtn, &QPushButton::clicked, this, [this, updateButtonColors]() {
QColor col = QColorDialog::getColor(currentHighlight, this, "Select Next Color");
if (col.isValid()) { currentHighlight = col; updateButtonColors(); }
});
autoStartCheck = new QComboBox(this);
autoStartCheck->addItems(QStringList() << "false" << "true");
autoStartCheck->setCurrentIndex(data.autoStart ? 1 : 0);
hideTaskbarCheck = new QComboBox(this);
hideTaskbarCheck->addItems(QStringList() << "false" << "true");
hideTaskbarCheck->setCurrentIndex(data.hideTaskbar ? 1 : 0);
form->addRow("Font Family", fontCombo);
form->addRow("Font Size", sizeSpin);
form->addRow("Font Color", textLayout);
form->addRow("Focus Color", focusLayout);
form->addRow("Next Color", highlightLayout);
form->addRow("Ground Color", bgLayout);
form->addItem(makeSpacer(2));
form->addRow(makeSectionHeader("System"));
form->addItem(makeSpacer(2));
form->addRow("Auto Start", autoStartCheck);
form->addRow("Hide Task Bar", hideTaskbarCheck);
form->addItem(makeSpacer(13));
layout->addLayout(form);
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->setSpacing(8);
actionLayout->addWidget(saveBtn);
actionLayout->addWidget(cancelBtn);
form->addRow("", actionLayout);
connect(saveBtn, &QPushButton::clicked, this, &QDialog::accept);
connect(cancelBtn, &QPushButton::clicked, this, &QDialog::reject);
}
NoteData SettingsDialog::getUpdatedData() const {
NoteData data = originalData;
data.autoStart = (autoStartCheck->currentIndex() == 1);
data.bgColor = currentBg;
data.focusColor = currentFocus;
data.fontFamily = fontCombo->currentFont().family();
data.fontSize = sizeSpin->value();
data.hideTaskbar = (hideTaskbarCheck->currentIndex() == 1);
data.highlightColor = currentHighlight;
data.textColor = currentText;
return data;
}