Пример #1
0
DMDialog::DMDialog( const QString &screenName, QWidget *parent) :
        QDialog(parent),
        progress( new QMovie( ":/icons/progress.gif", "", this ) ),
        screenName( screenName ),
        m_ui(new Ui::DMDialog)
{
    m_ui->setupUi(this);

    m_ui->messageTextEdit->setAllowEnters( true );

    QFont charsLeftFont = m_ui->charsLeftLabel->font();
    charsLeftFont.setPointSize( charsLeftFont.pointSize() - 2 );
    m_ui->charsLeftLabel->setFont( charsLeftFont );
    m_ui->sendingLabel->setFont( charsLeftFont );
    m_ui->progressLabel->resize( m_ui->progressLabel->width(), m_ui->sendingLabel->height() );

    m_ui->charsLeftLabel->setText( tr( "%n characters left", "", charsLeft() ) );
    m_ui->sendingLabel->hide();
    m_ui->progressLabel->hide();
    m_ui->progressLabel->setMovie( progress );

    setWindowTitle( tr( "Direct message %1" ).arg( screenName ) );

    connect( m_ui->messageTextEdit, SIGNAL(textChanged()), this, SLOT(updateCharsLeft()) );
    connect( m_ui->sendButton, SIGNAL(clicked()), this, SLOT(sendDM()) );

    adjustSize();
}
Пример #2
0
bool Wheel::checkPermutation(std::string permutation) {
    // Copy of the string
    std::string permut(permutation);

    // Permutation must have the exact size
    if (permut.length() != NUMCHARACTERSINALPHABET) {
        return false;
    } else {
        // This holds the remainig / unused character to make sure a letter is only used once
        std::list<char> charsLeft(alphabet, alphabet + NUMCHARACTERSINALPHABET);
        
        // Check all letters of the permutation
        for (int i = 0; i < NUMCHARACTERSINALPHABET; i++) {
            // Check if the letter is in the list of remaining letters
            for (char currentChar : charsLeft) {
                // If the letter was not used before remove it and proceed
                if (toupper(currentChar) == toupper(permut[i])) {
                    charsLeft.remove(permut[i]);
                    break;
                // If end of list reached this means that the current character is used twice
                } else if (charsLeft.back() == currentChar) {
                    return false;
                }
            }
        }
    }
    return true;
}
Пример #3
0
void DMDialog::sendDM()
{
    if( charsLeft() < 0 ) {
        QMessageBox *messageBox = new QMessageBox( QMessageBox::Warning, tr( "Message too long" ), tr( "Your message is too long." ) );
        QPushButton *accept = messageBox->addButton( tr( "&Truncate" ), QMessageBox::AcceptRole );
        QPushButton *reject = messageBox->addButton( tr( "&Edit" ), QMessageBox::RejectRole );
        messageBox->setInformativeText( tr( "You can still post it like this, but it will be truncated." ) );
        messageBox->setDefaultButton( accept );
        messageBox->setEscapeButton( reject );
        messageBox->exec();
        if ( messageBox->clickedButton() == reject )
            return;
        messageBox->deleteLater();
    }

    emit dmRequest( screenName, m_ui->messageTextEdit->toPlainText() );

    progress->start();
    m_ui->sendingLabel->setText( tr( "Sending..." ) );
    m_ui->charsLeftLabel->hide();
    m_ui->sendingLabel->show();
    m_ui->progressLabel->show();
    m_ui->resetButton->setEnabled( false );
    m_ui->sendButton->setEnabled( false );
    m_ui->messageTextEdit->setEnabled( false );
    m_ui->closeButton->setFocus();
}
Пример #4
0
// ---------------------------------------------------------------------------
// Writes to log.
// ---------------------------------------------------------------------------
//
void CKmdDebugLogger::LogWrite( const TDesC& aText )
    {
    const TInt KMaxLineWidth( 100 );
    const TInt textLength( aText.Length() );
    TInt charsLeft( textLength );
    
    while ( charsLeft )
        {
        if ( charsLeft >= KMaxLineWidth )
            {
            // Write next KMaxLineWidth chars.
            iFileLogger.Write( aText.Mid( textLength-charsLeft, KMaxLineWidth ) );
            charsLeft -= KMaxLineWidth;            
            }
        else
            {
            // Write remaining chars (<KMaxLineWidth chars).
            iFileLogger.Write( aText.Mid( textLength-charsLeft, charsLeft ) );
            charsLeft = 0;            
            }
        }
    }
Пример #5
0
void DMDialog::updateCharsLeft()
{
    QString text;
    QPalette palette( m_ui->charsLeftLabel->palette() );
    int length = charsLeft();

    if ( length < 0 ) {
        palette.setColor( QPalette::Foreground, Qt::red );
        if ( length == -1 )
            text = tr( "%n character over the limit", "", length * -1 );
        else
            text = tr( "%n characters over the limit", "", length * -1 );
    } else {
        palette.setColor( QPalette::Foreground, Qt::black );
        if ( length == 1 )
            text = tr( "%n character left", "", length );
        else
            text = tr( "%n characters left", "", length );
    }

    m_ui->charsLeftLabel->setText( text );
    m_ui->charsLeftLabel->setPalette( palette );
}