optionsdialog.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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(mw->GetOverallVolume() * 100);
  37. ui->checkBox_videoFix->setChecked(mw->GetVideoFix());
  38. ui->checkBox_HTML5Extras->setChecked(mw->GetAllowHTML5Extras());
  39. QDirIterator qmIt(QCoreApplication::applicationDirPath(), QStringList() << "*.qm", QDir::Files);
  40. while(qmIt.hasNext())
  41. {
  42. qmIt.next();
  43. QFileInfo finfo = qmIt.fileInfo();
  44. QTranslator translator;
  45. if(translator.load(finfo.completeBaseName(), finfo.absolutePath()))
  46. ui->comboBox_language->addItem(translator.translate("__LANG__", "__LANGNAME__"), QVariant(translator.translate("__LANG__", "__LANGID__")));
  47. }
  48. QDirIterator qmItRC(":/translations/", QStringList() << "*.qm", QDir::Files);
  49. while(qmItRC.hasNext())
  50. {
  51. qmItRC.next();
  52. QFileInfo finfo = qmItRC.fileInfo();
  53. QTranslator translator;
  54. if(translator.load(finfo.completeBaseName(), finfo.absolutePath()))
  55. ui->comboBox_language->addItem(translator.translate("__LANG__", "__LANGNAME__"), QVariant(translator.translate("__LANG__", "__LANGID__")));
  56. }
  57. langid = mw->GetLangID();
  58. int index = ui->comboBox_language->findData(langid);
  59. if ( index != -1 )
  60. ui->comboBox_language->setCurrentIndex(index);
  61. }
  62. OptionsDialog::~OptionsDialog()
  63. {
  64. delete ui;
  65. }
  66. void OptionsDialog::on_pushButton_font_clicked()
  67. {
  68. bool ok;
  69. QFont new_font = QFontDialog::getFont(&ok, m_font, this);
  70. if (ok)
  71. {
  72. m_font = new_font;
  73. ui->label_font->setText(m_font.family());
  74. ui->label_font->setFont(m_font);
  75. }
  76. }
  77. void OptionsDialog::on_pushButton_backColor_clicked()
  78. {
  79. QColor new_color = QColorDialog::getColor(m_backColor, this);
  80. if(new_color.isValid())
  81. {
  82. m_backColor = new_color;
  83. 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())));
  84. }
  85. }
  86. void OptionsDialog::on_pushButton_fontColor_clicked()
  87. {
  88. QColor new_color = QColorDialog::getColor(m_fontColor, this);
  89. if(new_color.isValid())
  90. {
  91. m_fontColor = new_color;
  92. 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())));
  93. }
  94. }
  95. void OptionsDialog::on_pushButton_linkColor_clicked()
  96. {
  97. QColor new_color = QColorDialog::getColor(m_linkColor, this);
  98. if(new_color.isValid())
  99. {
  100. m_linkColor = new_color;
  101. 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())));
  102. }
  103. }
  104. void OptionsDialog::on_pushButton_cancel_clicked()
  105. {
  106. close();
  107. }
  108. void OptionsDialog::on_pushButton_ok_clicked()
  109. {
  110. if(this->parent() == 0)
  111. {
  112. close();
  113. return;
  114. }
  115. MainWindow *mw = qobject_cast<MainWindow*>(this->parent());
  116. mw->SetUseFontSize(ui->checkBox_fontSize->isChecked());
  117. mw->SetFontSize(ui->spinBox_fontSize->value());
  118. mw->SetUseFont(ui->checkBox_font->isChecked());
  119. if(ui->checkBox_font->isChecked())
  120. mw->SetFont(m_font);
  121. mw->SetUseBackColor(ui->checkBox_backColor->isChecked());
  122. mw->SetUseLinkColor(ui->checkBox_linkColor->isChecked());
  123. mw->SetUseFontColor(ui->checkBox_fontColor->isChecked());
  124. if(ui->checkBox_backColor->isChecked())
  125. mw->SetBackgroundColor(m_backColor);
  126. if(ui->checkBox_linkColor->isChecked())
  127. mw->SetLinkColor(m_linkColor);
  128. if(ui->checkBox_fontColor->isChecked())
  129. mw->SetForegroundColor(m_fontColor);
  130. mw->SetDisableVideo(ui->checkBox_disableVideo->isChecked());
  131. mw->SetPerGameConfig(ui->checkBox_perGameConfig->isChecked());
  132. mw->SetAutostart(ui->checkBox_autostart->isChecked());
  133. mw->SetVideoFix(ui->checkBox_videoFix->isChecked());
  134. mw->SetAllowHTML5Extras(ui->checkBox_HTML5Extras->isChecked());
  135. if(ui->comboBox_language->count() > 0)
  136. mw->SetLangID(ui->comboBox_language->itemData(ui->comboBox_language->currentIndex()).toString());
  137. if(mw->GetOverallVolume() != ui->horizontalSlider_volume->value() / 100)
  138. mw->SetOverallVolume(ui->horizontalSlider_volume->value() / 100);
  139. close();
  140. }