mirror-chatterino2/src/widgets/helper/notebooktab.hpp

155 lines
3.5 KiB
C++
Raw Normal View History

#pragma once
2016-12-29 17:31:07 +01:00
2017-12-26 12:30:32 +01:00
#include "common.hpp"
2017-08-13 16:10:53 +02:00
#include "widgets/basewidget.hpp"
#include <QMenu>
2017-01-22 12:46:35 +01:00
#include <QPropertyAnimation>
#include <pajlada/settings/setting.hpp>
#include <pajlada/signals/connection.hpp>
2016-12-29 17:31:07 +01:00
2017-01-18 21:30:23 +01:00
namespace chatterino {
namespace widgets {
2016-12-29 18:02:13 +01:00
class Notebook;
2018-04-18 09:12:29 +02:00
class Notebook2;
2017-11-12 17:21:50 +01:00
class SplitContainer;
2016-12-29 18:02:13 +01:00
2018-04-18 09:12:29 +02:00
class NotebookTab2 : public BaseWidget
{
Q_OBJECT
public:
explicit NotebookTab2(Notebook2 *_notebook);
void updateSize();
QWidget *page;
const QString &getTitle() const;
void setTitle(const QString &newTitle);
bool isSelected() const;
void setSelected(bool value);
void setHighlightState(HighlightState style);
void moveAnimated(QPoint pos, bool animated = true);
QRect getDesiredRect() const;
void hideTabXChanged(bool);
protected:
virtual void themeRefreshEvent() override;
virtual void paintEvent(QPaintEvent *) override;
virtual void mousePressEvent(QMouseEvent *event) override;
virtual void mouseReleaseEvent(QMouseEvent *event) override;
virtual void enterEvent(QEvent *) override;
virtual void leaveEvent(QEvent *) override;
virtual void dragEnterEvent(QDragEnterEvent *event) override;
virtual void mouseMoveEvent(QMouseEvent *event) override;
private:
std::vector<pajlada::Signals::ScopedConnection> managedConnections;
QPropertyAnimation positionChangedAnimation;
bool positionChangedAnimationRunning = false;
QPoint positionAnimationDesiredPoint;
Notebook2 *notebook;
QString title;
public:
bool useDefaultTitle = true;
private:
bool selected = false;
bool mouseOver = false;
bool mouseDown = false;
bool mouseOverX = false;
bool mouseDownX = false;
HighlightState highlightState = HighlightState::None;
QMenu menu;
QRect getXRect();
};
2017-08-13 16:10:53 +02:00
class NotebookTab : public BaseWidget
2016-12-29 17:31:07 +01:00
{
2017-01-11 18:52:09 +01:00
Q_OBJECT
2016-12-29 17:31:07 +01:00
public:
explicit NotebookTab(Notebook *_notebook);
2016-12-30 12:20:26 +01:00
2018-01-25 20:49:49 +01:00
void updateSize();
2016-12-30 18:00:25 +01:00
2017-11-12 17:21:50 +01:00
SplitContainer *page;
2016-12-30 18:00:25 +01:00
const QString &getTitle() const;
2017-08-13 16:07:00 +02:00
void setTitle(const QString &newTitle);
bool isSelected() const;
2017-04-12 17:46:44 +02:00
void setSelected(bool value);
2017-01-01 02:30:42 +01:00
void setHighlightState(HighlightState style);
2017-01-01 02:30:42 +01:00
2017-01-26 05:26:21 +01:00
void moveAnimated(QPoint pos, bool animated = true);
2017-04-12 17:46:44 +02:00
QRect getDesiredRect() const;
void hideTabXChanged(bool);
2017-02-02 02:46:33 +01:00
2016-12-30 12:20:26 +01:00
protected:
2018-01-25 20:49:49 +01:00
virtual void themeRefreshEvent() override;
2016-12-30 12:20:26 +01:00
2018-01-25 20:49:49 +01:00
virtual void paintEvent(QPaintEvent *) override;
2016-12-30 12:20:26 +01:00
2018-01-25 20:49:49 +01:00
virtual void mousePressEvent(QMouseEvent *event) override;
virtual void mouseReleaseEvent(QMouseEvent *event) override;
virtual void enterEvent(QEvent *) override;
virtual void leaveEvent(QEvent *) override;
2018-01-25 20:49:49 +01:00
virtual void dragEnterEvent(QDragEnterEvent *event) override;
virtual void mouseMoveEvent(QMouseEvent *event) override;
2017-01-01 02:30:42 +01:00
2016-12-29 17:31:07 +01:00
private:
std::vector<pajlada::Signals::ScopedConnection> managedConnections;
2017-02-02 02:46:33 +01:00
2017-08-13 16:07:00 +02:00
QPropertyAnimation positionChangedAnimation;
bool positionChangedAnimationRunning = false;
QPoint positionAnimationDesiredPoint;
2017-01-22 12:46:35 +01:00
2017-08-13 16:07:00 +02:00
Notebook *notebook;
2017-01-15 16:38:30 +01:00
QString title;
2016-12-30 12:20:26 +01:00
public:
bool useDefaultTitle = true;
private:
2017-08-13 16:07:00 +02:00
bool selected = false;
bool mouseOver = false;
bool mouseDown = false;
bool mouseOverX = false;
bool mouseDownX = false;
HighlightState highlightState = HighlightState::None;
QMenu menu;
2017-04-12 17:46:44 +02:00
QRect getXRect()
{
2018-01-28 16:29:47 +01:00
float s = this->getScale();
return QRect(this->width() - static_cast<int>(20 * s), static_cast<int>(4 * s),
static_cast<int>(16 * s), static_cast<int>(16 * s));
}
2016-12-29 17:31:07 +01:00
};
2017-04-14 17:52:22 +02:00
} // namespace widgets
} // namespace chatterino