Skip to content

Commit

Permalink
core/toolmenu: Show icons when collapsed.
Browse files Browse the repository at this point in the history
Signed-off-by: andreidanila1 <[email protected]>
  • Loading branch information
andreidanila1 committed Dec 2, 2024
1 parent d818696 commit 759e92c
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 7 deletions.
1 change: 1 addition & 0 deletions core/include/core/browsemenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class SCOPY_CORE_EXPORT BrowseMenu : public QWidget
private:
void add(QWidget *w, QString name, MenuAlignment position);
void toggleCollapsed();
void hideBtnText(QPushButton *btn, QString name, bool hide);
QPushButton *createBtn(QString name, QString iconPath, QWidget *parent = nullptr);
QFrame *createHLine(QWidget *parent = nullptr);
QWidget *createHeader(QWidget *parent = nullptr);
Expand Down
2 changes: 1 addition & 1 deletion core/include/core/toolmenuitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ class ToolMenuItem : public QPushButton
public Q_SLOTS:
void setDisabled(bool disabled);
void updateItem();
void onCollapsed(bool collapsed);

protected:
void enterEvent(QEvent *event);
void leaveEvent(QEvent *event);

private:
// QPushButton *m_toolBtn;
CustomPushButton *m_toolRunBtn;

QString m_uuid;
Expand Down
3 changes: 3 additions & 0 deletions core/include/core/toolmenumanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ public Q_SLOTS:
Q_SIGNALS:
void requestToolSelect(QString id);
void connState(QString id, bool isConnected);
void menuCollapsed(bool collapsed);

private Q_SLOTS:
void updateTool(QWidget *old);
void updateToolAttached(bool oldAttach, ToolMenuItem *toolMenuItem);
void setCollapsed(bool collapse);

private:
void loadToolAttachedState(ToolMenuEntry *tme);
Expand All @@ -88,6 +90,7 @@ private Q_SLOTS:
void initToolMenuHeaderWidget(MenuCollapseHeader *header, const DeviceInfo &dInfo);
void initCompositeHeaderWidget(MenuCollapseHeader *header, const DeviceInfo &dInfo);

bool m_collapsed;
QString m_prevItem;
QStringList m_connectedDev;
ToolStack *m_ts;
Expand Down
21 changes: 18 additions & 3 deletions core/src/browsemenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ BrowseMenu::BrowseMenu(QWidget *parent)
homeBtn->setIconSize(QSize(32, 32));
homeBtn->setStyleSheet("text-align: left");
connect(homeBtn, &QPushButton::clicked, this, [=]() { Q_EMIT requestTool("home"); });
connect(this, &BrowseMenu::collapsed, homeBtn,
[this, homeBtn](bool collapsed) { hideBtnText(homeBtn, tr("Home"), collapsed); });

QWidget *saveLoadWidget = new QWidget(m_content);
saveLoadWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
Expand Down Expand Up @@ -93,6 +95,8 @@ BrowseMenu::BrowseMenu(QWidget *parent)
QPushButton *aboutBtn = createBtn(
"About", ":/gui/icons/" + Style::getAttribute(json::theme::icon_theme_folder) + "/icons/info.svg",
m_content);
aboutBtn->setIconSize(
QSize(Style::getDimension(json::global::unit_2), Style::getDimension(json::global::unit_2)));
connect(aboutBtn, &QPushButton::clicked, this, [=]() { Q_EMIT requestTool("about"); });
aboutBtn->setCheckable(true);

Expand Down Expand Up @@ -139,16 +143,26 @@ void BrowseMenu::toggleCollapsed()
{
m_collapsed = !m_collapsed;
m_btnCollapse->setHidden(m_collapsed);
m_content->setHidden(m_collapsed);
Q_EMIT collapsed(m_collapsed);
}

void BrowseMenu::hideBtnText(QPushButton *btn, QString name, bool hide)
{
if(hide) {
btn->setText("");
} else {
btn->setText(name);
}
}

QPushButton *BrowseMenu::createBtn(QString name, QString iconPath, QWidget *parent)
{
QPushButton *btn = new QPushButton(parent);
btn->setIcon(QIcon(iconPath));
btn->setText(tr(name.toStdString().c_str()));
Style::setStyle(btn, style::properties::button::toolButton);
Style::setStyle(btn, style::properties::button::toolButton, true);
connect(this, &BrowseMenu::collapsed, btn,
[this, btn, name](bool collapsed) { hideBtnText(btn, tr(name.toStdString().c_str()), collapsed); });
return btn;
}

Expand All @@ -172,7 +186,7 @@ QWidget *BrowseMenu::createHeader(QWidget *parent)
Style::setStyle(btnCollapseMini, style::properties::widget::toolMenu);
Style::setStyle(btnCollapseMini, style::properties::button::toolButton);
btnCollapseMini->setCheckable(true);
btnCollapseMini->setFixedSize(Style::getDimension(json::global::unit_4),
btnCollapseMini->setFixedSize(Style::getDimension(json::global::unit_4_5),
Style::getDimension(json::global::unit_4));
headerLay->addWidget(btnCollapseMini);

Expand All @@ -190,6 +204,7 @@ QLabel *BrowseMenu::createScopyLogo(QWidget *parent)
{
QLabel *logo = new QLabel(m_content);
Style::setStyle(logo, style::properties::widget::logo);
connect(this, &BrowseMenu::collapsed, logo, &QWidget::setHidden);
return logo;
}

Expand Down
3 changes: 2 additions & 1 deletion core/src/scopymainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ ScopyMainWindow::ScopyMainWindow(QWidget *parent)
connect(m_toolMenuManager, &ToolMenuManager::requestToolSelect, ts, &ToolStack::show);
connect(m_toolMenuManager, &ToolMenuManager::requestToolSelect, dtm, &DetachedToolWindowManager::show);
connect(hp, &ScopyHomePage::displayNameChanged, m_toolMenuManager, &ToolMenuManager::onDisplayNameChanged);
connect(browseMenu, &BrowseMenu::collapsed, m_toolMenuManager, &ToolMenuManager::menuCollapsed);

connect(hp, &ScopyHomePage::newDeviceAvailable, dm, &DeviceManager::addDevice);

Expand Down Expand Up @@ -247,7 +248,7 @@ void ScopyMainWindow::deviceAutoconnect()
void ScopyMainWindow::collapseToolMenu(bool collapse)
{
if(collapse) {
ui->animHolder->setAnimMin(Style::getDimension(json::global::unit_4));
ui->animHolder->setAnimMin(Style::getDimension(json::global::unit_4_5));
} else {
ui->animHolder->setAnimMax(230);
}
Expand Down
10 changes: 10 additions & 0 deletions core/src/toolmenuitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ void ToolMenuItem::updateItem()
qDebug(CAT_TOOLMENUITEM) << "updating toolmenuentry for " << tme->name() << " - " << tme->uuid();
}

void ToolMenuItem::onCollapsed(bool collapsed)
{
m_toolRunBtn->setHidden(collapsed);
if(collapsed) {
setText("");
} else {
setText(m_name);
}
}

void ToolMenuItem::enterEvent(QEvent *event)
{
#ifndef __ANDROID__
Expand Down
12 changes: 10 additions & 2 deletions core/src/toolmenumanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ ToolMenuManager::ToolMenuManager(ToolStack *ts, DetachedToolWindowManager *dtm,
, m_ts(ts)
, m_dtm(dtm)
, m_toolMenu(toolMenu)
{}
, m_collapsed(false)
{
connect(this, &ToolMenuManager::menuCollapsed, this, &ToolMenuManager::setCollapsed);
}

ToolMenuManager::~ToolMenuManager() {}

Expand Down Expand Up @@ -153,7 +156,6 @@ void ToolMenuManager::onIioEvent(QString id, int retCode)

void ToolMenuManager::updateTool(QWidget *old)
{

ToolMenuEntry *tme = dynamic_cast<ToolMenuEntry *>(QObject::sender());
Q_ASSERT(tme);
QString id = tme->uuid();
Expand Down Expand Up @@ -221,6 +223,8 @@ void ToolMenuManager::updateToolAttached(bool oldAttach, ToolMenuItem *toolMenuI
}
}

void ToolMenuManager::setCollapsed(bool collapse) { m_collapsed = collapse; }

void ToolMenuManager::loadToolAttachedState(ToolMenuEntry *tme)
{
Preferences *p = Preferences::GetInstance();
Expand Down Expand Up @@ -357,18 +361,22 @@ void ToolMenuManager::initCompositeHeaderWidget(MenuCollapseHeader *header, cons
}
chw->add(new QLabel(dInfo.param));
chw->layout()->setContentsMargins(Style::getDimension(json::global::unit_1), 0, 0, 0);
chw->setHidden(m_collapsed);
connect(this, &ToolMenuManager::menuCollapsed, chw, &QWidget::setHidden);
}

ToolMenuItem *ToolMenuManager::createToolMenuItem(ToolMenuEntry *tme, QWidget *parent)
{
ToolMenuItem *toolMenuItem = new ToolMenuItem(tme->uuid(), tme->name(), tme->icon(), parent);
toolMenuItem->onCollapsed(m_collapsed);
connect(toolMenuItem->getToolRunBtn(), &QPushButton::toggled, tme, &ToolMenuEntry::runToggled);
connect(toolMenuItem->getToolRunBtn(), &QPushButton::clicked, tme, &ToolMenuEntry::runClicked);
connect(toolMenuItem, &QPushButton::clicked, this, [=]() { Q_EMIT requestToolSelect(toolMenuItem->getId()); });
connect(toolMenuItem, &QPushButton::toggled, this,
[this, toolMenuItem](bool on) { selectTool(toolMenuItem, on); });
connect(toolMenuItem, &ToolMenuItem::doubleclick, this, [this, tme]() { setTmeAttached(tme); });
connect(tme, &ToolMenuEntry::updateToolEntry, toolMenuItem, &ToolMenuItem::updateItem);
connect(this, &ToolMenuManager::menuCollapsed, toolMenuItem, &ToolMenuItem::onCollapsed);

return toolMenuItem;
}
Expand Down
1 change: 1 addition & 0 deletions gui/style/json/global.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"unit_2_5": "32",
"unit_3": "36",
"unit_4": "48",
"unit_4_5": "54",
"unit_5": "80",
"unit_6": "128",
"radius_interactive": "4",
Expand Down

0 comments on commit 759e92c

Please sign in to comment.