Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize the styles of run, kill and always buttons #1483

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 78 additions & 38 deletions ui/zenoedit/dock/docktabcontent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,42 @@ void ZToolRecordingButton::paintEvent(QPaintEvent *event)
}
#endif

ZTextIconButton::ZTextIconButton(const QString& text, QWidget* parent)
: QWidget(parent)
, m_pButton(new QPushButton(this))
, m_pLablel(new QLabel(text, this))
, m_shortcut(nullptr)
{
setAttribute(Qt::WA_StyledBackground, true);
m_pButton->setCursor(Qt::PointingHandCursor);
m_pButton->setMaximumWidth(ZenoStyle::dpiScaled(24));
m_pButton->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding));
m_pLablel->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
QHBoxLayout* pLayout = new QHBoxLayout(this);
pLayout->setMargin(0);
pLayout->addWidget(m_pLablel);
pLayout->addWidget(m_pButton);
connect(m_pButton, &QPushButton::clicked, this, &ZTextIconButton::clicked);
}

ZTextIconButton::~ZTextIconButton()
{
}

void ZTextIconButton::setShortcut(QKeySequence text)
{
if (!m_shortcut)
{
m_shortcut = new QShortcut(text, this);
connect(m_shortcut, &QShortcut::activated, this, &ZTextIconButton::clicked);
}
else
{
m_shortcut->setKey(text);
}
}


const int DockToolbarWidget::sToolbarHeight = 28;


Expand Down Expand Up @@ -267,7 +303,9 @@ void DockContent_Editor::initToolbar(QHBoxLayout* pToolLayout)
pSearchBtn = new ZToolBarButton(true, ":/icons/toolbar_search_idle.svg", ":/icons/toolbar_search_light.svg");
pSettings = new ZToolBarButton(false, ":/icons/toolbar_localSetting_idle.svg", ":/icons/toolbar_localSetting_light.svg");
pLinkLineShape = new ZToolBarButton(true, ":/icons/timeline-curvemap.svg",":/icons/timeline-curvemap.svg");
pAlways = new ZToolBarButton(true, ":/icons/Always.svg", ":/icons/AlwaysOn.svg");
pAlways = new QCheckBox(tr("Auto"), this);
pAlways->setChecked(false);
pAlways->setProperty("cssClass", "AlwaysCheckBox");

pListView->setToolTip(tr("Subnet List"));
pTreeView->setToolTip(tr("Node List"));
Expand All @@ -284,37 +322,27 @@ void DockContent_Editor::initToolbar(QHBoxLayout* pToolLayout)
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;
m_btnKill = new ZTextIconButton(tr("Running..."), this);

QFont fnt = QApplication::font();

m_btnRun->setIcon(ZenoStyle::dpiScaledSize(QSize(16, 16)), ":/icons/run_all.svg",
":/icons/run_all.svg", "", "", ":/icons/run_all_disable.svg");
m_btnRun->setIcon(ZenoStyle::dpiScaledSize(QSize(16, 16)), ":/icons/run_all_btn.svg",
":/icons/run_all_btn.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("#4073B6"), QColor("#4073B6"), QColor("#4073B6"), QColor("#4073B6"), QColor("#4D5561"));
m_btnRun->setBackgroundClr(QColor("#1978E6"), QColor("#599EED"), QColor("#1978E6"), QColor("#1978E6"));
m_btnRun->setTextClr(QColor("#FFFFFF"), QColor("#FFFFFF"), QColor("#FFFFFF"), QColor("#FFFFFF"));
ZenoSettingsManager &settings = ZenoSettingsManager::GetInstance();
m_btnRun->setShortcut(settings.getShortCut(ShortCut_Run));
m_btnRun->setCursor(QCursor(Qt::PointingHandCursor));

//kill
m_btnKill->setButtonOptions(ZToolButton::Opt_TextRightToIcon);
m_btnKill->setIcon(ZenoStyle::dpiScaledSize(QSize(14, 14)), ":/icons/timeline_kill_clean.svg",
":/icons/timeline_kill_clean.svg", "", "");
m_btnKill->setRadius(ZenoStyle::dpiScaled(2));
m_btnKill->setFont(fnt);
m_btnKill->setText(tr("Kill"));
m_btnKill->setCursor(QCursor(Qt::PointingHandCursor));
m_btnKill->setMargins(ZenoStyle::dpiScaledMargins(QMargins(11, 5, 14, 5)));
m_btnKill->setBackgroundClr(QColor("#4578AC"), QColor("#4578AC"), QColor("#4578AC"), QColor("#4578AC"), QColor("#4D5561"));
m_btnKill->setTextClr(QColor("#FFFFFF"), QColor("#FFFFFF"), QColor("#FFFFFF"), QColor("#FFFFFF"));
m_btnKill->setShortcut(settings.getShortCut(ShortCut_Kill));
m_btnKill->setCursor(QCursor(Qt::PointingHandCursor));
m_btnKill->setEnabled(false);
m_btnKill->setVisible(false);

QFontMetrics fontMetrics(fnt);

Expand Down Expand Up @@ -369,7 +397,7 @@ void DockContent_Editor::initToolbar(QHBoxLayout* pToolLayout)
pToolLayout->addWidget(pLinkLineShape);
pToolLayout->addWidget(pAlways);

pToolLayout->addWidget(new ZLineWidget(false, QColor("#121416")));
//pToolLayout->addWidget(new ZLineWidget(false, QColor("#121416")));

pToolLayout->addWidget(m_btnRun);
pToolLayout->addWidget(m_btnKill);
Expand Down Expand Up @@ -444,14 +472,14 @@ void DockContent_Editor::initConnections()
ZenoMainWindow* pMainWin = zenoApp->getMainWindow();
ZASSERT_EXIT(pMainWin);
std::function<void()> resetAlways = [=]() {
pAlways->toggle(false);
pAlways->setChecked(false);
pMainWin->setAlways(false);
pMainWin->setAlwaysLightCameraMaterial(false, false);
};
connect(zenoApp->graphsManagment(), &GraphsManagment::fileOpened, this, resetAlways);
connect(zenoApp->graphsManagment(), &GraphsManagment::modelInited, this, resetAlways);
connect(pAlways, &ZToolBarButton::toggled, this, [=](bool bChecked) {
if (bChecked)
connect(pAlways, &QCheckBox::toggled, this, [=](bool checked) {
if (checked)
{
QSettings settings(zsCompanyName, zsEditor);
if (!settings.value("zencache-enable").toBool()) {
Expand Down Expand Up @@ -506,8 +534,8 @@ void DockContent_Editor::initConnections()
IGraphsModel* pGraphsModel = zenoApp->graphsManagment()->currentModel();
if (!pGraphsModel)
return;
m_btnRun->setEnabled(false);
m_btnKill->setEnabled(true);
m_btnRun->setVisible(false);
m_btnKill->setVisible(true);
std::shared_ptr<ZCacheMgr> mgr = zenoApp->cacheMgr();
ZASSERT_EXIT(mgr);
ZenoMainWindow *pMainWin = zenoApp->getMainWindow();
Expand Down Expand Up @@ -548,33 +576,37 @@ void DockContent_Editor::initConnections()

connect(m_btnRun, &ZToolMenuButton::textChanged, this, [=]() {
if (pAlways->isChecked())
emit pAlways->toggled(true);
pAlways->setChecked(false);
QString text = m_btnRun->text();
QColor clr;
QColor hoverClr;
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");
clr = QColor("#1978E6");
hoverClr = QColor("#599EED");
m_btnRun->setIcon(ZenoStyle::dpiScaledSize(QSize(16, 16)), ":/icons/run_all_btn.svg",
":/icons/run_all_btn.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");
clr = QColor("#E67B19");
hoverClr = QColor("#EDA059");
m_btnRun->setIcon(ZenoStyle::dpiScaledSize(QSize(16, 16)), ":/icons/run_lightcamera_btn.svg",
":/icons/run_lightcamera_btn.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");
clr = QColor("#BD19E6");
hoverClr = QColor("#CF59ED");
m_btnRun->setIcon(ZenoStyle::dpiScaledSize(QSize(16, 16)), ":/icons/run_material_btn.svg",
":/icons/run_material_btn.svg", "", "");
}
m_btnRun->setBackgroundClr(clr, clr, clr, clr);
m_btnRun->setBackgroundClr(clr, hoverClr, clr, clr);
});
connect(m_btnKill, &ZToolButton::clicked, this, [=]() {
connect(m_btnKill, &ZTextIconButton::clicked, this, [=]() {
killProgram();
m_btnRun->setEnabled(true);
m_btnKill->setEnabled(false);
m_btnRun->setVisible(true);
m_btnKill->setVisible(false);
});

connect(&ZenoSettingsManager::GetInstance(), &ZenoSettingsManager::valueChanged, this, [=](QString name) {
Expand Down Expand Up @@ -602,6 +634,14 @@ void DockContent_Editor::initConnections()
m_btnKill->setShortcut(ZenoSettingsManager::GetInstance().getShortCut(ShortCut_Kill));
}
});

connect(pGraphsMgm, &GraphsManagment::modelDataChanged, this, [=]() {
if (pAlways->isChecked())
{
m_btnRun->setVisible(false);
m_btnKill->setVisible(true);
}
});
}

ZenoGraphsEditor* DockContent_Editor::getEditor() const
Expand All @@ -611,8 +651,8 @@ ZenoGraphsEditor* DockContent_Editor::getEditor() const

void DockContent_Editor::runFinished()
{
m_btnRun->setEnabled(true);
m_btnKill->setEnabled(false);
m_btnRun->setVisible(true);
m_btnKill->setVisible(false);
}

void DockContent_Editor::onCommandDispatched(QAction* pAction, bool bTriggered)
Expand Down
20 changes: 18 additions & 2 deletions ui/zenoedit/dock/docktabcontent.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ class ZToolRecordingButton : public ZToolButton {
#endif


class ZTextIconButton : public QWidget
{
Q_OBJECT
public:
ZTextIconButton(const QString &text, QWidget *parent = nullptr);
~ZTextIconButton();
void setShortcut(QKeySequence text);
signals:
void clicked();

private:
QPushButton* m_pButton;
QLabel* m_pLablel;
QShortcut* m_shortcut;
};

class DockToolbarWidget : public QWidget
{
Q_OBJECT
Expand Down Expand Up @@ -98,12 +114,12 @@ class DockContent_Editor : public DockToolbarWidget
ZToolBarButton *pCustomParam;
ZToolBarButton *pGroup;
ZToolBarButton *pLinkLineShape;
ZToolBarButton *pAlways;
QCheckBox*pAlways;
ZToolBarButton *pSearchBtn;
ZToolBarButton *pSettings;

ZToolMenuButton *m_btnRun;
ZToolButton* m_btnKill;
ZTextIconButton* m_btnKill;

QComboBox* cbZoom;
};
Expand Down
10 changes: 7 additions & 3 deletions ui/zenoedit/res/icons.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,16 @@
<file>icons/ZENO-logo64.png</file>
<file>icons/update_main.png</file>
<file>icons/update-reboot.png</file>
<file>icons/run_all_btn.svg</file>
<file>icons/run_lightcamera_btn.svg</file>
<file>icons/run_material_btn.svg</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>
<file>icons/RunKill.svg</file>
<file>icons/RunKill_on.svg</file>
<file>icons/always_checkbox.svg</file>
<file>icons/always_checkbox_on.svg</file>
</qresource>
</RCC>
10 changes: 10 additions & 0 deletions ui/zenoedit/res/icons/RunKill.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions ui/zenoedit/res/icons/RunKill_on.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/always_checkbox.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/always_checkbox_on.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 3 additions & 4 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_btn.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: 0 additions & 3 deletions ui/zenoedit/res/icons/run_all_disable.svg

This file was deleted.

Loading
Loading