Pith - wedge_linux
wedge_linux/SettingsDialog.cpp [10.1 kb]
Modified: 06:16:06 91 026 (18 Jun 026)
6 Days Ago
#include "SettingsDialog.h"
#include <QVBoxLayout>
#include <QFormLayout>
#include <QTimer>
#include <QColorDialog>
#include <QHBoxLayout>
#include <QFrame>
#include <QLabel>
#include <QDesktopServices>
#include <QUrl>
#include <QFile>
#include <QCoreApplication>

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 = "90.026.1";

    setWindowTitle("");
    setFixedWidth(333);

    auto *layout = new QVBoxLayout(this);
    auto *form = new QFormLayout();

    form->setVerticalSpacing(7);
    form->setHorizontalSpacing(7);

    routeCombo = new QComboBox(this);
    //routeCombo->addItems(QStringList() << "USB" << "WIFI" << "Bluetooth");
    routeCombo->addItems(QStringList() << "USB" << "WIFI");
    routeCombo->setCurrentIndex(data.networkRoute);

    roleCombo = new QComboBox(this);
    //roleCombo->addItems(QStringList() << "Client" << "Server");
    roleCombo->addItem("Client");
    roleCombo->setCurrentIndex(data.networkRole);

    netStatusValLabel = new QLabel("Disconnected", this);
    netStatusValLabel->setStyleSheet("padding-top: 4px; padding-bottom: 4px;");

    connectBtn = new QPushButton("Connect", this);
    syncBtn = new QPushButton("Send", this);
    connectBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    syncBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);

    QHBoxLayout *netActionLayout = new QHBoxLayout();
    netActionLayout->addWidget(connectBtn);
    netActionLayout->addWidget(syncBtn);

    passKeyEdit = new QLineEdit(this);
    passKeyEdit->setText(data.passKey.isEmpty() ? "wedge03569" : data.passKey);

    ipEdit = new QLineEdit(this);
    ipEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    ipEdit->setPlaceholderText("192.168.1.255");
    if (!data.ipAddress.isEmpty()) {
        ipEdit->setText(data.ipAddress);
    }

    form->addRow("Route", routeCombo);
    form->addRow("Role", roleCombo);
    form->addRow("Address", ipEdit);
    form->addRow("Pass Key", passKeyEdit);
    form->addRow("Status", netStatusValLabel);
    form->addRow("", netActionLayout);
    
    form->addRow(addDivider());

    connect(connectBtn, &QPushButton::clicked, this, [this]() {
        netStatusValLabel->setText("Connecting");
        emit connectRequested(routeCombo->currentIndex(), roleCombo->currentIndex());
    });
    connect(syncBtn, &QPushButton::clicked, this, &SettingsDialog::syncRequested);

    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;
    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->addWidget(bgPreview); bgLayout->addWidget(bgColorBtn);
    QHBoxLayout *textLayout = new QHBoxLayout(); textLayout->addWidget(textPreview); textLayout->addWidget(textColorBtn);
    QHBoxLayout *focusLayout = new QHBoxLayout(); focusLayout->addWidget(focusPreview); focusLayout->addWidget(focusColorBtn);
    QHBoxLayout *highlightLayout = new QHBoxLayout(); 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->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.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.networkRole = roleCombo->currentIndex();
    data.networkRoute = routeCombo->currentIndex();
    data.passKey = passKeyEdit->text();
    data.ipAddress = ipEdit->text();
    data.textColor = currentText;
    return data;
}

void SettingsDialog::updateStatusText(const QString &status) {
    netStatusValLabel->setText(status);
}
Updates
OTC Applet - Linux 93.026.1
Wedge - Linux 90.026.1
Wedge - Android 90.026.1
Shim - Android 86.026.1
Kerf - Android 86.026.4
Dev
TVShow (227) 'CSA'
TVShow (228) 'APT'
TVProgram (83) 'BXT'
Miter Update(s)
Peen (Messaging)

Menu
Calendar
Project Tin (024/029)
Miter
RSS Feed
User Avatar
@vgmlr
=SUM(parts)