diff --git a/ui/zenoedit/dock/docktabcontent.cpp b/ui/zenoedit/dock/docktabcontent.cpp index dd297c26e0..4e4d9dc391 100644 --- a/ui/zenoedit/dock/docktabcontent.cpp +++ b/ui/zenoedit/dock/docktabcontent.cpp @@ -28,6 +28,7 @@ #include #include #include +#include ZToolBarButton::ZToolBarButton(bool bCheckable, const QString& icon, const QString& iconOn) @@ -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; @@ -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)); @@ -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) { @@ -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) { diff --git a/ui/zenoedit/dock/docktabcontent.h b/ui/zenoedit/dock/docktabcontent.h index 5980be5a8a..dfb99d7527 100644 --- a/ui/zenoedit/dock/docktabcontent.h +++ b/ui/zenoedit/dock/docktabcontent.h @@ -12,6 +12,7 @@ class ZTextLabel; class DisplayWidget; class ZComboBox; class ZLineEdit; +class ZToolMenuButton; class ZToolBarButton : public ZToolButton { @@ -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 { diff --git a/ui/zenoedit/res/icons.qrc b/ui/zenoedit/res/icons.qrc index 4a15ffd72a..36d75be084 100644 --- a/ui/zenoedit/res/icons.qrc +++ b/ui/zenoedit/res/icons.qrc @@ -351,5 +351,12 @@ icons/ZENO-logo64.png icons/update_main.png icons/update-reboot.png + icons/run_all.svg + icons/run_lightcamera.svg + icons/run_material.svg + icons/down_arrow.svg + icons/run_lightcamera_disable.svg + icons/run_material_disable.svg + icons/run_all_disable.svg diff --git a/ui/zenoedit/res/icons/down_arrow.svg b/ui/zenoedit/res/icons/down_arrow.svg new file mode 100644 index 0000000000..a86735e2f7 --- /dev/null +++ b/ui/zenoedit/res/icons/down_arrow.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/ui/zenoedit/res/icons/run_all.svg b/ui/zenoedit/res/icons/run_all.svg new file mode 100644 index 0000000000..6518128617 --- /dev/null +++ b/ui/zenoedit/res/icons/run_all.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/ui/zenoedit/res/icons/run_all_disable.svg b/ui/zenoedit/res/icons/run_all_disable.svg new file mode 100644 index 0000000000..21a767258f --- /dev/null +++ b/ui/zenoedit/res/icons/run_all_disable.svg @@ -0,0 +1,3 @@ + + + diff --git a/ui/zenoedit/res/icons/run_lightcamera.svg b/ui/zenoedit/res/icons/run_lightcamera.svg new file mode 100644 index 0000000000..075a45fdb0 --- /dev/null +++ b/ui/zenoedit/res/icons/run_lightcamera.svg @@ -0,0 +1,4 @@ + + + + diff --git a/ui/zenoedit/res/icons/run_lightcamera_disable.svg b/ui/zenoedit/res/icons/run_lightcamera_disable.svg new file mode 100644 index 0000000000..f3ddd6e2f1 --- /dev/null +++ b/ui/zenoedit/res/icons/run_lightcamera_disable.svg @@ -0,0 +1,3 @@ + + + diff --git a/ui/zenoedit/res/icons/run_material.svg b/ui/zenoedit/res/icons/run_material.svg new file mode 100644 index 0000000000..0c6090dcb7 --- /dev/null +++ b/ui/zenoedit/res/icons/run_material.svg @@ -0,0 +1,4 @@ + + + + diff --git a/ui/zenoedit/res/icons/run_material_disable.svg b/ui/zenoedit/res/icons/run_material_disable.svg new file mode 100644 index 0000000000..021d42d483 --- /dev/null +++ b/ui/zenoedit/res/icons/run_material_disable.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/ui/zenoedit/res/stylesheet/menu.qss b/ui/zenoedit/res/stylesheet/menu.qss index 26c9373194..aafe77f293 100644 --- a/ui/zenoedit/res/stylesheet/menu.qss +++ b/ui/zenoedit/res/stylesheet/menu.qss @@ -37,6 +37,11 @@ QMenu::separator { margin-bottom: 4px; } +QMenu[cssClass="menuButton"]::item:selected { + background: #282D34; + color: #FFFFFF; +} + QMenuBar { background-color: #191D21; spacing: 3px; diff --git a/ui/zenoui/comctrl/ztoolbutton.cpp b/ui/zenoui/comctrl/ztoolbutton.cpp index fa546c55a0..9b64e19fcf 100644 --- a/ui/zenoui/comctrl/ztoolbutton.cpp +++ b/ui/zenoui/comctrl/ztoolbutton.cpp @@ -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; @@ -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 @@ -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) @@ -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()) { @@ -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) @@ -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; diff --git a/ui/zenoui/comctrl/ztoolbutton.h b/ui/zenoui/comctrl/ztoolbutton.h index 007793a297..b8c9f461a8 100644 --- a/ui/zenoui/comctrl/ztoolbutton.h +++ b/ui/zenoui/comctrl/ztoolbutton.h @@ -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); @@ -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; diff --git a/ui/zenoui/comctrl/ztoolmenubutton.cpp b/ui/zenoui/comctrl/ztoolmenubutton.cpp new file mode 100644 index 0000000000..850e3fb4db --- /dev/null +++ b/ui/zenoui/comctrl/ztoolmenubutton.cpp @@ -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; +} \ No newline at end of file diff --git a/ui/zenoui/comctrl/ztoolmenubutton.h b/ui/zenoui/comctrl/ztoolmenubutton.h new file mode 100644 index 0000000000..d170bbc5e2 --- /dev/null +++ b/ui/zenoui/comctrl/ztoolmenubutton.h @@ -0,0 +1,23 @@ +#ifndef __ZTOOLMENUBUTTON_H__ +#define __ZTOOLMENUBUTTON_H__ + +class ZStyleOptionToolButton; + +#include +#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 diff --git a/ui/zenoui/style/zenostyle.cpp b/ui/zenoui/style/zenostyle.cpp index 849a5eabda..6e3cd1c1bc 100644 --- a/ui/zenoui/style/zenostyle.cpp +++ b/ui/zenoui/style/zenostyle.cpp @@ -282,9 +282,9 @@ QRect ZenoStyle::rect_ZToolButtonArrow(const QStyleOptionComplex* option, const { QRect rcIcon = rect_ZToolButtonText(option, widget); QRect rc; - rc.setLeft(rcIcon.right() + ZenoStyle::dpiScaled(12)); - rc.setTop(rcIcon.top() + rcIcon.height() / 3); - rc.setSize(ZenoStyle::dpiScaledSize(QSize(8, 9))); + rc.setLeft(rcIcon.right() + ZenoStyle::dpiScaled(10)); + rc.setTop(rcIcon.top() + rcIcon.height() / 10); + rc.setSize(ZenoStyle::dpiScaledSize(QSize(14, 14))); return rc; } return QRect(); @@ -486,7 +486,7 @@ void ZenoStyle::drawZenoToolButton(const ZStyleOptionToolButton* option, QPainte //draw text if (!option->text.isEmpty()) { - QColor text_color = option->buttonEnabled ? option->palette.brush(QPalette::Active, QPalette::WindowText).color() : QColor(); + QColor text_color = option->buttonEnabled ? option->palette.brush(QPalette::Active, QPalette::WindowText).color() : option->palette.brush(QPalette::Disabled, QPalette::WindowText).color(); if (option->buttonOpts & ZToolButton::Opt_TextUnderIcon) { QStringList textList = option->text.split('\n'); @@ -522,14 +522,25 @@ void ZenoStyle::drawZenoToolButton(const ZStyleOptionToolButton* option, QPainte { if (option->m_arrowOption == ZStyleOptionToolButton::DOWNARROW) { - QIcon icon = QApplication::style()->standardIcon(QStyle::SP_TitleBarUnshadeButton); + QIcon icon(":/icons/down_arrow.svg"); icon.paint(painter, rcArrow, Qt::AlignCenter); + painter->setPen(QColor(255, 255, 255, 50)); + rcArrow.adjust(ZenoStyle::dpiScaled(-4), 0, 0, 0); + painter->drawLine(rcArrow.topLeft(), rcArrow.bottomLeft()); } else if (option->m_arrowOption == ZStyleOptionToolButton::RIGHTARROW) { //todo } } + + //draw border + if (option->borderColor.isValid()) + { + painter->setPen(option->borderColor); + QRect rect = option->rect.adjusted(0, 0, -1, -1); + painter->drawRoundedRect(rect, option->bgRadius, option->bgRadius); + } } void ZenoStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget) const