示例#1
0
FilterEffectEditWidget::FilterEffectEditWidget(QWidget *parent)
    : QWidget(parent), m_scene(new FilterEffectScene(this))
    , m_shape(0), m_canvas(0), m_effects(0)
{
    setupUi(this);

    FilterResourceServerProvider * serverProvider = FilterResourceServerProvider::instance();
    KoResourceServer<FilterEffectResource> * server = serverProvider->filterEffectServer();
    KoAbstractResourceServerAdapter * adapter = new KoResourceServerAdapter<FilterEffectResource>(server, this);

    presets->setResourceAdapter(adapter);
    presets->setDisplayMode(KoResourceSelector::TextMode);
    presets->setColumnCount(1);

    connect(presets, SIGNAL(resourceSelected(KoResource*)),
            this, SLOT(presetSelected(KoResource*)));

    connect(presets, SIGNAL(resourceApplied(KoResource*)),
            this, SLOT(presetSelected(KoResource*)));

    KoGenericRegistryModel<KFilterEffectFactoryBase*> * filterEffectModel = new KoGenericRegistryModel<KFilterEffectFactoryBase*>(KFilterEffectRegistry::instance());

    effectSelector->setModel(filterEffectModel);
    removeEffect->setIcon(KIcon("list-remove"));
    connect(removeEffect, SIGNAL(clicked()), this, SLOT(removeSelectedItem()));
    addEffect->setIcon(KIcon("list-add"));
    addEffect->setToolTip(i18n("Add effect to current filter stack"));
    connect(addEffect, SIGNAL(clicked()), this, SLOT(addSelectedEffect()));

    raiseEffect->setIcon(KIcon("arrow-up"));
    lowerEffect->setIcon(KIcon("arrow-down"));

    addPreset->setIcon(KIcon("list-add"));
    addPreset->setToolTip(i18n("Add to filter presets"));
    connect(addPreset, SIGNAL(clicked()), this, SLOT(addToPresets()));

    removePreset->setIcon(KIcon("list-remove"));
    removePreset->setToolTip(i18n("Remove filter preset"));

    view->setScene(m_scene);
    view->setRenderHint(QPainter::Antialiasing, true);
    view->setResizeAnchor(QGraphicsView::AnchorViewCenter);

    connect(m_scene, SIGNAL(connectionCreated(ConnectionSource,ConnectionTarget)),
            this, SLOT(connectionCreated(ConnectionSource,ConnectionTarget)));
    connect(m_scene, SIGNAL(selectionChanged()), this, SLOT(sceneSelectionChanged()));

    QSet<ConnectionSource::SourceType> inputs;
    inputs << ConnectionSource::SourceGraphic;
    inputs << ConnectionSource::SourceAlpha;
    inputs << ConnectionSource::BackgroundImage;
    inputs << ConnectionSource::BackgroundAlpha;
    inputs << ConnectionSource::FillPaint;
    inputs << ConnectionSource::StrokePaint;

    m_defaultSourceSelector = new KComboBox(this);
    foreach(ConnectionSource::SourceType source, inputs) {
        m_defaultSourceSelector->addItem(ConnectionSource::typeToString(source));
    }
示例#2
0
	Stream* Hub::connect(const std::string &target)
	{
		std::string proto, params;
		size_t c = target.find_first_of(':');
		if (c == std::string::npos)
			throw DashelException(DashelException::InvalidTarget, 0, "No protocol specified in target.");
		proto = target.substr(0, c);
		params = target.substr(c+1);
		
		SelectableStream *s(dynamic_cast<SelectableStream*>(streamTypeRegistry.create(proto, target, *this)));
		if(!s)
		{
			std::string r = "Invalid protocol in target: ";
			r += proto;
			r += ", known protocol are: ";
			r += streamTypeRegistry.list();
			throw DashelException(DashelException::InvalidTarget, 0, r.c_str());
		}
		
		/* The caller must have the stream lock held */
		
		streams.insert(s);
		if (proto != "tcpin")
		{
			dataStreams.insert(s);
			connectionCreated(s);
		}
		
		return s;
	}
void ClientConnectionManager::incomingConnection()
{
    QTcpSocket * connection;
    while((connection = mServer.nextPendingConnection()) != nullptr)
    {
        mSockets.append(connection);
        mRequestMan.addWatchList(connection);
        QString socket_id = QString::number(int(connection->socketDescriptor()));
        emit connectionCreated(socket_id);
        connect(connection,SIGNAL(disconnected()),this,SLOT(socketDisconnected()));
        connect(connection,
                SIGNAL(error(QAbstractSocket::SocketError)),
                this,
                SLOT(connectionErrorOccured(QAbstractSocket::SocketError)));
        connect(connection,
                SIGNAL(stateChanged(QAbstractSocket::SocketState)),
                this,
                SLOT(connectionStateChanged(QAbstractSocket::SocketState)));
    }
}
void MpuReader::run()
{
    //連線藍芽
    #ifndef USE_WIRE_CONNECTION
        blue_connector = new cwz_c_blue();
        int result = blue_connector->connect(this->stopFlag);
        if(result == 1)//如果成功連線
            emit connectionCreated();
    #endif

    //********************************************************//
    //							變數宣告
    //********************************************************//
    //Handle Serial Buffer
    const int incomming_buf_len = 2048;
    char incomingData[incomming_buf_len] = "";			// don't forget to pre-allocate memory
    int dataLength = 256;
    const int bSize = 10000;
    char buffer[bSize] = "";
    int bLen = 0;

    //Decode information from buffer string
    int count = 0;
    int flag = -1; //-1等於上次是不合法結束的情況
    int accl[3]; // x, y, z
    int gyro[3]; // x, y, z
    float gravity[3];
    float quatern[4];
    int buttons[2];
    int period;

    //中位值濾波
    int MFLen = 5;   //濾波器長度為5
    int **Accls = allcIntDArray(MFLen, 3);
    int **Gyros = allcIntDArray(MFLen, 3);
    int MFCount = 0; // 只用於前五次, 確認filter的data set是不是被裝滿了, 裝滿了才開始濾波

    //Symbol record
    //SymbolRecorder SR = SymbolRecorder();

    //fileNameSStream << racketFilePath << date_string << "_" << type_string << "_" << person_string << "_" << racket_file_count << ".txt";

    //********************************************************//
    //					連接Com port並確認連線
    //********************************************************//
    #ifdef USE_WIRE_CONNECTION
        std::cout << "Arduino with GY521 board and chip MPU6050!" << std::endl;
        char *COM_NUM = "COM5";
        Serial* SP = new Serial(COM_NUM);    // adjust as needed
        if (SP->IsConnected()){
            emit connectionCreated();
            std::cout << "We're connected" << std::endl;
        }else{
            stopFlag = true;
        }
        //read few set of data until it's getting stable
        waitUntilSerialStable(SP, incomingData, dataLength);

        std::cout << "Data should be stable, start to read MPU6050" << std::endl;
    #else
        blue_connector->send("Start to read mpu6050 data from bluetooth.\n");
    #endif

    while(!stopFlag){
        #ifdef USE_WIRE_CONNECTION
            if(!SP->IsConnected()){
                std::cout << "Failed to read " << COM_NUM << " Mpu6050 reader is off." << std::endl;
                emit readingEnded();
                break;
            }
            if( !readSerialIntoBuffer(SP, incomingData, dataLength, readResult, bLen, bSize, buffer) )
                continue;//If no valid serial data are read or buffer overflow, skip this round
        #else
            dataLength = blue_connector->receive(incomingData, incomming_buf_len);
            if(dataLength > 0){//有收到東西
                incomingData[dataLength] = '\0';
                strcpy_s(&buffer[bLen], bSize, incomingData);
                bLen += dataLength;
            }
        #endif
        //decode mpu6050 data from buffer str, take off processed part from buffer
        strcpy_s(buffer, bSize, getAccelAndGyro(&count, &flag, &bLen, buffer, accl, gyro, quatern, buttons, &period, bSize));

        //   每一組合法數值為 (acclX,acclY,acclZ,gyroX,gyroY,gyroZ,quatern1,quatern2,quatern3,quatern4,buttonRight,buttonLeft,readperiod)
        if( flag != GETAANDG_NEW_VALID_DATA )
            continue;//尚未讀到整組完整資料 不處理 繼續讀

        SHORT downKeyState = GetAsyncKeyState( VK_DOWN );
        //std::cout << "gravity: " << gravity[0] << ", " << gravity[1] << ", " << gravity[2] << std::endl;
        if( writeRawToFile )
        {//按ctrl鍵
            std::cout << "period: " << period << std::endl;

            if( ( 1 << 16 ) & downKeyState ){
                //writeAcclAndGyroAndGravity(fileNameSStream.str().c_str(), accl, gyro, gravity, 1);
                writeMpu6050RawToFile(fileNameSStream.str().c_str(), accl, gyro, quatern, period, 1);
                //std::cout << "Down Key State: " << 1 << std::endl;
            }else{
                //writeAcclAndGyroAndGravity(fileNameSStream.str().c_str(), accl, gyro, gravity, 0);
                writeMpu6050RawToFile(fileNameSStream.str().c_str(), accl, gyro, quatern, period, 0);
                //std::cout << "Down Key State: " << 0 << std::endl;
            }
        }

        //********************************************************//
        //				處理加速度計與陀螺儀Raw Data
        //********************************************************//
        //get gravity
        QtoGravity(quatern, gravity);
        //std::cout << "Gyro: " << gyro[0] << "," << gyro[1] << "," << gyro[2] << std::endl;
        //去重力
        removeGravity(accl, gravity);

        double total_q = sqrt(gravity[0]*gravity[0] + gravity[1]*gravity[1] + gravity[2]*gravity[2]);

        this->my_glwidget->setNewZ(gravity[0], gravity[1], gravity[2]);

        //check if gravity value is invalid
        if( total_q >= 1.1 ){
            std::cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
            std::cout << "total_q: " << total_q << std::endl;
            std::cout << "Wrong gravity ............................................" << std::endl;
            std::cout << "quatern: " << quatern[0] << "," << quatern[1] << "," << quatern[2] << "," << quatern[3] << std::endl;
            std::cout << "gravity: " << gravity[0] << "," << gravity[1] << "," << gravity[2] << std::endl;
            std::cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
            system("PAUSE");

        }

        //Median Filter(中位值濾波)
        agMedianFilter(Accls, Gyros, accl, gyro, MFCount, MFLen, true, true); //是否做濾波 accl=true gyro=true
    }
#ifdef USE_WIRE_CONNECTION
    SP->~Serial();
#else
    blue_connector->disconnect();
#endif
    //釋放中位值濾波使用的記憶體空間
    freeIntDArray(Accls, MFLen);
    freeIntDArray(Gyros, MFLen);
}