From 753dfe9d8f8cf31c0906894eae7e5bb98fdbc229 Mon Sep 17 00:00:00 2001 From: huxingyi Date: Wed, 14 Nov 2018 11:11:31 +0800 Subject: [PATCH] Make the inverted component more obvious Mark inverted components as blue to differentiate with normal components. --- src/documentwindow.cpp | 1 + src/parttreewidget.cpp | 26 ++++++++++++++++++-------- src/parttreewidget.h | 2 ++ src/partwidget.cpp | 16 +++++++++++++--- src/partwidget.h | 2 ++ src/theme.cpp | 26 ++++++++++++++++++-------- src/theme.h | 2 +- 7 files changed, 55 insertions(+), 20 deletions(-) diff --git a/src/documentwindow.cpp b/src/documentwindow.cpp index 8ad85a65..934dfb94 100644 --- a/src/documentwindow.cpp +++ b/src/documentwindow.cpp @@ -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); diff --git a/src/parttreewidget.cpp b/src/parttreewidget.cpp index 6253f257..0d450e3f 100644 --- a/src/parttreewidget.cpp +++ b/src/parttreewidget.cpp @@ -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); diff --git a/src/parttreewidget.h b/src/parttreewidget.h index 54fef091..a03486a3 100644 --- a/src/parttreewidget.h +++ b/src/parttreewidget.h @@ -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; diff --git a/src/partwidget.cpp b/src/partwidget.cpp index 724239e2..85bf5ce3 100644 --- a/src/partwidget.cpp +++ b/src/partwidget.cpp @@ -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() diff --git a/src/partwidget.h b/src/partwidget.h index 3641aa1c..15a4ef72 100644 --- a/src/partwidget.h +++ b/src/partwidget.h @@ -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; diff --git a/src/theme.cpp b/src/theme.cpp index 7c21085b..8742d9ec 100644 --- a/src/theme.cpp +++ b/src/theme.cpp @@ -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 + bool needDesaturation = true; + + if (highlighted) { + if (inverted) { + color = Theme::blue; + needDesaturation = false; + } else { + color = Theme::red; + } + } else { color = QColor("#525252"); - - color = color.toHsv(); - color.setHsv(color.hue(), color.saturation() / 5, color.value() * 2 / 3); - color = color.toRgb(); + } + + 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() + ";}"); } diff --git a/src/theme.h b/src/theme.h index 30351182..4c68fe62 100644 --- a/src/theme.h +++ b/src/theme.h @@ -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); };