datetimedialog.cpp 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. #include "datetimedialog.h"
  2. void DateTimeDialog::setPaneContents() {
  3. mContentsWidget = new QWidget();
  4. QVBoxLayout* contentsLayout = new QVBoxLayout(mContentsWidget);
  5. mContentsWidget->setObjectName("innerPane");
  6. // Adding widgets
  7. QHBoxLayout* timeFormatLayout = new QHBoxLayout();
  8. QLabel* timeFormatLabel = new QLabel(tr("Time Format"));
  9. timeFormatLabel->setFont(mTitleFont);
  10. timeFormatLayout->addWidget(timeFormatLabel);
  11. QLineEdit* timeFormatLineEdit = new QLineEdit();
  12. timeFormatLineEdit->setFont(mFont);
  13. timeFormatLineEdit->setToolTip("h - 0~23, 1-12\n"
  14. "hh - 00~23, 01-12\n"
  15. "m - 0~59\n"
  16. "mm - 00~59\n"
  17. "s - 0~59\n"
  18. "ss - 00~59\n"
  19. "AP - AM/PM\n"
  20. "t - timezone");
  21. timeFormatLayout->addWidget(timeFormatLineEdit);
  22. contentsLayout->addLayout(timeFormatLayout);
  23. QCheckBox* showDateCheckBox = new QCheckBox(tr("Show date"));
  24. showDateCheckBox->setFont(mTitleFont);
  25. contentsLayout->addWidget(showDateCheckBox);
  26. QHBoxLayout* dateFormatLayout = new QHBoxLayout();
  27. QLabel* dateFormatLabel = new QLabel(tr("Date Format"));
  28. dateFormatLabel->setFont(mTitleFont);
  29. dateFormatLayout->addWidget(dateFormatLabel);
  30. QLineEdit* dateFormatLineEdit = new QLineEdit();
  31. dateFormatLineEdit->setFont(mFont);
  32. dateFormatLineEdit->setToolTip("d - 1~31\n"
  33. "dd - 01~31\n"
  34. "ddd - Mon~Sun\n"
  35. "M - 1~12\n"
  36. "MM 01~12\n"
  37. "MMM - Jan~Dec\n"
  38. "yy - 00~99\n"
  39. "yyyy - 1970-9999");
  40. dateFormatLayout->addWidget(dateFormatLineEdit);
  41. contentsLayout->addLayout(dateFormatLayout);
  42. QCheckBox* weekNumbersCheckBox = new QCheckBox(tr("Show Week Numbers"));
  43. weekNumbersCheckBox->setFont(mTitleFont);
  44. contentsLayout->addWidget(weekNumbersCheckBox);
  45. QLabel* firstDayOfWeekLabel = new QLabel(tr("First Day of Week"));
  46. firstDayOfWeekLabel->setFont(mTitleFont);
  47. contentsLayout->addWidget(firstDayOfWeekLabel);
  48. QRadioButton* mondayRadioButton = new QRadioButton(tr("Monday"));
  49. mondayRadioButton->setFont(mFont);
  50. mondayRadioButton->setChecked(true);
  51. contentsLayout->addWidget(mondayRadioButton);
  52. QRadioButton* tuesdayRadioButton = new QRadioButton(tr("Tuesday"));
  53. tuesdayRadioButton->setFont(mFont);
  54. contentsLayout->addWidget(tuesdayRadioButton);
  55. QRadioButton* wednesdayRadioButton = new QRadioButton(tr("Wednesday"));
  56. wednesdayRadioButton->setFont(mFont);
  57. contentsLayout->addWidget(wednesdayRadioButton);
  58. QRadioButton* thursdayRadioButton = new QRadioButton(tr("Thursday"));
  59. thursdayRadioButton->setFont(mFont);
  60. contentsLayout->addWidget(thursdayRadioButton);
  61. QRadioButton* fridayRadioButton = new QRadioButton(tr("Friday"));
  62. fridayRadioButton->setFont(mFont);
  63. contentsLayout->addWidget(fridayRadioButton);
  64. QRadioButton* saturdayRadioButton = new QRadioButton(tr("Saturday"));
  65. saturdayRadioButton->setFont(mFont);
  66. contentsLayout->addWidget(saturdayRadioButton);
  67. QRadioButton* sundayRadioButton = new QRadioButton(tr("Sunday"));
  68. sundayRadioButton->setFont(mFont);
  69. contentsLayout->addWidget(sundayRadioButton);
  70. contentsLayout->addSpacerItem(new QSpacerItem(0, 0,
  71. QSizePolicy::Ignored,
  72. QSizePolicy::MinimumExpanding));
  73. QHBoxLayout* buttonsLayout = new QHBoxLayout();
  74. buttonsLayout->addSpacerItem(new QSpacerItem(0, 0,
  75. QSizePolicy::MinimumExpanding,
  76. QSizePolicy::Ignored));
  77. QPushButton* cancelButton = new QPushButton(tr("Cancel"));
  78. cancelButton->setFont(mFont);
  79. buttonsLayout->addWidget(cancelButton);
  80. QPushButton* okButton = new QPushButton(tr("OK"));
  81. okButton->setFont(mFont);
  82. buttonsLayout->addWidget(okButton);
  83. contentsLayout->addLayout(buttonsLayout);
  84. // Making connections
  85. connect(cancelButton, &QPushButton::clicked, this, [this]() {
  86. this->hide();
  87. delete this;
  88. });
  89. connect(okButton, &QPushButton::clicked, this, [this, timeFormatLineEdit, showDateCheckBox,
  90. dateFormatLineEdit, weekNumbersCheckBox,
  91. mondayRadioButton, tuesdayRadioButton,
  92. wednesdayRadioButton, thursdayRadioButton,
  93. fridayRadioButton, saturdayRadioButton]() {
  94. prepareToSave(timeFormatLineEdit, showDateCheckBox,
  95. dateFormatLineEdit, weekNumbersCheckBox,
  96. mondayRadioButton, tuesdayRadioButton,
  97. wednesdayRadioButton, thursdayRadioButton,
  98. fridayRadioButton, saturdayRadioButton);
  99. saveConfig();
  100. this->hide();
  101. delete this;
  102. });
  103. connect(showDateCheckBox, &QCheckBox::stateChanged, this, [this, showDateCheckBox,
  104. dateFormatLineEdit, dateFormatLabel]() {
  105. dateFormatLabel->setVisible(showDateCheckBox->isChecked());
  106. dateFormatLineEdit->setVisible(showDateCheckBox->isChecked());
  107. });
  108. // Setting current settings
  109. timeFormatLineEdit->setText(getConfigValue("timeFormat").toString());
  110. showDateCheckBox->setChecked(getConfigValue("showDate").toBool());
  111. dateFormatLineEdit->setText(getConfigValue("dateFormat").toString());
  112. weekNumbersCheckBox->setChecked(getConfigValue("showWeekNumbers").toBool());
  113. int firstDayOfWeek = getConfigValue("firstDayOfWeek").toInt();
  114. switch (firstDayOfWeek) {
  115. case 1:
  116. mondayRadioButton->setChecked(true);
  117. break;
  118. case 2:
  119. tuesdayRadioButton->setChecked(true);
  120. break;
  121. case 3:
  122. wednesdayRadioButton->setChecked(true);
  123. break;
  124. case 4:
  125. thursdayRadioButton->setChecked(true);
  126. break;
  127. case 5:
  128. fridayRadioButton->setChecked(true);
  129. break;
  130. case 6:
  131. saturdayRadioButton->setChecked(true);
  132. break;
  133. case 7:
  134. sundayRadioButton->setChecked(true);
  135. break;
  136. default:
  137. break;
  138. }
  139. finalizeUI();
  140. setWindowGeometry();
  141. setTransparency(this);
  142. }
  143. void DateTimeDialog::prepareToSave(QLineEdit* timeFormatLineEdit,
  144. QCheckBox* showDateCheckBox,
  145. QLineEdit* dateFormatLineEdit,
  146. QCheckBox* weekNumbersCheckBox,
  147. QRadioButton* mondayRadioButton,
  148. QRadioButton* tuesdayRadioButton,
  149. QRadioButton* wednesdayRadioButton,
  150. QRadioButton* thursdayRadioButton,
  151. QRadioButton* fridayRadioButton,
  152. QRadioButton* saturdayRadioButton) {
  153. setEntry("timeFormat", timeFormatLineEdit->text());
  154. setEntry("showDate", showDateCheckBox->isChecked());
  155. setEntry("dateFormat", dateFormatLineEdit->text());
  156. setEntry("showWeekNumbers", weekNumbersCheckBox->isChecked());
  157. int firstDayOfWeek;
  158. if (mondayRadioButton->isChecked()) {
  159. firstDayOfWeek = 1;
  160. }
  161. else if (tuesdayRadioButton->isChecked()) {
  162. firstDayOfWeek = 2;
  163. }
  164. else if (wednesdayRadioButton->isChecked()) {
  165. firstDayOfWeek = 3;
  166. }
  167. else if (thursdayRadioButton->isChecked()) {
  168. firstDayOfWeek = 4;
  169. }
  170. else if (fridayRadioButton->isChecked()) {
  171. firstDayOfWeek = 5;
  172. }
  173. else if (saturdayRadioButton->isChecked()) {
  174. firstDayOfWeek = 6;
  175. }
  176. else { // Sunday
  177. firstDayOfWeek = 7;
  178. }
  179. setEntry("firstDayOfWeek", firstDayOfWeek);
  180. }
  181. DateTimeDialog::DateTimeDialog(QJsonObject* cfgObj) : Dialog(cfgObj,
  182. tr("Date & Time applet settings"),
  183. "calendar") {
  184. }