Skip to content

Commit

Permalink
Merge pull request #1461 from 1445643474/master
Browse files Browse the repository at this point in the history
optimize toolmenubutton style
  • Loading branch information
legobadman authored Oct 12, 2023
2 parents 02e7cae + 3f41bb4 commit 8faefee
Show file tree
Hide file tree
Showing 16 changed files with 173 additions and 81 deletions.
91 changes: 35 additions & 56 deletions ui/zenoedit/dock/docktabcontent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <zeno/core/Session.h>
#include <zeno/types/UserData.h>
#include <zenovis/ObjectsManager.h>
#include <zenoui/comctrl/ztoolmenubutton.h>


ZToolBarButton::ZToolBarButton(bool bCheckable, const QString& icon, const QString& iconOn)
Expand Down Expand Up @@ -102,54 +103,6 @@ void ZToolRecordingButton::paintEvent(QPaintEvent *event)
}
#endif


ZToolMenuButton::ZToolMenuButton() {
setButtonOptions(ZToolButton::Opt_TextRightToIcon);
setArrowOption(ZStyleOptionToolButton::DOWNARROW);
menu = new QMenu(this);
run = new QAction(icon(), tr("Run"), this);
runLightCamera = new QAction(icon(), tr("RunLightCamera"), this);
runMaterial = new QAction(icon(), tr("RunMaterial"), this);
connect(run, &QAction::triggered, this, [=]() {
setText(tr("Run"));
this->setMinimumWidth(sizeHint().width());
emit runModeChanged();
});
connect(runLightCamera, &QAction::triggered, this, [=]() {
setText(tr("RunLightCamera"));
this->setMinimumWidth(sizeHint().width());
emit runModeChanged();
});
connect(runMaterial, &QAction::triggered, this, [=]() {
setText(tr("RunMaterial"));
this->setMinimumWidth(sizeHint().width());
emit runModeChanged();
});
menu->addAction(run);
menu->addAction(runLightCamera);
menu->addAction(runMaterial);
}


void ZToolMenuButton::mouseReleaseEvent(QMouseEvent *e) {
QSize size = ZToolButton::sizeHint();
if (e->x() >= (size.width() - ZenoStyle::dpiScaled(10)))
{
QPoint pos;
pos.setY(pos.y() + this->geometry().height());
menu->exec(this->mapToGlobal(pos));
return;
}
emit clicked();
}


QSize ZToolMenuButton::sizeHint() const {
QSize size = ZToolButton::sizeHint();
size.setWidth(size.width() + ZenoStyle::dpiScaled(12));
return size;
}

const int DockToolbarWidget::sToolbarHeight = 28;


Expand Down Expand Up @@ -327,19 +280,22 @@ void DockContent_Editor::initToolbar(QHBoxLayout* pToolLayout)
pSettings->setToolTip(tr("Settings"));
pAlways->setToolTip(tr("Always mode"));

m_btnRun = new ZToolMenuButton;
m_btnRun = new ZToolMenuButton(this);
m_btnRun->addAction(tr("Run"), ":/icons/run_all.svg");
m_btnRun->addAction(tr("RunLightCamera"), ":/icons/run_lightcamera.svg");
m_btnRun->addAction(tr("RunMaterial"), ":/icons/run_material.svg");
m_btnKill = new ZToolButton;

QFont fnt = QApplication::font();

m_btnRun->setIcon(ZenoStyle::dpiScaledSize(QSize(14, 14)), ":/icons/timeline_run_thunder.svg",
":/icons/timeline_run_thunder.svg", "", "");
m_btnRun->setIcon(ZenoStyle::dpiScaledSize(QSize(16, 16)), ":/icons/run_all.svg",
":/icons/run_all.svg", "", "", ":/icons/run_all_disable.svg");
m_btnRun->setRadius(ZenoStyle::dpiScaled(2));
m_btnRun->setFont(fnt);
m_btnRun->setText(tr("Run"));
m_btnRun->setCursor(QCursor(Qt::PointingHandCursor));
m_btnRun->setMargins(ZenoStyle::dpiScaledMargins(QMargins(11, 5, 14, 5)));
m_btnRun->setBackgroundClr(QColor("#4578AC"), QColor("#4578AC"), QColor("#4578AC"), QColor("#4578AC"), QColor("#4D5561"));
m_btnRun->setBackgroundClr(QColor("#4073B6"), QColor("#4073B6"), QColor("#4073B6"), QColor("#4073B6"), QColor("#4D5561"));
m_btnRun->setTextClr(QColor("#FFFFFF"), QColor("#FFFFFF"), QColor("#FFFFFF"), QColor("#FFFFFF"));
ZenoSettingsManager &settings = ZenoSettingsManager::GetInstance();
m_btnRun->setShortcut(settings.getShortCut(ShortCut_Run));
Expand Down Expand Up @@ -494,10 +450,6 @@ void DockContent_Editor::initConnections()
};
connect(zenoApp->graphsManagment(), &GraphsManagment::fileOpened, this, resetAlways);
connect(zenoApp->graphsManagment(), &GraphsManagment::modelInited, this, resetAlways);
connect(m_btnRun, &ZToolMenuButton::runModeChanged, this, [=]() {
if (pAlways->isChecked())
emit pAlways->toggled(true);
});
connect(pAlways, &ZToolBarButton::toggled, this, [=](bool bChecked) {
if (bChecked)
{
Expand Down Expand Up @@ -594,8 +546,35 @@ void DockContent_Editor::initConnections()
}
});

connect(m_btnRun, &ZToolMenuButton::textChanged, this, [=]() {
if (pAlways->isChecked())
emit pAlways->toggled(true);
QString text = m_btnRun->text();
QColor clr;
if (text == tr("Run"))
{
clr = QColor("#4073B6");
m_btnRun->setIcon(ZenoStyle::dpiScaledSize(QSize(16, 16)), ":/icons/run_all.svg",
":/icons/run_all.svg", "", "", ":/icons/run_all_disable.svg");
}
else if (text == tr("RunLightCamera"))
{
clr = QColor("#B66A40");
m_btnRun->setIcon(ZenoStyle::dpiScaledSize(QSize(16, 16)), ":/icons/run_lightcamera.svg",
":/icons/run_lightcamera.svg", "", "", ":/icons/run_lightcamera_disable.svg");
}
else if (text == tr("RunMaterial"))
{
clr = QColor("#9740B6");
m_btnRun->setIcon(ZenoStyle::dpiScaledSize(QSize(16, 16)), ":/icons/run_material.svg",
":/icons/run_material.svg", "", "", ":/icons/run_material_disable.svg");
}
m_btnRun->setBackgroundClr(clr, clr, clr, clr);
});
connect(m_btnKill, &ZToolButton::clicked, this, [=]() {
killProgram();
m_btnRun->setEnabled(true);
m_btnKill->setEnabled(false);
});

connect(&ZenoSettingsManager::GetInstance(), &ZenoSettingsManager::valueChanged, this, [=](QString name) {
Expand Down
18 changes: 1 addition & 17 deletions ui/zenoedit/dock/docktabcontent.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class ZTextLabel;
class DisplayWidget;
class ZComboBox;
class ZLineEdit;
class ZToolMenuButton;

class ZToolBarButton : public ZToolButton
{
Expand All @@ -33,23 +34,6 @@ class ZToolRecordingButton : public ZToolButton {
};
#endif

class ZToolMenuButton : public ZToolButton {
Q_OBJECT
public:
ZToolMenuButton();

signals:
void runModeChanged();

protected:
virtual void mouseReleaseEvent(QMouseEvent* e) override;
virtual QSize sizeHint() const override;
private:
QMenu *menu;
QAction *run;
QAction *runLightCamera;
QAction *runMaterial;
};

class DockToolbarWidget : public QWidget
{
Expand Down
7 changes: 7 additions & 0 deletions ui/zenoedit/res/icons.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -351,5 +351,12 @@
<file>icons/ZENO-logo64.png</file>
<file>icons/update_main.png</file>
<file>icons/update-reboot.png</file>
<file>icons/run_all.svg</file>
<file>icons/run_lightcamera.svg</file>
<file>icons/run_material.svg</file>
<file>icons/down_arrow.svg</file>
<file>icons/run_lightcamera_disable.svg</file>
<file>icons/run_material_disable.svg</file>
<file>icons/run_all_disable.svg</file>
</qresource>
</RCC>
3 changes: 3 additions & 0 deletions ui/zenoedit/res/icons/down_arrow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions ui/zenoedit/res/icons/run_all.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions ui/zenoedit/res/icons/run_all_disable.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions ui/zenoedit/res/icons/run_lightcamera.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions ui/zenoedit/res/icons/run_lightcamera_disable.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions ui/zenoedit/res/icons/run_material.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions ui/zenoedit/res/icons/run_material_disable.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions ui/zenoedit/res/stylesheet/menu.qss
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ QMenu::separator {
margin-bottom: 4px;
}

QMenu[cssClass="menuButton"]::item:selected {
background: #282D34;
color: #FFFFFF;
}

QMenuBar {
background-color: #191D21;
spacing: 3px;
Expand Down
15 changes: 13 additions & 2 deletions ui/zenoui/comctrl/ztoolbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ void ZToolButton::initStyleOption(ZStyleOptionToolButton* option) const
if (!isChecked() && !isDown() && !isPressed())
option->state |= QStyle::State_Raised;
if (isHovered())
{
option->state |= QStyle::State_MouseOver;
option->borderColor = m_clrBorder;
}

option->state |= QStyle::State_AutoRaise;

Expand All @@ -211,6 +214,7 @@ void ZToolButton::initStyleOption(ZStyleOptionToolButton* option) const

option->hideText = m_bHideText;
option->m_arrowOption = ZStyleOptionToolButton::ArrowOption(m_arrowOption);
option->buttonEnabled = isEnabled();
}

QBrush ZToolButton::backgrondColor(QStyle::State state) const
Expand Down Expand Up @@ -272,7 +276,8 @@ void ZToolButton::setBackgroundClr(const QColor& normalClr, const QColor& hoverC
m_clrBgNormalHover = hoverClr;
m_clrBgOn = downClr;
m_clrBgOnHovered = checkedClr;
m_clrBgDisabled = disabledClr;
if (disabledClr.isValid())
m_clrBgDisabled = disabledClr;
}

void ZToolButton::setTextClr(const QColor& normal, const QColor& hover, const QColor& normalOn, const QColor& hoverOn)
Expand All @@ -290,7 +295,7 @@ void ZToolButton::initColors(ZStyleOptionToolButton* option) const
option->ActiveBgColor = QColor();
}

void ZToolButton::setIcon(const QSize& size, QString icon, QString iconHover, QString iconOn, QString iconOnHover)
void ZToolButton::setIcon(const QSize& size, QString icon, QString iconHover, QString iconOn, QString iconOnHover, QString iconDisabled)
{
if (size.isValid())
{
Expand All @@ -311,6 +316,7 @@ void ZToolButton::setIcon(const QSize& size, QString icon, QString iconHover, QS
m_icon.addFile(iconOn, m_iconSize, QIcon::Normal, QIcon::On);
m_icon.addFile(iconOnHover, m_iconSize, QIcon::Active, QIcon::On);
m_icon.addFile(iconOnHover, m_iconSize, QIcon::Selected, QIcon::On);
m_icon.addFile(iconDisabled, m_iconSize, QIcon::Disabled, QIcon::Off);
}

void ZToolButton::setFont(const QFont& font)
Expand Down Expand Up @@ -343,6 +349,11 @@ void ZToolButton::setArrowOption(int arrOpt ) {
m_arrowOption = arrOpt;
}

void ZToolButton::setBorderColor(const QColor& clr)
{
m_clrBorder = clr;
}

void ZToolButton::setIconSize(const QSize& size)
{
m_iconSize = size;
Expand Down
4 changes: 3 additions & 1 deletion ui/zenoui/comctrl/ztoolbutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ class ZToolButton : public QWidget
void setFont(const QFont& font);
void initAnimation();
void setArrowOption(int arrOpt);
void setBorderColor(const QColor &clr);

public slots:
void setText(const QString& text);
void setIcon(const QSize& size, QString icon, QString iconHover, QString iconOn, QString iconOnHover);
void setIcon(const QSize& size, QString icon, QString iconHover, QString iconOn, QString iconOnHover, QString iconDisabled = "");
void setIconSize(const QSize& size);
void setChecked(bool bChecked);
void setDown(bool bDown);
Expand Down Expand Up @@ -124,6 +125,7 @@ public slots:
QColor m_clrBgDisabled;

QColor m_clrText, m_clrTextHover, m_clrTextOn, m_clrTextOnHover;
QColor m_clrBorder;

int m_radius;
int m_options;
Expand Down
43 changes: 43 additions & 0 deletions ui/zenoui/comctrl/ztoolmenubutton.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "ztoolmenubutton.h"
#include "../style/zstyleoption.h"
#include "../style/zenostyle.h"

ZToolMenuButton::ZToolMenuButton(QWidget* parent)
: ZToolButton(parent)
{
setButtonOptions(ZToolButton::Opt_TextRightToIcon);
setArrowOption(ZStyleOptionToolButton::DOWNARROW);
setBorderColor(QColor(255,255,255,102));
m_pMenu = new QMenu(this);
m_pMenu->setProperty("cssClass", "menuButton");
}

void ZToolMenuButton::addAction(const QString& action, const QString& icon)
{
QAction* pAction = new QAction(QIcon(icon), action, this);
connect(pAction, &QAction::triggered, this, [=]() {
setText(action);
this->setMinimumWidth(sizeHint().width());
emit textChanged();
});
m_pMenu->addAction(pAction);
}

void ZToolMenuButton::mouseReleaseEvent(QMouseEvent* e) {
QSize size = ZToolButton::sizeHint();
if (e->x() >= (size.width() - ZenoStyle::dpiScaled(10)))
{
QPoint pos;
pos.setY(pos.y() + this->geometry().height());
m_pMenu->exec(this->mapToGlobal(pos));
return;
}
emit clicked();
}


QSize ZToolMenuButton::sizeHint() const {
QSize size = ZToolButton::sizeHint();
size.setWidth(size.width() + ZenoStyle::dpiScaled(12));
return size;
}
23 changes: 23 additions & 0 deletions ui/zenoui/comctrl/ztoolmenubutton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef __ZTOOLMENUBUTTON_H__
#define __ZTOOLMENUBUTTON_H__

class ZStyleOptionToolButton;

#include <QtWidgets>
#include "ztoolbutton.h"

class ZToolMenuButton : public ZToolButton {
Q_OBJECT
public:
ZToolMenuButton(QWidget *parent = nullptr);
void addAction(const QString& action, const QString& icon = "");
signals:
void textChanged();
protected:
virtual void mouseReleaseEvent(QMouseEvent* e) override;
virtual QSize sizeHint() const override;
private:
QMenu* m_pMenu;
};

#endif
Loading

0 comments on commit 8faefee

Please sign in to comment.