mirror-chatterino2/widgets/notebooktab.h

131 lines
2.2 KiB
C
Raw Normal View History

2016-12-29 17:31:07 +01:00
#ifndef NOTEBOOKTAB_H
#define NOTEBOOKTAB_H
2017-01-22 12:46:35 +01:00
#include <QPropertyAnimation>
2017-01-15 16:38:30 +01:00
#include <QWidget>
#include <boost/property_tree/ptree.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;
2016-12-30 18:00:25 +01:00
class NotebookPage;
2016-12-29 18:02:13 +01:00
2016-12-29 17:31:07 +01:00
class NotebookTab : public QWidget
{
2017-01-11 18:52:09 +01:00
Q_OBJECT
2016-12-29 17:31:07 +01:00
public:
2017-01-15 16:38:30 +01:00
enum HighlightStyle {
HighlightNone,
HighlightHighlighted,
HighlightNewMessage
};
2017-01-22 12:46:35 +01:00
explicit NotebookTab(Notebook *notebook);
~NotebookTab();
2016-12-30 12:20:26 +01:00
2016-12-30 18:00:25 +01:00
void calcSize();
2017-01-11 18:52:09 +01:00
NotebookPage *page;
2016-12-30 18:00:25 +01:00
2017-01-15 16:38:30 +01:00
const QString &
2017-01-18 04:33:30 +01:00
getText() const
2017-01-15 16:38:30 +01:00
{
2017-01-18 04:33:30 +01:00
return this->text;
2017-01-15 16:38:30 +01:00
}
void
setText(const QString &text)
{
2017-01-18 04:33:30 +01:00
this->text = text;
2017-01-15 16:38:30 +01:00
}
bool
2017-01-18 04:33:30 +01:00
getSelected()
2017-01-15 16:38:30 +01:00
{
2017-01-18 04:33:30 +01:00
return this->selected;
2017-01-15 16:38:30 +01:00
}
2016-12-30 18:00:25 +01:00
2017-01-15 16:38:30 +01:00
void
setSelected(bool value)
{
2017-01-18 04:33:30 +01:00
this->selected = value;
2017-01-26 07:10:46 +01:00
update();
2017-01-15 16:38:30 +01:00
}
2017-01-01 02:30:42 +01:00
2017-01-15 16:38:30 +01:00
HighlightStyle
2017-01-18 04:33:30 +01:00
getHighlightStyle() const
2017-01-15 16:38:30 +01:00
{
2017-01-18 04:33:30 +01:00
return this->highlightStyle;
2017-01-15 16:38:30 +01:00
}
void
setHighlightStyle(HighlightStyle style)
{
2017-01-18 04:33:30 +01:00
this->highlightStyle = style;
2017-01-26 07:10:46 +01:00
update();
2017-01-15 16:38:30 +01:00
}
2017-01-01 02:30:42 +01:00
2017-01-26 05:26:21 +01:00
void moveAnimated(QPoint pos, bool animated = true);
public:
QRect
getDesiredRect() const
{
return QRect(posAnimationDesired, this->size());
}
2017-01-22 12:46:35 +01:00
2016-12-30 12:20:26 +01:00
protected:
void paintEvent(QPaintEvent *) override;
2016-12-30 12:20:26 +01:00
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void enterEvent(QEvent *) override;
void leaveEvent(QEvent *) override;
2016-12-30 12:20:26 +01:00
void dragEnterEvent(QDragEnterEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
2017-01-01 02:30:42 +01:00
2016-12-29 17:31:07 +01:00
private:
2017-01-26 05:26:21 +01:00
QPropertyAnimation posAnimation;
bool posAnimated;
QPoint posAnimationDesired;
2017-01-22 12:46:35 +01:00
2017-01-18 04:33:30 +01:00
Notebook *notebook;
2017-01-15 16:38:30 +01:00
2017-01-18 04:33:30 +01:00
QString text;
2016-12-30 12:20:26 +01:00
2017-01-18 04:33:30 +01:00
bool selected;
bool mouseOver;
bool mouseDown;
bool mouseOverX;
bool mouseDownX;
2017-01-18 04:33:30 +01:00
HighlightStyle highlightStyle;
QRect
getXRect()
{
return QRect(this->width() - 20, 4, 16, 16);
}
private slots:
void
2017-01-22 12:46:35 +01:00
hideTabXChanged(bool)
{
calcSize();
2017-01-26 07:10:46 +01:00
update();
}
public:
void load(const boost::property_tree::ptree &tree);
boost::property_tree::ptree save();
2016-12-29 17:31:07 +01:00
};
} // namespace widgets
} // namespace chatterino
2016-12-29 17:31:07 +01:00
2017-01-11 18:52:09 +01:00
#endif // NOTEBOOKTAB_H