Added mouse click support to point details widget.
This commit is contained in:
parent
eb0ab9609f
commit
fcc6aaed91
|
@ -1125,7 +1125,8 @@ void ChartWidget::setupDetails() {
|
|||
_details.widget = base::make_unique_q<PointDetailsWidget>(
|
||||
this,
|
||||
_chartData,
|
||||
maxAbsoluteValue);
|
||||
maxAbsoluteValue,
|
||||
false);
|
||||
|
||||
_details.widget->shownValue(
|
||||
) | rpl::start_with_next([=](bool shown) {
|
||||
|
|
|
@ -33,8 +33,10 @@ namespace {
|
|||
PointDetailsWidget::PointDetailsWidget(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
const Data::StatisticalChart &chartData,
|
||||
float64 maxAbsoluteValue)
|
||||
: Ui::RpWidget(parent)
|
||||
float64 maxAbsoluteValue,
|
||||
bool zoomEnabled)
|
||||
: Ui::AbstractButton(parent)
|
||||
, _zoomEnabled(zoomEnabled)
|
||||
, _chartData(chartData)
|
||||
, _textStyle(st::statisticsDetailsPopupStyle)
|
||||
, _headerStyle(st::semiboldTextStyle)
|
||||
|
@ -118,6 +120,7 @@ void PointDetailsWidget::setXIndex(int xIndex) {
|
|||
|
||||
_lines.clear();
|
||||
_lines.reserve(_chartData.lines.size());
|
||||
auto hasPositiveValues = false;
|
||||
for (const auto &dataLine : _chartData.lines) {
|
||||
auto textLine = Line();
|
||||
textLine.id = dataLine.id;
|
||||
|
@ -125,9 +128,14 @@ void PointDetailsWidget::setXIndex(int xIndex) {
|
|||
textLine.value.setText(
|
||||
_textStyle,
|
||||
QString("%L1").arg(dataLine.y[xIndex]));
|
||||
hasPositiveValues |= (dataLine.y[xIndex] > 0);
|
||||
textLine.valueColor = QColor(dataLine.color);
|
||||
_lines.push_back(std::move(textLine));
|
||||
}
|
||||
const auto clickable = _zoomEnabled && hasPositiveValues;
|
||||
setAttribute(
|
||||
Qt::WA_TransparentForMouseEvents,
|
||||
!clickable);
|
||||
}
|
||||
|
||||
void PointDetailsWidget::setAlpha(float64 alpha) {
|
||||
|
|
|
@ -8,16 +8,17 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#pragma once
|
||||
|
||||
#include "data/data_statistics.h"
|
||||
#include "ui/rp_widget.h"
|
||||
#include "ui/abstract_button.h"
|
||||
|
||||
namespace Statistic {
|
||||
|
||||
class PointDetailsWidget : public Ui::RpWidget {
|
||||
class PointDetailsWidget : public Ui::AbstractButton {
|
||||
public:
|
||||
PointDetailsWidget(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
const Data::StatisticalChart &chartData,
|
||||
float64 maxAbsoluteValue);
|
||||
float64 maxAbsoluteValue,
|
||||
bool zoomEnabled);
|
||||
|
||||
[[nodiscard]] int xIndex() const;
|
||||
void setXIndex(int xIndex);
|
||||
|
@ -28,6 +29,7 @@ protected:
|
|||
void paintEvent(QPaintEvent *e) override;
|
||||
|
||||
private:
|
||||
const bool _zoomEnabled;
|
||||
const Data::StatisticalChart &_chartData;
|
||||
const style::TextStyle &_textStyle;
|
||||
const style::TextStyle &_headerStyle;
|
||||
|
|
Loading…
Reference in New Issue