mirror-chatterino2/src/widgets/dialogs/switcher/NewTabItem.cpp
pajlada fdb0a1582c
SplitContainer refactor (#4261)
* Remove unused include util/Helpers.hpp

* SplitContainer::setTag fix parameter naming

* autofy/constify where possible

* More const auto ptr magicifying

* Make SplitNode::Type an enum class

* Move QuickSwitcherPopup includes from header to source file

* Remove unused DropRegion code

* use empty() instead of size() == 0

* Add curly braces everywhere

* Remove useless reinterpret_cast

It was casting Node* to Node*

* Clarify that the connect is QObject::connect

* SplitContainer::setSelected fix parameter naming

* Rename function variables to remove unneccesary underscore

Also move addSpacing parameter out of the layout function

* emplace_back where possible

* Name parameters

* Remove ineffective const from return type

* Make node getters const

* Flatten Node::releaseSplit

* Rename in-function variable to match code style

* [ACTUAL CODE CHANGE/MOVE] Move clamp logic to its own function

* name params

* applyFromDescriptorRecursively: rename node param to baseNode

* [ACTUAL CODE CHANGE/MOVE] Remove the many overloads for append/insertSplit

This utilizes the C++20 designed initializers aggregate initialization feature

* Remove unused includes

* [ACTUAL CODE CHANGE] Clean up dragging logic

There's no need to keep a pointer around to which split is being
dragged, it's already stored in the QDropEvent source()

* UNRELATED .clang-tidy: Only suggest UPPER_CASE for constant global variables

* Remove unused SplitContainer::getSplitCount function

* Use std::max in Node's clamp function

* Remove test code

* DraggedSplit.hpp: remove unused include

* Split `setDraggingSplit` into two functions, `startDraggingSplit` and `stopDraggingSplit`
2022-12-25 11:09:25 +00:00

60 lines
1.7 KiB
C++

#include "widgets/dialogs/switcher/NewTabItem.hpp"
#include "Application.hpp"
#include "providers/twitch/TwitchIrcServer.hpp"
#include "singletons/Fonts.hpp"
#include "singletons/Theme.hpp"
#include "singletons/WindowManager.hpp"
#include "widgets/helper/NotebookTab.hpp"
#include "widgets/Notebook.hpp"
#include "widgets/splits/Split.hpp"
#include "widgets/Window.hpp"
namespace chatterino {
NewTabItem::NewTabItem(const QString &channelName)
: AbstractSwitcherItem(QIcon(":/switcher/plus.svg"))
, channelName_(channelName)
, text_(QString(TEXT_FORMAT).arg(channelName))
{
}
void NewTabItem::action()
{
auto &nb = getApp()->windows->getMainWindow().getNotebook();
SplitContainer *container = nb.addPage(true);
Split *split = new Split(container);
split->setChannel(getApp()->twitch->getOrAddChannel(this->channelName_));
container->insertSplit(split);
}
void NewTabItem::paint(QPainter *painter, const QRect &rect) const
{
painter->save();
painter->setRenderHint(QPainter::Antialiasing, true);
// TODO(leon): Right pen/brush/font settings?
painter->setPen(getApp()->themes->splits.header.text);
painter->setBrush(Qt::SolidPattern);
painter->setFont(getApp()->fonts->getFont(FontStyle::UiMediumBold, 1.0));
QRect iconRect(rect.topLeft(), ICON_SIZE);
this->icon_.paint(painter, iconRect, Qt::AlignLeft | Qt::AlignVCenter);
QRect textRect =
QRect(iconRect.topRight(),
QSize(rect.width() - iconRect.width(), iconRect.height()));
painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, this->text_);
painter->restore();
}
QSize NewTabItem::sizeHint(const QRect &rect) const
{
return QSize(rect.width(), ICON_SIZE.height());
}
} // namespace chatterino