void ShaderParamsDialog::onParameterLabelContextMenuRequested(const QPoint&) { QLabel *label = NULL; QPointer<QAction> action; QList<QAction*> actions; QScopedPointer<QAction> resetParamAction; QVariant paramVariant; QString parameter; label = qobject_cast<QLabel*>(sender()); if (!label) return; paramVariant = label->property("parameter"); if (!paramVariant.isValid()) return; parameter = paramVariant.toString(); resetParamAction.reset(new QAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_RESET_PARAMETER), 0)); actions.append(resetParamAction.data()); action = QMenu::exec(actions, QCursor::pos(), NULL, label); if (!action) return; if (action == resetParamAction.data()) { onShaderResetParameter(parameter); } }
void ParamWidget::AddDouble(const QString& name, double min, double max, double step, double initial_value, DisplayHint display_hint) { ExpectNameNotFound(name); if (display_hint == DisplayHint::kSpinBox) { QDoubleSpinBox* spinbox = new QDoubleSpinBox(this); spinbox->setRange(min, max); spinbox->setSingleStep(step); spinbox->setValue(initial_value); spinbox->setProperty("param_widget_type", kParamDouble); widgets_[name] = spinbox; AddLabeledRow(name, spinbox); connect(spinbox, static_cast<void(QDoubleSpinBox::*)(double)>( &QDoubleSpinBox::valueChanged), [this, name](double value) { emit ParamChanged(name); }); } else if (display_hint == DisplayHint::kSlider) { QWidget* row_widget = new QWidget(this); QHBoxLayout* row_hbox = new QHBoxLayout(row_widget); QSlider* slider = new QSlider(Qt::Horizontal, this); const int num_steps = static_cast<int>((max - min) / step); const int initial_value_int = static_cast<int>((initial_value - min) / step); slider->setRange(0, num_steps); slider->setSingleStep(1); slider->setValue(initial_value_int); slider->setProperty("min", min); slider->setProperty("max", max); slider->setProperty("step", step); slider->setProperty("param_widget_type", kParamDouble); QLabel* label = new QLabel(this); label->setText(QString::number((initial_value_int - min) * step)); row_hbox->addWidget(new QLabel(name, this)); row_hbox->addWidget(slider); row_hbox->addWidget(label); widgets_[name] = slider; layout_->addWidget(row_widget); slider->setProperty("param_widget_label", QVariant::fromValue(label)); label->setProperty("format_str", ""); connect(slider, &QSlider::valueChanged, [this, name, label, min, step](int position) { const double value = min + step * position; const QString format_str = label->property("format_str").toString(); if (format_str == "") { label->setText(QString::number(value)); label->setMinimumWidth(std::max(label->width(), label->minimumWidth())); } else { QString text; text.sprintf(format_str.toStdString().c_str(), value); label->setText(text); } emit ParamChanged(name); }); } else { throw std::invalid_argument("Invalid display hint"); } }
void DragDropArea::mousePressEvent(QMouseEvent *event) { QLabel *child = static_cast<QLabel*>(childAt(event->pos())); if (!child) return; // Only drag children with dynamic property: "drag" if (!child->property("drag").toBool()) return; QPoint hotSpot = event->pos() - child->pos(); QMimeData *mimeData = new QMimeData; mimeData->setText(child->text()); mimeData->setData("application/x-hotspot", QByteArray::number(hotSpot.x()) + " " + QByteArray::number(hotSpot.y())); QPixmap pixmap(child->size()); child->render(&pixmap); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); drag->setPixmap(pixmap); drag->setHotSpot(hotSpot); drag->exec(); }
void CustomFunctionsPanel::fsw_customContextMenuRequested(QPoint pos) { QLabel *label = (QLabel *)sender(); selectedFunction = label->property("index").toInt(); QPoint globalPos = label->mapToGlobal(pos); const QClipboard *clipboard = QApplication::clipboard(); const QMimeData *mimeData = clipboard->mimeData(); bool hasData = mimeData->hasFormat("application/x-companion-fsw"); QMenu contextMenu; contextMenu.addAction(CompanionIcon("copy.png"), tr("&Copy"),this,SLOT(fswCopy()),tr("Ctrl+C")); contextMenu.addAction(CompanionIcon("cut.png"), tr("&Cut"),this,SLOT(fswCut()),tr("Ctrl+X")); contextMenu.addAction(CompanionIcon("paste.png"), tr("&Paste"),this,SLOT(fswPaste()),tr("Ctrl+V"))->setEnabled(hasData); contextMenu.addAction(CompanionIcon("clear.png"), tr("&Delete"),this,SLOT(fswDelete()),tr("Delete")); contextMenu.exec(globalPos); }
void PreferencesDialog::changeSyntaxElementColor(int ElementRow) { QLabel* StyleNameLabel = qobject_cast<QLabel*>(ui->SyntaxGridLayout->itemAtPosition(ElementRow,0)->widget()); QString ColorName = StyleNameLabel->property("ColorName").toString(); QColor Color = QColorDialog::getColor(QColor(ColorName),this); // Cancel on QColorDialog returns an invalid Color if(Color.isValid()) { QString NewColorName = Color.name(); StyleNameLabel->setProperty("ColorName",NewColorName); changeSyntaxElementDecoration(ElementRow); m_TextEditorSettingsChanged = true; } }
void PreferencesDialog::changeSyntaxElementDecoration(int ElementRow) { QLabel* StyleNameLabel = qobject_cast<QLabel*>(ui->SyntaxGridLayout->itemAtPosition(ElementRow,0)->widget()); QString StyleName = StyleNameLabel->text(); QStringList Decorations; int col = 1; for(const QString& Format : m_Formats) { if(qobject_cast<QCheckBox*>(ui->SyntaxGridLayout->itemAtPosition(ElementRow,col)->widget())->isChecked()) Decorations << Format; col ++; } QString ColorName = StyleNameLabel->property("ColorName").toString(); openfluid::base::PreferencesManager* PrefMgr = openfluid::base::PreferencesManager::instance(); openfluid::base::PreferencesManager::SyntaxHighlightingRules_t Rules = PrefMgr->getWaresdevSyntaxHighlightingRules(); openfluid::base::PreferencesManager::SyntaxHighlightingRules_t::iterator it = Rules.find(StyleName); if(it != Rules.end()) { it->m_Decoration = Decorations; it->m_Color = ColorName; } else Rules.insert(StyleName, openfluid::base::PreferencesManager::SyntaxHighlightingRule_t(ColorName,Decorations)); openfluid::base::PreferencesManager::instance()->setWaresdevSyntaxHighlightingRules(Rules); updateSyntaxElementLabel(StyleNameLabel, Decorations,ColorName); QToolButton* ColorButton = qobject_cast<QToolButton*>( ui->SyntaxGridLayout->itemAtPosition(ElementRow, m_Formats.size() + 1)->widget()); updateSyntaxElementColorButton(ColorButton, ColorName); m_TextEditorSettingsChanged = true; }
void SettingsWidget::updateNetworkInterfaces(const Protos::GUI::State& state) { this->disconnectAllAddressButtons(); QList<QLabel*> interfaceNotUpdated = this->ui->scoInterfacesContent->findChildren<QLabel*>(""); for (int i = 0; i < state.interface_size(); i++) { const QString& interfaceName = Common::ProtoHelper::getStr(state.interface(i), &Protos::Common::Interface::name); for (QListIterator<QObject*> j(this->ui->scoInterfacesContent->children()); j.hasNext();) { QLabel* lblInterface = dynamic_cast<QLabel*>(j.next()); if (lblInterface && lblInterface->property("id").toUInt() == state.interface(i).id()) { interfaceNotUpdated.removeOne(lblInterface); lblInterface->setText(interfaceName + (state.interface(i).isup() ? "" : " <img src= \":/icons/ressources/error.png\" /> <em>" + tr("Interface not active") + "</em>")); this->updateAddresses(state.interface(i), static_cast<QWidget*>(j.next())); goto nextInterface; } } { // Interface not found -> add a new one. QLabel* label = new QLabel(interfaceName, this->ui->scoInterfacesContent); label->setProperty("id", state.interface(i).id()); this->ui->layInterfaces->addWidget(label); QWidget* addressesContainer = new QWidget(this->ui->scoInterfacesContent); this->ui->layInterfaces->addWidget(addressesContainer); this->updateAddresses(state.interface(i), addressesContainer); } nextInterface: ; } // Remove the non-existant interfaces. for (QListIterator<QObject*> i(this->ui->scoInterfacesContent->children()); i.hasNext();) { QLabel* current = dynamic_cast<QLabel*>(i.next()); if (current && interfaceNotUpdated.contains(current)) { this->ui->layInterfaces->removeWidget(current); QWidget* addressesContainer = dynamic_cast<QWidget*>(i.next()); this->ui->layInterfaces->removeWidget(addressesContainer); delete current; delete addressesContainer; } } // Set the current address. if (state.has_listenany()) { if (state.listenany() == Protos::Common::Interface::Address::IPv6) this->ui->radIPv6->setChecked(true); else this->ui->radIPv4->setChecked(true); } this->connectAllAddressButtons(); }