mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
Adjustments for the minimized sidebar
This commit is contained in:
parent
2295d681a4
commit
aa486a5c0c
12 changed files with 74 additions and 46 deletions
|
@ -76,7 +76,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
|
|||
// SideBar
|
||||
sideBar_ = new QFrame(this);
|
||||
sideBar_->setObjectName("sideBar");
|
||||
sideBar_->setMinimumWidth(ui::sidebar::NormalSize);
|
||||
sideBar_->setMinimumWidth(utils::calculateSidebarSizes(QFont{}).normal);
|
||||
sideBarLayout_ = new QVBoxLayout(sideBar_);
|
||||
sideBarLayout_->setSpacing(0);
|
||||
sideBarLayout_->setMargin(0);
|
||||
|
@ -1344,7 +1344,8 @@ ChatPage::timelineWidth()
|
|||
bool
|
||||
ChatPage::isSideBarExpanded()
|
||||
{
|
||||
return sideBar_->size().width() > ui::sidebar::NormalSize;
|
||||
const auto sz = utils::calculateSidebarSizes(QFont{});
|
||||
return sideBar_->size().width() > sz.normal;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#include "CommunitiesList.h"
|
||||
#include "Cache.h"
|
||||
#include "CommunitiesList.h"
|
||||
#include "Logging.h"
|
||||
#include "MatrixClient.h"
|
||||
#include "Utils.h"
|
||||
|
||||
#include <QLabel>
|
||||
|
||||
|
@ -19,7 +20,8 @@ CommunitiesList::CommunitiesList(QWidget *parent)
|
|||
topLayout_->setSpacing(0);
|
||||
topLayout_->setMargin(0);
|
||||
|
||||
setFixedWidth(ui::sidebar::CommunitiesSidebarSize);
|
||||
const auto sideBarSizes = utils::calculateSidebarSizes(QFont{});
|
||||
setFixedWidth(sideBarSizes.groups);
|
||||
|
||||
scrollArea_ = new QScrollArea(this);
|
||||
scrollArea_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
// Font sizes are in pixels.
|
||||
|
||||
namespace conf {
|
||||
constexpr int sideBarCollapsePoint = 450;
|
||||
// Global settings.
|
||||
constexpr int fontSize = 14;
|
||||
constexpr int textInputFontSize = 14;
|
||||
|
|
|
@ -181,9 +181,10 @@ MainWindow::resizeEvent(QResizeEvent *event)
|
|||
void
|
||||
MainWindow::adjustSideBars()
|
||||
{
|
||||
const auto sz = utils::calculateSidebarSizes(QFont{});
|
||||
|
||||
const uint64_t timelineWidth = chat_page_->timelineWidth();
|
||||
const uint64_t minAvailableWidth =
|
||||
conf::sideBarCollapsePoint + ui::sidebar::CommunitiesSidebarSize;
|
||||
const uint64_t minAvailableWidth = sz.collapsePoint + sz.groups;
|
||||
|
||||
if (timelineWidth < minAvailableWidth && !chat_page_->isSideBarExpanded()) {
|
||||
chat_page_->hideSideBars();
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include "ui/Menu.h"
|
||||
#include "ui/Ripple.h"
|
||||
#include "ui/RippleOverlay.h"
|
||||
#include "ui/Theme.h"
|
||||
|
||||
constexpr int MaxUnreadCountDisplayed = 99;
|
||||
|
||||
|
@ -65,11 +64,6 @@ getMetrics(const QFont &font)
|
|||
m.inviteBtnX = m.iconSize + 2 * m.padding;
|
||||
m.inviteBtnX = m.iconSize / 2.0 + m.padding + m.padding / 3.0;
|
||||
|
||||
// std::cout << "unit " << m.unit << '\n';
|
||||
// std::cout << "maxHeight " << m.maxHeight << '\n';
|
||||
// std::cout << "iconSize " << m.iconSize << '\n';
|
||||
// std::cout << "padding " << m.padding << '\n';
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
|
@ -130,7 +124,9 @@ RoomInfoListItem::resizeEvent(QResizeEvent *)
|
|||
QPainterPath path;
|
||||
path.addRect(0, 0, width(), height());
|
||||
|
||||
if (width() > ui::sidebar::SmallSize)
|
||||
const auto sidebarSizes = utils::calculateSidebarSizes(QFont{});
|
||||
|
||||
if (width() > sidebarSizes.small)
|
||||
setToolTip("");
|
||||
else
|
||||
setToolTip(roomName_);
|
||||
|
@ -171,7 +167,9 @@ RoomInfoListItem::paintEvent(QPaintEvent *event)
|
|||
// Description line with the default font.
|
||||
int bottom_y = wm.maxHeight - wm.padding - metrics.ascent() / 2;
|
||||
|
||||
if (width() > ui::sidebar::SmallSize) {
|
||||
const auto sidebarSizes = utils::calculateSidebarSizes(QFont{});
|
||||
|
||||
if (width() > sidebarSizes.small) {
|
||||
QFont headingFont;
|
||||
headingFont.setWeight(QFont::Medium);
|
||||
p.setFont(headingFont);
|
||||
|
@ -314,7 +312,7 @@ RoomInfoListItem::paintEvent(QPaintEvent *event)
|
|||
bubbleDiameter_ + x_width,
|
||||
bubbleDiameter_);
|
||||
|
||||
if (width() == ui::sidebar::SmallSize)
|
||||
if (width() == sidebarSizes.small)
|
||||
r = QRectF(width() - bubbleDiameter_ - 5,
|
||||
height() - bubbleDiameter_ - 5,
|
||||
bubbleDiameter_ + x_width,
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
#include "Config.h"
|
||||
#include "MainWindow.h"
|
||||
#include "SideBarActions.h"
|
||||
#include "Utils.h"
|
||||
#include "ui/FlatButton.h"
|
||||
#include "ui/Menu.h"
|
||||
#include "ui/OverlayModal.h"
|
||||
#include "ui/Theme.h"
|
||||
|
||||
SideBarActions::SideBarActions(QWidget *parent)
|
||||
: QWidget{parent}
|
||||
|
@ -93,7 +93,9 @@ SideBarActions::resizeEvent(QResizeEvent *event)
|
|||
{
|
||||
Q_UNUSED(event);
|
||||
|
||||
if (width() <= ui::sidebar::SmallSize) {
|
||||
const auto sidebarSizes = utils::calculateSidebarSizes(QFont{});
|
||||
|
||||
if (width() <= sidebarSizes.small) {
|
||||
roomDirectory_->hide();
|
||||
createRoomBtn_->hide();
|
||||
} else {
|
||||
|
|
|
@ -23,12 +23,12 @@
|
|||
|
||||
#include "Config.h"
|
||||
#include "Splitter.h"
|
||||
#include "ui/Theme.h"
|
||||
|
||||
constexpr auto MaxWidth = (1 << 24) - 1;
|
||||
|
||||
Splitter::Splitter(QWidget *parent)
|
||||
: QSplitter(parent)
|
||||
, sz_{utils::calculateSidebarSizes(QFont{})}
|
||||
{
|
||||
connect(this, &QSplitter::splitterMoved, this, &Splitter::onSplitterMoved);
|
||||
setChildrenCollapsible(false);
|
||||
|
@ -45,17 +45,17 @@ Splitter::restoreSizes(int fallback)
|
|||
if (savedWidth == 0) {
|
||||
hideSidebar();
|
||||
return;
|
||||
} else if (savedWidth == ui::sidebar::SmallSize) {
|
||||
} else if (savedWidth == sz_.small) {
|
||||
if (left) {
|
||||
left->setMinimumWidth(ui::sidebar::SmallSize);
|
||||
left->setMaximumWidth(ui::sidebar::SmallSize);
|
||||
left->setMinimumWidth(sz_.small);
|
||||
left->setMaximumWidth(sz_.small);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
left->setMinimumWidth(ui::sidebar::NormalSize);
|
||||
left->setMaximumWidth(2 * ui::sidebar::NormalSize);
|
||||
setSizes({ui::sidebar::NormalSize, fallback - ui::sidebar::NormalSize});
|
||||
left->setMinimumWidth(sz_.normal);
|
||||
left->setMaximumWidth(2 * sz_.normal);
|
||||
setSizes({sz_.normal, fallback - sz_.normal});
|
||||
|
||||
setStretchFactor(0, 0);
|
||||
setStretchFactor(1, 1);
|
||||
|
@ -84,7 +84,7 @@ Splitter::onSplitterMoved(int pos, int index)
|
|||
return;
|
||||
}
|
||||
|
||||
if (s[0] == ui::sidebar::NormalSize) {
|
||||
if (s[0] == sz_.normal) {
|
||||
rightMoveCount_ += 1;
|
||||
|
||||
if (rightMoveCount_ > moveEventLimit_) {
|
||||
|
@ -94,13 +94,13 @@ Splitter::onSplitterMoved(int pos, int index)
|
|||
// if we are coming from the right, the cursor should
|
||||
// end up on the first widget.
|
||||
if (left->rect().contains(cursorPosition)) {
|
||||
left->setMinimumWidth(ui::sidebar::SmallSize);
|
||||
left->setMaximumWidth(ui::sidebar::SmallSize);
|
||||
left->setMinimumWidth(sz_.small);
|
||||
left->setMaximumWidth(sz_.small);
|
||||
|
||||
rightMoveCount_ = 0;
|
||||
}
|
||||
}
|
||||
} else if (s[0] == ui::sidebar::SmallSize) {
|
||||
} else if (s[0] == sz_.small) {
|
||||
leftMoveCount_ += 1;
|
||||
|
||||
if (leftMoveCount_ > moveEventLimit_) {
|
||||
|
@ -115,10 +115,9 @@ Splitter::onSplitterMoved(int pos, int index)
|
|||
// if we are coming from the left, the cursor should
|
||||
// end up on the second widget.
|
||||
if (extended.contains(cursorPosition) &&
|
||||
right->size().width() >=
|
||||
conf::sideBarCollapsePoint + ui::sidebar::NormalSize) {
|
||||
left->setMinimumWidth(ui::sidebar::NormalSize);
|
||||
left->setMaximumWidth(2 * ui::sidebar::NormalSize);
|
||||
right->size().width() >= sz_.collapsePoint + sz_.normal) {
|
||||
left->setMinimumWidth(sz_.normal);
|
||||
left->setMaximumWidth(2 * sz_.normal);
|
||||
|
||||
leftMoveCount_ = 0;
|
||||
}
|
||||
|
@ -145,12 +144,12 @@ Splitter::showChatView()
|
|||
right->show();
|
||||
|
||||
// Restore previous size.
|
||||
if (left->minimumWidth() == ui::sidebar::SmallSize) {
|
||||
left->setMinimumWidth(ui::sidebar::SmallSize);
|
||||
left->setMaximumWidth(ui::sidebar::SmallSize);
|
||||
if (left->minimumWidth() == sz_.small) {
|
||||
left->setMinimumWidth(sz_.small);
|
||||
left->setMaximumWidth(sz_.small);
|
||||
} else {
|
||||
left->setMinimumWidth(ui::sidebar::NormalSize);
|
||||
left->setMaximumWidth(2 * ui::sidebar::NormalSize);
|
||||
left->setMinimumWidth(sz_.normal);
|
||||
left->setMaximumWidth(2 * sz_.normal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "Utils.h"
|
||||
#include <QSplitter>
|
||||
|
||||
class Splitter : public QSplitter
|
||||
|
@ -43,4 +44,6 @@ private:
|
|||
|
||||
int leftMoveCount_ = 0;
|
||||
int rightMoveCount_ = 0;
|
||||
|
||||
utils::SideBarSizes sz_;
|
||||
};
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "Config.h"
|
||||
#include "MainWindow.h"
|
||||
#include "UserInfoWidget.h"
|
||||
#include "Utils.h"
|
||||
#include "ui/Avatar.h"
|
||||
#include "ui/FlatButton.h"
|
||||
#include "ui/OverlayModal.h"
|
||||
|
@ -107,8 +108,10 @@ UserInfoWidget::resizeEvent(QResizeEvent *event)
|
|||
{
|
||||
Q_UNUSED(event);
|
||||
|
||||
if (width() <= ui::sidebar::SmallSize) {
|
||||
topLayout_->setContentsMargins(0, 0, logoutButtonSize_ / 2 - 5 / 2, 0);
|
||||
const auto sz = utils::calculateSidebarSizes(QFont{});
|
||||
|
||||
if (width() <= sz.small) {
|
||||
topLayout_->setContentsMargins(0, 0, logoutButtonSize_, 0);
|
||||
|
||||
userAvatar_->hide();
|
||||
displayNameLabel_->hide();
|
||||
|
|
|
@ -412,3 +412,17 @@ utils::restoreCombobox(QComboBox *combo, const QString &value)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
utils::SideBarSizes
|
||||
utils::calculateSidebarSizes(const QFont &f)
|
||||
{
|
||||
const auto height = static_cast<double>(QFontMetrics{f}.lineSpacing());
|
||||
|
||||
SideBarSizes sz;
|
||||
sz.small = std::ceil(3.5 * height + height / 4.0);
|
||||
sz.normal = std::ceil(16 * height);
|
||||
sz.groups = std::ceil(3 * height);
|
||||
sz.collapsePoint = 2 * sz.normal;
|
||||
|
||||
return sz;
|
||||
}
|
||||
|
|
11
src/Utils.h
11
src/Utils.h
|
@ -233,4 +233,15 @@ centerWidget(QWidget *widget, QWidget *parent);
|
|||
|
||||
void
|
||||
restoreCombobox(QComboBox *combo, const QString &value);
|
||||
|
||||
struct SideBarSizes
|
||||
{
|
||||
int small;
|
||||
int normal;
|
||||
int groups;
|
||||
int collapsePoint;
|
||||
};
|
||||
|
||||
SideBarSizes
|
||||
calculateSidebarSizes(const QFont &f);
|
||||
}
|
||||
|
|
|
@ -12,11 +12,6 @@ enum class AvatarType
|
|||
Letter
|
||||
};
|
||||
|
||||
namespace sidebar {
|
||||
static const int SmallSize = 60;
|
||||
static const int NormalSize = 260;
|
||||
static const int CommunitiesSidebarSize = 48;
|
||||
}
|
||||
// Default font size.
|
||||
const int FontSize = 16;
|
||||
|
||||
|
|
Loading…
Reference in a new issue