Make the inverted component more obvious
Mark inverted components as blue to differentiate with normal components.master
parent
1f8f7913a7
commit
753dfe9d8f
|
@ -796,6 +796,7 @@ DocumentWindow::DocumentWindow() :
|
|||
connect(m_document, &Document::componentRemoved, partTreeWidget, &PartTreeWidget::componentRemoved);
|
||||
connect(m_document, &Document::componentAdded, partTreeWidget, &PartTreeWidget::componentAdded);
|
||||
connect(m_document, &Document::componentExpandStateChanged, partTreeWidget, &PartTreeWidget::componentExpandStateChanged);
|
||||
connect(m_document, &Document::componentInverseStateChanged, partTreeWidget, &PartTreeWidget::componentInverseStateChanged);
|
||||
connect(m_document, &Document::partPreviewChanged, partTreeWidget, &PartTreeWidget::partPreviewChanged);
|
||||
connect(m_document, &Document::partLockStateChanged, partTreeWidget, &PartTreeWidget::partLockStateChanged);
|
||||
connect(m_document, &Document::partVisibleStateChanged, partTreeWidget, &PartTreeWidget::partVisibleStateChanged);
|
||||
|
|
|
@ -103,6 +103,11 @@ void PartTreeWidget::selectComponent(QUuid componentId, bool multiple)
|
|||
}
|
||||
}
|
||||
|
||||
void PartTreeWidget::updateComponentAppearance(QUuid componentId)
|
||||
{
|
||||
updateComponentSelectState(componentId, isComponentSelected(componentId));
|
||||
}
|
||||
|
||||
void PartTreeWidget::updateComponentSelectState(QUuid componentId, bool selected)
|
||||
{
|
||||
const Component *component = m_document->findComponent(componentId);
|
||||
|
@ -114,19 +119,19 @@ void PartTreeWidget::updateComponentSelectState(QUuid componentId, bool selected
|
|||
auto item = m_partItemMap.find(component->linkToPartId);
|
||||
if (item != m_componentItemMap.end()) {
|
||||
PartWidget *widget = (PartWidget *)itemWidget(item->second, 0);
|
||||
// Inverse state updating call should be called before check state updating call
|
||||
widget->updateInverseState(component->inverse);
|
||||
widget->updateCheckedState(selected);
|
||||
}
|
||||
return;
|
||||
}
|
||||
auto item = m_componentItemMap.find(componentId);
|
||||
if (item != m_componentItemMap.end()) {
|
||||
if (selected) {
|
||||
item->second->setFont(0, m_selectedFont);
|
||||
item->second->setForeground(0, QBrush(Theme::red));
|
||||
} else {
|
||||
item->second->setFont(0, m_normalFont);
|
||||
item->second->setForeground(0, QBrush(Theme::white));
|
||||
}
|
||||
item->second->setFont(0, selected ? m_selectedFont : m_normalFont);
|
||||
if (component->inverse)
|
||||
item->second->setForeground(0, selected ? QBrush(Theme::blue) : QBrush(Theme::blue));
|
||||
else
|
||||
item->second->setForeground(0, selected ? QBrush(Theme::red) : QBrush(Theme::white));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -254,7 +259,7 @@ void PartTreeWidget::showContextMenu(const QPoint &pos)
|
|||
} else {
|
||||
QLabel *previewLabel = new QLabel;
|
||||
previewLabel->setFixedHeight(Theme::partPreviewImageSize);
|
||||
previewLabel->setStyleSheet("QLabel {color: " + Theme::red.name() + "}");
|
||||
previewLabel->setStyleSheet("QLabel {color: " + (component && component->inverse ? Theme::blue.name() : Theme::red.name()) + "}");
|
||||
if (nullptr != component) {
|
||||
previewLabel->setText(component->name);
|
||||
} else if (!componentIds.empty()) {
|
||||
|
@ -650,6 +655,11 @@ void PartTreeWidget::componentExpandStateChanged(QUuid componentId)
|
|||
componentItem->second->setExpanded(component->expanded);
|
||||
}
|
||||
|
||||
void PartTreeWidget::componentInverseStateChanged(QUuid componentId)
|
||||
{
|
||||
updateComponentAppearance(componentId);
|
||||
}
|
||||
|
||||
void PartTreeWidget::addComponentChildrenToItem(QUuid componentId, QTreeWidgetItem *parentItem)
|
||||
{
|
||||
const Component *parentComponent = m_document->findComponent(componentId);
|
||||
|
|
|
@ -49,6 +49,7 @@ public slots:
|
|||
void componentRemoved(QUuid componentId);
|
||||
void componentAdded(QUuid componentId);
|
||||
void componentExpandStateChanged(QUuid componentId);
|
||||
void componentInverseStateChanged(QUuid componentId);
|
||||
void partRemoved(QUuid partId);
|
||||
void partPreviewChanged(QUuid partid);
|
||||
void partLockStateChanged(QUuid partId);
|
||||
|
@ -77,6 +78,7 @@ private:
|
|||
void selectComponent(QUuid componentId, bool multiple=false);
|
||||
QWidget *createSmoothMenuWidget(QUuid componentId);
|
||||
void updateComponentSelectState(QUuid componentId, bool selected);
|
||||
void updateComponentAppearance(QUuid componentId);
|
||||
bool isComponentSelected(QUuid componentId);
|
||||
private:
|
||||
const Document *m_document = nullptr;
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
|
||||
PartWidget::PartWidget(const Document *document, QUuid partId) :
|
||||
m_document(document),
|
||||
m_partId(partId)
|
||||
m_partId(partId),
|
||||
m_inverted(false)
|
||||
{
|
||||
QSizePolicy retainSizePolicy = sizePolicy();
|
||||
retainSizePolicy.setRetainSizeWhenHidden(true);
|
||||
|
@ -262,11 +263,20 @@ void PartWidget::updateAllButtons()
|
|||
void PartWidget::updateCheckedState(bool checked)
|
||||
{
|
||||
if (checked)
|
||||
m_backgroundWidget->setStyleSheet("QWidget#background {border: 1px solid " + Theme::red.name() + ";}");
|
||||
m_backgroundWidget->setStyleSheet("QWidget#background {border: 1px solid " + (m_inverted ? Theme::blue.name() : Theme::red.name()) + ";}");
|
||||
else
|
||||
m_backgroundWidget->setStyleSheet("QWidget#background {border: 1px solid transparent;}");
|
||||
}
|
||||
|
||||
void PartWidget::updateInverseState(bool inverse)
|
||||
{
|
||||
if (m_inverted == inverse)
|
||||
return;
|
||||
|
||||
m_inverted = inverse;
|
||||
updateAllButtons();
|
||||
}
|
||||
|
||||
void PartWidget::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
{
|
||||
QWidget::mouseDoubleClickEvent(event);
|
||||
|
@ -429,7 +439,7 @@ void PartWidget::initButton(QPushButton *button)
|
|||
|
||||
void PartWidget::updateButton(QPushButton *button, QChar icon, bool highlighted)
|
||||
{
|
||||
Theme::updateAwesomeMiniButton(button, icon, highlighted);
|
||||
Theme::updateAwesomeMiniButton(button, icon, highlighted, m_inverted);
|
||||
}
|
||||
|
||||
void PartWidget::updatePreview()
|
||||
|
|
|
@ -45,6 +45,7 @@ public:
|
|||
void updateColorButton();
|
||||
void updateWrapButton();
|
||||
void updateCheckedState(bool checked);
|
||||
void updateInverseState(bool inverse);
|
||||
static QSize preferredSize();
|
||||
ModelWidget *previewWidget();
|
||||
protected:
|
||||
|
@ -55,6 +56,7 @@ public slots:
|
|||
private: // need initialize
|
||||
const Document *m_document;
|
||||
QUuid m_partId;
|
||||
bool m_inverted;
|
||||
private:
|
||||
ModelWidget *m_previewWidget;
|
||||
QPushButton *m_visibleButton;
|
||||
|
|
|
@ -103,18 +103,28 @@ void Theme::initAwesomeMiniButton(QPushButton *button)
|
|||
button->setFocusPolicy(Qt::NoFocus);
|
||||
}
|
||||
|
||||
void Theme::updateAwesomeMiniButton(QPushButton *button, QChar icon, bool highlighted)
|
||||
void Theme::updateAwesomeMiniButton(QPushButton *button, QChar icon, bool highlighted, bool inverted)
|
||||
{
|
||||
button->setText(icon);
|
||||
QColor color;
|
||||
if (highlighted)
|
||||
color = QColor("#fc6621");
|
||||
else
|
||||
color = QColor("#525252");
|
||||
bool needDesaturation = true;
|
||||
|
||||
color = color.toHsv();
|
||||
color.setHsv(color.hue(), color.saturation() / 5, color.value() * 2 / 3);
|
||||
color = color.toRgb();
|
||||
if (highlighted) {
|
||||
if (inverted) {
|
||||
color = Theme::blue;
|
||||
needDesaturation = false;
|
||||
} else {
|
||||
color = Theme::red;
|
||||
}
|
||||
} else {
|
||||
color = QColor("#525252");
|
||||
}
|
||||
|
||||
if (needDesaturation) {
|
||||
color = color.toHsv();
|
||||
color.setHsv(color.hue(), color.saturation() / 5, color.value() * 2 / 3);
|
||||
color = color.toRgb();
|
||||
}
|
||||
|
||||
button->setStyleSheet("QPushButton {border: none; background: none; color: " + color.name() + ";}");
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ public:
|
|||
static void initAwesomeLabel(QLabel *label);
|
||||
static void initAwesomeSmallButton(QPushButton *button);
|
||||
static void initAwesomeMiniButton(QPushButton *button);
|
||||
static void updateAwesomeMiniButton(QPushButton *button, QChar icon, bool highlighted);
|
||||
static void updateAwesomeMiniButton(QPushButton *button, QChar icon, bool highlighted, bool inverted=false);
|
||||
static void initAwesomeToolButton(QPushButton *button);
|
||||
static void initAwesomeToolButtonWithoutFont(QPushButton *button);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue