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