MCPcopy Create free account
hub / github.com/NatronGitHub/Natron / createWidget

Method createWidget

Gui/KnobGuiButton.cpp:94–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92}
93
94void
95KnobGuiButton::createWidget(QHBoxLayout* layout)
96{
97 KnobButtonPtr knob = _knob.lock();
98 QString label = QString::fromUtf8( knob->getLabel().c_str() );
99 QString onIconFilePath = QString::fromUtf8( knob->getIconLabel(true).c_str() );
100 QString offIconFilePath = QString::fromUtf8( knob->getIconLabel(false).c_str() );
101
102
103 if ( !onIconFilePath.isEmpty() && !QFile::exists(onIconFilePath) ) {
104 EffectInstance* isEffect = dynamic_cast<EffectInstance*>( knob->getHolder() );
105 if (isEffect) {
106 //Prepend the resources path
107 QString resourcesPath = QString::fromUtf8( isEffect->getNode()->getPluginResourcesPath().c_str() );
108 if ( !resourcesPath.endsWith( QLatin1Char('/') ) ) {
109 resourcesPath += QLatin1Char('/');
110 }
111 onIconFilePath.prepend(resourcesPath);
112 }
113 }
114 if ( !offIconFilePath.isEmpty() && !QFile::exists(offIconFilePath) ) {
115 EffectInstance* isEffect = dynamic_cast<EffectInstance*>( knob->getHolder() );
116 if (isEffect) {
117 //Prepend the resources path
118 QString resourcesPath = QString::fromUtf8( isEffect->getNode()->getPluginResourcesPath().c_str() );
119 if ( !resourcesPath.endsWith( QLatin1Char('/') ) ) {
120 resourcesPath += QLatin1Char('/');
121 }
122 offIconFilePath.prepend(resourcesPath);
123 }
124 }
125
126 bool checkable = knob->getIsCheckable();
127 QIcon icon;
128 QPixmap pixChecked, pixUnchecked;
129 if ( !offIconFilePath.isEmpty() ) {
130 if ( pixUnchecked.load(offIconFilePath) ) {
131 icon.addPixmap(pixUnchecked, QIcon::Normal, QIcon::Off);
132 }
133 }
134 if ( !onIconFilePath.isEmpty() ) {
135 if ( pixChecked.load(onIconFilePath) ) {
136 icon.addPixmap(pixChecked, QIcon::Normal, QIcon::On);
137 }
138 }
139
140 if ( !icon.isNull() ) {
141 _button = new Button( icon, QString(), layout->parentWidget() );
142 _button->setFixedSize(NATRON_MEDIUM_BUTTON_SIZE, NATRON_MEDIUM_BUTTON_SIZE);
143 _button->setIconSize( QSize(NATRON_MEDIUM_BUTTON_ICON_SIZE, NATRON_MEDIUM_BUTTON_ICON_SIZE) );
144 } else {
145 _button = new Button( label, layout->parentWidget() );
146 }
147 if (checkable) {
148 _button->setCheckable(true);
149 bool checked = knob->getValue();
150 _button->setChecked(checked);
151 _button->setDown(checked);

Callers

nothing calls this directly

Calls 15

toolTipFunction · 0.85
getIsCheckableMethod · 0.80
setCheckableMethod · 0.80
addWidgetMethod · 0.80
QStringClass · 0.50
lockMethod · 0.45
getLabelMethod · 0.45
isEmptyMethod · 0.45
getHolderMethod · 0.45
getNodeMethod · 0.45
loadMethod · 0.45
isNullMethod · 0.45

Tested by

no test coverage detected