2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2014-12-01 10:47:38 +00:00
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2015-10-03 13:16:42 +00:00
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2016-02-08 10:56:18 +00:00
|
|
|
Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2016-04-07 18:05:28 +00:00
|
|
|
#include "ui/twidget.h"
|
2016-10-01 12:34:23 +00:00
|
|
|
#include "ui/effects/rect_shadow.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-12-08 12:33:37 +00:00
|
|
|
class Dropdown : public TWidget {
|
2014-05-30 08:53:19 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2015-04-11 10:04:10 +00:00
|
|
|
Dropdown(QWidget *parent, const style::dropdown &st = st::dropdownDef);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
IconedButton *addButton(IconedButton *button);
|
2014-08-21 12:18:56 +00:00
|
|
|
void resetButtons();
|
2015-04-11 10:04:10 +00:00
|
|
|
void updateButtons();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
void resizeEvent(QResizeEvent *e);
|
|
|
|
void paintEvent(QPaintEvent *e);
|
|
|
|
|
|
|
|
void enterEvent(QEvent *e);
|
|
|
|
void leaveEvent(QEvent *e);
|
2015-04-11 10:04:10 +00:00
|
|
|
void keyPressEvent(QKeyEvent *e);
|
2014-05-30 08:53:19 +00:00
|
|
|
void otherEnter();
|
|
|
|
void otherLeave();
|
|
|
|
|
|
|
|
void fastHide();
|
2015-04-11 10:04:10 +00:00
|
|
|
void ignoreShow(bool ignore = true);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-12-08 12:33:37 +00:00
|
|
|
void step_appearance(float64 ms, bool timer);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
bool eventFilter(QObject *obj, QEvent *e);
|
|
|
|
|
2015-10-01 14:05:05 +00:00
|
|
|
bool overlaps(const QRect &globalRect) {
|
2015-12-08 12:33:37 +00:00
|
|
|
if (isHidden() || _a_appearance.animating()) return false;
|
2015-10-01 14:05:05 +00:00
|
|
|
|
|
|
|
return QRect(_st.padding.left(),
|
|
|
|
_st.padding.top(),
|
|
|
|
_width - _st.padding.left() - _st.padding.right(),
|
|
|
|
_height - _st.padding.top() - _st.padding.bottom()
|
|
|
|
).contains(QRect(mapFromGlobal(globalRect.topLeft()), globalRect.size()));
|
|
|
|
}
|
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
signals:
|
|
|
|
void hiding();
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
public slots:
|
|
|
|
void hideStart();
|
|
|
|
void hideFinish();
|
|
|
|
|
|
|
|
void showStart();
|
2015-02-09 13:26:59 +00:00
|
|
|
void onWndActiveChanged();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
void buttonStateChanged(int oldState, ButtonStateChangeSource source);
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
private:
|
|
|
|
void adjustButtons();
|
|
|
|
|
2016-09-09 15:52:46 +00:00
|
|
|
bool _ignore = false;
|
2015-04-11 10:04:10 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
typedef QVector<IconedButton*> Buttons;
|
|
|
|
Buttons _buttons;
|
|
|
|
|
2016-09-09 15:52:46 +00:00
|
|
|
int32 _selected = -1;
|
2015-04-11 10:04:10 +00:00
|
|
|
|
|
|
|
const style::dropdown &_st;
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
int32 _width, _height;
|
2016-09-09 15:52:46 +00:00
|
|
|
bool _hiding = false;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
anim::fvalue a_opacity;
|
2015-12-08 12:33:37 +00:00
|
|
|
Animation _a_appearance;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
QTimer _hideTimer;
|
|
|
|
|
2016-10-01 12:34:23 +00:00
|
|
|
Ui::RectShadow _shadow;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2015-12-08 12:33:37 +00:00
|
|
|
class DragArea : public TWidget {
|
2014-05-30 08:53:19 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
DragArea(QWidget *parent);
|
|
|
|
|
|
|
|
void setText(const QString &text, const QString &subtext);
|
|
|
|
|
|
|
|
void otherEnter();
|
|
|
|
void otherLeave();
|
|
|
|
|
|
|
|
void fastHide();
|
|
|
|
|
2015-12-08 12:33:37 +00:00
|
|
|
void step_appearance(float64 ms, bool timer);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-10-01 14:05:05 +00:00
|
|
|
bool overlaps(const QRect &globalRect) {
|
2015-12-08 12:33:37 +00:00
|
|
|
if (isHidden() || _a_appearance.animating()) return false;
|
2015-10-01 14:05:05 +00:00
|
|
|
|
|
|
|
return QRect(st::dragPadding.left(),
|
|
|
|
st::dragPadding.top(),
|
|
|
|
width() - st::dragPadding.left() - st::dragPadding.right(),
|
|
|
|
height() - st::dragPadding.top() - st::dragPadding.bottom()
|
|
|
|
).contains(QRect(mapFromGlobal(globalRect.topLeft()), globalRect.size()));
|
|
|
|
}
|
|
|
|
|
2016-10-01 12:34:23 +00:00
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
|
|
|
void dragEnterEvent(QDragEnterEvent *e) override;
|
|
|
|
void dragLeaveEvent(QDragLeaveEvent *e) override;
|
|
|
|
void dropEvent(QDropEvent *e) override;
|
|
|
|
void dragMoveEvent(QDragMoveEvent *e) override;
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
signals:
|
2015-06-26 09:07:59 +00:00
|
|
|
void dropped(const QMimeData *data);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void hideStart();
|
|
|
|
void hideFinish();
|
|
|
|
|
|
|
|
void showStart();
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool _hiding, _in;
|
|
|
|
|
|
|
|
anim::fvalue a_opacity;
|
|
|
|
anim::cvalue a_color;
|
2015-12-08 12:33:37 +00:00
|
|
|
Animation _a_appearance;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-10-01 12:34:23 +00:00
|
|
|
Ui::RectShadow _shadow;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
QString _text, _subtext;
|
|
|
|
|
|
|
|
};
|