MCPcopy Create free account
hub / github.com/KDE/kdevelop / updateButtonForWidget

Function updateButtonForWidget

kdevplatform/sublime/idealbuttonbarwidget.cpp:118–146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

116 }
117
118 void updateButtonForWidget()
119 {
120 Q_ASSERT(m_button);
121
122 // Use the inactive color for the text of the tool button if its tool view widget is disabled
123 // in order to indicate whether the tool view is enabled even while it is hidden.
124
125 const auto enabled = toolViewWidget()->isEnabled();
126 if (enabled && !m_wasToolViewWidgetEverDisabled) {
127 // Most tool view widgets are never disabled. So this is a fast path:
128 // keep the default (enabled) button text color, nothing to do.
129 return;
130 }
131
132 if (!m_wasToolViewWidgetEverDisabled) {
133 Q_ASSERT(!enabled); // otherwise should have returned earlier
134 m_wasToolViewWidgetEverDisabled = true;
135 // Once the palette of the button is adjusted, we have to handle its palette-change events because the text
136 // color of the button is no longer updated automatically when the user switches between color schemes.
137 m_button->installEventFilter(this);
138 }
139
140 auto palette = m_button->palette();
141 // Replacing the specialized color role QPalette::ButtonText has no effect
142 // for some reason, so replace the more general role QPalette::WindowText instead.
143 KColorScheme::adjustForeground(palette, enabled ? KColorScheme::NormalText : KColorScheme::InactiveText,
144 QPalette::WindowText, KColorScheme::Button);
145 m_button->setPalette(palette);
146 }
147
148 IdealDockWidget* const m_dock;
149 IdealToolButton* m_button = nullptr;

Callers 2

setButtonFunction · 0.85
eventFilterFunction · 0.85

Calls 1

isEnabledMethod · 0.45

Tested by

no test coverage detected