2016-10-05 18:37:48 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
|
|
|
Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
#include "styles/style_widgets.h"
|
|
|
|
|
2016-10-05 18:37:48 +00:00
|
|
|
namespace Ui {
|
|
|
|
|
2016-12-02 19:16:35 +00:00
|
|
|
class RippleAnimation;
|
|
|
|
|
2016-10-05 18:37:48 +00:00
|
|
|
class DiscreteSlider : public TWidget {
|
|
|
|
public:
|
|
|
|
DiscreteSlider(QWidget *parent);
|
|
|
|
|
2016-10-06 16:41:09 +00:00
|
|
|
void addSection(const QString &label);
|
2016-11-22 09:48:13 +00:00
|
|
|
void setSections(const QStringList &labels);
|
2016-10-05 18:37:48 +00:00
|
|
|
int activeSection() const {
|
|
|
|
return _activeIndex;
|
|
|
|
}
|
|
|
|
void setActiveSection(int index);
|
|
|
|
void setActiveSectionFast(int index);
|
2016-10-06 16:41:09 +00:00
|
|
|
|
2016-11-20 12:54:07 +00:00
|
|
|
using SectionActivatedCallback = base::lambda<void()>;
|
2016-10-06 16:41:09 +00:00
|
|
|
void setSectionActivatedCallback(SectionActivatedCallback &&callback);
|
2016-10-05 18:37:48 +00:00
|
|
|
|
|
|
|
protected:
|
2016-12-02 19:16:35 +00:00
|
|
|
void timerEvent(QTimerEvent *e) override;
|
2016-10-05 18:37:48 +00:00
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
int resizeGetHeight(int newWidth) override = 0;
|
2016-10-05 18:37:48 +00:00
|
|
|
|
|
|
|
struct Section {
|
2016-11-22 09:48:13 +00:00
|
|
|
Section(const QString &label, const style::font &font);
|
2016-10-05 18:37:48 +00:00
|
|
|
|
|
|
|
int left, width;
|
|
|
|
QString label;
|
|
|
|
int labelWidth;
|
2016-12-02 19:16:35 +00:00
|
|
|
QSharedPointer<RippleAnimation> ripple;
|
2016-10-05 18:37:48 +00:00
|
|
|
};
|
2016-11-22 09:48:13 +00:00
|
|
|
|
2016-12-01 19:20:33 +00:00
|
|
|
int getCurrentActiveLeft(TimeMs ms);
|
2016-11-22 09:48:13 +00:00
|
|
|
|
|
|
|
int getSectionsCount() const {
|
|
|
|
return _sections.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Lambda>
|
|
|
|
void enumerateSections(Lambda callback);
|
|
|
|
|
2016-12-02 19:16:35 +00:00
|
|
|
virtual void startRipple(int index) {
|
|
|
|
}
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
void stopAnimation() {
|
|
|
|
_a_left.finish();
|
|
|
|
}
|
|
|
|
|
2016-12-02 19:16:35 +00:00
|
|
|
void setSelectOnPress(bool selectOnPress);
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
private:
|
2016-12-02 19:16:35 +00:00
|
|
|
void activateCallback();
|
2016-11-22 09:48:13 +00:00
|
|
|
virtual const style::font &getLabelFont() const = 0;
|
|
|
|
virtual int getAnimationDuration() const = 0;
|
|
|
|
|
|
|
|
int getIndexFromPosition(QPoint pos);
|
|
|
|
void setSelectedSection(int index);
|
|
|
|
|
2016-10-05 18:37:48 +00:00
|
|
|
QList<Section> _sections;
|
|
|
|
int _activeIndex = 0;
|
2016-11-22 09:48:13 +00:00
|
|
|
bool _selectOnPress = true;
|
2016-10-05 18:37:48 +00:00
|
|
|
|
2016-10-06 16:41:09 +00:00
|
|
|
SectionActivatedCallback _callback;
|
|
|
|
|
2016-12-05 08:45:56 +00:00
|
|
|
int _pressed = -1;
|
2016-10-05 18:37:48 +00:00
|
|
|
int _selected = 0;
|
2016-12-07 13:32:25 +00:00
|
|
|
Animation _a_left;
|
2016-11-22 09:48:13 +00:00
|
|
|
|
2016-12-02 19:16:35 +00:00
|
|
|
int _timerId = -1;
|
|
|
|
TimeMs _callbackAfterMs = 0;
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SettingsSlider : public DiscreteSlider {
|
|
|
|
public:
|
|
|
|
SettingsSlider(QWidget *parent, const style::SettingsSlider &st = st::defaultSettingsSlider);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
int resizeGetHeight(int newWidth) override;
|
|
|
|
|
2016-12-02 19:16:35 +00:00
|
|
|
void startRipple(int index) override;
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
private:
|
|
|
|
const style::font &getLabelFont() const override;
|
|
|
|
int getAnimationDuration() const override;
|
|
|
|
|
|
|
|
void resizeSections(int newWidth);
|
|
|
|
|
|
|
|
const style::SettingsSlider &_st;
|
2016-10-05 18:37:48 +00:00
|
|
|
|
2016-12-02 19:16:35 +00:00
|
|
|
|
2016-10-05 18:37:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Ui
|