mainwindow.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. MainWindow::MainWindow(QWidget *parent) :
  4. QMainWindow(parent),
  5. ui(new Ui::MainWindow)
  6. {
  7. ui->setupUi(this);
  8. //Initialize classes
  9. m_textColorTab = new textColorTab;
  10. m_loadingColorTab = new loadingColorTab;
  11. m_themeInfoTab = new themeInfoTab;
  12. //Connect elements for Menu Bar
  13. QObject::connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(openFile()));
  14. QObject::connect(ui->actionSave, SIGNAL(triggered()), this, SLOT(saveFile()));
  15. QObject::connect(ui->actionAbout_Qt, SIGNAL(triggered()), this, SLOT(aboutQt()));
  16. QObject::connect(ui->actionClose, SIGNAL(triggered()), this, SLOT(close()));
  17. QObject::connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(aboutMyself()));
  18. //Connect elements for Tab#1 (Color text)
  19. QObject::connect(this, SIGNAL(jsonDataUpdated(QString)), m_textColorTab, SLOT(updateLabels(QString)));
  20. QObject::connect(m_textColorTab, SIGNAL(setLabelsColor(QColor,QColor,QColor,QColor,QColor)), this, SLOT(updateLabelColor(QColor,QColor,QColor,QColor,QColor)));
  21. QObject::connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(updatePrimaryColor()));
  22. QObject::connect(ui->pushButton_2, SIGNAL(clicked()), this, SLOT(updateSecondaryColor()));
  23. QObject::connect(ui->pushButton_3, SIGNAL(clicked()), this, SLOT(updateIconSetColor()));
  24. QObject::connect(ui->pushButton_4, SIGNAL(clicked()), this, SLOT(updateIconSetActiveColor()));
  25. QObject::connect(ui->pushButton_5, SIGNAL(clicked()), this, SLOT(updateTransitionScreenColor()));
  26. //Connect elements for Tab#2 (Loading text)
  27. QObject::connect(this, SIGNAL(jsonDataUpdated(QString)), m_loadingColorTab, SLOT(updateLabels(QString)));
  28. QObject::connect(m_loadingColorTab, SIGNAL(setLabelsColor(QColor,QColor,QColor,QColor,QColor)), this, SLOT(updateLabelLoadingColor(QColor,QColor,QColor,QColor,QColor)));
  29. QObject::connect(ui->pushButton_6, SIGNAL(clicked()), this, SLOT(updateLoadingIconColor()));
  30. QObject::connect(ui->pushButton_7, SIGNAL(clicked()), this, SLOT(updateLoadingTextColor()));
  31. QObject::connect(ui->pushButton_8, SIGNAL(clicked()), this, SLOT(updateFreTextColor()));
  32. QObject::connect(ui->pushButton_9, SIGNAL(clicked()), this, SLOT(updateVersionTextColor()));
  33. QObject::connect(ui->pushButton_10, SIGNAL(clicked()), this, SLOT(updatePercentageTextColor()));
  34. //Connect elements for Tab#3 (Theme informations)
  35. QObject::connect(this, SIGNAL(jsonDataUpdated(QString)), m_themeInfoTab, SLOT(updateData(QString)));
  36. QObject::connect(m_themeInfoTab, SIGNAL(setTextBox(QString,QString,QString)), this, SLOT(updateThemeInfos(QString,QString,QString)));
  37. QObject::connect(ui->lineEdit, SIGNAL(editingFinished()), this, SLOT(updateThemeName()));
  38. QObject::connect(ui->lineEdit_2, SIGNAL(editingFinished()), this, SLOT(updateThemeVersion()));
  39. QObject::connect(ui->textEdit, SIGNAL(textChanged()), this, SLOT(updateThemeDescription()));
  40. }
  41. MainWindow::~MainWindow()
  42. {
  43. delete ui;
  44. }
  45. void MainWindow::openFile()
  46. {
  47. //Open the file dialog, showing only json files
  48. QString fileName = QFileDialog::getOpenFileName(this, tr("Open Config File"),
  49. QDir::homePath(),
  50. tr("JSON Files (*.json)"));
  51. //Open the file in a text stream
  52. QFile configFile(fileName);
  53. if (!configFile.open(QFile::ReadOnly | QFile::Text)) return;
  54. QTextStream in(&configFile);
  55. m_jsonData = in.readAll();
  56. //Convert json content to Json Object
  57. QJsonDocument jsonDataDocument = QJsonDocument::fromJson(m_jsonData.toUtf8());
  58. m_jsonObject = jsonDataDocument.object();
  59. //Emit the update event
  60. qDebug() << m_jsonObject;
  61. emit jsonDataUpdated(m_jsonData);
  62. }
  63. void MainWindow::saveFile()
  64. {
  65. //Open the save file dialog, showing only json files
  66. QString fileName = QFileDialog::getSaveFileName(this, tr("Save Config File"),
  67. QDir::homePath(),
  68. tr("JSON Files (*.json)"));
  69. //Remove the file to clear it's content
  70. QFile::remove(fileName);
  71. //Open the file in a text stream
  72. QFile configFile(fileName);
  73. if (!configFile.open(QFile::ReadWrite | QFile::Text)) return;
  74. QTextStream in(&configFile);
  75. //Write the QJsonObject to the file
  76. QJsonDocument doc(m_jsonObject);
  77. in << doc.toJson(QJsonDocument::Compact);
  78. }
  79. void MainWindow::updateLabelColor(QColor labelPrimaryColor, QColor labelSecondaryColor, QColor labelIconSetColor, QColor labelSetActiveColor, QColor labelTransitionScreen)
  80. {
  81. //Update the preview labels color for Tab#1
  82. ui->label->setStyleSheet("QLabel {color : " + labelPrimaryColor.name() + "}");
  83. ui->label_2->setStyleSheet("QLabel {color : " + labelSecondaryColor.name() + "}");
  84. ui->label_3->setStyleSheet("QLabel {color : " + labelIconSetColor.name() + "}");
  85. ui->label_4->setStyleSheet("QLabel {color : " + labelSetActiveColor.name() + "}");
  86. ui->label_5->setStyleSheet("QLabel {color : " + labelTransitionScreen.name() + "}");
  87. }
  88. void MainWindow::updatePrimaryColor()
  89. {
  90. //Get color from user
  91. QString colorName = m_textColorTab->getColorFromUser().name();
  92. //Update Primary Text Label color + write new value to the JSON Object
  93. ui->label->setStyleSheet("QLabel {color : " + colorName + "}");
  94. m_jsonObject["primaryText"] = QJsonValue(QString(colorName.mid(1, 6)));
  95. }
  96. void MainWindow::updateSecondaryColor()
  97. {
  98. //Get color from user
  99. QString colorName = m_textColorTab->getColorFromUser().name();
  100. //Update Secondary Text Label color + write new value to the JSON Object
  101. ui->label_2->setStyleSheet("QLabel {color : " + colorName + "}");
  102. m_jsonObject["secondaryText"] = QJsonValue(QString(colorName.mid(1, 6)));
  103. }
  104. void MainWindow::updateIconSetColor()
  105. {
  106. //Get color from user
  107. QString colorName = m_textColorTab->getColorFromUser().name();
  108. //Update IconSet Text Label color + write new value to the JSON Object
  109. ui->label_3->setStyleSheet("QLabel {color : " + colorName + "}");
  110. m_jsonObject["iconSet"] = QJsonValue(QString(colorName.mid(1, 6)));
  111. }
  112. void MainWindow::updateIconSetActiveColor()
  113. {
  114. //Get color from user
  115. QString colorName = m_textColorTab->getColorFromUser().name();
  116. //Update IconSet Text Label color + write new value to the JSON Object
  117. ui->label_4->setStyleSheet("QLabel {color : " + colorName + "}");
  118. m_jsonObject["iconSetActive"] = QJsonValue(QString(colorName.mid(1, 6)));
  119. }
  120. void MainWindow::updateTransitionScreenColor()
  121. {
  122. //Get color from user
  123. QString colorName = m_textColorTab->getColorFromUser().name();
  124. //Update IconSet Text Label color + write new value to the JSON Object
  125. ui->label_5->setStyleSheet("QLabel {color : " + colorName + "}");
  126. m_jsonObject["transitionScreen"] = QJsonValue(QString(colorName.mid(1, 6)));
  127. }
  128. void MainWindow::aboutQt()
  129. {
  130. //Just to open the "About Qt" dialog
  131. QMessageBox::aboutQt(this);
  132. }
  133. void MainWindow::aboutMyself()
  134. {
  135. //Open the "About Timmy Companion" dialog
  136. QMessageBox::about(this, "About Timmy Companion", "Timmy Companion\n\nMake freeShop themer's life easier (Sometimes)\nv. " APP_VERSION);
  137. }
  138. void MainWindow::updateThemeInfos(QString themeName, QString themeVer, QString themeDesc)
  139. {
  140. ui->lineEdit->setText(themeName);
  141. ui->lineEdit_2->setText(themeVer);
  142. ui->textEdit->setText(themeDesc);
  143. }
  144. void MainWindow::updateThemeName()
  145. {
  146. m_jsonObject["themeName"] = QJsonValue(ui->lineEdit->text());
  147. }
  148. void MainWindow::updateThemeVersion()
  149. {
  150. m_jsonObject["themeVer"] = QJsonValue(ui->lineEdit_2->text());
  151. }
  152. void MainWindow::updateThemeDescription()
  153. {
  154. m_jsonObject["themeDesc"] = QJsonValue(ui->textEdit->toPlainText());
  155. }
  156. void MainWindow::updateLabelLoadingColor(QColor labelLoadingIconColor, QColor labelLoadingTextColor, QColor labelFreTextColor, QColor labelVersionTextColor, QColor labelPercentageTextColor)
  157. {
  158. //Update the preview labels color for Tab#2
  159. ui->label_9->setStyleSheet("QLabel {color : " + labelLoadingIconColor.name() + "}");
  160. ui->label_10->setStyleSheet("QLabel {color : " + labelLoadingTextColor.name() + "}");
  161. ui->label_11->setStyleSheet("QLabel {color : " + labelFreTextColor.name() + "}");
  162. ui->label_12->setStyleSheet("QLabel {color : " + labelVersionTextColor.name() + "}");
  163. ui->label_13->setStyleSheet("QLabel {color : " + labelPercentageTextColor.name() + "}");
  164. }
  165. void MainWindow::updateLoadingIconColor()
  166. {
  167. //Get color from user
  168. QString colorName = m_loadingColorTab->getColorFromUser().name();
  169. //Update Loading Icon Label color + write new value to the JSON Object
  170. ui->label_9->setStyleSheet("QLabel {color : " + colorName + "}");
  171. m_jsonObject["loadingColor"] = QJsonValue(QString(colorName.mid(1, 6)));
  172. }
  173. void MainWindow::updateLoadingTextColor()
  174. {
  175. //Get color from user
  176. QString colorName = m_loadingColorTab->getColorFromUser().name();
  177. //Update Loading Text Label color + write new value to the JSON Object
  178. ui->label_10->setStyleSheet("QLabel {color : " + colorName + "}");
  179. m_jsonObject["loadingText"] = QJsonValue(QString(colorName.mid(1, 6)));
  180. }
  181. void MainWindow::updateFreTextColor()
  182. {
  183. //Get color from user
  184. QString colorName = m_loadingColorTab->getColorFromUser().name();
  185. //Update Fre Text Label color + write new value to the JSON Object
  186. ui->label_11->setStyleSheet("QLabel {color : " + colorName + "}");
  187. m_jsonObject["freText"] = QJsonValue(QString(colorName.mid(1, 6)));
  188. }
  189. void MainWindow::updateVersionTextColor()
  190. {
  191. //Get color from user
  192. QString colorName = m_loadingColorTab->getColorFromUser().name();
  193. //Update freeShop Version Text Label color + write new value to the JSON Object
  194. ui->label_12->setStyleSheet("QLabel {color : " + colorName + "}");
  195. m_jsonObject["versionText"] = QJsonValue(QString(colorName.mid(1, 6)));
  196. }
  197. void MainWindow::updatePercentageTextColor()
  198. {
  199. //Get color from user
  200. QString colorName = m_loadingColorTab->getColorFromUser().name();
  201. //Update Percentage Text Label color + write new value to the JSON Object
  202. ui->label_13->setStyleSheet("QLabel {color : " + colorName + "}");
  203. m_jsonObject["percentageText"] = QJsonValue(QString(colorName.mid(1, 6)));
  204. }