2018-06-26 14:09:39 +02:00
|
|
|
#include "widgets/helper/NotebookTab.hpp"
|
2018-04-27 22:11:19 +02:00
|
|
|
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "Application.hpp"
|
2018-06-26 15:33:51 +02:00
|
|
|
#include "common/Common.hpp"
|
2022-10-09 17:20:44 +02:00
|
|
|
#include "controllers/hotkeys/HotkeyCategory.hpp"
|
|
|
|
#include "controllers/hotkeys/HotkeyController.hpp"
|
2018-08-11 22:23:06 +02:00
|
|
|
#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"
|
2018-10-07 18:27:40 +02:00
|
|
|
#include "singletons/WindowManager.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "util/Clamp.hpp"
|
|
|
|
#include "util/Helpers.hpp"
|
2018-06-26 15:11:45 +02:00
|
|
|
#include "widgets/dialogs/SettingsDialog.hpp"
|
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories
In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:
In ChatterSet.hpp, I changed lrucache to a <>include
In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00
|
|
|
#include "widgets/Notebook.hpp"
|
2022-12-25 12:09:25 +01:00
|
|
|
#include "widgets/splits/DraggedSplit.hpp"
|
2018-08-11 22:23:06 +02:00
|
|
|
#include "widgets/splits/SplitContainer.hpp"
|
2016-12-29 17:31:07 +01:00
|
|
|
|
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories
In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:
In ChatterSet.hpp, I changed lrucache to a <>include
In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00
|
|
|
#include <boost/bind/bind.hpp>
|
2017-08-17 19:15:03 +02:00
|
|
|
#include <QApplication>
|
2017-08-13 16:52:16 +02:00
|
|
|
#include <QDebug>
|
2021-05-08 15:57:00 +02:00
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QLabel>
|
2018-03-30 16:25:49 +02:00
|
|
|
#include <QLinearGradient>
|
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories
In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:
In ChatterSet.hpp, I changed lrucache to a <>include
In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00
|
|
|
#include <QLineEdit>
|
2018-06-01 14:57:18 +02:00
|
|
|
#include <QMimeData>
|
2017-01-15 16:38:30 +01:00
|
|
|
#include <QPainter>
|
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
2019-10-06 21:31:12 +02:00
|
|
|
namespace {
|
|
|
|
qreal deviceDpi(QWidget *widget)
|
|
|
|
{
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
return widget->devicePixelRatioF();
|
|
|
|
#else
|
|
|
|
return 1.0;
|
|
|
|
#endif
|
|
|
|
}
|
2022-11-08 22:46:43 +01:00
|
|
|
|
|
|
|
// Translates the given rectangle by an amount in the direction to appear like the tab is selected.
|
|
|
|
// For example, if location is Top, the rectangle will be translated in the negative Y direction,
|
|
|
|
// or "up" on the screen, by amount.
|
|
|
|
void translateRectForLocation(QRect &rect, NotebookTabLocation location,
|
|
|
|
int amount)
|
|
|
|
{
|
|
|
|
switch (location)
|
|
|
|
{
|
|
|
|
case NotebookTabLocation::Top:
|
|
|
|
rect.translate(0, -amount);
|
|
|
|
break;
|
|
|
|
case NotebookTabLocation::Left:
|
|
|
|
rect.translate(-amount, 0);
|
|
|
|
break;
|
|
|
|
case NotebookTabLocation::Right:
|
|
|
|
rect.translate(amount, 0);
|
|
|
|
break;
|
|
|
|
case NotebookTabLocation::Bottom:
|
|
|
|
rect.translate(0, amount);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-10-06 21:31:12 +02:00
|
|
|
} // 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
|
|
|
|
2018-11-03 13:00:07 +01:00
|
|
|
getSettings()->showTabCloseButton.connectSimple(
|
|
|
|
boost::bind(&NotebookTab::hideTabXChanged, this),
|
2018-08-06 21:17:03 +02:00
|
|
|
this->managedConnections_);
|
2020-11-08 12:02:19 +01:00
|
|
|
getSettings()->showTabLive.connect(
|
|
|
|
[this](auto, auto) {
|
|
|
|
this->update();
|
|
|
|
},
|
|
|
|
this->managedConnections_);
|
2018-04-18 09:12:29 +02:00
|
|
|
|
|
|
|
this->setMouseTracking(true);
|
|
|
|
|
2021-05-02 12:59:14 +02:00
|
|
|
this->menu_.addAction("Rename Tab", [this]() {
|
2020-11-08 12:02:19 +01:00
|
|
|
this->showRenameDialog();
|
|
|
|
});
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2022-10-09 17:20:44 +02:00
|
|
|
// XXX: this doesn't update after changing hotkeys
|
|
|
|
|
2021-10-09 18:09:11 +02:00
|
|
|
this->menu_.addAction(
|
|
|
|
"Close Tab",
|
2022-12-24 12:56:11 +01:00
|
|
|
[this]() {
|
2021-10-09 18:09:11 +02:00
|
|
|
this->notebook_->removePage(this->page);
|
|
|
|
},
|
2022-10-09 17:20:44 +02:00
|
|
|
getApp()->hotkeys->getDisplaySequence(HotkeyCategory::Window,
|
|
|
|
"removeTab"));
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2021-08-21 14:16:00 +02:00
|
|
|
this->menu_.addAction(
|
|
|
|
"Popup Tab",
|
2022-12-24 12:56:11 +01:00
|
|
|
[this]() {
|
2021-08-21 14:16:00 +02:00
|
|
|
if (auto container = dynamic_cast<SplitContainer *>(this->page))
|
|
|
|
{
|
|
|
|
container->popup();
|
|
|
|
}
|
|
|
|
},
|
2022-10-09 17:20:44 +02:00
|
|
|
getApp()->hotkeys->getDisplaySequence(HotkeyCategory::Window, "popup",
|
|
|
|
{{"window"}}));
|
2021-08-21 14:16:00 +02:00
|
|
|
|
2018-09-30 15:02:30 +02:00
|
|
|
highlightNewMessagesAction_ =
|
2021-05-02 12:59:14 +02:00
|
|
|
new QAction("Mark Tab as Unread on New Messages", &this->menu_);
|
2018-09-30 15:02:30 +02:00
|
|
|
highlightNewMessagesAction_->setCheckable(true);
|
|
|
|
highlightNewMessagesAction_->setChecked(highlightEnabled_);
|
2020-11-08 12:02:19 +01:00
|
|
|
QObject::connect(highlightNewMessagesAction_, &QAction::triggered,
|
|
|
|
[this](bool checked) {
|
|
|
|
this->highlightEnabled_ = checked;
|
|
|
|
});
|
2018-09-30 15:02:30 +02:00
|
|
|
this->menu_.addAction(highlightNewMessagesAction_);
|
2021-05-30 13:39:34 +02:00
|
|
|
|
|
|
|
this->menu_.addSeparator();
|
|
|
|
|
2022-03-26 14:16:45 +01:00
|
|
|
this->notebook_->addNotebookActionsToMenu(&this->menu_);
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-10-22 19:57:02 +02:00
|
|
|
void NotebookTab::showRenameDialog()
|
|
|
|
{
|
2021-05-02 12:59:14 +02:00
|
|
|
auto dialog = new QDialog(this);
|
2018-10-22 19:57:02 +02:00
|
|
|
|
2021-05-02 12:59:14 +02:00
|
|
|
auto vbox = new QVBoxLayout;
|
2018-10-22 19:57:02 +02:00
|
|
|
|
2021-05-02 12:59:14 +02:00
|
|
|
auto lineEdit = new QLineEdit;
|
|
|
|
lineEdit->setText(this->getCustomTitle());
|
|
|
|
lineEdit->setPlaceholderText(this->getDefaultTitle());
|
|
|
|
lineEdit->selectAll();
|
|
|
|
|
|
|
|
vbox->addWidget(new QLabel("Name:"));
|
|
|
|
vbox->addWidget(lineEdit);
|
|
|
|
vbox->addStretch(1);
|
|
|
|
|
|
|
|
auto buttonBox =
|
|
|
|
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
|
|
|
|
|
|
|
vbox->addWidget(buttonBox);
|
|
|
|
dialog->setLayout(vbox);
|
|
|
|
|
|
|
|
QObject::connect(buttonBox, &QDialogButtonBox::accepted, [dialog] {
|
|
|
|
dialog->accept();
|
|
|
|
dialog->close();
|
|
|
|
});
|
|
|
|
|
|
|
|
QObject::connect(buttonBox, &QDialogButtonBox::rejected, [dialog] {
|
|
|
|
dialog->reject();
|
|
|
|
dialog->close();
|
|
|
|
});
|
|
|
|
|
|
|
|
dialog->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
|
|
|
dialog->setMinimumSize(dialog->minimumSizeHint().width() + 50,
|
|
|
|
dialog->minimumSizeHint().height() + 10);
|
|
|
|
|
|
|
|
dialog->setWindowFlags(
|
|
|
|
(dialog->windowFlags() & ~(Qt::WindowContextHelpButtonHint)) |
|
|
|
|
Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
|
|
|
|
|
|
|
|
dialog->setWindowTitle("Rename Tab");
|
|
|
|
|
|
|
|
if (dialog->exec() == QDialog::Accepted)
|
2018-10-22 19:57:02 +02:00
|
|
|
{
|
2021-05-02 12:59:14 +02:00
|
|
|
QString newTitle = lineEdit->text();
|
2018-10-22 19:57:02 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-08-13 15:43:08 +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;
|
2019-10-06 21:31:12 +02:00
|
|
|
|
2018-05-25 13:53:55 +02:00
|
|
|
QFontMetrics metrics = getApp()->fonts->getFontMetrics(
|
2019-10-06 21:31:12 +02:00
|
|
|
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())
|
|
|
|
{
|
2021-03-13 14:47:02 +01:00
|
|
|
width = (metrics.horizontalAdvance(this->getTitle()) + int(32 * scale));
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-13 14:47:02 +01:00
|
|
|
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));
|
|
|
|
}
|
2020-08-13 15:43:08 +02:00
|
|
|
|
|
|
|
return width;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NotebookTab::updateSize()
|
|
|
|
{
|
|
|
|
float scale = this->scale();
|
|
|
|
int width = this->normalTabWidth();
|
2018-10-21 11:02:14 +02:00
|
|
|
auto height = int(NOTEBOOK_TAB_HEIGHT * scale);
|
2018-05-23 04:22:17 +02:00
|
|
|
|
2020-08-13 15:43:08 +02:00
|
|
|
if (width < this->growWidth_)
|
|
|
|
{
|
|
|
|
width = this->growWidth_;
|
|
|
|
}
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->width() != width || this->height() != height)
|
|
|
|
{
|
2018-10-21 11:02:14 +02:00
|
|
|
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()
|
|
|
|
{
|
2018-10-07 18:27:40 +02:00
|
|
|
// Queue up save because: Tab title changed
|
|
|
|
getApp()->windows->queueSave();
|
2020-08-13 15:43:08 +02:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-08 22:46:43 +01:00
|
|
|
void NotebookTab::setTabLocation(NotebookTabLocation location)
|
|
|
|
{
|
|
|
|
if (this->tabLocation_ != location)
|
|
|
|
{
|
|
|
|
this->tabLocation_ = location;
|
|
|
|
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
|
|
|
{
|
2018-10-26 23:29:07 +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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-30 15:02:30 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-11-03 13:00:07 +01: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
|
|
|
{
|
2018-04-27 22:11:19 +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
|
|
|
|
2020-04-19 21:05:40 +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
|
2019-10-06 21:31:12 +02:00
|
|
|
:*/
|
2018-08-06 21:17:03 +02:00
|
|
|
(windowFocused ? colors.backgrounds.regular
|
|
|
|
: colors.backgrounds.unfocused);
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2022-11-08 22:46:43 +01:00
|
|
|
auto selectionOffset = ceil((this->selected_ ? 0.f : 1.f) * scale);
|
|
|
|
|
2018-05-23 04:22:17 +02:00
|
|
|
// fill the tab background
|
2019-10-06 21:31:12 +02:00
|
|
|
auto bgRect = this->rect();
|
2022-11-08 22:46:43 +01:00
|
|
|
switch (this->tabLocation_)
|
|
|
|
{
|
|
|
|
case NotebookTabLocation::Top:
|
|
|
|
bgRect.setTop(selectionOffset);
|
|
|
|
break;
|
|
|
|
case NotebookTabLocation::Left:
|
|
|
|
bgRect.setLeft(selectionOffset);
|
|
|
|
break;
|
|
|
|
case NotebookTabLocation::Right:
|
|
|
|
bgRect.setRight(bgRect.width() - selectionOffset);
|
|
|
|
break;
|
|
|
|
case NotebookTabLocation::Bottom:
|
|
|
|
bgRect.setBottom(bgRect.height() - selectionOffset);
|
|
|
|
break;
|
|
|
|
}
|
2018-06-04 14:39:26 +02:00
|
|
|
|
|
|
|
painter.fillRect(bgRect, tabBackground);
|
2018-05-23 04:22:17 +02:00
|
|
|
|
2022-11-08 22:46:43 +01:00
|
|
|
// draw color indicator line
|
|
|
|
auto lineThickness = ceil((this->selected_ ? 2.f : 1.f) * scale);
|
|
|
|
auto lineColor = this->mouseOver_ ? colors.line.hover
|
|
|
|
: (windowFocused ? colors.line.regular
|
|
|
|
: colors.line.unfocused);
|
|
|
|
|
|
|
|
QRect lineRect;
|
|
|
|
switch (this->tabLocation_)
|
|
|
|
{
|
|
|
|
case NotebookTabLocation::Top:
|
|
|
|
lineRect =
|
|
|
|
QRect(bgRect.left(), bgRect.y(), bgRect.width(), lineThickness);
|
|
|
|
break;
|
|
|
|
case NotebookTabLocation::Left:
|
|
|
|
lineRect =
|
|
|
|
QRect(bgRect.x(), bgRect.top(), lineThickness, bgRect.height());
|
|
|
|
break;
|
|
|
|
case NotebookTabLocation::Right:
|
|
|
|
lineRect = QRect(bgRect.right() - lineThickness, bgRect.top(),
|
|
|
|
lineThickness, bgRect.height());
|
|
|
|
break;
|
|
|
|
case NotebookTabLocation::Bottom:
|
|
|
|
lineRect = QRect(bgRect.left(), bgRect.bottom() - lineThickness,
|
|
|
|
bgRect.width(), lineThickness);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
painter.fillRect(lineRect, lineColor);
|
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);
|
2022-11-08 22:46:43 +01:00
|
|
|
auto y = 4 * scale;
|
2018-10-21 12:13:09 +02:00
|
|
|
auto diameter = 4 * scale;
|
2022-11-08 22:46:43 +01:00
|
|
|
QRect liveIndicatorRect(x, y, diameter, diameter);
|
|
|
|
translateRectForLocation(liveIndicatorRect, this->tabLocation_,
|
|
|
|
this->selected_ ? 0 : -1);
|
|
|
|
painter.drawEllipse(liveIndicatorRect);
|
2018-10-13 14:20:06 +02:00
|
|
|
}
|
|
|
|
|
2018-04-18 09:12:29 +02:00
|
|
|
// set the pen color
|
|
|
|
painter.setPen(colors.text);
|
|
|
|
|
|
|
|
// set area for text
|
2018-08-12 12:56:28 +02:00
|
|
|
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);
|
2022-11-08 22:46:43 +01:00
|
|
|
QRect textRect(offset, 0, this->width() - offset - offset, height);
|
|
|
|
translateRectForLocation(textRect, this->tabLocation_,
|
|
|
|
this->selected_ ? -1 : -2);
|
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
|
|
|
|
2021-03-13 14:47:02 +01: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())
|
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
|
2022-11-08 22:46:43 +01:00
|
|
|
// draw line at border
|
2018-10-21 13:43:02 +02:00
|
|
|
if (!this->selected_ && this->isInLastRow_)
|
|
|
|
{
|
2022-11-08 22:46:43 +01:00
|
|
|
QRect borderRect;
|
|
|
|
switch (this->tabLocation_)
|
|
|
|
{
|
|
|
|
case NotebookTabLocation::Top:
|
|
|
|
borderRect = QRect(0, this->height() - 1, this->width(), 1);
|
|
|
|
break;
|
|
|
|
case NotebookTabLocation::Left:
|
|
|
|
borderRect = QRect(this->width() - 1, 0, 1, this->height());
|
|
|
|
break;
|
|
|
|
case NotebookTabLocation::Right:
|
|
|
|
borderRect = QRect(0, 0, 1, this->height());
|
|
|
|
break;
|
|
|
|
case NotebookTabLocation::Bottom:
|
|
|
|
borderRect = QRect(0, 0, this->width(), 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
painter.fillRect(borderRect, 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
|
|
|
{
|
2018-08-12 12:56:28 +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)
|
|
|
|
{
|
2018-09-29 22:30:31 +02:00
|
|
|
this->mouseDown_ = true;
|
|
|
|
this->mouseDownX_ = this->getXRect().contains(event->pos());
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2018-09-29 22:30:31 +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
|
|
|
|
2018-05-23 20:02:12 +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-05-23 20:02:12 +02:00
|
|
|
|
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);
|
2018-05-23 20:02:12 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-12-01 11:00:06 +01:00
|
|
|
if (event->button() == Qt::MiddleButton &&
|
|
|
|
this->notebook_->getAllowUserTabManagement())
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
|
|
|
if (this->rect().contains(event->pos()))
|
|
|
|
{
|
2018-05-23 20:02:12 +02:00
|
|
|
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
|
|
|
|
2018-05-23 20:02:12 +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"))
|
2022-12-25 12:09:25 +01:00
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
return;
|
2022-12-25 12:09:25 +01:00
|
|
|
}
|
2018-05-23 12:35:10 +02:00
|
|
|
|
2022-12-25 12:09:25 +01:00
|
|
|
if (!isDraggingSplit())
|
|
|
|
{
|
|
|
|
// Ensure dragging a split from a different Chatterino instance doesn't switch tabs around
|
2018-10-21 13:43:02 +02:00
|
|
|
return;
|
2022-12-25 12:09:25 +01:00
|
|
|
}
|
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
|
|
|
{
|
2018-08-12 12:56:28 +02:00
|
|
|
if (getSettings()->showTabCloseButton &&
|
2020-11-08 12:02:19 +01:00
|
|
|
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) &&
|
2020-11-08 12:02:19 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-10-01 02:32:20 +02:00
|
|
|
void NotebookTab::wheelEvent(QWheelEvent *event)
|
|
|
|
{
|
2019-08-04 17:44:06 +02:00
|
|
|
const auto defaultMouseDelta = 120;
|
2021-04-26 21:38:16 +02:00
|
|
|
const auto verticalDelta = event->angleDelta().y();
|
2019-08-04 17:44:06 +02:00
|
|
|
const auto selectTab = [this](int delta) {
|
2019-08-11 21:08:18 +02:00
|
|
|
delta > 0 ? this->notebook_->selectPreviousTab()
|
|
|
|
: this->notebook_->selectNextTab();
|
2019-08-04 17:44:06 +02:00
|
|
|
};
|
|
|
|
// If it's true
|
|
|
|
// Then the user uses the trackpad or perhaps the most accurate mouse
|
|
|
|
// Which has small delta.
|
2021-04-26 21:38:16 +02:00
|
|
|
if (std::abs(verticalDelta) < defaultMouseDelta)
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2021-04-26 21:38:16 +02:00
|
|
|
this->mouseWheelDelta_ += verticalDelta;
|
2019-08-04 17:44:06 +02:00
|
|
|
if (std::abs(this->mouseWheelDelta_) >= defaultMouseDelta)
|
|
|
|
{
|
|
|
|
selectTab(this->mouseWheelDelta_);
|
|
|
|
this->mouseWheelDelta_ = 0;
|
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-04-26 21:38:16 +02:00
|
|
|
selectTab(verticalDelta);
|
2018-10-01 02:32:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
QRect NotebookTab::getXRect()
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2022-11-08 22:46:43 +01:00
|
|
|
QRect rect = this->rect();
|
2018-11-21 21:37:41 +01:00
|
|
|
float s = this->scale();
|
2022-11-08 22:46:43 +01:00
|
|
|
int size = static_cast<int>(16 * s);
|
|
|
|
|
|
|
|
int centerAdjustment =
|
|
|
|
this->tabLocation_ ==
|
|
|
|
(NotebookTabLocation::Top ||
|
|
|
|
this->tabLocation_ == NotebookTabLocation::Bottom)
|
|
|
|
? (size / 3) // slightly off true center
|
|
|
|
: (size / 2); // true center
|
|
|
|
|
|
|
|
QRect xRect(rect.right() - static_cast<int>(20 * s),
|
|
|
|
rect.center().y() - centerAdjustment, size, size);
|
|
|
|
|
|
|
|
if (this->selected_)
|
|
|
|
{
|
|
|
|
translateRectForLocation(xRect, this->tabLocation_, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return xRect;
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
} // namespace chatterino
|