2016-12-29 17:31:07 +01:00
|
|
|
#include "notebooktab.h"
|
2017-01-01 02:30:42 +01:00
|
|
|
#include "colorscheme.h"
|
2017-01-11 18:52:09 +01:00
|
|
|
#include "notebook.h"
|
2016-12-29 17:31:07 +01:00
|
|
|
|
2017-01-15 16:38:30 +01:00
|
|
|
#include <QPainter>
|
|
|
|
|
2016-12-30 12:20:26 +01:00
|
|
|
NotebookTab::NotebookTab(Notebook *notebook)
|
|
|
|
: QWidget(notebook)
|
2017-01-15 16:38:30 +01:00
|
|
|
, m_notebook(notebook)
|
|
|
|
, m_text("<no title>")
|
|
|
|
, m_selected(false)
|
|
|
|
, m_mouseOver(false)
|
|
|
|
, m_mouseDown(false)
|
|
|
|
, m_highlightStyle(HighlightNone)
|
2016-12-29 17:31:07 +01:00
|
|
|
{
|
2016-12-30 18:00:25 +01:00
|
|
|
calcSize();
|
2017-01-01 02:30:42 +01:00
|
|
|
|
|
|
|
setAcceptDrops(true);
|
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
void
|
|
|
|
NotebookTab::calcSize()
|
2016-12-30 18:00:25 +01:00
|
|
|
{
|
2017-01-15 16:38:30 +01:00
|
|
|
resize(fontMetrics().width(m_text) + 8, 24);
|
2016-12-30 12:20:26 +01:00
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
void
|
|
|
|
NotebookTab::paintEvent(QPaintEvent *)
|
2016-12-30 12:20:26 +01:00
|
|
|
{
|
|
|
|
QPainter painter(this);
|
|
|
|
|
2017-01-01 02:30:42 +01:00
|
|
|
QColor fg = QColor(0, 0, 0);
|
|
|
|
|
2017-01-06 23:28:48 +01:00
|
|
|
auto colorScheme = ColorScheme::instance();
|
2017-01-01 02:30:42 +01:00
|
|
|
|
2017-01-15 16:38:30 +01:00
|
|
|
if (m_selected) {
|
2017-01-01 02:30:42 +01:00
|
|
|
painter.fillRect(rect(), colorScheme.TabSelectedBackground);
|
|
|
|
fg = colorScheme.TabSelectedText;
|
2017-01-15 16:38:30 +01:00
|
|
|
} else if (m_mouseOver) {
|
2017-01-01 02:30:42 +01:00
|
|
|
painter.fillRect(rect(), colorScheme.TabHoverBackground);
|
|
|
|
fg = colorScheme.TabHoverText;
|
2017-01-15 16:38:30 +01:00
|
|
|
} else if (m_highlightStyle == HighlightHighlighted) {
|
2017-01-01 02:30:42 +01:00
|
|
|
painter.fillRect(rect(), colorScheme.TabHighlightedBackground);
|
|
|
|
fg = colorScheme.TabHighlightedText;
|
2017-01-15 16:38:30 +01:00
|
|
|
} else if (m_highlightStyle == HighlightNewMessage) {
|
2017-01-01 02:30:42 +01:00
|
|
|
painter.fillRect(rect(), colorScheme.TabNewMessageBackground);
|
|
|
|
fg = colorScheme.TabHighlightedText;
|
2017-01-11 18:52:09 +01:00
|
|
|
} else {
|
2017-01-01 02:30:42 +01:00
|
|
|
painter.fillRect(rect(), colorScheme.TabBackground);
|
|
|
|
fg = colorScheme.TabText;
|
|
|
|
}
|
2016-12-30 18:00:25 +01:00
|
|
|
|
|
|
|
painter.setPen(fg);
|
2017-01-15 16:38:30 +01:00
|
|
|
painter.drawText(4, (height() + fontMetrics().height()) / 2, m_text);
|
2016-12-30 12:20:26 +01:00
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
void
|
|
|
|
NotebookTab::mousePressEvent(QMouseEvent *)
|
2016-12-30 12:20:26 +01:00
|
|
|
{
|
2017-01-15 16:38:30 +01:00
|
|
|
m_mouseDown = true;
|
2016-12-30 12:20:26 +01:00
|
|
|
|
2016-12-30 18:00:25 +01:00
|
|
|
repaint();
|
2017-01-01 02:30:42 +01:00
|
|
|
|
2017-01-15 16:38:30 +01:00
|
|
|
m_notebook->select(page);
|
2016-12-30 12:20:26 +01:00
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
void
|
|
|
|
NotebookTab::mouseReleaseEvent(QMouseEvent *)
|
2016-12-30 12:20:26 +01:00
|
|
|
{
|
2017-01-15 16:38:30 +01:00
|
|
|
m_mouseDown = false;
|
2016-12-30 12:20:26 +01:00
|
|
|
|
2016-12-30 18:00:25 +01:00
|
|
|
repaint();
|
2016-12-30 12:20:26 +01:00
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
void
|
|
|
|
NotebookTab::enterEvent(QEvent *)
|
2016-12-30 12:20:26 +01:00
|
|
|
{
|
2017-01-15 16:38:30 +01:00
|
|
|
m_mouseOver = true;
|
2016-12-30 12:20:26 +01:00
|
|
|
|
2016-12-30 18:00:25 +01:00
|
|
|
repaint();
|
2016-12-30 12:20:26 +01:00
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
void
|
|
|
|
NotebookTab::leaveEvent(QEvent *)
|
2016-12-30 12:20:26 +01:00
|
|
|
{
|
2017-01-15 16:38:30 +01:00
|
|
|
m_mouseOver = false;
|
2016-12-30 12:20:26 +01:00
|
|
|
|
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
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
void
|
|
|
|
NotebookTab::dragEnterEvent(QDragEnterEvent *event)
|
2017-01-01 02:30:42 +01:00
|
|
|
{
|
2017-01-15 16:38:30 +01:00
|
|
|
m_notebook->select(page);
|
2017-01-01 02:30:42 +01:00
|
|
|
}
|