mirror-chatterino2/notebooktab.cpp

116 lines
2.1 KiB
C++
Raw Normal View History

2017-01-01 02:30:42 +01:00
#include <QPainter>
2016-12-29 17:31:07 +01:00
#include "notebook.h"
#include "notebooktab.h"
2017-01-01 02:30:42 +01:00
#include "colorscheme.h"
2016-12-29 17:31:07 +01:00
2016-12-30 12:20:26 +01:00
NotebookTab::NotebookTab(Notebook *notebook)
: QWidget(notebook)
2016-12-29 17:31:07 +01:00
{
this->notebook = notebook;
2016-12-30 18:00:25 +01:00
text = "<no title>";
2016-12-30 12:20:26 +01:00
2016-12-30 18:00:25 +01:00
calcSize();
2017-01-01 02:30:42 +01:00
setAcceptDrops(true);
}
int NotebookTab::getHighlightStyle()
{
return highlightStyle;
}
void NotebookTab::setHighlightStyle(int style)
{
highlightStyle = style;
repaint();
2016-12-30 18:00:25 +01:00
}
void NotebookTab::setSelected(bool value)
{
selected = value;
repaint();
}
bool NotebookTab::getSelected()
{
return selected;
}
void NotebookTab::calcSize()
{
resize(fontMetrics().width(text) + 8, 24);
2016-12-30 12:20:26 +01:00
}
void NotebookTab::paintEvent(QPaintEvent *)
{
QPainter painter(this);
2017-01-01 02:30:42 +01:00
QColor fg = QColor(0, 0, 0);
auto colorScheme = ColorScheme::getInstance();
if (selected)
{
painter.fillRect(rect(), colorScheme.TabSelectedBackground);
fg = colorScheme.TabSelectedText;
}
else if (mouseOver)
{
painter.fillRect(rect(), colorScheme.TabHoverBackground);
fg = colorScheme.TabHoverText;
}
else if (highlightStyle == HighlightHighlighted)
{
painter.fillRect(rect(), colorScheme.TabHighlightedBackground);
fg = colorScheme.TabHighlightedText;
}
else if (highlightStyle == HighlightNewMessage)
{
painter.fillRect(rect(), colorScheme.TabNewMessageBackground);
fg = colorScheme.TabHighlightedText;
}
else
{
painter.fillRect(rect(), colorScheme.TabBackground);
fg = colorScheme.TabText;
}
2016-12-30 18:00:25 +01:00
painter.setPen(fg);
painter.drawText(4, (height() + fontMetrics().height()) / 2, text);
2016-12-30 12:20:26 +01:00
}
void NotebookTab::mousePressEvent(QMouseEvent *)
{
mouseDown = true;
2016-12-30 18:00:25 +01:00
repaint();
2017-01-01 02:30:42 +01:00
notebook->select(page);
2016-12-30 12:20:26 +01:00
}
void NotebookTab::mouseReleaseEvent(QMouseEvent *)
{
mouseDown = false;
2016-12-30 18:00:25 +01:00
repaint();
2016-12-30 12:20:26 +01:00
}
void NotebookTab::enterEvent(QEvent *)
{
mouseOver = true;
2016-12-30 18:00:25 +01:00
repaint();
2016-12-30 12:20:26 +01:00
}
void NotebookTab::leaveEvent(QEvent *)
{
mouseOver = false;
2016-12-30 18:00:25 +01:00
repaint();
2016-12-29 17:31:07 +01:00
}
2017-01-01 02:30:42 +01:00
void NotebookTab::dragEnterEvent(QDragEnterEvent *event)
{
notebook->select(page);
}