mainwindow.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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_dialogBoxesTab = new dialogBoxesTab;
  12. m_themeInfoTab = new themeInfoTab;
  13. //Connect elements for Menu Bar
  14. QObject::connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(openFile()));
  15. QObject::connect(ui->actionSave, SIGNAL(triggered()), this, SLOT(saveFile()));
  16. QObject::connect(ui->actionAbout_Qt, SIGNAL(triggered()), this, SLOT(aboutQt()));
  17. QObject::connect(ui->actionClose, SIGNAL(triggered()), this, SLOT(close()));
  18. QObject::connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(aboutMyself()));
  19. //Connect elements for Tab#1 (Color text)
  20. QObject::connect(this, SIGNAL(jsonDataUpdated(QString)), m_textColorTab, SLOT(updateLabels(QString)));
  21. QObject::connect(m_textColorTab, SIGNAL(setLabelsColor(QColor,QColor,QColor,QColor,QColor)), this, SLOT(updateLabelColor(QColor,QColor,QColor,QColor,QColor)));
  22. QObject::connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(updatePrimaryColor()));
  23. QObject::connect(ui->pushButton_2, SIGNAL(clicked()), this, SLOT(updateSecondaryColor()));
  24. QObject::connect(ui->pushButton_3, SIGNAL(clicked()), this, SLOT(updateIconSetColor()));
  25. QObject::connect(ui->pushButton_4, SIGNAL(clicked()), this, SLOT(updateIconSetActiveColor()));
  26. QObject::connect(ui->pushButton_5, SIGNAL(clicked()), this, SLOT(updateTransitionScreenColor()));
  27. //Connect elements for Tab#2 (Loading text)
  28. QObject::connect(this, SIGNAL(jsonDataUpdated(QString)), m_loadingColorTab, SLOT(updateLabels(QString)));
  29. QObject::connect(m_loadingColorTab, SIGNAL(setLabelsColor(QColor,QColor,QColor,QColor,QColor)), this, SLOT(updateLabelLoadingColor(QColor,QColor,QColor,QColor,QColor)));
  30. QObject::connect(ui->pushButton_6, SIGNAL(clicked()), this, SLOT(updateLoadingIconColor()));
  31. QObject::connect(ui->pushButton_7, SIGNAL(clicked()), this, SLOT(updateLoadingTextColor()));
  32. QObject::connect(ui->pushButton_8, SIGNAL(clicked()), this, SLOT(updateFreTextColor()));
  33. QObject::connect(ui->pushButton_9, SIGNAL(clicked()), this, SLOT(updateVersionTextColor()));
  34. QObject::connect(ui->pushButton_10, SIGNAL(clicked()), this, SLOT(updatePercentageTextColor()));
  35. //Connect elements for Tab#3 (Dialog and Boxes)
  36. QObject::connect(this, SIGNAL(jsonDataUpdated(QString)), m_dialogBoxesTab, SLOT(updateLabels(QString)));
  37. QObject::connect(m_dialogBoxesTab, SIGNAL(setLabelsColor(QColor,QColor,QColor,QColor,QColor)), this, SLOT(updateLabelDialogBoxesColor(QColor,QColor,QColor,QColor,QColor)));
  38. QObject::connect(ui->pushButton_11, SIGNAL(clicked()), this, SLOT(updateBoxColor()));
  39. QObject::connect(ui->pushButton_12, SIGNAL(clicked()), this, SLOT(updateBoxOutlineColor()));
  40. QObject::connect(ui->pushButton_13, SIGNAL(clicked()), this, SLOT(updateDialogBackground()));
  41. QObject::connect(ui->pushButton_14, SIGNAL(clicked()), this, SLOT(updateDialogButton()));
  42. QObject::connect(ui->pushButton_15, SIGNAL(clicked()), this, SLOT(updateDialogButtonText()));
  43. //Connect elements for Tab#4 (Theme informations)
  44. QObject::connect(this, SIGNAL(jsonDataUpdated(QString)), m_themeInfoTab, SLOT(updateData(QString)));
  45. QObject::connect(m_themeInfoTab, SIGNAL(setTextBox(QString,QString,QString)), this, SLOT(updateThemeInfos(QString,QString,QString)));
  46. QObject::connect(ui->lineEdit, SIGNAL(editingFinished()), this, SLOT(updateThemeName()));
  47. QObject::connect(ui->lineEdit_2, SIGNAL(editingFinished()), this, SLOT(updateThemeVersion()));
  48. QObject::connect(ui->textEdit, SIGNAL(textChanged()), this, SLOT(updateThemeDescription()));
  49. }
  50. MainWindow::~MainWindow()
  51. {
  52. delete ui;
  53. }
  54. void MainWindow::openFile()
  55. {
  56. //Open the file dialog, showing only json files
  57. QString fileName = QFileDialog::getOpenFileName(this, tr("Open Config File"),
  58. QDir::homePath(),
  59. tr("JSON Files (*.json)"));
  60. //Open the file in a text stream
  61. QFile configFile(fileName);
  62. if (!configFile.open(QFile::ReadOnly | QFile::Text)) return;
  63. QTextStream in(&configFile);
  64. m_jsonData = in.readAll();
  65. //Convert json content to Json Object
  66. QJsonDocument jsonDataDocument = QJsonDocument::fromJson(m_jsonData.toUtf8());
  67. m_jsonObject = jsonDataDocument.object();
  68. //Emit the update event
  69. qDebug() << m_jsonObject;
  70. emit jsonDataUpdated(m_jsonData);
  71. }
  72. void MainWindow::saveFile()
  73. {
  74. //Open the save file dialog, showing only json files
  75. QString fileName = QFileDialog::getSaveFileName(this, tr("Save Config File"),
  76. QDir::homePath(),
  77. tr("JSON Files (*.json)"));
  78. //Remove the file to clear it's content
  79. QFile::remove(fileName);
  80. //Open the file in a text stream
  81. QFile configFile(fileName);
  82. if (!configFile.open(QFile::ReadWrite | QFile::Text)) return;
  83. QTextStream in(&configFile);
  84. //Write the QJsonObject to the file
  85. QJsonDocument doc(m_jsonObject);
  86. in << doc.toJson(QJsonDocument::Compact);
  87. }
  88. void MainWindow::updateLabelColor(QColor labelPrimaryColor, QColor labelSecondaryColor, QColor labelIconSetColor, QColor labelSetActiveColor, QColor labelTransitionScreen)
  89. {
  90. //Update the preview labels color for Tab#1
  91. ui->label->setStyleSheet("QLabel {color : " + labelPrimaryColor.name() + "}");
  92. ui->label_2->setStyleSheet("QLabel {color : " + labelSecondaryColor.name() + "}");
  93. ui->label_3->setStyleSheet("QLabel {color : " + labelIconSetColor.name() + "}");
  94. ui->label_4->setStyleSheet("QLabel {color : " + labelSetActiveColor.name() + "}");
  95. ui->label_5->setStyleSheet("QLabel {color : " + labelTransitionScreen.name() + "}");
  96. }
  97. void MainWindow::updatePrimaryColor()
  98. {
  99. //Get color from user
  100. QString colorName = m_textColorTab->getColorFromUser().name();
  101. //Update Primary Text Label color + write new value to the JSON Object
  102. ui->label->setStyleSheet("QLabel {color : " + colorName + "}");
  103. m_jsonObject["primaryText"] = QJsonValue(QString(colorName.mid(1, 6)));
  104. }
  105. void MainWindow::updateSecondaryColor()
  106. {
  107. //Get color from user
  108. QString colorName = m_textColorTab->getColorFromUser().name();
  109. //Update Secondary Text Label color + write new value to the JSON Object
  110. ui->label_2->setStyleSheet("QLabel {color : " + colorName + "}");
  111. m_jsonObject["secondaryText"] = QJsonValue(QString(colorName.mid(1, 6)));
  112. }
  113. void MainWindow::updateIconSetColor()
  114. {
  115. //Get color from user
  116. QString colorName = m_textColorTab->getColorFromUser().name();
  117. //Update IconSet Text Label color + write new value to the JSON Object
  118. ui->label_3->setStyleSheet("QLabel {color : " + colorName + "}");
  119. m_jsonObject["iconSet"] = QJsonValue(QString(colorName.mid(1, 6)));
  120. }
  121. void MainWindow::updateIconSetActiveColor()
  122. {
  123. //Get color from user
  124. QString colorName = m_textColorTab->getColorFromUser().name();
  125. //Update IconSet Text Label color + write new value to the JSON Object
  126. ui->label_4->setStyleSheet("QLabel {color : " + colorName + "}");
  127. m_jsonObject["iconSetActive"] = QJsonValue(QString(colorName.mid(1, 6)));
  128. }
  129. void MainWindow::updateTransitionScreenColor()
  130. {
  131. //Get color from user
  132. QString colorName = m_textColorTab->getColorFromUser().name();
  133. //Update IconSet Text Label color + write new value to the JSON Object
  134. ui->label_5->setStyleSheet("QLabel {color : " + colorName + "}");
  135. m_jsonObject["transitionScreen"] = QJsonValue(QString(colorName.mid(1, 6)));
  136. }
  137. void MainWindow::aboutQt()
  138. {
  139. //Just to open the "About Qt" dialog
  140. QMessageBox::aboutQt(this);
  141. }
  142. void MainWindow::aboutMyself()
  143. {
  144. //Open the "About Timmy Companion" dialog
  145. QMessageBox::about(this, "About Timmy Companion", "Timmy Companion\n\nMake freeShop themer's life easier (Sometimes)\nv. " APP_VERSION);
  146. }
  147. void MainWindow::updateThemeInfos(QString themeName, QString themeVer, QString themeDesc)
  148. {
  149. ui->lineEdit->setText(themeName);
  150. ui->lineEdit_2->setText(themeVer);
  151. ui->textEdit->setText(themeDesc);
  152. }
  153. void MainWindow::updateThemeName()
  154. {
  155. m_jsonObject["themeName"] = QJsonValue(ui->lineEdit->text());
  156. }
  157. void MainWindow::updateThemeVersion()
  158. {
  159. m_jsonObject["themeVer"] = QJsonValue(ui->lineEdit_2->text());
  160. }
  161. void MainWindow::updateThemeDescription()
  162. {
  163. m_jsonObject["themeDesc"] = QJsonValue(ui->textEdit->toPlainText());
  164. }
  165. void MainWindow::updateLabelLoadingColor(QColor labelLoadingIconColor, QColor labelLoadingTextColor, QColor labelFreTextColor, QColor labelVersionTextColor, QColor labelPercentageTextColor)
  166. {
  167. //Update the preview labels color for Tab#2
  168. ui->label_9->setStyleSheet("QLabel {color : " + labelLoadingIconColor.name() + "}");
  169. ui->label_10->setStyleSheet("QLabel {color : " + labelLoadingTextColor.name() + "}");
  170. ui->label_11->setStyleSheet("QLabel {color : " + labelFreTextColor.name() + "}");
  171. ui->label_12->setStyleSheet("QLabel {color : " + labelVersionTextColor.name() + "}");
  172. ui->label_13->setStyleSheet("QLabel {color : " + labelPercentageTextColor.name() + "}");
  173. }
  174. void MainWindow::updateLoadingIconColor()
  175. {
  176. //Get color from user
  177. QString colorName = m_loadingColorTab->getColorFromUser().name();
  178. //Update Loading Icon Label color + write new value to the JSON Object
  179. ui->label_9->setStyleSheet("QLabel {color : " + colorName + "}");
  180. m_jsonObject["loadingColor"] = QJsonValue(QString(colorName.mid(1, 6)));
  181. }
  182. void MainWindow::updateLoadingTextColor()
  183. {
  184. //Get color from user
  185. QString colorName = m_loadingColorTab->getColorFromUser().name();
  186. //Update Loading Text Label color + write new value to the JSON Object
  187. ui->label_10->setStyleSheet("QLabel {color : " + colorName + "}");
  188. m_jsonObject["loadingText"] = QJsonValue(QString(colorName.mid(1, 6)));
  189. }
  190. void MainWindow::updateFreTextColor()
  191. {
  192. //Get color from user
  193. QString colorName = m_loadingColorTab->getColorFromUser().name();
  194. //Update Fre Text Label color + write new value to the JSON Object
  195. ui->label_11->setStyleSheet("QLabel {color : " + colorName + "}");
  196. m_jsonObject["freText"] = QJsonValue(QString(colorName.mid(1, 6)));
  197. }
  198. void MainWindow::updateVersionTextColor()
  199. {
  200. //Get color from user
  201. QString colorName = m_loadingColorTab->getColorFromUser().name();
  202. //Update freeShop Version Text Label color + write new value to the JSON Object
  203. ui->label_12->setStyleSheet("QLabel {color : " + colorName + "}");
  204. m_jsonObject["versionText"] = QJsonValue(QString(colorName.mid(1, 6)));
  205. }
  206. void MainWindow::updatePercentageTextColor()
  207. {
  208. //Get color from user
  209. QString colorName = m_loadingColorTab->getColorFromUser().name();
  210. //Update Percentage Text Label color + write new value to the JSON Object
  211. ui->label_13->setStyleSheet("QLabel {color : " + colorName + "}");
  212. m_jsonObject["percentageText"] = QJsonValue(QString(colorName.mid(1, 6)));
  213. }
  214. void MainWindow::updateLabelDialogBoxesColor(QColor labelBoxColor, QColor labelBoxOutlineColor, QColor labelDialogBackground, QColor labelDialogButton, QColor labelDialogButtonText)
  215. {
  216. //Update the preview labels color for Tab#3
  217. ui->label_14->setStyleSheet("QLabel {color : " + labelBoxColor.name() + "}");
  218. ui->label_15->setStyleSheet("QLabel {color : " + labelBoxOutlineColor.name() + "}");
  219. ui->label_16->setStyleSheet("QLabel {color : " + labelDialogBackground.name() + "}");
  220. ui->label_17->setStyleSheet("QLabel {color : " + labelDialogButton.name() + "}");
  221. ui->label_18->setStyleSheet("QLabel {color : " + labelDialogButtonText.name() + "}");
  222. }
  223. void MainWindow::updateBoxColor()
  224. {
  225. //Get color from user
  226. QString colorName = m_loadingColorTab->getColorFromUser().name();
  227. //Update Loading Icon Label color + write new value to the JSON Object
  228. ui->label_14->setStyleSheet("QLabel {color : " + colorName + "}");
  229. m_jsonObject["boxColor"] = QJsonValue(QString(colorName.mid(1, 6)));
  230. }
  231. void MainWindow::updateBoxOutlineColor()
  232. {
  233. //Get color from user
  234. QString colorName = m_loadingColorTab->getColorFromUser().name();
  235. //Update Loading Text Label color + write new value to the JSON Object
  236. ui->label_15->setStyleSheet("QLabel {color : " + colorName + "}");
  237. m_jsonObject["boxOutlineColor"] = QJsonValue(QString(colorName.mid(1, 6)));
  238. }
  239. void MainWindow::updateDialogBackground()
  240. {
  241. //Get color from user
  242. QString colorName = m_loadingColorTab->getColorFromUser().name();
  243. //Update Fre Text Label color + write new value to the JSON Object
  244. ui->label_16->setStyleSheet("QLabel {color : " + colorName + "}");
  245. m_jsonObject["dialogBackground"] = QJsonValue(QString(colorName.mid(1, 6)));
  246. }
  247. void MainWindow::updateDialogButton()
  248. {
  249. //Get color from user
  250. QString colorName = m_loadingColorTab->getColorFromUser().name();
  251. //Update freeShop Version Text Label color + write new value to the JSON Object
  252. ui->label_17->setStyleSheet("QLabel {color : " + colorName + "}");
  253. m_jsonObject["dialogButton"] = QJsonValue(QString(colorName.mid(1, 6)));
  254. }
  255. void MainWindow::updateDialogButtonText()
  256. {
  257. //Get color from user
  258. QString colorName = m_loadingColorTab->getColorFromUser().name();
  259. //Update Percentage Text Label color + write new value to the JSON Object
  260. ui->label_18->setStyleSheet("QLabel {color : " + colorName + "}");
  261. m_jsonObject["dialogButtonText"] = QJsonValue(QString(colorName.mid(1, 6)));
  262. }