added emote button and text length label

This commit is contained in:
fourtf
2017-01-22 05:58:23 +01:00
parent 9165d5cc2e
commit 8d85f91c4d
17 changed files with 268 additions and 72 deletions
+68 -7
View File
@@ -1,5 +1,6 @@
#include "widgets/notebooktab.h"
#include "colorscheme.h"
#include "settings/settings.h"
#include "widgets/notebook.h"
#include <QPainter>
@@ -14,17 +15,38 @@ NotebookTab::NotebookTab(Notebook *notebook)
, selected(false)
, mouseOver(false)
, mouseDown(false)
, mouseOverX(false)
, mouseDownX(false)
, highlightStyle(HighlightNone)
{
calcSize();
setAcceptDrops(true);
QObject::connect(&settings::Settings::getHideTabX(),
SIGNAL(settings::BoolSetting::valueChanged(bool)), this,
SLOT(NotebookTab::hideTabXChanged(bool)));
this->installEventFilter(this);
this->setMouseTracking(true);
}
NotebookTab::~NotebookTab()
{
QObject::disconnect(&settings::Settings::getHideTabX(),
SIGNAL(settings::BoolSetting::valueChanged(bool)), this,
SLOT(NotebookTab::hideTabXChanged(bool)));
}
void
NotebookTab::calcSize()
{
resize(fontMetrics().width(this->text) + 8, 24);
if (settings::Settings::getHideTabX().get()) {
this->resize(this->fontMetrics().width(this->text) + 8, 24);
} else {
this->resize(this->fontMetrics().width(this->text) + 8 + 24, 24);
}
}
void
@@ -54,25 +76,52 @@ NotebookTab::paintEvent(QPaintEvent *)
}
painter.setPen(fg);
painter.drawText(4, (height() + fontMetrics().height()) / 2, this->text);
QRect rect(0, 0,
width() - (settings::Settings::getHideTabX().get() ? 0 : 16),
height());
painter.drawText(rect, this->text, QTextOption(Qt::AlignCenter));
if (!settings::Settings::getHideTabX().get() && (mouseOver || selected)) {
if (mouseOverX) {
painter.fillRect(getXRect(), QColor(0, 0, 0, 64));
if (mouseDownX) {
painter.fillRect(getXRect(), QColor(0, 0, 0, 64));
}
}
painter.drawLine(getXRect().topLeft() + QPoint(4, 4),
getXRect().bottomRight() + QPoint(-4, -4));
painter.drawLine(getXRect().topRight() + QPoint(-4, 4),
getXRect().bottomLeft() + QPoint(4, -4));
}
}
void
NotebookTab::mousePressEvent(QMouseEvent *)
NotebookTab::mousePressEvent(QMouseEvent *event)
{
this->mouseDown = true;
this->mouseDownX = this->getXRect().contains(event->pos());
repaint();
this->repaint();
this->notebook->select(page);
}
void
NotebookTab::mouseReleaseEvent(QMouseEvent *)
NotebookTab::mouseReleaseEvent(QMouseEvent *event)
{
this->mouseDown = false;
repaint();
if (this->mouseDownX) {
this->mouseDownX = false;
this->notebook->removePage(this->page);
} else {
repaint();
}
}
void
@@ -86,7 +135,7 @@ NotebookTab::enterEvent(QEvent *)
void
NotebookTab::leaveEvent(QEvent *)
{
this->mouseOver = false;
this->mouseOverX = this->mouseOver = false;
repaint();
}
@@ -96,5 +145,17 @@ NotebookTab::dragEnterEvent(QDragEnterEvent *event)
{
this->notebook->select(page);
}
void
NotebookTab::mouseMoveEvent(QMouseEvent *event)
{
bool overX = this->getXRect().contains(event->pos());
if (overX != this->mouseOverX) {
this->mouseOverX = overX;
this->repaint();
}
}
}
}