void UITextFieldPropertyGridWidget::ProcessPushButtonClicked(QPushButton *senderWidget)
{
	    if ((activeMetadata == NULL) || (senderWidget != this->ui->fontSelectButton))
    {
        // No control already assinged or not fontSelectButton
        return;
    }
    
	// Get current value of Font property
	Font *fontPropertyValue = PropertiesHelper::GetPropertyValue<Font *>(this->activeMetadata,
																		 PropertyNames::FONT_PROPERTY_NAME,
																		 false);
	// Get sprite path from graphics font
	QString currentGFontPath = ResourcesManageHelper::GetGraphicsFontPath(fontPropertyValue);

    //Call font selection dialog - with ok button and preset of graphics font path
    FontManagerDialog *fontDialog = new FontManagerDialog(true, currentGFontPath);
    Font *resultFont = NULL;
    
    if ( fontDialog->exec() == QDialog::Accepted )
    {
        resultFont = fontDialog->ResultFont();
    }
    
    //Delete font select dialog reference
    SafeDelete(fontDialog);
    
    if (!resultFont)
    {
        return;
    }
    
    PROPERTYGRIDWIDGETSITER iter = propertyGridWidgetsMap.find(senderWidget);
    if (iter == propertyGridWidgetsMap.end())
    {
        Logger::Error("OnPushButtonClicked - unable to find attached property in the propertyGridWidgetsMap!");
        return;
    }
    
	// Don't update the property if the text wasn't actually changed.
    Font* curValue = PropertiesHelper::GetAllPropertyValues<Font*>(this->activeMetadata, iter->second.getProperty().name());
	if (curValue && curValue->IsEqual(resultFont))
	{
		SafeRelease(resultFont);
		return;
	}

    BaseCommand* command = new ChangePropertyCommand<Font *>(activeMetadata, iter->second, resultFont);
    CommandsController::Instance()->ExecuteCommand(command);
    SafeRelease(command);
	// TODO - probable memory leak. Need to investigate how to fix it
	// SafeRelease(resultFont);
}
void TextPropertyGridWidget::ProcessPushButtonClicked(QPushButton *senderWidget)
{
    if (activeMetadata == NULL)
    {
        // No control already assinged or not fontSelectButton
        return;
    }
    
    if(senderWidget == this->ui->fontSelectButton)
    {
        //TODO: remove this code or modify it to set preset instead of setting font
#if 0
        
        // Get current value of Font property
        Font *fontPropertyValue = PropertiesHelper::GetPropertyValue<Font *>(this->activeMetadata,
                                                                             PropertyNames::FONT_PROPERTY_NAME,
                                                                             false);
        // Get sprite path from graphics font
        QString currentGFontPath = ResourcesManageHelper::GetGraphicsFontPath(fontPropertyValue);
        
        //Call font selection dialog - with ok button and preset of graphics font path
        FontManagerDialog *fontDialog = new FontManagerDialog(true, currentGFontPath);
        Font *resultFont = NULL;
        
        if ( fontDialog->exec() == QDialog::Accepted )
        {
            resultFont = fontDialog->ResultFont();
        }
        
        //Delete font select dialog reference
        SafeDelete(fontDialog);
        
        if (!resultFont)
        {
            return;
        }
        
        PROPERTYGRIDWIDGETSITER iter = propertyGridWidgetsMap.find(senderWidget);
        if (iter == propertyGridWidgetsMap.end())
        {
            Logger::Error("OnPushButtonClicked - unable to find attached property in the propertyGridWidgetsMap!");
            return;
        }
        
        // Don't update the property if the text wasn't actually changed.
        Font* curValue = PropertiesHelper::GetAllPropertyValues<Font*>(this->activeMetadata, iter->second.getProperty().name());
        if (curValue && curValue->IsEqual(resultFont))
        {
            SafeRelease(resultFont);
            return;
        }
        
        BaseCommand* command = new ChangePropertyCommand<Font *>(activeMetadata, iter->second, resultFont);
        CommandsController::Instance()->ExecuteCommand(command);
        SafeRelease(command);
        // TODO - probable memory leak. Need to investigate how to fix it
        // SafeRelease(resultFont);
#endif
    }
    else if(senderWidget == this->ui->fontPresetEditButton)
    {
        // open font preset dialog, edit preset, apply changes
        
        // Get current value of Font property
        Font *fontPropertyValue = PropertiesHelper::GetPropertyValue<Font *>(this->activeMetadata,
                                                                             PropertyNames::FONT_PROPERTY_NAME,
                                                                             false);
        String fontPresetName = EditorFontManager::Instance()->GetLocalizedFontName(fontPropertyValue);
        
        Logger::FrameworkDebug("TextPropertyGridWidget::ProcessPushButtonClicked fontPropertyValue=%p fontPresetName=%s", fontPropertyValue, fontPresetName.c_str());
        // Get sprite path from graphics font
        //QString currentGFontPath = ResourcesManageHelper::GetGraphicsFontPath(fontPropertyValue);
        
        //Call font selection dialog - with ok button and preset of graphics font path
        //FontManagerDialog *fontDialog = new FontManagerDialog(true, currentGFontPath);
        EditFontDialog *editFontDialog = new EditFontDialog(fontPresetName);
        
        if ( editFontDialog->exec() == QDialog::Accepted )
        {
            PROPERTYGRIDWIDGETSITER iter = propertyGridWidgetsMap.find(senderWidget);
            if (iter == propertyGridWidgetsMap.end())
            {
                Logger::Error("OnPushButtonClicked - unable to find attached property in the propertyGridWidgetsMap!");
                SafeDelete(editFontDialog);
                return;
            }
            
            BaseCommand* command = new ChangeFontPropertyCommand(activeMetadata, iter->second, editFontDialog->GetResult());
            CommandsController::Instance()->ExecuteCommand(command);
            SafeRelease(command);
        }
        
        //Delete font select dialog reference
        SafeDelete(editFontDialog);
    }
}
예제 #3
0
void EditFontDialog::ProcessPushButtonClicked(QPushButton *senderWidget)
{
    if(senderWidget == ui->fontSelectButton || senderWidget == ui->localizedFontSelectButton)
    {
        
        // Get current value of Font property
        Font *fontPropertyValue = (senderWidget == ui->fontSelectButton ? dialogResult.font : dialogResult.GetLocalizedFont(currentLocale));

        // Get sprite path from graphics font
        QString currentGFontPath = ResourcesManageHelper::GetGraphicsFontPath(fontPropertyValue);
        
        //Call font selection dialog - with ok button and preset of graphics font path
        FontManagerDialog *fontDialog = new FontManagerDialog(true, currentGFontPath);
        Font *resultFont = NULL;
        
        if ( fontDialog->exec() == QDialog::Accepted )
        {
            resultFont = fontDialog->ResultFont();
        }
        
        //Delete font select dialog reference
        SafeDelete(fontDialog);
        
        if (!resultFont)
        {
            return;
        }
        
        //        PROPERTYGRIDWIDGETSITER iter = propertyGridWidgetsMap.find(senderWidget);
        //        if (iter == propertyGridWidgetsMap.end())
        //        {
        //            Logger::Error("OnPushButtonClicked - unable to find attached property in the propertyGridWidgetsMap!");
        //            return;
        //        }
        
        // Don't update the property if the text wasn't actually changed.
        //Font* curValue = PropertiesHelper::GetAllPropertyValues<Font*>(this->activeMetadata, iter->second.getProperty().name());
        Font* curValue = fontPropertyValue;
        if (curValue && curValue->IsEqual(resultFont))
        {
            SafeRelease(resultFont);
            return;
        }
        
        if(senderWidget == ui->fontSelectButton)
        {
            SafeRelease(dialogResult.font);
            dialogResult.font = SafeRetain(resultFont);
            
            UpdateDefaultFontParams();
        }
        else
        {
            dialogResult.SetLocalizedFont(resultFont, currentLocale);
            
            UpdateLocalizedFontParams();
        }
        SafeRelease(resultFont);
    }
    else if(senderWidget == ui->resetFontForLocalePushButton)
    {
        Font *defaultFontClone = dialogResult.font->Clone();
        dialogResult.SetLocalizedFont(defaultFontClone, currentLocale);
        SafeRelease(defaultFontClone);
        
        UpdateLocalizedFontParams();
    }
}