mirror-chatterino2/src/widgets/helper/NotebookTab.cpp

639 lines
16 KiB
C++
Raw Normal View History

2018-06-26 14:09:39 +02:00
#include "widgets/helper/NotebookTab.hpp"
2018-06-26 14:09:39 +02:00
#include "Application.hpp"
2018-06-26 15:33:51 +02:00
#include "common/Common.hpp"
#include "singletons/Fonts.hpp"
2018-06-28 19:46:45 +02:00
#include "singletons/Settings.hpp"
2018-06-28 20:03:04 +02:00
#include "singletons/Theme.hpp"
#include "singletons/WindowManager.hpp"
2018-06-26 14:09:39 +02:00
#include "util/Clamp.hpp"
#include "util/Helpers.hpp"
#include "widgets/Notebook.hpp"
2018-06-26 15:11:45 +02:00
#include "widgets/dialogs/SettingsDialog.hpp"
#include "widgets/dialogs/TextInputDialog.hpp"
#include "widgets/splits/SplitContainer.hpp"
2016-12-29 17:31:07 +01:00
#include <QApplication>
#include <QDebug>
2018-03-30 16:25:49 +02:00
#include <QLinearGradient>
2018-06-01 14:57:18 +02:00
#include <QMimeData>
2017-01-15 16:38:30 +01:00
#include <QPainter>
#include <boost/bind/bind.hpp>
2017-01-15 16:38:30 +01:00
2017-04-14 17:52:22 +02:00
namespace chatterino {
namespace {
qreal deviceDpi(QWidget *widget)
{
#ifdef Q_OS_WIN
return widget->devicePixelRatioF();
#else
return 1.0;
#endif
}
} // namespace
2017-01-18 21:30:23 +01:00
2018-06-01 14:57:18 +02:00
NotebookTab::NotebookTab(Notebook *notebook)
2018-08-08 15:35:54 +02:00
: Button(notebook)
2018-06-01 14:57:18 +02:00
, positionChangedAnimation_(this, "pos")
, notebook_(notebook)
, menu_(this)
2018-04-18 09:12:29 +02:00
{
this->setAcceptDrops(true);
2018-08-06 21:17:03 +02:00
this->positionChangedAnimation_.setEasingCurve(
QEasingCurve(QEasingCurve::InCubic));
2018-04-18 09:12:29 +02:00
getSettings()->showTabCloseButton.connectSimple(
boost::bind(&NotebookTab::hideTabXChanged, this),
2018-08-06 21:17:03 +02:00
this->managedConnections_);
getSettings()->showTabLive.connect(
[this](auto, auto) {
this->update();
},
this->managedConnections_);
2018-04-18 09:12:29 +02:00
this->setMouseTracking(true);
this->menu_.addAction("Rename", [this]() {
this->showRenameDialog();
});
2018-04-18 09:12:29 +02:00
this->menu_.addAction("Close", [=]() {
this->notebook_->removePage(this->page);
});
2018-04-18 09:12:29 +02:00
highlightNewMessagesAction_ =
2018-09-30 13:44:41 +02:00
new QAction("Enable highlights on new messages", &this->menu_);
highlightNewMessagesAction_->setCheckable(true);
highlightNewMessagesAction_->setChecked(highlightEnabled_);
QObject::connect(highlightNewMessagesAction_, &QAction::triggered,
[this](bool checked) {
this->highlightEnabled_ = checked;
});
this->menu_.addAction(highlightNewMessagesAction_);
2018-04-18 09:12:29 +02:00
}
2018-10-22 19:57:02 +02:00
void NotebookTab::showRenameDialog()
{
TextInputDialog d(this);
d.setWindowTitle("Choose tab title (Empty for default)");
d.setText(this->getCustomTitle());
d.highlightText();
if (d.exec() == QDialog::Accepted)
{
QString newTitle = d.getText();
this->setCustomTitle(newTitle);
}
}
2018-07-06 17:11:37 +02:00
void NotebookTab::themeChangedEvent()
2018-04-18 09:12:29 +02:00
{
this->update();
2018-06-11 21:57:17 +02:00
// this->setMouseEffectColor(QColor("#999"));
2018-07-06 17:11:37 +02:00
this->setMouseEffectColor(this->theme->tabs.regular.text);
2018-04-18 09:12:29 +02:00
}
void NotebookTab::growWidth(int width)
{
if (this->growWidth_ != width)
{
this->growWidth_ = width;
this->updateSize();
}
else
{
this->growWidth_ = width;
}
}
int NotebookTab::normalTabWidth()
2018-04-18 09:12:29 +02:00
{
2018-11-21 21:37:41 +01:00
float scale = this->scale();
2018-04-18 09:12:29 +02:00
int width;
2018-05-25 13:53:55 +02:00
QFontMetrics metrics = getApp()->fonts->getFontMetrics(
FontStyle::UiTabs, float(qreal(this->scale()) * deviceDpi(this)));
2018-04-18 09:12:29 +02:00
2018-10-21 13:43:02 +02:00
if (this->hasXButton())
{
width = (metrics.horizontalAdvance(this->getTitle()) + int(32 * scale));
2018-10-21 13:43:02 +02:00
}
else
{
width = (metrics.horizontalAdvance(this->getTitle()) + int(16 * scale));
2018-04-18 09:12:29 +02:00
}
2018-11-25 21:14:42 +01:00
if (this->height() > 150 * scale)
{
width = this->height();
}
else
{
width = clamp(width, this->height(), int(150 * scale));
}
return width;
}
void NotebookTab::updateSize()
{
float scale = this->scale();
int width = this->normalTabWidth();
auto height = int(NOTEBOOK_TAB_HEIGHT * scale);
2018-05-23 04:22:17 +02:00
if (width < this->growWidth_)
{
width = this->growWidth_;
}
2018-10-21 13:43:02 +02:00
if (this->width() != width || this->height() != height)
{
this->resize(width, height);
2018-06-01 14:57:18 +02:00
this->notebook_->performLayout();
2018-05-23 04:22:17 +02:00
}
2018-04-18 09:12:29 +02:00
}
2018-06-01 16:01:49 +02:00
const QString &NotebookTab::getCustomTitle() const
2018-04-18 09:12:29 +02:00
{
2018-06-01 16:01:49 +02:00
return this->customTitle_;
2018-04-18 09:12:29 +02:00
}
2018-06-01 16:01:49 +02:00
void NotebookTab::setCustomTitle(const QString &newTitle)
2018-04-18 09:12:29 +02:00
{
2018-10-21 13:43:02 +02:00
if (this->customTitle_ != newTitle)
{
2018-06-01 16:01:49 +02:00
this->customTitle_ = newTitle;
this->titleUpdated();
2018-04-18 09:12:29 +02:00
}
}
2018-06-01 16:01:49 +02:00
void NotebookTab::resetCustomTitle()
{
this->setCustomTitle(QString());
}
bool NotebookTab::hasCustomTitle() const
{
return !this->customTitle_.isEmpty();
}
void NotebookTab::setDefaultTitle(const QString &title)
{
2018-10-21 13:43:02 +02:00
if (this->defaultTitle_ != title)
{
2018-06-01 16:01:49 +02:00
this->defaultTitle_ = title;
2018-10-21 13:43:02 +02:00
if (this->customTitle_.isEmpty())
{
2018-06-01 16:01:49 +02:00
this->titleUpdated();
}
}
}
const QString &NotebookTab::getDefaultTitle() const
{
return this->defaultTitle_;
}
const QString &NotebookTab::getTitle() const
{
2018-08-06 21:17:03 +02:00
return this->customTitle_.isEmpty() ? this->defaultTitle_
: this->customTitle_;
2018-06-01 16:01:49 +02:00
}
void NotebookTab::titleUpdated()
{
// Queue up save because: Tab title changed
getApp()->windows->queueSave();
this->notebook_->performLayout();
2018-06-01 16:01:49 +02:00
this->updateSize();
this->update();
}
2018-05-23 11:59:37 +02:00
bool NotebookTab::isSelected() const
2018-04-18 09:12:29 +02:00
{
2018-06-01 14:57:18 +02:00
return this->selected_;
2018-04-18 09:12:29 +02:00
}
2018-05-23 11:59:37 +02:00
void NotebookTab::setSelected(bool value)
2018-04-18 09:12:29 +02:00
{
2018-06-01 14:57:18 +02:00
this->selected_ = value;
2018-04-18 09:12:29 +02:00
2018-06-01 14:57:18 +02:00
this->highlightState_ = HighlightState::None;
2018-04-18 09:12:29 +02:00
this->update();
}
2018-10-21 12:13:09 +02:00
void NotebookTab::setInLastRow(bool value)
{
2018-10-21 13:43:02 +02:00
if (this->isInLastRow_ != value)
{
2018-10-21 12:13:09 +02:00
this->isInLastRow_ = value;
this->update();
}
}
2018-10-13 14:20:06 +02:00
void NotebookTab::setLive(bool isLive)
{
2018-10-21 13:43:02 +02:00
if (this->isLive_ != isLive)
{
2018-10-13 14:20:06 +02:00
this->isLive_ = isLive;
this->update();
}
}
2018-05-23 11:59:37 +02:00
void NotebookTab::setHighlightState(HighlightState newHighlightStyle)
2018-04-18 09:12:29 +02:00
{
if (this->isSelected() || (!this->highlightEnabled_ &&
newHighlightStyle == HighlightState::NewMessage))
2018-10-21 13:43:02 +02:00
{
2018-04-18 09:12:29 +02:00
return;
}
2018-10-21 13:43:02 +02:00
if (this->highlightState_ != HighlightState::Highlighted)
{
2018-06-01 14:57:18 +02:00
this->highlightState_ = newHighlightStyle;
2018-04-18 09:12:29 +02:00
this->update();
}
}
void NotebookTab::setHighlightsEnabled(const bool &newVal)
{
this->highlightNewMessagesAction_->setChecked(newVal);
this->highlightEnabled_ = newVal;
}
bool NotebookTab::hasHighlightsEnabled() const
{
return this->highlightEnabled_;
}
2018-05-23 11:59:37 +02:00
QRect NotebookTab::getDesiredRect() const
2018-04-18 09:12:29 +02:00
{
2018-06-01 14:57:18 +02:00
return QRect(this->positionAnimationDesiredPoint_, size());
2018-04-18 09:12:29 +02:00
}
void NotebookTab::hideTabXChanged()
2018-04-18 09:12:29 +02:00
{
this->updateSize();
this->update();
}
2018-05-23 11:59:37 +02:00
void NotebookTab::moveAnimated(QPoint pos, bool animated)
2018-04-18 09:12:29 +02:00
{
2018-06-01 14:57:18 +02:00
this->positionAnimationDesiredPoint_ = pos;
2018-04-18 09:12:29 +02:00
QWidget *w = this->window();
2018-08-06 21:17:03 +02:00
if ((w != nullptr && !w->isVisible()) || !animated ||
2018-10-21 13:43:02 +02:00
!this->positionChangedAnimationRunning_)
{
2018-04-18 09:12:29 +02:00
this->move(pos);
2018-06-01 14:57:18 +02:00
this->positionChangedAnimationRunning_ = true;
2018-04-18 09:12:29 +02:00
return;
}
2018-10-21 13:43:02 +02:00
if (this->positionChangedAnimation_.endValue() == pos)
{
2018-04-18 09:12:29 +02:00
return;
}
2018-06-01 14:57:18 +02:00
this->positionChangedAnimation_.stop();
this->positionChangedAnimation_.setDuration(75);
this->positionChangedAnimation_.setStartValue(this->pos());
this->positionChangedAnimation_.setEndValue(pos);
this->positionChangedAnimation_.start();
2018-04-18 09:12:29 +02:00
}
2018-05-23 11:59:37 +02:00
void NotebookTab::paintEvent(QPaintEvent *)
2018-04-18 09:12:29 +02:00
{
auto app = getApp();
2018-04-18 09:12:29 +02:00
QPainter painter(this);
2018-11-21 21:37:41 +01:00
float scale = this->scale();
2018-04-18 09:12:29 +02:00
auto div = std::max<float>(0.01f, this->logicalDpiX() * deviceDpi(this));
painter.setFont(
getApp()->fonts->getFont(FontStyle::UiTabs, scale * 96.f / div));
QFontMetrics metrics =
app->fonts->getFontMetrics(FontStyle::UiTabs, scale * 96.f / div);
2018-05-23 04:22:17 +02:00
2018-05-25 13:53:55 +02:00
int height = int(scale * NOTEBOOK_TAB_HEIGHT);
2018-04-18 09:12:29 +02:00
// select the right tab colors
2018-06-28 20:03:04 +02:00
Theme::TabColors colors;
2018-07-06 17:11:37 +02:00
Theme::TabColors regular = this->theme->tabs.regular;
2018-04-18 09:12:29 +02:00
2018-10-21 13:43:02 +02:00
if (this->selected_)
2018-07-06 17:11:37 +02:00
colors = this->theme->tabs.selected;
2018-10-21 13:43:02 +02:00
else if (this->highlightState_ == HighlightState::Highlighted)
2018-07-06 17:11:37 +02:00
colors = this->theme->tabs.highlighted;
2018-10-21 13:43:02 +02:00
else if (this->highlightState_ == HighlightState::NewMessage)
2018-07-06 17:11:37 +02:00
colors = this->theme->tabs.newMessage;
2018-10-21 13:43:02 +02:00
else
2018-07-06 17:11:37 +02:00
colors = this->theme->tabs.regular;
2018-04-18 09:12:29 +02:00
bool windowFocused = this->window() == QApplication::activeWindow();
2018-06-11 21:57:17 +02:00
QBrush tabBackground = /*this->mouseOver_ ? colors.backgrounds.hover
:*/
2018-08-06 21:17:03 +02:00
(windowFocused ? colors.backgrounds.regular
: colors.backgrounds.unfocused);
2018-04-18 09:12:29 +02:00
2018-05-23 04:22:17 +02:00
// fill the tab background
auto bgRect = this->rect();
bgRect.setTop(ceil((this->selected_ ? 0.f : 1.f) * scale));
painter.fillRect(bgRect, tabBackground);
2018-05-23 04:22:17 +02:00
// top line
2018-08-06 21:17:03 +02:00
painter.fillRect(
QRectF(0, ceil((this->selected_ ? 0.f : 1.f) * scale), this->width(),
ceil((this->selected_ ? 2.f : 1.f) * scale)),
2018-08-06 21:17:03 +02:00
this->mouseOver_
? colors.line.hover
: (windowFocused ? colors.line.regular : colors.line.unfocused));
2018-04-18 09:12:29 +02:00
2018-10-13 14:20:06 +02:00
// draw live indicator
2018-10-31 19:45:51 +01:00
if (this->isLive_ && getSettings()->showTabLive)
2018-10-21 13:43:02 +02:00
{
2018-10-13 14:20:06 +02:00
painter.setPen(QColor(Qt::GlobalColor::red));
2018-10-21 12:13:09 +02:00
painter.setRenderHint(QPainter::Antialiasing);
2018-10-13 14:20:06 +02:00
QBrush b;
b.setColor(QColor(Qt::GlobalColor::red));
b.setStyle(Qt::SolidPattern);
painter.setBrush(b);
2018-10-21 12:13:09 +02:00
auto x = this->width() - (7 * scale);
auto y = 4 * scale + (this->isSelected() ? 0 : 1);
auto diameter = 4 * scale;
2018-10-13 14:20:06 +02:00
painter.drawEllipse(QRectF(x, y, diameter, diameter));
}
2018-04-18 09:12:29 +02:00
// set the pen color
painter.setPen(colors.text);
// set area for text
int rectW = (!getSettings()->showTabCloseButton ? 0 : int(16 * scale));
2018-04-18 09:12:29 +02:00
QRect rect(0, 0, this->width() - rectW, height);
// draw text
2018-06-01 14:57:18 +02:00
int offset = int(scale * 8);
2018-08-06 21:17:03 +02:00
QRect textRect(offset, this->selected_ ? 1 : 2,
this->width() - offset - offset, height);
2018-05-23 04:22:17 +02:00
2018-10-21 13:43:02 +02:00
if (this->shouldDrawXButton())
{
2018-06-01 14:57:18 +02:00
textRect.setRight(textRect.right() - this->height() / 2);
}
2018-04-18 09:12:29 +02:00
int width = metrics.horizontalAdvance(this->getTitle());
2018-08-06 21:17:03 +02:00
Qt::Alignment alignment = width > textRect.width()
? Qt::AlignLeft | Qt::AlignVCenter
: Qt::AlignHCenter | Qt::AlignVCenter;
2018-05-25 13:53:55 +02:00
2018-06-01 14:57:18 +02:00
QTextOption option(alignment);
option.setWrapMode(QTextOption::NoWrap);
painter.drawText(textRect, this->getTitle(), option);
2018-04-18 09:12:29 +02:00
// draw close x
2018-10-21 13:43:02 +02:00
if (this->shouldDrawXButton())
{
2018-10-31 19:45:51 +01:00
painter.setRenderHint(QPainter::Antialiasing, false);
2018-04-18 09:12:29 +02:00
QRect xRect = this->getXRect();
2018-10-21 13:43:02 +02:00
if (!xRect.isNull())
{
if (this->selected_)
xRect.moveTop(xRect.top() - 1);
2018-09-04 22:29:21 +02:00
2018-05-23 04:22:17 +02:00
painter.setBrush(QColor("#fff"));
2018-10-21 13:43:02 +02:00
if (this->mouseOverX_)
{
2018-04-18 09:12:29 +02:00
painter.fillRect(xRect, QColor(0, 0, 0, 64));
2018-10-21 13:43:02 +02:00
if (this->mouseDownX_)
{
2018-04-18 09:12:29 +02:00
painter.fillRect(xRect, QColor(0, 0, 0, 64));
}
}
int a = static_cast<int>(scale * 4);
2018-08-06 21:17:03 +02:00
painter.drawLine(xRect.topLeft() + QPoint(a, a),
xRect.bottomRight() + QPoint(-a, -a));
painter.drawLine(xRect.topRight() + QPoint(-a, a),
xRect.bottomLeft() + QPoint(a, -a));
2018-04-18 09:12:29 +02:00
}
}
2018-05-23 04:22:17 +02:00
2018-10-22 19:57:02 +02:00
// draw mouse over effect
if (!this->selected_)
{
this->fancyPaint(painter);
}
2018-05-23 04:22:17 +02:00
// draw line at bottom
2018-10-21 13:43:02 +02:00
if (!this->selected_ && this->isInLastRow_)
{
2018-08-06 21:17:03 +02:00
painter.fillRect(0, this->height() - 1, this->width(), 1,
app->themes->window.background);
2018-10-21 12:13:09 +02:00
}
2018-05-23 04:22:17 +02:00
}
2018-05-23 11:59:37 +02:00
bool NotebookTab::hasXButton()
2018-05-23 04:22:17 +02:00
{
return getSettings()->showTabCloseButton &&
2018-08-06 21:17:03 +02:00
this->notebook_->getAllowUserTabManagement();
2018-05-23 04:22:17 +02:00
}
2018-05-23 11:59:37 +02:00
bool NotebookTab::shouldDrawXButton()
2018-05-23 04:22:17 +02:00
{
2018-06-01 14:57:18 +02:00
return this->hasXButton() && (this->mouseOver_ || this->selected_);
2018-04-18 09:12:29 +02:00
}
2018-05-23 11:59:37 +02:00
void NotebookTab::mousePressEvent(QMouseEvent *event)
2018-04-18 09:12:29 +02:00
{
2018-10-21 13:43:02 +02:00
if (event->button() == Qt::LeftButton)
{
this->mouseDown_ = true;
this->mouseDownX_ = this->getXRect().contains(event->pos());
2018-04-18 09:12:29 +02:00
this->notebook_->select(page);
}
2018-04-18 09:12:29 +02:00
2018-09-29 22:35:33 +02:00
this->update();
2018-10-21 13:43:02 +02:00
if (this->notebook_->getAllowUserTabManagement())
{
switch (event->button())
{
2019-09-26 00:51:05 +02:00
case Qt::RightButton: {
2020-08-13 20:59:57 +02:00
this->menu_.popup(event->globalPos() + QPoint(0, 8));
2018-10-21 13:43:02 +02:00
}
break;
2018-06-01 14:57:18 +02:00
default:;
2018-04-18 09:12:29 +02:00
}
}
}
2018-05-23 11:59:37 +02:00
void NotebookTab::mouseReleaseEvent(QMouseEvent *event)
2018-04-18 09:12:29 +02:00
{
2018-06-01 14:57:18 +02:00
this->mouseDown_ = false;
2018-04-18 09:12:29 +02:00
auto removeThisPage = [this] {
2018-08-06 21:17:03 +02:00
auto reply = QMessageBox::question(
this, "Remove this tab",
"Are you sure that you want to remove this tab?",
QMessageBox::Yes | QMessageBox::Cancel);
2018-10-21 13:43:02 +02:00
if (reply == QMessageBox::Yes)
{
2018-06-01 14:57:18 +02:00
this->notebook_->removePage(this->page);
}
};
if (event->button() == Qt::MiddleButton &&
this->notebook_->getAllowUserTabManagement())
2018-10-21 13:43:02 +02:00
{
if (this->rect().contains(event->pos()))
{
removeThisPage();
2018-04-18 09:12:29 +02:00
}
2018-10-21 13:43:02 +02:00
}
else
{
2018-08-06 21:17:03 +02:00
if (this->hasXButton() && this->mouseDownX_ &&
2018-10-21 13:43:02 +02:00
this->getXRect().contains(event->pos()))
{
2018-06-01 14:57:18 +02:00
this->mouseDownX_ = false;
2018-04-18 09:12:29 +02:00
removeThisPage();
2018-10-21 13:43:02 +02:00
}
else
{
2018-04-18 09:12:29 +02:00
this->update();
}
}
}
2018-10-22 19:57:02 +02:00
void NotebookTab::mouseDoubleClickEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton &&
this->notebook_->getAllowUserTabManagement())
{
this->showRenameDialog();
}
}
2018-06-11 21:57:17 +02:00
void NotebookTab::enterEvent(QEvent *event)
2018-04-18 09:12:29 +02:00
{
2018-06-01 14:57:18 +02:00
this->mouseOver_ = true;
2018-04-18 09:12:29 +02:00
this->update();
2018-06-11 21:57:17 +02:00
2018-08-08 15:35:54 +02:00
Button::enterEvent(event);
2018-04-18 09:12:29 +02:00
}
2018-06-11 21:57:17 +02:00
void NotebookTab::leaveEvent(QEvent *event)
2018-04-18 09:12:29 +02:00
{
2018-06-01 14:57:18 +02:00
this->mouseOverX_ = false;
this->mouseOver_ = false;
2018-04-18 09:12:29 +02:00
this->update();
2018-06-11 21:57:17 +02:00
2018-08-08 15:35:54 +02:00
Button::leaveEvent(event);
2018-04-18 09:12:29 +02:00
}
2018-05-23 12:35:10 +02:00
void NotebookTab::dragEnterEvent(QDragEnterEvent *event)
2018-04-18 09:12:29 +02:00
{
2018-10-21 13:43:02 +02:00
if (!event->mimeData()->hasFormat("chatterino/split"))
return;
2018-05-23 12:35:10 +02:00
2018-10-21 13:43:02 +02:00
if (!SplitContainer::isDraggingSplit)
return;
2018-05-23 12:35:10 +02:00
2018-10-21 13:43:02 +02:00
if (this->notebook_->getAllowUserTabManagement())
{
2018-06-01 14:57:18 +02:00
this->notebook_->select(this->page);
2018-04-18 18:55:49 +02:00
}
2018-04-18 09:12:29 +02:00
}
2018-05-23 11:59:37 +02:00
void NotebookTab::mouseMoveEvent(QMouseEvent *event)
2018-04-18 09:12:29 +02:00
{
if (getSettings()->showTabCloseButton &&
this->notebook_->getAllowUserTabManagement())
2018-04-18 09:12:29 +02:00
{
bool overX = this->getXRect().contains(event->pos());
2018-10-21 13:43:02 +02:00
if (overX != this->mouseOverX_)
{
2018-04-18 09:12:29 +02:00
// Over X state has been changed (we either left or entered it;
2018-06-01 14:57:18 +02:00
this->mouseOverX_ = overX;
2018-04-18 09:12:29 +02:00
this->update();
}
}
QPoint relPoint = this->mapToParent(event->pos());
2018-06-01 14:57:18 +02:00
if (this->mouseDown_ && !this->getDesiredRect().contains(relPoint) &&
this->notebook_->getAllowUserTabManagement())
2018-04-18 09:12:29 +02:00
{
int index;
2018-08-06 21:17:03 +02:00
QWidget *clickedPage =
this->notebook_->tabAt(relPoint, index, this->width());
2018-04-18 09:12:29 +02:00
2018-10-21 13:43:02 +02:00
if (clickedPage != nullptr && clickedPage != this->page)
{
2018-06-01 14:57:18 +02:00
this->notebook_->rearrangePage(this->page, index);
2018-04-18 09:12:29 +02:00
}
}
2018-06-11 21:57:17 +02:00
2018-08-08 15:35:54 +02:00
Button::mouseMoveEvent(event);
2018-04-18 09:12:29 +02:00
}
void NotebookTab::wheelEvent(QWheelEvent *event)
{
const auto defaultMouseDelta = 120;
const auto delta = event->delta();
const auto selectTab = [this](int delta) {
2019-08-11 21:08:18 +02:00
delta > 0 ? this->notebook_->selectPreviousTab()
: this->notebook_->selectNextTab();
};
// If it's true
// Then the user uses the trackpad or perhaps the most accurate mouse
// Which has small delta.
if (std::abs(delta) < defaultMouseDelta)
2018-10-21 13:43:02 +02:00
{
this->mouseWheelDelta_ += delta;
if (std::abs(this->mouseWheelDelta_) >= defaultMouseDelta)
{
selectTab(this->mouseWheelDelta_);
this->mouseWheelDelta_ = 0;
}
2018-10-21 13:43:02 +02:00
}
else
{
selectTab(delta);
}
}
2018-05-23 11:59:37 +02:00
QRect NotebookTab::getXRect()
2018-04-18 09:12:29 +02:00
{
2018-05-23 04:22:17 +02:00
// if (!this->notebook->getAllowUserTabManagement()) {
// return QRect();
// }
2018-04-18 09:12:29 +02:00
2018-11-21 21:37:41 +01:00
float s = this->scale();
2018-08-06 21:17:03 +02:00
return QRect(this->width() - static_cast<int>(20 * s),
2018-09-04 22:29:21 +02:00
static_cast<int>(9 * s), static_cast<int>(16 * s),
2018-08-06 21:17:03 +02:00
static_cast<int>(16 * s));
2018-04-18 09:12:29 +02:00
}
2017-04-14 17:52:22 +02:00
} // namespace chatterino