feat: Add tab style option (Normal & Combat) (#5858)
This commit is contained in:
@@ -54,6 +54,30 @@ namespace {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
float getCompactDivider(TabStyle tabStyle)
|
||||
{
|
||||
switch (tabStyle)
|
||||
{
|
||||
case TabStyle::Compact:
|
||||
return 1.5;
|
||||
case TabStyle::Normal:
|
||||
default:
|
||||
return 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
float getCompactReducer(TabStyle tabStyle)
|
||||
{
|
||||
switch (tabStyle)
|
||||
{
|
||||
case TabStyle::Compact:
|
||||
return 4.0;
|
||||
case TabStyle::Normal:
|
||||
default:
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
NotebookTab::NotebookTab(Notebook *notebook)
|
||||
@@ -67,8 +91,15 @@ NotebookTab::NotebookTab(Notebook *notebook)
|
||||
this->positionChangedAnimation_.setEasingCurve(
|
||||
QEasingCurve(QEasingCurve::InCubic));
|
||||
|
||||
getSettings()->showTabCloseButton.connectSimple(
|
||||
boost::bind(&NotebookTab::hideTabXChanged, this),
|
||||
getSettings()->showTabCloseButton.connect(
|
||||
[this] {
|
||||
this->tabSizeChanged();
|
||||
},
|
||||
this->managedConnections_);
|
||||
getSettings()->tabStyle.connect(
|
||||
[this] {
|
||||
this->tabSizeChanged();
|
||||
},
|
||||
this->managedConnections_);
|
||||
getSettings()->showTabLive.connect(
|
||||
[this](auto, auto) {
|
||||
@@ -204,13 +235,16 @@ int NotebookTab::normalTabWidthForHeight(int height) const
|
||||
QFontMetrics metrics =
|
||||
getApp()->getFonts()->getFontMetrics(FontStyle::UiTabs, scale);
|
||||
|
||||
float compactDivider = getCompactDivider(getSettings()->tabStyle);
|
||||
if (this->hasXButton())
|
||||
{
|
||||
width = (metrics.horizontalAdvance(this->getTitle()) + int(32 * scale));
|
||||
width = (metrics.horizontalAdvance(this->getTitle()) +
|
||||
int(32 / compactDivider * scale));
|
||||
}
|
||||
else
|
||||
{
|
||||
width = (metrics.horizontalAdvance(this->getTitle()) + int(16 * scale));
|
||||
width = (metrics.horizontalAdvance(this->getTitle()) +
|
||||
int(16 / compactDivider * scale));
|
||||
}
|
||||
|
||||
if (static_cast<float>(height) > 150 * scale)
|
||||
@@ -608,7 +642,7 @@ QRect NotebookTab::getDesiredRect() const
|
||||
return QRect(this->positionAnimationDesiredPoint_, size());
|
||||
}
|
||||
|
||||
void NotebookTab::hideTabXChanged()
|
||||
void NotebookTab::tabSizeChanged()
|
||||
{
|
||||
this->updateSize();
|
||||
this->update();
|
||||
@@ -760,12 +794,15 @@ void NotebookTab::paintEvent(QPaintEvent *)
|
||||
// set the pen color
|
||||
painter.setPen(colors.text);
|
||||
|
||||
float compactDivider = getCompactDivider(getSettings()->tabStyle);
|
||||
// set area for text
|
||||
int rectW = (!getSettings()->showTabCloseButton ? 0 : int(16 * scale));
|
||||
int rectW =
|
||||
(!getSettings()->showTabCloseButton ? 0
|
||||
: int(16 * scale / compactDivider));
|
||||
QRect rect(0, 0, this->width() - rectW, height);
|
||||
|
||||
// draw text
|
||||
int offset = int(scale * 8);
|
||||
int offset = int(scale * 4 / compactDivider);
|
||||
QRect textRect(offset, 0, this->width() - offset - offset, height);
|
||||
translateRectForLocation(textRect, this->tabLocation_,
|
||||
this->selected_ ? -1 : -2);
|
||||
@@ -1044,7 +1081,8 @@ QRect NotebookTab::getXRect() const
|
||||
? (size / 3) // slightly off true center
|
||||
: (size / 2); // true center
|
||||
|
||||
QRect xRect(rect.right() - static_cast<int>(20 * s),
|
||||
float compactReducer = getCompactReducer(getSettings()->tabStyle);
|
||||
QRect xRect(rect.right() - static_cast<int>((20 - compactReducer) * s),
|
||||
rect.center().y() - centerAdjustment, size, size);
|
||||
|
||||
if (this->selected_)
|
||||
|
||||
Reference in New Issue
Block a user