diff --git a/src/common/ProviderId.hpp b/src/common/ProviderId.hpp index c5e2075d2..8113f3faf 100644 --- a/src/common/ProviderId.hpp +++ b/src/common/ProviderId.hpp @@ -2,5 +2,6 @@ namespace chatterino { -enum class ProviderId { Twitch }; -} +enum class ProviderId { Twitch, Irc }; +// +} // namespace chatterino diff --git a/src/widgets/Notebook.cpp b/src/widgets/Notebook.cpp index 2a0eaf208..5df9d4af6 100644 --- a/src/widgets/Notebook.cpp +++ b/src/widgets/Notebook.cpp @@ -210,7 +210,8 @@ void Notebook::selectNextTab() 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); } @@ -252,11 +253,11 @@ QWidget *Notebook::getSelectedPage() const QWidget *Notebook::tabAt(QPoint point, int &index, int maxWidth) { - int i = 0; + auto i = 0; for (auto &item : this->items_) { - QRect rect = item.tab->getDesiredRect(); - rect.setHeight((int)(this->getScale() * 24)); + auto rect = item.tab->getDesiredRect(); + rect.setHeight(int(this->getScale() * 24)); rect.setWidth(std::min(maxWidth, rect.width())); @@ -322,47 +323,59 @@ void Notebook::resizeEvent(QResizeEvent *) 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; - float scale = this->getScale(); - - int h = int(NOTEBOOK_TAB_HEIGHT * this->getScale()); + auto x = left; + auto y = 0; + // set size of custom buttons (settings, user, ...) for (auto *btn : this->customButtons_) { if (!btn->isVisible()) { continue; } - btn->setFixedSize(h, h); + btn->setFixedSize(tabHeight, tabHeight); btn->move(x, 0); - x += h; + x += tabHeight; } - int tabHeight = static_cast(NOTEBOOK_TAB_HEIGHT * scale); - bool first = true; + // layout tabs + /// 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++) { - bool wrap = - !first && - (((i + 1 == this->items_.end() && this->showAddButton_) ? tabHeight - : 0) + - x + i->tab->width()) > width(); + for (auto &item : this->items_) { + /// Break line if element doesn't fit. + auto isFirst = &item == &this->items_.front(); + auto isLast = &item == &this->items_.back(); - if (wrap) { - y += i->tab->height(); - i->tab->moveAnimated(QPoint(xStart, y), animated); - x = i->tab->width() + xStart; - } else { - i->tab->moveAnimated(QPoint(x, y), animated); - x += i->tab->width(); + auto fitsInLine = + ((isLast ? addButtonWidth : 0) + x + item.tab->width()) <= width(); + + if (!isFirst && !fitsInLine) { + y += item.tab->height(); + x = left; + firstInBottomRow = &item; } - x += int(scale * 1); - - first = false; + /// Layout tab + item.tab->moveAnimated(QPoint(x, y), animated); + 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_) { this->addButton_->move(x, y); } @@ -372,8 +385,10 @@ void Notebook::performLayout(bool animated) this->update(); } - y += int(3 * scale); + /// Increment for the line at the bottom + y += int(2 * scale); + // raise elements for (auto &i : this->items_) { i.tab->raise(); } @@ -382,6 +397,7 @@ void Notebook::performLayout(bool animated) this->addButton_->raise(); } + // set page bounds if (this->selectedPage_ != nullptr) { this->selectedPage_->move(0, y + tabHeight); this->selectedPage_->resize(width(), height() - y - tabHeight); @@ -394,8 +410,8 @@ void Notebook::paintEvent(QPaintEvent *event) BaseWidget::paintEvent(event); QPainter painter(this); - painter.fillRect(0, this->lineY_, this->width(), - (int)(3 * this->getScale()), this->theme->tabs.bottomLine); + painter.fillRect(0, this->lineY_, this->width(), int(2 * this->getScale()), + this->theme->tabs.bottomLine); } NotebookButton *Notebook::getAddButton() @@ -431,9 +447,8 @@ SplitNotebook::SplitNotebook(Window *parent) QTimer::singleShot(80, this, [this] { this->addPage(true); }); }); - bool customFrame = parent->hasCustomWindowFrame(); - - if (!customFrame) { + // add custom buttons if they are not in the parent window frame + if (!parent->hasCustomWindowFrame()) { this->addCustomButtons(); } } @@ -475,8 +490,8 @@ void SplitNotebook::addCustomButtons() SplitContainer *SplitNotebook::addPage(bool select) { - SplitContainer *container = new SplitContainer(this); - auto *tab = Notebook::addPage(container, QString(), select); + auto container = new SplitContainer(this); + auto tab = Notebook::addPage(container, QString(), select); container->setTab(tab); tab->setParent(this); tab->show(); diff --git a/src/widgets/Window.cpp b/src/widgets/Window.cpp index 5b0ce1fc2..0257bb63e 100644 --- a/src/widgets/Window.cpp +++ b/src/widgets/Window.cpp @@ -337,21 +337,19 @@ void Window::onAccountSelected() #ifdef CHATTERINO_NIGHTLY_VERSION_STRING auto windowTitleEnd = - QString(" - Chatterino Nightly " CHATTERINO_VERSION + QString("Chatterino Nightly " CHATTERINO_VERSION " (" UGLYMACROHACK(CHATTERINO_NIGHTLY_VERSION_STRING) ")"); #else - auto windowTitleEnd = QString(" - Chatterino Beta " CHATTERINO_VERSION); + auto windowTitleEnd = QString("Chatterino Beta " CHATTERINO_VERSION); #endif - if (user->isAnon()) { - this->setWindowTitle("Not logged in" + windowTitleEnd); + this->setWindowTitle(windowTitleEnd); + if (user->isAnon()) { if (this->userLabel_) { this->userLabel_->getLabel().setText("anonymous"); } } else { - this->setWindowTitle(user->getUserName() + windowTitleEnd); - if (this->userLabel_) { this->userLabel_->getLabel().setText(user->getUserName()); } diff --git a/src/widgets/dialogs/SelectChannelDialog.cpp b/src/widgets/dialogs/SelectChannelDialog.cpp index 4bdeb0d7a..3a8faaf7c 100644 --- a/src/widgets/dialogs/SelectChannelDialog.cpp +++ b/src/widgets/dialogs/SelectChannelDialog.cpp @@ -8,6 +8,7 @@ #include "widgets/helper/NotebookTab.hpp" #include +#include #include #include #include @@ -115,20 +116,26 @@ SelectChannelDialog::SelectChannelDialog(QWidget *parent) watching_btn.getElement()); // tab - NotebookTab *tab = notebook->addPage(obj.getElement()); + auto tab = notebook->addPage(obj.getElement()); tab->setCustomTitle("Twitch"); } // irc - /*{ - LayoutCreator obj(new QWidget()); - auto vbox = obj.setLayoutType(); + /* + { + LayoutCreator obj(new QWidget()); + auto vbox = obj.setLayoutType(); + auto form = vbox.emplace(); - auto edit = vbox.emplace("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()); - tab->setTitle("Irc"); - }*/ + auto tab = notebook->addPage(obj.getElement()); + tab->setCustomTitle("Irc"); + } + */ layout->setStretchFactor(notebook.getElement(), 1); @@ -143,7 +150,7 @@ SelectChannelDialog::SelectChannelDialog(QWidget *parent) [=](bool) { this->close(); }); } - this->setScaleIndependantSize(300, 210); + this->setScaleIndependantSize(300, 310); this->ui_.notebook->selectIndex(TAB_TWITCH); this->ui_.twitch.channel->setFocus(); diff --git a/src/widgets/helper/NotebookTab.cpp b/src/widgets/helper/NotebookTab.cpp index 258df9774..5cf4a3f26 100644 --- a/src/widgets/helper/NotebookTab.cpp +++ b/src/widgets/helper/NotebookTab.cpp @@ -168,6 +168,14 @@ void NotebookTab::setSelected(bool value) this->update(); } +void NotebookTab::setInLastRow(bool value) +{ + if (this->isInLastRow_ != value) { + this->isInLastRow_ = value; + this->update(); + } +} + void NotebookTab::setLive(bool isLive) { if (this->isLive_ != isLive) { @@ -249,7 +257,6 @@ void NotebookTab::paintEvent(QPaintEvent *) scale * 96.f / this->logicalDpiX() * this->devicePixelRatioF()); int height = int(scale * NOTEBOOK_TAB_HEIGHT); - // int fullHeight = (int)(scale * 48); // select the right tab colors Theme::TabColors colors; @@ -266,34 +273,18 @@ void NotebookTab::paintEvent(QPaintEvent *) } bool windowFocused = this->window() == QApplication::activeWindow(); - // || SettingsDialog::getHandle() == QApplication::activeWindow(); QBrush tabBackground = /*this->mouseOver_ ? colors.backgrounds.hover :*/ (windowFocused ? colors.backgrounds.regular : colors.backgrounds.unfocused); - // painter.fillRect(rect(), this->mouseOver_ ? regular.backgrounds.hover - // : (windowFocused ? - // regular.backgrounds.regular - // : - // regular.backgrounds.unfocused)); - // fill the tab background auto bgRect = rect(); bgRect.setTop(bgRect.top() + 2); 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 painter.fillRect( QRectF(0, (this->selected_ ? 0.f : 1.f) * scale, this->width(), @@ -305,14 +296,15 @@ void NotebookTab::paintEvent(QPaintEvent *) // draw live indicator if (this->isLive_) { painter.setPen(QColor(Qt::GlobalColor::red)); + painter.setRenderHint(QPainter::Antialiasing); QBrush b; b.setColor(QColor(Qt::GlobalColor::red)); b.setStyle(Qt::SolidPattern); painter.setBrush(b); - auto x = this->width() - (7.f * scale); - auto y = 4.f * scale; - auto diameter = 4.f * scale; + auto x = this->width() - (7 * scale); + auto y = 4 * scale + (this->isSelected() ? 0 : 1); + auto diameter = 4 * scale; painter.drawEllipse(QRectF(x, y, diameter, diameter)); } @@ -367,10 +359,13 @@ void NotebookTab::paintEvent(QPaintEvent *) } // draw line at bottom - if (!this->selected_) { + if (!this->selected_ && this->isInLastRow_) { painter.fillRect(0, this->height() - 1, this->width(), 1, app->themes->window.background); + } + // draw mouse over effect + if (!this->selected_) { this->fancyPaint(painter); } } diff --git a/src/widgets/helper/NotebookTab.hpp b/src/widgets/helper/NotebookTab.hpp index 0e8889611..0cd6d1091 100644 --- a/src/widgets/helper/NotebookTab.hpp +++ b/src/widgets/helper/NotebookTab.hpp @@ -39,6 +39,8 @@ public: bool isSelected() const; void setSelected(bool value); + void setInLastRow(bool value); + void setLive(bool isLive); void setHighlightState(HighlightState style); void setHighlightsEnabled(const bool &newVal); @@ -79,11 +81,12 @@ private: QString customTitle_; QString defaultTitle_; - bool selected_ = false; - bool mouseOver_ = false; - bool mouseDown_ = false; - bool mouseOverX_ = false; - bool mouseDownX_ = false; + bool selected_{}; + bool mouseOver_{}; + bool mouseDown_{}; + bool mouseOverX_{}; + bool mouseDownX_{}; + bool isInLastRow_{}; HighlightState highlightState_ = HighlightState::None; bool highlightEnabled_ = true;