123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- //Initialize classes
- m_textColorTab = new textColorTab;
- m_themeInfoTab = new themeInfoTab;
- //Connect elements for Menu Bar
- QObject::connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(openFile()));
- QObject::connect(ui->actionSave, SIGNAL(triggered()), this, SLOT(saveFile()));
- QObject::connect(ui->actionAbout_Qt, SIGNAL(triggered()), this, SLOT(aboutQt()));
- QObject::connect(ui->actionClose, SIGNAL(triggered()), this, SLOT(close()));
- QObject::connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(aboutMyself()));
- //Connect elements for Tab#1 (Color text)
- QObject::connect(this, SIGNAL(jsonDataUpdated(QString)), m_textColorTab, SLOT(updateLabels(QString)));
- QObject::connect(m_textColorTab, SIGNAL(setLabelsColor(QColor,QColor,QColor,QColor,QColor)), this, SLOT(updateLabelColor(QColor,QColor,QColor,QColor,QColor)));
- QObject::connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(updatePrimaryColor()));
- QObject::connect(ui->pushButton_2, SIGNAL(clicked()), this, SLOT(updateSecondaryColor()));
- QObject::connect(ui->pushButton_3, SIGNAL(clicked()), this, SLOT(updateIconSetColor()));
- QObject::connect(ui->pushButton_4, SIGNAL(clicked()), this, SLOT(updateIconSetActiveColor()));
- QObject::connect(ui->pushButton_5, SIGNAL(clicked()), this, SLOT(updateTransitionScreenColor()));
- //Connect elements for Tab#2 (Theme informations)
- QObject::connect(this, SIGNAL(jsonDataUpdated(QString)), m_themeInfoTab, SLOT(updateData(QString)));
- QObject::connect(m_themeInfoTab, SIGNAL(setTextBox(QString,QString,QString)), this, SLOT(updateThemeInfos(QString,QString,QString)));
- QObject::connect(ui->lineEdit, SIGNAL(editingFinished()), this, SLOT(updateThemeName()));
- QObject::connect(ui->lineEdit_2, SIGNAL(editingFinished()), this, SLOT(updateThemeVersion()));
- QObject::connect(ui->textEdit, SIGNAL(textChanged()), this, SLOT(updateThemeDescription()));
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }
- void MainWindow::openFile()
- {
- //Open the file dialog, showing only json files
- QString fileName = QFileDialog::getOpenFileName(this, tr("Open Config File"),
- QDir::homePath(),
- tr("JSON Files (*.json)"));
- //Open the file in a text stream
- QFile configFile(fileName);
- if (!configFile.open(QFile::ReadOnly | QFile::Text)) return;
- QTextStream in(&configFile);
- m_jsonData = in.readAll();
- //Convert json content to Json Object
- QJsonDocument jsonDataDocument = QJsonDocument::fromJson(m_jsonData.toUtf8());
- m_jsonObject = jsonDataDocument.object();
- //Emit the update event
- qDebug() << m_jsonObject;
- emit jsonDataUpdated(m_jsonData);
- }
- void MainWindow::saveFile()
- {
- //Open the save file dialog, showing only json files
- QString fileName = QFileDialog::getSaveFileName(this, tr("Save Config File"),
- QDir::homePath(),
- tr("JSON Files (*.json)"));
- //Remove the file to clear it's content
- QFile::remove(fileName);
- //Open the file in a text stream
- QFile configFile(fileName);
- if (!configFile.open(QFile::ReadWrite | QFile::Text)) return;
- QTextStream in(&configFile);
- //Write the QJsonObject to the file
- QJsonDocument doc(m_jsonObject);
- in << doc.toJson(QJsonDocument::Compact);
- }
- void MainWindow::updateLabelColor(QColor labelPrimaryColor, QColor labelSecondaryColor, QColor labelIconSetColor, QColor labelSetActiveColor, QColor labelTransitionScreen)
- {
- //Update the preview labels color for Tab#1
- ui->label->setStyleSheet("QLabel {color : " + labelPrimaryColor.name() + "}");
- ui->label_2->setStyleSheet("QLabel {color : " + labelSecondaryColor.name() + "}");
- ui->label_3->setStyleSheet("QLabel {color : " + labelIconSetColor.name() + "}");
- ui->label_4->setStyleSheet("QLabel {color : " + labelSetActiveColor.name() + "}");
- ui->label_5->setStyleSheet("QLabel {color : " + labelTransitionScreen.name() + "}");
- }
- void MainWindow::updatePrimaryColor()
- {
- //Get color from user
- QString colorName = m_textColorTab->getColorFromUser().name();
- //Update Primary Text Label color + write new value to the JSON Object
- ui->label->setStyleSheet("QLabel {color : " + colorName + "}");
- m_jsonObject["primaryText"] = QJsonValue(QString(colorName.mid(1, 6)));
- }
- void MainWindow::updateSecondaryColor()
- {
- //Get color from user
- QString colorName = m_textColorTab->getColorFromUser().name();
- //Update Secondary Text Label color + write new value to the JSON Object
- ui->label_2->setStyleSheet("QLabel {color : " + colorName + "}");
- m_jsonObject["secondaryText"] = QJsonValue(QString(colorName.mid(1, 6)));
- }
- void MainWindow::updateIconSetColor()
- {
- //Get color from user
- QString colorName = m_textColorTab->getColorFromUser().name();
- //Update IconSet Text Label color + write new value to the JSON Object
- ui->label_3->setStyleSheet("QLabel {color : " + colorName + "}");
- m_jsonObject["iconSet"] = QJsonValue(QString(colorName.mid(1, 6)));
- }
- void MainWindow::updateIconSetActiveColor()
- {
- //Get color from user
- QString colorName = m_textColorTab->getColorFromUser().name();
- //Update IconSet Text Label color + write new value to the JSON Object
- ui->label_4->setStyleSheet("QLabel {color : " + colorName + "}");
- m_jsonObject["iconSetActive"] = QJsonValue(QString(colorName.mid(1, 6)));
- }
- void MainWindow::updateTransitionScreenColor()
- {
- //Get color from user
- QString colorName = m_textColorTab->getColorFromUser().name();
- //Update IconSet Text Label color + write new value to the JSON Object
- ui->label_5->setStyleSheet("QLabel {color : " + colorName + "}");
- m_jsonObject["transitionScreen"] = QJsonValue(QString(colorName.mid(1, 6)));
- }
- void MainWindow::aboutQt()
- {
- //Just to open the "About Qt" dialog
- QMessageBox::aboutQt(this);
- }
- void MainWindow::aboutMyself()
- {
- //Open the "About Timmy Companion" dialog
- QMessageBox::about(this, "About Timmy Companion", "Timmy Companion\n\nMake freeShop themer's life easier (Sometimes)\nv. " APP_VERSION);
- }
- void MainWindow::updateThemeInfos(QString themeName, QString themeVer, QString themeDesc)
- {
- ui->lineEdit->setText(themeName);
- ui->lineEdit_2->setText(themeVer);
- ui->textEdit->setText(themeDesc);
- }
- void MainWindow::updateThemeName()
- {
- m_jsonObject["themeName"] = QJsonValue(ui->lineEdit->text());
- }
- void MainWindow::updateThemeVersion()
- {
- m_jsonObject["themeVer"] = QJsonValue(ui->lineEdit_2->text());
- }
- void MainWindow::updateThemeDescription()
- {
- m_jsonObject["themeDesc"] = QJsonValue(ui->textEdit->toPlainText());
- }
|