Typica is a free program for professional coffee roasters. https://typica.us
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

graphsettings.w 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. @* Graph widget configuration.
  2. \noindent There are many features of the graph in Typica which ought to be
  3. configurable. Most of these cannot be configured until changes are made to the
  4. graph widget. The original motivation for the class comes from a need to
  5. configure secondary axes.
  6. @<Class declarations@>=
  7. class GraphSettingsWidget : public QWidget@/
  8. {@/
  9. @[Q_OBJECT@]@;
  10. public:@/
  11. GraphSettingsWidget();
  12. };
  13. @ At present there are three types of data that the graph might present. This
  14. will likely be expanded as support for additional unit types are added.
  15. Different measurement categories are presently organized into different tabs.
  16. This will potentially need to change later as more features are added and the
  17. tab set becomes excessively large but for now this is the best that I can
  18. think of. If anybody with UI design experience would like to propose something
  19. better I would be glad to consider it.
  20. @s GraphSettingsRelativeTab int
  21. @<GraphSettingsWidget implementation@>=
  22. GraphSettingsWidget::GraphSettingsWidget() : QWidget(NULL)
  23. {
  24. QTabWidget *graphCategories = new QTabWidget;
  25. GraphSettingsRelativeTab *relative = new GraphSettingsRelativeTab;
  26. graphCategories->addTab(relative, tr("Relative Temperatures"));
  27. QVBoxLayout *layout = new QVBoxLayout;
  28. layout->addWidget(graphCategories);
  29. setLayout(layout);
  30. }
  31. @ Relative temperature measurements are different from the absolute temperature
  32. measurements that fall on the primary axis in that it is likely that negative
  33. values will be presented. These may be important and should not be hidden off
  34. the bottom of the graph, but the most important values will be in a relatively
  35. small range of positive values. The particulars will depend on the settings
  36. used to construct the relative values and the style of coffee roasting. It is
  37. also possible to disable the graphing of relative temperature measurements.
  38. @<Class declarations@>=
  39. class GraphSettingsRelativeTab : public QWidget@/
  40. {@/
  41. @[Q_OBJECT@]@;
  42. public:@/
  43. GraphSettingsRelativeTab();@/
  44. @[public slots@]:@/
  45. void updateEnableSetting(bool enable);
  46. void updateColorSetting(const QString &color);
  47. void updateAxisSetting(const QString &gridList);
  48. void updateUnit(int unit);
  49. void showColorPicker();@/
  50. private:@/
  51. QLineEdit *colorEdit;
  52. };
  53. @ The constructor sets up the interface and restores any previous values from
  54. settings.
  55. @<GraphSettingsWidget implementation@>=
  56. GraphSettingsRelativeTab::GraphSettingsRelativeTab() : QWidget(NULL),
  57. colorEdit(new QLineEdit)
  58. {
  59. QSettings settings;
  60. QVBoxLayout *layout = new QVBoxLayout;
  61. QCheckBox *enable = new QCheckBox(tr("Graph relative temperatures"));
  62. enable->setChecked(settings.value("settings/graph/relative/enable", true).toBool());
  63. updateEnableSetting(enable->isChecked());
  64. connect(enable, SIGNAL(toggled(bool)), this, SLOT(updateEnableSetting(bool)));
  65. layout->addWidget(enable);
  66. QHBoxLayout *colorLayout = new QHBoxLayout;
  67. QLabel *colorLabel = new QLabel(tr("Axis color:"));
  68. colorEdit->setText(settings.value("settings/graph/relative/color", "#000000").toString());
  69. updateColorSetting(colorEdit->text());
  70. connect(colorEdit, SIGNAL(textChanged(QString)), this, SLOT(updateColorSetting(QString)));
  71. QToolButton *colorPickerButton = new QToolButton();
  72. colorPickerButton->setIcon(QIcon::fromTheme("applications-graphics"));
  73. connect(colorPickerButton, SIGNAL(clicked()), this, SLOT(showColorPicker()));
  74. colorLayout->addWidget(colorLabel);
  75. colorLayout->addWidget(colorEdit);
  76. colorLayout->addWidget(colorPickerButton);
  77. colorLayout->addStretch();
  78. layout->addLayout(colorLayout);
  79. QHBoxLayout *unitLayout = new QHBoxLayout;
  80. QLabel *unitLabel = new QLabel(tr("Unit"));
  81. QComboBox *unitSelector = new QComboBox;
  82. unitSelector->addItem(tr("Fahrenheit"));
  83. unitSelector->addItem(tr("Celsius"));
  84. unitSelector->setCurrentIndex(settings.value("settings/graph/relative/unit", 0).toInt());
  85. updateUnit(unitSelector->currentIndex());
  86. connect(unitSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUnit(int)));
  87. unitLayout->addWidget(unitLabel);
  88. unitLayout->addWidget(unitSelector);
  89. unitLayout->addStretch();
  90. layout->addLayout(unitLayout);
  91. QHBoxLayout *axisLayout = new QHBoxLayout;
  92. QLabel *axisLabel = new QLabel(tr("Grid line positions (comma separated):"));
  93. QLineEdit *axisEdit = new QLineEdit;
  94. axisEdit->setText(settings.value("settings/graph/relative/grid", "-300, -100, -10, 0, 10, 30, 50").toString());
  95. updateAxisSetting(axisEdit->text());
  96. connect(axisEdit, SIGNAL(textChanged(QString)), this, SLOT(updateAxisSetting(QString)));
  97. axisLayout->addWidget(axisLabel);
  98. axisLayout->addWidget(axisEdit);
  99. layout->addLayout(axisLayout);
  100. layout->addStretch();
  101. setLayout(layout);
  102. }
  103. @ A set of methods updates the settings as they are adjusted.
  104. @<GraphSettingsWidget implementation@>=
  105. void GraphSettingsRelativeTab::updateEnableSetting(bool enabled)
  106. {
  107. QSettings settings;
  108. settings.setValue("settings/graph/relative/enable", enabled);
  109. }
  110. void GraphSettingsRelativeTab::updateColorSetting(const QString &color)
  111. {
  112. QSettings settings;
  113. settings.setValue("settings/graph/relative/color", color);
  114. }
  115. void GraphSettingsRelativeTab::updateAxisSetting(const QString &gridList)
  116. {
  117. QSettings settings;
  118. QString settingValue;
  119. QStringList points = gridList.split(QRegExp("[\\s,]+"), QString::SkipEmptyParts);
  120. QStringList numbers;
  121. foreach(QString text, points)
  122. {
  123. bool okay = @[false@];
  124. text.toDouble(&okay);
  125. if(okay)
  126. {
  127. numbers.append(text);
  128. }
  129. }
  130. numbers.removeDuplicates();
  131. settings.setValue("settings/graph/relative/grid", numbers.join(","));
  132. }
  133. void GraphSettingsRelativeTab::updateUnit(int unit)
  134. {
  135. QSettings settings;
  136. settings.setValue("settings/graph/relative/unit", unit);
  137. }
  138. @ When selecting a color, it is possible to either type the color into the line
  139. edit directly or use a color picker to select the color graphically. A tool
  140. button displays a color picker and pushes the selected color into the line edit
  141. which in turn updates the setting.
  142. @<GraphSettingsWidget implementation@>=
  143. void GraphSettingsRelativeTab::showColorPicker()
  144. {
  145. QColor color = QColorDialog::getColor(QColor(colorEdit->text()), this);
  146. colorEdit->setText(color.name());
  147. }