Exemplo n.º 1
0
void FormImageProp::pasteFromClipboard(){
    const QClipboard *clipboard = QApplication::clipboard();
    const QMimeData *mimeData = clipboard->mimeData();

    if (mimeData->hasImage()) {
        qDebug() << "<FormImageProp> Image :"+
                    PostfixNames::getTextureName(imageProp.imageType)+
                    " loaded from clipboard.";
        QPixmap pixmap = qvariant_cast<QPixmap>(mimeData->imageData());
        QImage image = pixmap.toImage();
        pasteImageFromClipboard(image);

    }
}
Exemplo n.º 2
0
// ----------------------------------------------------------------
// Key events
// ----------------------------------------------------------------
void FormImageBase::keyPressEvent(QKeyEvent *event){



    if (event->type() == QEvent::KeyPress){



        QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
        int keyInt = keyEvent->key();
        Qt::Key key = static_cast<Qt::Key>(keyInt);
        if(key == Qt::Key_unknown){
            qDebug() << "Unknown key from a macro probably";
            return;
        }

        // check for a combination of user clicks
        Qt::KeyboardModifiers modifiers = keyEvent->modifiers();


        if(modifiers & Qt::ShiftModifier)
            keyInt += Qt::SHIFT;
        if(modifiers & Qt::ControlModifier)
            keyInt += Qt::CTRL;
        if(modifiers & Qt::AltModifier)
            keyInt += Qt::ALT;
        if(modifiers & Qt::MetaModifier)
            keyInt += Qt::META;

        QString keySequenceName = QKeySequence(keyInt).toString(QKeySequence::NativeText);

        if(keySequenceName.compare("Ctrl+V",Qt::CaseInsensitive) == 0){

            const QClipboard *clipboard = QApplication::clipboard();
            const QMimeData *mimeData = clipboard->mimeData();

            if (mimeData->hasImage()) {
                qDebug() << "<FormImageProp> Image :"+
                            PostfixNames::getTextureName(imageProp.imageType)+
                            " loaded from clipboard.";
                QPixmap pixmap = qvariant_cast<QPixmap>(mimeData->imageData());
                QImage image = pixmap.toImage();
                pasteImageFromClipboard(image);

            }
        } // end of Ctrl + V (paste From clipboard)


        if(keySequenceName.compare("Ctrl+C",Qt::CaseInsensitive) == 0){
            qDebug() << "<FormImageProp> Image :"+
                        PostfixNames::getTextureName(imageProp.imageType)+
                        " copied to clipboard.";

            QApplication::processEvents();
            image = imageProp.getImage();
            QApplication::clipboard()->setImage(image,QClipboard::Clipboard);


        } // end of Ctrl + C (copy To clipboard)

    }// end of


}