|
4 | 4 | * |
5 | 5 | */ |
6 | 6 |
|
7 | | -#include <QMessageBox> |
8 | | -#include <QVBoxLayout> |
9 | | -#include <QLabel> |
10 | | -#include <QPushButton> |
| 7 | +#include <QMessageBox> |
| 8 | +#include <QHBoxLayout> |
| 9 | +#include <QVBoxLayout> |
| 10 | +#include <QLabel> |
| 11 | +#include <QPushButton> |
| 12 | +#include <QLineEdit> |
11 | 13 | #include "CommonFramework/Globals.h" |
12 | 14 | #include "CommonFramework/Options/Environment/ThemeSelectorOption.h" |
13 | 15 | #include "PanelElements.h" |
@@ -97,44 +99,84 @@ CollapsibleGroupBox* make_panel_header( |
97 | 99 |
|
98 | 100 |
|
99 | 101 |
|
100 | | -StatsBar::StatsBar(QWidget& parent) |
101 | | - : QLabel(&parent) |
102 | | -{ |
103 | | - this->setWordWrap(true); |
104 | | - this->setVisible(false); |
105 | | - this->setAlignment(Qt::AlignCenter); |
106 | | -// this->setText("<b>Encounters: 1,267 - Corrections: 0 - Star Shinies: 1 - Square Shinies: 0</b>"); |
107 | | - QFont font = this->font(); |
108 | | - font.setPointSize(10); |
109 | | - this->setFont(font); |
110 | | -} |
111 | | -void StatsBar::set_stats(std::string current_stats, std::string historical_stats){ |
112 | | - if (current_stats.empty() && historical_stats.empty()){ |
113 | | - this->setText(""); |
114 | | - this->setVisible(false); |
115 | | - return; |
116 | | - } |
117 | | - |
118 | | - if (!current_stats.empty() && historical_stats.empty()){ |
119 | | - this->setText(QString::fromStdString(current_stats)); |
120 | | - this->setVisible(true); |
121 | | - return; |
122 | | - } |
123 | | - |
124 | | - if (current_stats.empty() && !historical_stats.empty()){ |
125 | | - this->setText(QString::fromStdString("<b>Past Runs</b> - " + historical_stats)); |
126 | | - this->setVisible(true); |
127 | | - return; |
128 | | - } |
129 | | - |
130 | | - std::string str; |
131 | | - str += "<b>Current Run</b> - " + current_stats; |
132 | | - str += "<br>"; |
133 | | - str += "<b>Past Totals</b> - " + historical_stats; |
134 | | - |
135 | | - this->setText(QString::fromStdString(str)); |
136 | | - this->setVisible(true); |
137 | | -} |
| 102 | +StatsBar::StatsBar(QWidget& parent) |
| 103 | + : QWidget(&parent) |
| 104 | +{ |
| 105 | + QVBoxLayout* layout = new QVBoxLayout(this); |
| 106 | + layout->setContentsMargins(0, 0, 0, 0); |
| 107 | + layout->setSpacing(4); |
| 108 | + |
| 109 | + QFont font = this->font(); |
| 110 | + font.setPointSize(10); |
| 111 | + |
| 112 | + { |
| 113 | + QHBoxLayout* row = new QHBoxLayout(); |
| 114 | + row->setContentsMargins(0, 0, 0, 0); |
| 115 | + row->setSpacing(6); |
| 116 | + |
| 117 | + m_current_label = new QLabel("Current Run:", this); |
| 118 | + m_current_label->setFont(font); |
| 119 | + row->addWidget(m_current_label); |
| 120 | + |
| 121 | + m_current_stats = new QLineEdit(this); |
| 122 | + m_current_stats->setFont(font); |
| 123 | + row->addWidget(m_current_stats, 1); |
| 124 | + |
| 125 | + layout->addLayout(row); |
| 126 | + } |
| 127 | + |
| 128 | + { |
| 129 | + QHBoxLayout* row = new QHBoxLayout(); |
| 130 | + row->setContentsMargins(0, 0, 0, 0); |
| 131 | + row->setSpacing(6); |
| 132 | + |
| 133 | + m_historical_label = new QLabel("Past Totals:", this); |
| 134 | + m_historical_label->setFont(font); |
| 135 | + row->addWidget(m_historical_label); |
| 136 | + |
| 137 | + m_historical_stats = new QLineEdit(this); |
| 138 | + m_historical_stats->setFont(font); |
| 139 | + row->addWidget(m_historical_stats, 1); |
| 140 | + |
| 141 | + layout->addLayout(row); |
| 142 | + } |
| 143 | + |
| 144 | + m_apply_button = new QPushButton("Apply Stats", this); |
| 145 | + m_apply_button->setFont(font); |
| 146 | + layout->addWidget(m_apply_button, 0, Qt::AlignRight); |
| 147 | + |
| 148 | + connect( |
| 149 | + m_current_stats, &QLineEdit::textEdited, |
| 150 | + this, [this](const QString&){ |
| 151 | + m_user_editing = true; |
| 152 | + } |
| 153 | + ); |
| 154 | + connect( |
| 155 | + m_historical_stats, &QLineEdit::textEdited, |
| 156 | + this, [this](const QString&){ |
| 157 | + m_user_editing = true; |
| 158 | + } |
| 159 | + ); |
| 160 | + connect( |
| 161 | + m_apply_button, &QPushButton::clicked, |
| 162 | + this, [this](bool){ |
| 163 | + m_user_editing = false; |
| 164 | + emit stats_edited( |
| 165 | + m_current_stats->text().toStdString(), |
| 166 | + m_historical_stats->text().toStdString() |
| 167 | + ); |
| 168 | + } |
| 169 | + ); |
| 170 | + |
| 171 | + this->setVisible(false); |
| 172 | +} |
| 173 | +void StatsBar::set_stats(std::string current_stats, std::string historical_stats){ |
| 174 | + if (!m_user_editing){ |
| 175 | + m_current_stats->setText(QString::fromStdString(current_stats)); |
| 176 | + m_historical_stats->setText(QString::fromStdString(historical_stats)); |
| 177 | + } |
| 178 | + this->setVisible(!current_stats.empty() || !historical_stats.empty() || m_user_editing); |
| 179 | +} |
138 | 180 |
|
139 | 181 |
|
140 | 182 |
|
|
0 commit comments