2016-12-29 17:31:07 +01:00
|
|
|
#include "notebooktab.h"
|
2017-01-11 18:52:09 +01:00
|
|
|
#include <QPainter>
|
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
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
int
|
|
|
|
NotebookTab::getHighlightStyle()
|
2017-01-01 02:30:42 +01:00
|
|
|
{
|
|
|
|
return highlightStyle;
|
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
void
|
|
|
|
NotebookTab::setHighlightStyle(int style)
|
2017-01-01 02:30:42 +01:00
|
|
|
{
|
|
|
|
highlightStyle = style;
|
|
|
|
repaint();
|
2016-12-30 18:00:25 +01:00
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
void
|
|
|
|
NotebookTab::setSelected(bool value)
|
2016-12-30 18:00:25 +01:00
|
|
|
{
|
|
|
|
selected = value;
|
|
|
|
repaint();
|
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
bool
|
|
|
|
NotebookTab::getSelected()
|
2016-12-30 18:00:25 +01:00
|
|
|
{
|
|
|
|
return selected;
|
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
void
|
|
|
|
NotebookTab::calcSize()
|
2016-12-30 18:00:25 +01:00
|
|
|
{
|
|
|
|
resize(fontMetrics().width(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-11 18:52:09 +01:00
|
|
|
if (selected) {
|
2017-01-01 02:30:42 +01:00
|
|
|
painter.fillRect(rect(), colorScheme.TabSelectedBackground);
|
|
|
|
fg = colorScheme.TabSelectedText;
|
2017-01-11 18:52:09 +01:00
|
|
|
} else if (mouseOver) {
|
2017-01-01 02:30:42 +01:00
|
|
|
painter.fillRect(rect(), colorScheme.TabHoverBackground);
|
|
|
|
fg = colorScheme.TabHoverText;
|
2017-01-11 18:52:09 +01:00
|
|
|
} else if (highlightStyle == HighlightHighlighted) {
|
2017-01-01 02:30:42 +01:00
|
|
|
painter.fillRect(rect(), colorScheme.TabHighlightedBackground);
|
|
|
|
fg = colorScheme.TabHighlightedText;
|
2017-01-11 18:52:09 +01:00
|
|
|
} else if (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);
|
|
|
|
painter.drawText(4, (height() + fontMetrics().height()) / 2, 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
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
void
|
|
|
|
NotebookTab::mouseReleaseEvent(QMouseEvent *)
|
2016-12-30 12:20:26 +01:00
|
|
|
{
|
|
|
|
mouseDown = false;
|
|
|
|
|
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
|
|
|
{
|
|
|
|
mouseOver = true;
|
|
|
|
|
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
|
|
|
{
|
|
|
|
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
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
void
|
|
|
|
NotebookTab::dragEnterEvent(QDragEnterEvent *event)
|
2017-01-01 02:30:42 +01:00
|
|
|
{
|
|
|
|
notebook->select(page);
|
|
|
|
}
|