void MainWindow::joinServer()
{
  clientWidget = new TcpClientWidget(ui->connection_widget);
  clientWidget->setVisible(true);
  clientWidget->setUserName(ui->nickName_lineEdit->text());

  ui->connection_widget->layout()->addWidget(clientWidget);
  ui->stackedWidget->setCurrentIndex(1); 

  connect(ui->chatWidget,SIGNAL(textSent(QString)),clientWidget,SLOT(sendTextMessage(QString)));
  connect(clientWidget,SIGNAL(textMessage(QString)),ui->chatWidget,SLOT(textReceived(QString)));

  //clientWidget->connectSocket(ui->host_ip_lineEdit->text(),ui->port_lineEdit->text().toUInt());
  clientWidget->connectSocket(ui->host_ip_lineEdit->text(),ui->port_lineEdit->text().toUInt());
}
Esempio n. 2
0
/** Constructor
 *  Creates a texture instance for rendering text.
 *
 *  @param p_id The string identifier of the resource
 *  @param p_renderer The window renderer used to create the text texture
 *  @param p_font Pointer to a TTF_Font object used to render the text
 *  @param p_textureText The string to render
 *  @param p_textColor The color to render the text as
 */
n8::Texture::Texture(std::string p_id, SDL_Renderer* p_renderer, TTF_Font* p_font, std::string p_textureText, SDL_Color p_textColor ) : Resource(p_id)
{
    
    SDL_Surface* textSurface = TTF_RenderText_Solid( p_font, p_textureText.c_str(), p_textColor );
    if( textSurface == nullptr )
    {
        std::string msg( "Unable to render text surface! SDL_ttf Error: %s\n", TTF_GetError() );
        n8::Log::Error(TAG, msg);
        
        if(p_font == nullptr)
            n8::Log::Error( TAG, "   font was null");
        else
            n8::Log::Error( TAG, "   font wasn't null");
        
        string textMessage( "   texture text was: %s", p_textureText.c_str());
        n8::Log::Error(TAG, textMessage);
    }
    else
    {
        //Create texture from surface pixels
        m_texture = SDL_CreateTextureFromSurface( p_renderer, textSurface );
        if( m_texture == nullptr )
        {
            string textureCreationFailedMsg("Unable to create texture from rendered text! SDL Error: %s\n", SDL_GetError() );
            n8::Log::Error(TAG, textureCreationFailedMsg);
        }
        else
        {
            //Get image dimensions
            m_width = textSurface->w;
            m_height = textSurface->h;
        }
        
        //Get rid of old surface
        SDL_FreeSurface( textSurface );
    }
}