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

MAYA-128363 pin stage in layer editor #3052

Merged
merged 6 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
70 changes: 3 additions & 67 deletions lib/usd/ui/layerEditor/layerEditorWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,70 +48,6 @@ namespace {

using namespace UsdLayerEditor;

// returns image_100.png" when you pass "image",
// using the DPI setting and also returns always 100 on mac, because Qt doesn't
// properly support high dpi with style sheets
QString getDPIPixmapName(QString baseName)
{
#ifdef Q_OS_DARWIN
return baseName + "_100.png";
#else
const auto scale = utils->dpiScale();
if (scale >= 2.0)
return baseName + "_200.png";
else if (scale >= 1.5)
return baseName + "_150.png";
return baseName + "_100.png";
#endif
}

// setup a push button with DPI-appropriate regular, hover and pressed png in the
// autodesk human interface guideline style
static void setupButtonWithHIGBitmaps(QPushButton* button, const QString& baseName)
{
button->setFlat(true);

// regular size: 16px, pressed:24px
// therefore, border is 4
int padding = DPIScale(4);
QString cssTemplate(R"CSS(
QPushButton {
padding : %1px;
background-image: url(%2);
background-position: center center;
background-repeat: no-repeat;
border: 0px;
background-origin: content;
}
QPushButton::hover {
background-image: url(%3);
}
QPushButton::pressed {
background-image: url(%4);
border: 0px;
padding: 0px;
background-origin: content;
})CSS");

QString css = cssTemplate.arg(padding)
.arg(getDPIPixmapName(baseName))
.arg(getDPIPixmapName(baseName + "_hover"))
.arg(getDPIPixmapName(baseName + "_pressed"));

button->setStyleSheet(css);

// overkill, but used to generate the grayed out version
auto effect = new QGraphicsOpacityEffect(button);
button->setGraphicsEffect(effect);
}

void disableHIGButton(QPushButton* button, bool disable = true)
{
button->setDisabled(disable);
auto effect = dynamic_cast<QGraphicsOpacityEffect*>(button->graphicsEffect());
effect->setOpacity(disable ? 0.4 : 1.0);
}

// create the default menus on the parent QMainWindow
void setupDefaultMenu(SessionState* in_sessionState, QMainWindow* in_parent)
{
Expand Down Expand Up @@ -225,7 +161,7 @@ QLayout* LayerEditorWidget::setupLayout_toolbar()
auto higButtonYOffset = DPIScale(4);
auto higBtn = new QPushButton();
higBtn->move(0, higButtonYOffset);
setupButtonWithHIGBitmaps(higBtn, iconName);
QtUtils::setupButtonWithHIGBitmaps(higBtn, iconName);
higBtn->setFixedSize(buttonSize, buttonSize);
higBtn->setToolTip(tooltip);
toolbar->addWidget(higBtn, 0, buttonAlignment);
Expand Down Expand Up @@ -279,7 +215,7 @@ QLayout* LayerEditorWidget::setupLayout_toolbar()
_saveButtonParent->setFixedSize(saveButtonSize);
auto saveStageBtn = new QPushButton(_saveButtonParent);
saveStageBtn->move(0, saveButtonYOffset);
setupButtonWithHIGBitmaps(saveStageBtn, ":/UsdLayerEditor/LE_save_all");
QtUtils::setupButtonWithHIGBitmaps(saveStageBtn, ":/UsdLayerEditor/LE_save_all");
saveStageBtn->setFixedSize(buttonSize, buttonSize);
saveStageBtn->setToolTip(
StringResources::getAsQString(StringResources::kSaveAllEditsInLayerStack));
Expand Down Expand Up @@ -371,7 +307,7 @@ void LayerEditorWidget::updateButtons()
int count = static_cast<int>(layers.size());
_buttons._dirtyCountBadge->updateCount(count);
bool disable = count == 0;
disableHIGButton(_buttons._saveStageButton, disable);
QtUtils::disableHIGButton(_buttons._saveStageButton, disable);
} else {
_saveButtonParent->setVisible(false);
}
Expand Down
59 changes: 59 additions & 0 deletions lib/usd/ui/layerEditor/qtUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,65 @@ QPixmap QtUtils::createPixmap(QString const& in_pixmapName, int width, int heigh
return pixmap;
}

QString QtUtils::getDPIPixmapName(QString baseName)
{
#ifdef Q_OS_DARWIN
return baseName + "_100.png";
#else
const auto scale = utils->dpiScale();
if (scale >= 2.0)
return baseName + "_200.png";
else if (scale >= 1.5)
return baseName + "_150.png";
return baseName + "_100.png";
#endif
}

void QtUtils::setupButtonWithHIGBitmaps(QPushButton* button, const QString& baseName)
{
button->setFlat(true);

// regular size: 16px, pressed:24px
// therefore, border is 4
int padding = DPIScale(4);
QString cssTemplate(R"CSS(
QPushButton {
padding : %1px;
background-image: url(%2);
background-position: center center;
background-repeat: no-repeat;
border: 0px;
background-origin: content;
}
QPushButton::hover {
background-image: url(%3);
}
QPushButton::pressed {
background-image: url(%4);
border: 0px;
padding: 0px;
background-origin: content;
})CSS");

QString css = cssTemplate.arg(padding)
.arg(getDPIPixmapName(baseName))
.arg(getDPIPixmapName(baseName + "_hover"))
.arg(getDPIPixmapName(baseName + "_pressed"));

button->setStyleSheet(css);

// overkill, but used to generate the grayed out version
auto effect = new QGraphicsOpacityEffect(button);
button->setGraphicsEffect(effect);
}

void QtUtils::disableHIGButton(QPushButton* button, bool disable)
{
button->setDisabled(disable);
auto effect = dynamic_cast<QGraphicsOpacityEffect*>(button->graphicsEffect());
effect->setOpacity(disable ? 0.4 : 1.0);
}

UsdLayerEditor::QtUtils* utils;

void QtUtils::initLayoutMargins(QLayout* layout, int margin)
Expand Down
11 changes: 11 additions & 0 deletions lib/usd/ui/layerEditor/qtUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ class QtUtils
auto localPos = widget->mapFromGlobal(globalPos);
return rect.contains(localPos);
}

// Prepares a push button with DPI-appropriate regular, hover and pressed png in the
// autodesk human interface guideline style
static void setupButtonWithHIGBitmaps(QPushButton* button, const QString& baseName);

// Returns image_100.png" when you pass "image",
// using the DPI setting and also returns always 100 on mac, because Qt doesn't
// properly support high dpi with style sheets
static QString getDPIPixmapName(QString baseName);

static void disableHIGButton(QPushButton* button, bool disable = true);
};

/**
Expand Down
18 changes: 18 additions & 0 deletions lib/usd/ui/layerEditor/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@
<file alias="LE_import_layer_pressed_150.png">resources/import_layer_pressed_150.png</file>
<file alias="LE_import_layer_pressed_200.png">resources/import_layer_pressed_200.png</file>

<file alias="pin_off_100.png">resources/pin_off_100.png</file>
<file alias="pin_off_150.png">resources/pin_off_150.png</file>
<file alias="pin_off_200.png">resources/pin_off_200.png</file>
<file alias="pin_off_hover_100.png">resources/pin_off_hover_100.png</file>
<file alias="pin_off_hover_150.png">resources/pin_off_hover_150.png</file>
<file alias="pin_off_hover_200.png">resources/pin_off_hover_200.png</file>
<file alias="pin_off_pressed_100.png">resources/pin_on_hover_100.png</file>
<file alias="pin_off_pressed_150.png">resources/pin_on_hover_150.png</file>
<file alias="pin_off_pressed_200.png">resources/pin_on_hover_200.png</file>
<file alias="pin_on_100.png">resources/pin_on_100.png</file>
<file alias="pin_on_150.png">resources/pin_on_150.png</file>
<file alias="pin_on_200.png">resources/pin_on_200.png</file>
<file alias="pin_on_hover_100.png">resources/pin_on_hover_100.png</file>
<file alias="pin_on_hover_150.png">resources/pin_on_hover_150.png</file>
<file alias="pin_on_hover_200.png">resources/pin_on_hover_200.png</file>
<file alias="pin_on_pressed_100.png">resources/pin_off_hover_100.png</file>
<file alias="pin_on_pressed_150.png">resources/pin_off_hover_150.png</file>
<file alias="pin_on_pressed_200.png">resources/pin_off_hover_200.png</file>

<file alias="target_hover.png">resources/target_hover_100.png</file>
<file alias="target_hover_150.png">resources/target_hover_150.png</file>
Expand Down
Binary file added lib/usd/ui/layerEditor/resources/pin_off_100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/usd/ui/layerEditor/resources/pin_off_150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/usd/ui/layerEditor/resources/pin_off_200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/usd/ui/layerEditor/resources/pin_on_100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/usd/ui/layerEditor/resources/pin_on_150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/usd/ui/layerEditor/resources/pin_on_200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading