optionsdialog.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #include "optionsdialog.h"
  2. #include "ui_optionsdialog.h"
  3. #include <QFontDialog>
  4. #include <QColorDialog>
  5. #include <QDirIterator>
  6. #include <QFileInfo>
  7. #include <QCoreApplication>
  8. #include <QTranslator>
  9. #include "mainwindow.h"
  10. OptionsDialog::OptionsDialog(QWidget *parent) :
  11. QDialog(parent),
  12. ui(new Ui::OptionsDialog)
  13. {
  14. ui->setupUi(this);
  15. if(this->parent() == 0)
  16. return;
  17. MainWindow *mw = qobject_cast<MainWindow*>(this->parent());
  18. ui->checkBox_fontSize->setChecked(mw->GetUseFontSize());
  19. ui->spinBox_fontSize->setValue(mw->GetFontSize());
  20. ui->checkBox_font->setChecked(mw->GetUseFont());
  21. m_font = mw->GetFont();
  22. ui->label_font->setText(m_font.family());
  23. ui->label_font->setFont(m_font);
  24. m_backColor = mw->GetBackgroundColor();
  25. m_linkColor = mw->GetLinkColor();
  26. m_fontColor = mw->GetForegroundColor();
  27. ui->label_backColor->setStyleSheet(QString("background-color: rgb(%1, %2, %3);").arg(QString::number(m_backColor.red()),QString::number(m_backColor.green()), QString::number(m_backColor.blue())));
  28. ui->label_linkColor->setStyleSheet(QString("background-color: rgb(%1, %2, %3);").arg(QString::number(m_linkColor.red()),QString::number(m_linkColor.green()), QString::number(m_linkColor.blue())));
  29. ui->label_fontColor->setStyleSheet(QString("background-color: rgb(%1, %2, %3);").arg(QString::number(m_fontColor.red()),QString::number(m_fontColor.green()), QString::number(m_fontColor.blue())));
  30. ui->checkBox_backColor->setChecked(mw->GetUseBackColor());
  31. ui->checkBox_linkColor->setChecked(mw->GetUseLinkColor());
  32. ui->checkBox_fontColor->setChecked(mw->GetUseFontColor());
  33. ui->checkBox_disableVideo->setChecked(mw->GetDisableVideo());
  34. ui->checkBox_perGameConfig->setChecked(mw->GetPerGameConfig());
  35. ui->checkBox_autostart->setChecked(mw->GetAutostart());
  36. ui->horizontalSlider_volume->setValue((int)(mw->GetOverallVolume() * 100));
  37. ui->checkBox_videoFix->setChecked(mw->GetVideoFix());
  38. ui->checkBox_HTML5Extras->setChecked(mw->GetAllowHTML5Extras());
  39. ui->checkBox_CaseInsensitiveFilePath->setChecked(mw->GetUseCaseInsensitiveFilePath());
  40. #ifdef _WIN32
  41. ui->checkBox_CaseInsensitiveFilePath->setVisible(false);
  42. #endif
  43. QDirIterator qmIt(QCoreApplication::applicationDirPath(), QStringList() << "*.qm", QDir::Files);
  44. while(qmIt.hasNext())
  45. {
  46. qmIt.next();
  47. QFileInfo finfo = qmIt.fileInfo();
  48. QTranslator translator;
  49. if(translator.load(finfo.completeBaseName(), finfo.absolutePath()))
  50. ui->comboBox_language->addItem(translator.translate("__LANG__", "__LANGNAME__"), QVariant(translator.translate("__LANG__", "__LANGID__")));
  51. }
  52. QDirIterator qmItRC(":/translations/", QStringList() << "*.qm", QDir::Files);
  53. while(qmItRC.hasNext())
  54. {
  55. qmItRC.next();
  56. QFileInfo finfo = qmItRC.fileInfo();
  57. QTranslator translator;
  58. if(translator.load(finfo.completeBaseName(), finfo.absolutePath()))
  59. ui->comboBox_language->addItem(translator.translate("__LANG__", "__LANGNAME__"), QVariant(translator.translate("__LANG__", "__LANGID__")));
  60. }
  61. langid = mw->GetLangID();
  62. int index = ui->comboBox_language->findData(langid);
  63. if ( index != -1 )
  64. ui->comboBox_language->setCurrentIndex(index);
  65. }
  66. OptionsDialog::~OptionsDialog()
  67. {
  68. delete ui;
  69. }
  70. void OptionsDialog::on_pushButton_font_clicked()
  71. {
  72. bool ok;
  73. QFont new_font = QFontDialog::getFont(&ok, m_font, this);
  74. if (ok)
  75. {
  76. m_font = new_font;
  77. ui->label_font->setText(m_font.family());
  78. ui->label_font->setFont(m_font);
  79. }
  80. }
  81. void OptionsDialog::on_pushButton_backColor_clicked()
  82. {
  83. QColor new_color = QColorDialog::getColor(m_backColor, this);
  84. if(new_color.isValid())
  85. {
  86. m_backColor = new_color;
  87. ui->label_backColor->setStyleSheet(QString("background-color: rgb(%1, %2, %3);").arg(QString::number(m_backColor.red()),QString::number(m_backColor.green()), QString::number(m_backColor.blue())));
  88. }
  89. }
  90. void OptionsDialog::on_pushButton_fontColor_clicked()
  91. {
  92. QColor new_color = QColorDialog::getColor(m_fontColor, this);
  93. if(new_color.isValid())
  94. {
  95. m_fontColor = new_color;
  96. ui->label_fontColor->setStyleSheet(QString("background-color: rgb(%1, %2, %3);").arg(QString::number(m_fontColor.red()),QString::number(m_fontColor.green()), QString::number(m_fontColor.blue())));
  97. }
  98. }
  99. void OptionsDialog::on_pushButton_linkColor_clicked()
  100. {
  101. QColor new_color = QColorDialog::getColor(m_linkColor, this);
  102. if(new_color.isValid())
  103. {
  104. m_linkColor = new_color;
  105. ui->label_linkColor->setStyleSheet(QString("background-color: rgb(%1, %2, %3);").arg(QString::number(m_linkColor.red()),QString::number(m_linkColor.green()), QString::number(m_linkColor.blue())));
  106. }
  107. }
  108. void OptionsDialog::on_pushButton_cancel_clicked()
  109. {
  110. close();
  111. }
  112. void OptionsDialog::on_pushButton_ok_clicked()
  113. {
  114. if(this->parent() == 0)
  115. {
  116. close();
  117. return;
  118. }
  119. MainWindow *mw = qobject_cast<MainWindow*>(this->parent());
  120. mw->SetUseFontSize(ui->checkBox_fontSize->isChecked());
  121. if(ui->checkBox_fontSize->isChecked())
  122. mw->SetFontSize(ui->spinBox_fontSize->value());
  123. mw->SetUseFont(ui->checkBox_font->isChecked());
  124. if(ui->checkBox_font->isChecked())
  125. mw->SetFont(m_font);
  126. mw->SetUseBackColor(ui->checkBox_backColor->isChecked());
  127. mw->SetUseLinkColor(ui->checkBox_linkColor->isChecked());
  128. mw->SetUseFontColor(ui->checkBox_fontColor->isChecked());
  129. if(ui->checkBox_backColor->isChecked())
  130. mw->SetBackgroundColor(m_backColor);
  131. if(ui->checkBox_linkColor->isChecked())
  132. mw->SetLinkColor(m_linkColor);
  133. if(ui->checkBox_fontColor->isChecked())
  134. mw->SetForegroundColor(m_fontColor);
  135. mw->SetDisableVideo(ui->checkBox_disableVideo->isChecked());
  136. mw->SetPerGameConfig(ui->checkBox_perGameConfig->isChecked());
  137. mw->SetAutostart(ui->checkBox_autostart->isChecked());
  138. mw->SetVideoFix(ui->checkBox_videoFix->isChecked());
  139. mw->SetAllowHTML5Extras(ui->checkBox_HTML5Extras->isChecked());
  140. mw->SetUseCaseInsensitiveFilePath(ui->checkBox_CaseInsensitiveFilePath->isChecked());
  141. if(ui->comboBox_language->count() > 0)
  142. mw->SetLangID(ui->comboBox_language->itemData(ui->comboBox_language->currentIndex()).toString());
  143. if(mw->GetOverallVolume() != ui->horizontalSlider_volume->value() / 100.0f)
  144. mw->SetOverallVolume(ui->horizontalSlider_volume->value() / 100.0f);
  145. close();
  146. }