Ejemplo n.º 1
0
void CWizDocumentWebViewPage::on_editorCommandPaste_triggered()
{
    QClipboard* clip = QApplication::clipboard();
    Q_ASSERT(clip);

    //const QMimeData* mime = clip->mimeData();
    //qDebug() << mime->formats();
    //qDebug() << mime->data("text/html");
    //qDebug() << mime->hasImage();

    if (!clip->image().isNull()) {
        // save clipboard image to $TMPDIR
        QString strTempPath = Utils::PathResolve::tempPath();
        CString strFileName = strTempPath + WizIntToStr(GetTickCount()) + ".png";
        if (!clip->image().save(strFileName)) {
            TOLOG("ERROR: Can't save clipboard image to file");
            return;
        }

        QMimeData* data = new QMimeData();
        QString strHtml = getImageHtmlLabelByFile(strFileName);
        data->setHtml(strHtml);
        clip->setMimeData(data);
    }
}
void CWizDocumentWebViewPage::on_editorCommandPaste_triggered()
{
    QClipboard* clip = QApplication::clipboard();
    Q_ASSERT(clip);

    const QMimeData* mime = clip->mimeData();
//    QStringList formats = mime->formats();
//    for(int i = 0; i < formats.size(); ++ i) {
//        qDebug() << "Mime Format: " << formats.at(i) << " Mime data: " << mime->data(formats.at(i));
//    }

    if (mime->hasHtml())
    {
        QString strHtml = mime->html();
        QRegExp regHead("</?head[^>]*>", Qt::CaseInsensitive);
        if (strHtml.contains(regHead))
        {
            // convert mass html to rtf, then convert rft to html
            QTextDocument textParase;
            textParase.setHtml(strHtml);
            strHtml = textParase.toHtml();

            QRegExp regBodyContant("<body[^>]*>[\\s\\S]*</body>");
            int index = regBodyContant.indexIn(strHtml);
            if (index > -1)
            {
                QString strBody = regBodyContant.cap(0);
                if (strBody.isEmpty())
                    return;

                QRegExp regBody = QRegExp("</?body[^>]*>", Qt::CaseInsensitive);
                strBody.replace(regBody, "");
                strHtml = strBody;

                QMimeData* data = new QMimeData();
                data->setHtml(strHtml);
                clip->setMimeData(data);
                return;
            }
        }
    }

    if (!clip->image().isNull()) {
        // save clipboard image to $TMPDIR
        QString strTempPath = Utils::PathResolve::tempPath();
        CString strFileName = strTempPath + WizIntToStr(GetTickCount()) + ".png";
        if (!clip->image().save(strFileName)) {
            TOLOG("ERROR: Can't save clipboard image to file");
            return;
        }

        QMimeData* data = new QMimeData();
        QString strHtml = getImageHtmlLabelByFile(strFileName);
        data->setHtml(strHtml);
        clip->setMimeData(data);
    }
}
Ejemplo n.º 3
0
void SliceEditView::PasteFromClipboard()
{
	if(supportMode)
		return;

	QClipboard *clipboard = QApplication::clipboard();
	if(clipboard->image().isNull())
		return;

	modified = true;
	topImg = clipboard->image();
	pDrawingContext->SetUpperImg(&topImg);
	RefreshContext(1);//so we can undo the paste...
	SaveToUndoBuffer();//since the image is altered, save to the buffer.
	ReCompress();
}
Ejemplo n.º 4
0
void VoxelEditor::paste()
{
    deselect();

    // test for image in clipboard
    QClipboard * clipboard = QApplication::clipboard();
    QImage img = clipboard->image();
    if (img.isNull()) {
        // paste whatever we have in the internal copied list
        selected_list = copied_list;
    } else {
        // paste image from clipboard
        selected_list.clear();
        SelectedVoxel voxel;
        for (int x = 0; x < img.width(); x++)
        for (int y = 0; y < img.height(); y++) {
            QColor pixel = QColor(img.pixel(x, y));
            if (pixel.alpha() <= 0)
                continue;
            RGBColor c(pixel.red(), pixel.green(), pixel.blue());
            unsigned char cc = VoxelFile::get_closest_index(c);
            voxel.x = x;
            voxel.y = 0;
            voxel.z = img.height() - y;
            voxel.v = cc;
            selected_list.push_back(voxel);
        }
    }
    window->set_status("Pasted voxels");
    on_changed();
}
Ejemplo n.º 5
0
void SliceEditView::PasteFromClipboard()
{
	if(supportMode)
		return;

	QClipboard *clipboard = QApplication::clipboard();
	if(clipboard->image().isNull())
		return;

	modified = true;
	topImg = clipboard->image();
	pDrawingContext->SetUpperImg(&topImg);
    RefreshContext(1);//所以我们可以撤消粘贴...
    SaveToUndoBuffer();//由于图像被改变,保存到缓冲器。
	ReCompress();
}
Ejemplo n.º 6
0
void CopyPaste::paste() {
	QPoint point = QPoint::QPoint(0,0);
	QImage *image = ourImage->getImage();
	QPainter painter(image);
	QClipboard *clipboard = QApplication::clipboard();
	QImage paste = clipboard->image();
	painter.drawImage(point, paste);
	ourImage->update();
}
Ejemplo n.º 7
0
// ---------------------------------------------------------------------
void *wdclipreadimage(char * s)
{
  QClipboard *clipboard = app->clipboard();
  if (!clipboard) return 0;
  if (!strlen(s)) return 0;
  QImage image = clipboard->image();
  if (!image.isNull()) {
    return (image.save(s))?(char *)-1:0;
  }
  return 0;
}
Ejemplo n.º 8
0
	QScriptValue Clipboard::image() const
	{
		QClipboard *clipboard = QApplication::clipboard();

        return Image::constructor(clipboard->image(mMode), engine());
    }
Ejemplo n.º 9
0
// nsClipboard::GetNativeClipboardData ie. Paste
//
NS_IMETHODIMP
nsClipboard::GetNativeClipboardData(nsITransferable *aTransferable,
                                    QClipboard::Mode clipboardMode)
{
    if (nullptr == aTransferable)
    {
        NS_WARNING("GetNativeClipboardData: Transferable is null!");
        return NS_ERROR_FAILURE;
    }

    // get flavor list that includes all acceptable flavors (including
    // ones obtained through conversion)
    nsCOMPtr<nsISupportsArray> flavorList;
    nsresult errCode = aTransferable->FlavorsTransferableCanImport(
        getter_AddRefs(flavorList));

    if (NS_FAILED(errCode))
    {
        NS_WARNING("nsClipboard::GetNativeClipboardData(): no FlavorsTransferable!");
        return NS_ERROR_FAILURE;
    }

    QClipboard *cb = QGuiApplication::clipboard();
    const QMimeData *mimeData = cb->mimeData(clipboardMode);

    // Walk through flavors and see which flavor matches the one being pasted
    uint32_t flavorCount;
    flavorList->Count(&flavorCount);
    nsAutoCString foundFlavor;

    for (uint32_t i = 0; i < flavorCount; ++i)
    {
        nsCOMPtr<nsISupports> genericFlavor;
        flavorList->GetElementAt(i,getter_AddRefs(genericFlavor));
        nsCOMPtr<nsISupportsCString> currentFlavor(do_QueryInterface( genericFlavor) );

        if (currentFlavor)
        {
            nsXPIDLCString flavorStr;
            currentFlavor->ToString(getter_Copies(flavorStr));

            // Ok, so which flavor the data being pasted could be?
            // Text?
            if (!strcmp(flavorStr.get(), kUnicodeMime) && mimeData->hasText())
            {
                // Clipboard has text and flavor accepts text, so lets
                // handle the data as text
                foundFlavor = nsAutoCString(flavorStr);

                // Get the text data from clipboard
                QString text = mimeData->text();
                const QChar *unicode = text.unicode();
                // Is there a more correct way to get the size in UTF16?
                uint32_t len = (uint32_t) 2*text.size();

                // And then to genericDataWrapper
                nsCOMPtr<nsISupports> genericDataWrapper;
                nsPrimitiveHelpers::CreatePrimitiveForData(
                        foundFlavor.get(),
                        (void*)unicode,
                        len,
                        getter_AddRefs(genericDataWrapper));
                // Data is good, set it to the transferable
                aTransferable->SetTransferData(foundFlavor.get(),
                                               genericDataWrapper,len);
                // And thats all
                break;
            }

            // html?
            if (!strcmp(flavorStr.get(), kHTMLMime) && mimeData->hasHtml())
            {
                // Clipboard has text/html and flavor accepts text/html, so lets
                // handle the data as text/html
                foundFlavor = nsAutoCString(flavorStr);

                // Get the text data from clipboard
                QString html = mimeData->html();
                const QChar *unicode = html.unicode();
                // Is there a more correct way to get the size in UTF16?
                uint32_t len = (uint32_t) 2*html.size();

                // And then to genericDataWrapper
                nsCOMPtr<nsISupports> genericDataWrapper;
                nsPrimitiveHelpers::CreatePrimitiveForData(
                        foundFlavor.get(),
                        (void*)unicode,
                        len,
                        getter_AddRefs(genericDataWrapper));
                // Data is good, set it to the transferable
                aTransferable->SetTransferData(foundFlavor.get(),
                                               genericDataWrapper,len);
                // And thats all
                break;
            }

            // Image?
            if ((  !strcmp(flavorStr.get(), kJPEGImageMime)
                || !strcmp(flavorStr.get(), kJPGImageMime)
                || !strcmp(flavorStr.get(), kPNGImageMime)
                || !strcmp(flavorStr.get(), kGIFImageMime))
                && mimeData->hasImage())
            {
                // Try to retrieve an image from clipboard
                QImage image = cb->image();
                if(image.isNull())
                    continue;

                // Lets set the image format
                QByteArray imageFormat;
                if (!strcmp(flavorStr.get(), kJPEGImageMime) || !strcmp(flavorStr.get(), kJPGImageMime))
                    imageFormat = "jpeg";
                else if (!strcmp(flavorStr.get(), kPNGImageMime))
                    imageFormat = "png";
                else if (!strcmp(flavorStr.get(), kGIFImageMime))
                    imageFormat = "gif";
                else
                    continue;

                // Write image from clippboard to a QByteArrayBuffer
                QByteArray imageData;
                QBuffer imageBuffer(&imageData);
                QImageWriter imageWriter(&imageBuffer, imageFormat);
                if(!imageWriter.write(image))
                    continue;

                // Add the data to inputstream
                nsCOMPtr<nsIInputStream> byteStream;
                NS_NewByteInputStream(getter_AddRefs(byteStream), imageData.constData(),
                                      imageData.size(), NS_ASSIGNMENT_COPY);
                // Data is good, set it to the transferable
                aTransferable->SetTransferData(flavorStr, byteStream, sizeof(nsIInputStream*));

                imageBuffer.close();

                // And thats all
                break;
            }

            // Other mimetype?
            // Trying to forward the data "as is"
            if(mimeData->hasFormat(flavorStr.get()))
            {
                // get the data from the clipboard
                QByteArray clipboardData = mimeData->data(flavorStr.get());
                // And add it to genericDataWrapper
                nsCOMPtr<nsISupports> genericDataWrapper;
                nsPrimitiveHelpers::CreatePrimitiveForData(
                        foundFlavor.get(),
                        (void*) clipboardData.data(),
                        clipboardData.size(),
                        getter_AddRefs(genericDataWrapper));

                // Data is good, set it to the transferable
                aTransferable->SetTransferData(foundFlavor.get(),
                                               genericDataWrapper,clipboardData.size());
                // And thats all
                break;
            }
        }
    }

    return NS_OK;
}
Ejemplo n.º 10
0
ImageArea::ImageArea(const bool &isOpen, const QString &filePath, QWidget *parent) :
    QWidget(parent), mIsEdited(false), mIsPaint(false), mIsResize(false)
{
    setMouseTracking(true);

    mRightButtonPressed = false;
    mFilePath = QString();
    mOpenFilter = "Windows Bitmap(*.bmp)";
    mSaveFilter = "Windows Bitmap(*.bmp)";
    initializeImage();
    mZoomFactor = 1;

    mAdditionalTools = new AdditionalTools(this, this->parent());

    if(isOpen && filePath.isEmpty())
    {
        open();
    }
    else if(isOpen && !filePath.isEmpty())
    {
        open(filePath);
    }
    else
    {
        int width, height;
        width = Data::Instance()->getBaseSize().width();
        height = Data::Instance()->getBaseSize().height();
        if (Data::Instance()->getIsInitialized() &&
            Data::Instance()->getIsAskCanvasSize())
        {
            QClipboard *globalClipboard = QApplication::clipboard();
            QImage mClipboardImage = globalClipboard->image();
            if (!mClipboardImage.isNull())
            {
                width = mClipboardImage.width();
                height = mClipboardImage.height();
            }
            mAdditionalTools->resizeCanvas(width, height);
            mIsEdited = false;
        }
        QPainter *painter = new QPainter(mImage);
        painter->fillRect(0, 0, width, height, Qt::white);
        painter->end();

        resize(mImage->rect().right() + 6,
               mImage->rect().bottom() + 6);
        mFilePath = QString("");
    }

    SelectionInstrument *selectionInstrument = new SelectionInstrument(this);
    connect(selectionInstrument, SIGNAL(sendEnableCopyCutActions(bool)), this, SIGNAL(sendEnableCopyCutActions(bool)));
    connect(selectionInstrument, SIGNAL(sendEnableSelectionInstrument(bool)), this, SIGNAL(sendEnableSelectionInstrument(bool)));

    mInstrumentsHandlers.fill(0, (int)INSTRUMENTS_COUNT);
    mInstrumentsHandlers[CURSOR] = selectionInstrument;
    mInstrumentsHandlers[PEN] = new PencilInstrument(this);
    mInstrumentsHandlers[LINE] = new LineInstrument(this);
    mInstrumentsHandlers[ERASER] = new EraserInstrument(this);
    mInstrumentsHandlers[RECTANGLE] = new RectangleInstrument(this);
    mInstrumentsHandlers[ELLIPSE] = new EllipseInstrument(this);
    mInstrumentsHandlers[FILL] = new FillInstrument(this);
    mInstrumentsHandlers[CURVELINE] = new CurveLineInstrument(this);
}
Ejemplo n.º 11
0
void Widget::onClipboardUpdated()
{
    QClipboard *clip = qApp->clipboard();

    if (clip->mimeData()->hasImage()) {
        QImage image = clip->image();
        QSize origSize = image.size();
        const int minWidth = minimumWidth() - 20;
        const int minHeight = minimumHeight() - 20;
        if (image.width() <= image.height() && image.height() < minimumHeight() - 20) {
            image = image.scaledToHeight(minHeight);
        } else if (image.width() < minWidth) {
            image = image.scaledToWidth(minWidth);
        }
        if (image.width() > maximumWidth() - 10) {
            image = image.scaledToWidth(maximumWidth() - 10);
        }
        if (image.height() > maximumHeight() - 10) {
            image = image.scaledToHeight(maximumHeight() - 10);
        }

        {
            QPainter p(&image);
            QFont font;
            font.setPixelSize(15);
            p.setFont(font);
            QFontMetrics metrics(font);
            QString text = QString::number(origSize.width()) + "x" + QString::number(origSize.height());
            QRect rect = metrics.boundingRect(text).marginsAdded(QMargins(5, 5, 5, 5));
            rect.moveTopLeft(QPoint(0, 0));
            p.fillRect(rect, QColor(0, 0, 0, 128));
            p.setPen(Qt::white);
            p.drawText(rect, Qt::AlignCenter, text);
        }

        m_label->setPixmap(QPixmap::fromImage(image));
        resize(image.size());
        updateGeometry();
        m_hasTrimmed = false;
        return;
    }

    QString text = clip->text();

    const QStringList formats = clip->mimeData()->formats();
    bool onlyTextPlain = formats.contains("text/plain");
    if (onlyTextPlain) {
        for (const QString &format : formats) {
            // "Special" fake mimetypes to indicate multiselections etc.
            if (!format.contains('/') || format.toUpper() == format) {
                continue;
            }
            if (format == "text/plain" || format == "text/html") {
                continue;
            }
            onlyTextPlain = false;
            break;
        }

        QString trimmed = text.trimmed();

        if (onlyTextPlain && trimmed != text && !m_hasTrimmed) {
            clip->setText(trimmed);
            m_hasTrimmed = true;
            return;
        }
    }

    m_hasTrimmed = false;

    QFontMetrics metrics(font());

    QString filteredText;
    for (const QChar &c : text) {
        if ((c.isPrint() || c == '\n' || c == '\t') && (c.script() == QChar::Script_Latin || c.script() == QChar::Script_Common)) {
            filteredText += c;
            continue;
        }

        qDebug() << c << c.script() << c.category();

        filteredText += "0x" + QString::number(c.unicode(), 16);
    }
    text = filteredText;

    QRect boundingRect = QRect(0, 0, maximumWidth(), maximumHeight());
    boundingRect = metrics.boundingRect(boundingRect, Qt::TextWordWrap, text);
    boundingRect = boundingRect.marginsAdded(QMargins(20, 20, 20, 20));

    if (boundingRect.height() > maximumHeight()) {
        m_label->setWordWrap(false);

        QString newText;
        int h = metrics.height() * 2;
        for (const QString &line : text.split('\n')) {
            newText.append(metrics.elidedText(line, Qt::ElideRight, m_label->width() - 20) + '\n');
            h += metrics.height();
        }
        text = newText;
        boundingRect.setHeight(h);
    } else {
        m_label->setWordWrap(true);
    }
    resize(boundingRect.size());

    m_label->setText(text);
    m_label->setSelection(0, text.length());
    updateGeometry();
}