예제 #1
0
void QTextBrowserEx::insertFromMimeData( const QMimeData *source )
{
	Q_ASSERT(source);

	if(m_pasteFlags == NotSupport)
		return;

	QByteArray bytes = source->data(KTextEditMime);

	KTextCursor tc = textCursor();

	if(!bytes.isEmpty() && m_pasteFlags.testFlag(Custom))
	{
		QDataStream ds(bytes);
		QList<QByteArray> lstFrags;
		ds >> lstFrags;
		for(int i = 0; i < lstFrags.count(); i++)
		{
			const QByteArray frags = lstFrags.at(i);
			QDataStream ds(frags);
			QString text;
			QTextCharFormat format;
			ds >> text >> format;
			bool bHandled = false;
			/*自定义控件,则可由外部处理*/
			emit insertMimiData(tc, text, format, bHandled);
			if(bHandled)
				continue;
			/*尝试主动处理相关信息。*/
			if(text.at(0) == QChar::ObjectReplacementCharacter)
			{
				for(int i = 0; i < text.length(); i++)
				{
					QTextImageFormat fmt = format.toImageFormat();
					if(!fmt.isValid())
					{
						/*自定义控件出现比较多*/
						continue;
					}
					QVariant vimgkey = fmt.property(KImageKey);
					QString imgkey = vimgkey.toString();
					tc.insertImage(imgkey, fmt);
				}
			}
			else
			{
				/*文字处理*/
				tc.insertText(text, format);
			}
		}
		return;
	}
예제 #2
0
void ContactListEdit::decodePublicKey(const QTextImageFormat& storage,
  IMailProcessor::TRecipientPublicKey* key) const
  {
  assert(storage.hasProperty(QTextImageFormat::UserProperty));

  QVariant v = storage.property(QTextImageFormat::UserProperty);
  QByteArray pkArray = v.toByteArray();

  fc::ecc::public_key_data s;

  assert(pkArray.size() == s.size());

  memcpy(s.begin(), pkArray.data(), s.size());

  *key = IMailProcessor::TRecipientPublicKey(s);
  assert(key->valid());
  }
예제 #3
0
void KDReports::TextDocumentData::updatePercentSize( QTextImageFormat& imageFormat, const QSizeF& size )
{
    // "W50" means W=50%.  "H60" means H=60%.
    QString prop = imageFormat.property( ResizableImageProperty ).toString();
    const qreal imageRatio = imageFormat.height() / imageFormat.width();
    const qreal pageWidth = size.width();
    const qreal pageHeight = size.height();
    const qreal pageRatio = pageWidth ? pageHeight / pageWidth : 0;
    if ( prop[0] == QLatin1Char( 'T' ) ) {
        //qDebug() << "updatePercentSize fitToPage" << imageRatio << pageRatio;
        if ( imageRatio < pageRatio ) {
            prop = QString::fromLatin1( "W100" );
        } else {
            prop = QString::fromLatin1( "H100" );
        }
    }
    const qreal percent = prop.mid( 1 ).toDouble();
    switch ( prop[0].toLatin1() ) {
    case 'W':
        {
        const qreal newWidth = pageWidth * percent / 100.0;
        imageFormat.setWidth( newWidth );
        imageFormat.setHeight( newWidth * imageRatio );
        // ### I needed to add this -2 here for 100%-width images to fit in
        if ( percent == 100.0 )
            imageFormat.setWidth( imageFormat.width() - 2 );
        }
        break;
    case 'H':
        imageFormat.setHeight( pageHeight * percent / 100.0 );
        // ### I needed to add -6 here for 100%-height images to fit in (with Qt-4.4)
        // and it became -9 with Qt-4.5, and even QtSw doesn't know why.
        // Task number 241890
        if ( percent == 100.0 )
            imageFormat.setHeight( imageFormat.height() - 10 );
        imageFormat.setWidth( imageRatio ? imageFormat.height() / imageRatio : 0 );
        //qDebug() << "updatePercentSize" << size << "->" << imageFormat.width() << "x" << imageFormat.height();
        break;
    default:
        qWarning( "Unhandled image format property type - internal error" );
    }
}