mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
improved NotebookTab
This commit is contained in:
parent
888c594929
commit
69e0352648
6 changed files with 99 additions and 80 deletions
|
@ -2,5 +2,6 @@
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
enum class ProviderId { Twitch };
|
enum class ProviderId { Twitch, Irc };
|
||||||
}
|
//
|
||||||
|
} // namespace chatterino
|
||||||
|
|
|
@ -210,7 +210,8 @@ void Notebook::selectNextTab()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int index = (this->indexOf(this->selectedPage_) + 1) % this->items_.count();
|
auto index =
|
||||||
|
(this->indexOf(this->selectedPage_) + 1) % this->items_.count();
|
||||||
|
|
||||||
this->select(this->items_[index].page);
|
this->select(this->items_[index].page);
|
||||||
}
|
}
|
||||||
|
@ -252,11 +253,11 @@ QWidget *Notebook::getSelectedPage() const
|
||||||
|
|
||||||
QWidget *Notebook::tabAt(QPoint point, int &index, int maxWidth)
|
QWidget *Notebook::tabAt(QPoint point, int &index, int maxWidth)
|
||||||
{
|
{
|
||||||
int i = 0;
|
auto i = 0;
|
||||||
|
|
||||||
for (auto &item : this->items_) {
|
for (auto &item : this->items_) {
|
||||||
QRect rect = item.tab->getDesiredRect();
|
auto rect = item.tab->getDesiredRect();
|
||||||
rect.setHeight((int)(this->getScale() * 24));
|
rect.setHeight(int(this->getScale() * 24));
|
||||||
|
|
||||||
rect.setWidth(std::min(maxWidth, rect.width()));
|
rect.setWidth(std::min(maxWidth, rect.width()));
|
||||||
|
|
||||||
|
@ -322,47 +323,59 @@ void Notebook::resizeEvent(QResizeEvent *)
|
||||||
|
|
||||||
void Notebook::performLayout(bool animated)
|
void Notebook::performLayout(bool animated)
|
||||||
{
|
{
|
||||||
int xStart = int(2 * this->getScale());
|
const auto left = int(2 * this->getScale());
|
||||||
|
const auto scale = this->getScale();
|
||||||
|
const auto tabHeight = int(NOTEBOOK_TAB_HEIGHT * scale);
|
||||||
|
const auto addButtonWidth = this->showAddButton_ ? tabHeight : 0;
|
||||||
|
|
||||||
int x = xStart, y = 0;
|
auto x = left;
|
||||||
float scale = this->getScale();
|
auto y = 0;
|
||||||
|
|
||||||
int h = int(NOTEBOOK_TAB_HEIGHT * this->getScale());
|
|
||||||
|
|
||||||
|
// set size of custom buttons (settings, user, ...)
|
||||||
for (auto *btn : this->customButtons_) {
|
for (auto *btn : this->customButtons_) {
|
||||||
if (!btn->isVisible()) {
|
if (!btn->isVisible()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
btn->setFixedSize(h, h);
|
btn->setFixedSize(tabHeight, tabHeight);
|
||||||
btn->move(x, 0);
|
btn->move(x, 0);
|
||||||
x += h;
|
x += tabHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tabHeight = static_cast<int>(NOTEBOOK_TAB_HEIGHT * scale);
|
// layout tabs
|
||||||
bool first = true;
|
/// Notebook tabs need to know if they are in the last row.
|
||||||
|
auto firstInBottomRow =
|
||||||
|
this->items_.size() ? &this->items_.front() : nullptr;
|
||||||
|
|
||||||
for (auto i = this->items_.begin(); i != this->items_.end(); i++) {
|
for (auto &item : this->items_) {
|
||||||
bool wrap =
|
/// Break line if element doesn't fit.
|
||||||
!first &&
|
auto isFirst = &item == &this->items_.front();
|
||||||
(((i + 1 == this->items_.end() && this->showAddButton_) ? tabHeight
|
auto isLast = &item == &this->items_.back();
|
||||||
: 0) +
|
|
||||||
x + i->tab->width()) > width();
|
|
||||||
|
|
||||||
if (wrap) {
|
auto fitsInLine =
|
||||||
y += i->tab->height();
|
((isLast ? addButtonWidth : 0) + x + item.tab->width()) <= width();
|
||||||
i->tab->moveAnimated(QPoint(xStart, y), animated);
|
|
||||||
x = i->tab->width() + xStart;
|
if (!isFirst && !fitsInLine) {
|
||||||
} else {
|
y += item.tab->height();
|
||||||
i->tab->moveAnimated(QPoint(x, y), animated);
|
x = left;
|
||||||
x += i->tab->width();
|
firstInBottomRow = &item;
|
||||||
}
|
}
|
||||||
|
|
||||||
x += int(scale * 1);
|
/// Layout tab
|
||||||
|
item.tab->moveAnimated(QPoint(x, y), animated);
|
||||||
first = false;
|
x += item.tab->width() + int(scale * 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Update which tabs are in the last row
|
||||||
|
auto inLastRow = false;
|
||||||
|
for (const auto &item : this->items_) {
|
||||||
|
if (&item == firstInBottomRow) {
|
||||||
|
inLastRow = true;
|
||||||
|
}
|
||||||
|
item.tab->setInLastRow(inLastRow);
|
||||||
|
}
|
||||||
|
|
||||||
|
// move misc buttons
|
||||||
if (this->showAddButton_) {
|
if (this->showAddButton_) {
|
||||||
this->addButton_->move(x, y);
|
this->addButton_->move(x, y);
|
||||||
}
|
}
|
||||||
|
@ -372,8 +385,10 @@ void Notebook::performLayout(bool animated)
|
||||||
this->update();
|
this->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
y += int(3 * scale);
|
/// Increment for the line at the bottom
|
||||||
|
y += int(2 * scale);
|
||||||
|
|
||||||
|
// raise elements
|
||||||
for (auto &i : this->items_) {
|
for (auto &i : this->items_) {
|
||||||
i.tab->raise();
|
i.tab->raise();
|
||||||
}
|
}
|
||||||
|
@ -382,6 +397,7 @@ void Notebook::performLayout(bool animated)
|
||||||
this->addButton_->raise();
|
this->addButton_->raise();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set page bounds
|
||||||
if (this->selectedPage_ != nullptr) {
|
if (this->selectedPage_ != nullptr) {
|
||||||
this->selectedPage_->move(0, y + tabHeight);
|
this->selectedPage_->move(0, y + tabHeight);
|
||||||
this->selectedPage_->resize(width(), height() - y - tabHeight);
|
this->selectedPage_->resize(width(), height() - y - tabHeight);
|
||||||
|
@ -394,8 +410,8 @@ void Notebook::paintEvent(QPaintEvent *event)
|
||||||
BaseWidget::paintEvent(event);
|
BaseWidget::paintEvent(event);
|
||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
painter.fillRect(0, this->lineY_, this->width(),
|
painter.fillRect(0, this->lineY_, this->width(), int(2 * this->getScale()),
|
||||||
(int)(3 * this->getScale()), this->theme->tabs.bottomLine);
|
this->theme->tabs.bottomLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
NotebookButton *Notebook::getAddButton()
|
NotebookButton *Notebook::getAddButton()
|
||||||
|
@ -431,9 +447,8 @@ SplitNotebook::SplitNotebook(Window *parent)
|
||||||
QTimer::singleShot(80, this, [this] { this->addPage(true); });
|
QTimer::singleShot(80, this, [this] { this->addPage(true); });
|
||||||
});
|
});
|
||||||
|
|
||||||
bool customFrame = parent->hasCustomWindowFrame();
|
// add custom buttons if they are not in the parent window frame
|
||||||
|
if (!parent->hasCustomWindowFrame()) {
|
||||||
if (!customFrame) {
|
|
||||||
this->addCustomButtons();
|
this->addCustomButtons();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -475,8 +490,8 @@ void SplitNotebook::addCustomButtons()
|
||||||
|
|
||||||
SplitContainer *SplitNotebook::addPage(bool select)
|
SplitContainer *SplitNotebook::addPage(bool select)
|
||||||
{
|
{
|
||||||
SplitContainer *container = new SplitContainer(this);
|
auto container = new SplitContainer(this);
|
||||||
auto *tab = Notebook::addPage(container, QString(), select);
|
auto tab = Notebook::addPage(container, QString(), select);
|
||||||
container->setTab(tab);
|
container->setTab(tab);
|
||||||
tab->setParent(this);
|
tab->setParent(this);
|
||||||
tab->show();
|
tab->show();
|
||||||
|
|
|
@ -337,21 +337,19 @@ void Window::onAccountSelected()
|
||||||
|
|
||||||
#ifdef CHATTERINO_NIGHTLY_VERSION_STRING
|
#ifdef CHATTERINO_NIGHTLY_VERSION_STRING
|
||||||
auto windowTitleEnd =
|
auto windowTitleEnd =
|
||||||
QString(" - Chatterino Nightly " CHATTERINO_VERSION
|
QString("Chatterino Nightly " CHATTERINO_VERSION
|
||||||
" (" UGLYMACROHACK(CHATTERINO_NIGHTLY_VERSION_STRING) ")");
|
" (" UGLYMACROHACK(CHATTERINO_NIGHTLY_VERSION_STRING) ")");
|
||||||
#else
|
#else
|
||||||
auto windowTitleEnd = QString(" - Chatterino Beta " CHATTERINO_VERSION);
|
auto windowTitleEnd = QString("Chatterino Beta " CHATTERINO_VERSION);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (user->isAnon()) {
|
this->setWindowTitle(windowTitleEnd);
|
||||||
this->setWindowTitle("Not logged in" + windowTitleEnd);
|
|
||||||
|
|
||||||
|
if (user->isAnon()) {
|
||||||
if (this->userLabel_) {
|
if (this->userLabel_) {
|
||||||
this->userLabel_->getLabel().setText("anonymous");
|
this->userLabel_->getLabel().setText("anonymous");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this->setWindowTitle(user->getUserName() + windowTitleEnd);
|
|
||||||
|
|
||||||
if (this->userLabel_) {
|
if (this->userLabel_) {
|
||||||
this->userLabel_->getLabel().setText(user->getUserName());
|
this->userLabel_->getLabel().setText(user->getUserName());
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "widgets/helper/NotebookTab.hpp"
|
#include "widgets/helper/NotebookTab.hpp"
|
||||||
|
|
||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
|
#include <QFormLayout>
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
|
@ -115,20 +116,26 @@ SelectChannelDialog::SelectChannelDialog(QWidget *parent)
|
||||||
watching_btn.getElement());
|
watching_btn.getElement());
|
||||||
|
|
||||||
// tab
|
// tab
|
||||||
NotebookTab *tab = notebook->addPage(obj.getElement());
|
auto tab = notebook->addPage(obj.getElement());
|
||||||
tab->setCustomTitle("Twitch");
|
tab->setCustomTitle("Twitch");
|
||||||
}
|
}
|
||||||
|
|
||||||
// irc
|
// irc
|
||||||
/*{
|
/*
|
||||||
|
{
|
||||||
LayoutCreator<QWidget> obj(new QWidget());
|
LayoutCreator<QWidget> obj(new QWidget());
|
||||||
auto vbox = obj.setLayoutType<QVBoxLayout>();
|
auto vbox = obj.setLayoutType<QVBoxLayout>();
|
||||||
|
auto form = vbox.emplace<QFormLayout>();
|
||||||
|
|
||||||
auto edit = vbox.emplace<QLabel>("not implemented");
|
form->addRow(new QLabel("User name:"), new QLineEdit());
|
||||||
|
form->addRow(new QLabel("First nick choice:"), new QLineEdit());
|
||||||
|
form->addRow(new QLabel("Second nick choice:"), new QLineEdit());
|
||||||
|
form->addRow(new QLabel("Third nick choice:"), new QLineEdit());
|
||||||
|
|
||||||
NotebookTab2 *tab = notebook->addPage(obj.getElement());
|
auto tab = notebook->addPage(obj.getElement());
|
||||||
tab->setTitle("Irc");
|
tab->setCustomTitle("Irc");
|
||||||
}*/
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
layout->setStretchFactor(notebook.getElement(), 1);
|
layout->setStretchFactor(notebook.getElement(), 1);
|
||||||
|
|
||||||
|
@ -143,7 +150,7 @@ SelectChannelDialog::SelectChannelDialog(QWidget *parent)
|
||||||
[=](bool) { this->close(); });
|
[=](bool) { this->close(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
this->setScaleIndependantSize(300, 210);
|
this->setScaleIndependantSize(300, 310);
|
||||||
this->ui_.notebook->selectIndex(TAB_TWITCH);
|
this->ui_.notebook->selectIndex(TAB_TWITCH);
|
||||||
this->ui_.twitch.channel->setFocus();
|
this->ui_.twitch.channel->setFocus();
|
||||||
|
|
||||||
|
|
|
@ -168,6 +168,14 @@ void NotebookTab::setSelected(bool value)
|
||||||
this->update();
|
this->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NotebookTab::setInLastRow(bool value)
|
||||||
|
{
|
||||||
|
if (this->isInLastRow_ != value) {
|
||||||
|
this->isInLastRow_ = value;
|
||||||
|
this->update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void NotebookTab::setLive(bool isLive)
|
void NotebookTab::setLive(bool isLive)
|
||||||
{
|
{
|
||||||
if (this->isLive_ != isLive) {
|
if (this->isLive_ != isLive) {
|
||||||
|
@ -249,7 +257,6 @@ void NotebookTab::paintEvent(QPaintEvent *)
|
||||||
scale * 96.f / this->logicalDpiX() * this->devicePixelRatioF());
|
scale * 96.f / this->logicalDpiX() * this->devicePixelRatioF());
|
||||||
|
|
||||||
int height = int(scale * NOTEBOOK_TAB_HEIGHT);
|
int height = int(scale * NOTEBOOK_TAB_HEIGHT);
|
||||||
// int fullHeight = (int)(scale * 48);
|
|
||||||
|
|
||||||
// select the right tab colors
|
// select the right tab colors
|
||||||
Theme::TabColors colors;
|
Theme::TabColors colors;
|
||||||
|
@ -266,34 +273,18 @@ void NotebookTab::paintEvent(QPaintEvent *)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool windowFocused = this->window() == QApplication::activeWindow();
|
bool windowFocused = this->window() == QApplication::activeWindow();
|
||||||
// || SettingsDialog::getHandle() == QApplication::activeWindow();
|
|
||||||
|
|
||||||
QBrush tabBackground = /*this->mouseOver_ ? colors.backgrounds.hover
|
QBrush tabBackground = /*this->mouseOver_ ? colors.backgrounds.hover
|
||||||
:*/
|
:*/
|
||||||
(windowFocused ? colors.backgrounds.regular
|
(windowFocused ? colors.backgrounds.regular
|
||||||
: colors.backgrounds.unfocused);
|
: colors.backgrounds.unfocused);
|
||||||
|
|
||||||
// painter.fillRect(rect(), this->mouseOver_ ? regular.backgrounds.hover
|
|
||||||
// : (windowFocused ?
|
|
||||||
// regular.backgrounds.regular
|
|
||||||
// :
|
|
||||||
// regular.backgrounds.unfocused));
|
|
||||||
|
|
||||||
// fill the tab background
|
// fill the tab background
|
||||||
auto bgRect = rect();
|
auto bgRect = rect();
|
||||||
bgRect.setTop(bgRect.top() + 2);
|
bgRect.setTop(bgRect.top() + 2);
|
||||||
|
|
||||||
painter.fillRect(bgRect, tabBackground);
|
painter.fillRect(bgRect, tabBackground);
|
||||||
|
|
||||||
// draw border
|
|
||||||
// painter.setPen(QPen("#fff"));
|
|
||||||
// QPainterPath path(QPointF(0, height));
|
|
||||||
// path.lineTo(0, 0);
|
|
||||||
// path.lineTo(this->width() - 1, 0);
|
|
||||||
// path.lineTo(this->width() - 1, this->height() - 1);
|
|
||||||
// path.lineTo(0, this->height() - 1);
|
|
||||||
// painter.drawPath(path);
|
|
||||||
|
|
||||||
// top line
|
// top line
|
||||||
painter.fillRect(
|
painter.fillRect(
|
||||||
QRectF(0, (this->selected_ ? 0.f : 1.f) * scale, this->width(),
|
QRectF(0, (this->selected_ ? 0.f : 1.f) * scale, this->width(),
|
||||||
|
@ -305,14 +296,15 @@ void NotebookTab::paintEvent(QPaintEvent *)
|
||||||
// draw live indicator
|
// draw live indicator
|
||||||
if (this->isLive_) {
|
if (this->isLive_) {
|
||||||
painter.setPen(QColor(Qt::GlobalColor::red));
|
painter.setPen(QColor(Qt::GlobalColor::red));
|
||||||
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
QBrush b;
|
QBrush b;
|
||||||
b.setColor(QColor(Qt::GlobalColor::red));
|
b.setColor(QColor(Qt::GlobalColor::red));
|
||||||
b.setStyle(Qt::SolidPattern);
|
b.setStyle(Qt::SolidPattern);
|
||||||
painter.setBrush(b);
|
painter.setBrush(b);
|
||||||
|
|
||||||
auto x = this->width() - (7.f * scale);
|
auto x = this->width() - (7 * scale);
|
||||||
auto y = 4.f * scale;
|
auto y = 4 * scale + (this->isSelected() ? 0 : 1);
|
||||||
auto diameter = 4.f * scale;
|
auto diameter = 4 * scale;
|
||||||
painter.drawEllipse(QRectF(x, y, diameter, diameter));
|
painter.drawEllipse(QRectF(x, y, diameter, diameter));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,10 +359,13 @@ void NotebookTab::paintEvent(QPaintEvent *)
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw line at bottom
|
// draw line at bottom
|
||||||
if (!this->selected_) {
|
if (!this->selected_ && this->isInLastRow_) {
|
||||||
painter.fillRect(0, this->height() - 1, this->width(), 1,
|
painter.fillRect(0, this->height() - 1, this->width(), 1,
|
||||||
app->themes->window.background);
|
app->themes->window.background);
|
||||||
|
}
|
||||||
|
|
||||||
|
// draw mouse over effect
|
||||||
|
if (!this->selected_) {
|
||||||
this->fancyPaint(painter);
|
this->fancyPaint(painter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,8 @@ public:
|
||||||
bool isSelected() const;
|
bool isSelected() const;
|
||||||
void setSelected(bool value);
|
void setSelected(bool value);
|
||||||
|
|
||||||
|
void setInLastRow(bool value);
|
||||||
|
|
||||||
void setLive(bool isLive);
|
void setLive(bool isLive);
|
||||||
void setHighlightState(HighlightState style);
|
void setHighlightState(HighlightState style);
|
||||||
void setHighlightsEnabled(const bool &newVal);
|
void setHighlightsEnabled(const bool &newVal);
|
||||||
|
@ -79,11 +81,12 @@ private:
|
||||||
QString customTitle_;
|
QString customTitle_;
|
||||||
QString defaultTitle_;
|
QString defaultTitle_;
|
||||||
|
|
||||||
bool selected_ = false;
|
bool selected_{};
|
||||||
bool mouseOver_ = false;
|
bool mouseOver_{};
|
||||||
bool mouseDown_ = false;
|
bool mouseDown_{};
|
||||||
bool mouseOverX_ = false;
|
bool mouseOverX_{};
|
||||||
bool mouseDownX_ = false;
|
bool mouseDownX_{};
|
||||||
|
bool isInLastRow_{};
|
||||||
|
|
||||||
HighlightState highlightState_ = HighlightState::None;
|
HighlightState highlightState_ = HighlightState::None;
|
||||||
bool highlightEnabled_ = true;
|
bool highlightEnabled_ = true;
|
||||||
|
|
Loading…
Reference in a new issue