コード例 #1
0
ファイル: checkcurrport.cpp プロジェクト: HelloZB/Qt_Terminal
void CheckCurrPort::run()
{
//    qDebug()<<QTime::currentTime().toString()<<"startt";
    while(true){
        msleep(1500);
        bool found=0;
        foreach (const SerialPortInfo &info, SerialPortInfo::availablePorts()){  //SerialPortInfo &info, SerialPortInfo::availablePorts())

            if(info.portName()==currPort){
                found=1;
                SerialPort testConn;//(currPort);
                testConn.setPort(currPort);
                if(testConn.open(QIODevice::ReadWrite)){
                   //???? testConn.close();
                    emit portDisconnected();
                    //closeSerialPort(1);
//                    qDebug()<<QTime::currentTime().toString()<<"opened!";
                    //return;
                } /*else {
                    qDebug()<<QTime::currentTime().toString()<<"can not open";
                }*/
                break;
            }
       }
        if(!found){
//            closeSerialPort(1);            
//             qDebug()<<QTime::currentTime().toString()<<" not found!";
             emit portDisconnected();
             //return;
        }
    }
//    qDebug()<<QTime::currentTime().toString()<<"exitttt";
}
コード例 #2
0
ファイル: widget.cpp プロジェクト: HelloZB/Qt_Terminal
//#include <QDebug>
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    QTextCodec *utfcodec = QTextCodec::codecForName("UTF-8"); //qt4
    QTextCodec::setCodecForTr(utfcodec);
    QTextCodec::setCodecForCStrings(utfcodec);
    mySerialPort=new SerialPort(this);
    myTimer=new QTimer(this);
    connect(ui->toolButton, SIGNAL(clicked()), this, SLOT(refreshAvSerialPort()));
    connect(mySerialPort, SIGNAL(readyRead()), this , SLOT(readToPlainText()));
    //ui->groupBox->setHidden(ui->toolButton_3->isChecked());
    //ui->groupBox->hide();
    // fill data bits
    ui->comboBox_3->addItem(QLatin1String("8"), SerialPort::Data8);
    ui->comboBox_3->addItem(QLatin1String("7"), SerialPort::Data7);
    ui->comboBox_3->addItem(QLatin1String("6"), SerialPort::Data6);
    ui->comboBox_3->addItem(QLatin1String("5"), SerialPort::Data5);
    ui->comboBox_3->setCurrentIndex(0);

    // fill stop bits
    ui->comboBox_4->addItem(QLatin1String("2"), SerialPort::TwoStop);
#ifdef Q_OS_WIN
    ui->comboBox_4->addItem(QLatin1String("1.5"), SerialPort::OneAndHalfStop);
#endif
    ui->comboBox_4->addItem(QLatin1String("1"), SerialPort::OneStop);
    ui->comboBox_4->setCurrentIndex(ui->comboBox_4->count()-1);

    // fill parity
    ui->comboBox_5->addItem(QLatin1String("None"), SerialPort::NoParity);
    ui->comboBox_5->addItem(QLatin1String("Even"), SerialPort::EvenParity);
    ui->comboBox_5->addItem(QLatin1String("Odd"), SerialPort::OddParity);
    ui->comboBox_5->addItem(QLatin1String("Mark"), SerialPort::MarkParity);
    ui->comboBox_5->addItem(QLatin1String("Space"), SerialPort::SpaceParity);
    ui->comboBox_5->setCurrentIndex(0);

    // fill flow control
    ui->comboBox_6->addItem(QLatin1String("None"), SerialPort::NoFlowControl);
    ui->comboBox_6->addItem(QLatin1String("RTS/CTS"), SerialPort::HardwareControl);
    ui->comboBox_6->addItem(QLatin1String("XON/XOFF"), SerialPort::SoftwareControl);
    ui->comboBox_6->setCurrentIndex(0);
    refreshAvSerialPort();
    //currPortName="";
    loadSettings();
    if(complList.isEmpty())
        complList<<"ATID"<<"ATCH"<<"ATPL"<<"ATRE"<<"ATCN"<<"ATAC"<<"ATFR"<<"ATAD"<<"ATVR"<<"ATSH"<<"ATSL";

    myCompl=new QCompleter(complList, this);
    myCompl->setCaseSensitivity(Qt::CaseInsensitive);

    ui->lineEdit->setCompleter(myCompl);
    for(qint32 i=1; i<ui->comboBox_2->count(); i++) {
        if(ui->comboBox_2->itemText(i)==currPortName) {
            ui->comboBox_2->setCurrentIndex(i);
            break;
        }

    }
    dozvilNaOnovlPortiv=1;
    connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeIndxToPushButton(int)));
    connect(ui->comboBox_3, SIGNAL(currentIndexChanged(int)), this, SLOT(changeIndxToPushButton(int)));
    connect(ui->comboBox_4, SIGNAL(currentIndexChanged(int)), this, SLOT(changeIndxToPushButton(int)));
    connect(ui->comboBox_5, SIGNAL(currentIndexChanged(int)), this, SLOT(changeIndxToPushButton(int)));
    connect(ui->comboBox_6, SIGNAL(currentIndexChanged(int)), this, SLOT(changeIndxToPushButton(int)));

    connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(focusLineEdit(int)));
    connect(ui->comboBox_3, SIGNAL(currentIndexChanged(int)), this, SLOT(focusLineEdit(int)));
    connect(ui->comboBox_4, SIGNAL(currentIndexChanged(int)), this, SLOT(focusLineEdit(int)));
    connect(ui->comboBox_5, SIGNAL(currentIndexChanged(int)), this, SLOT(focusLineEdit(int)));
    connect(ui->comboBox_6, SIGNAL(currentIndexChanged(int)), this, SLOT(focusLineEdit(int)));
    connect(ui->comboBox_7, SIGNAL(currentIndexChanged(int)), this, SLOT(focusLineEdit(int)));
    connect(ui->comboBox_8, SIGNAL(currentIndexChanged(int)), this, SLOT(focusLineEdit(int)));
    connect(ui->cbTextSet, SIGNAL(currentIndexChanged(int)), this, SLOT(focusLineEdit(int)));
    connect(ui->toolButton_2,SIGNAL(clicked()), this , SLOT(focusLineEdit2()));
    connect(ui->toolButton_3,SIGNAL(clicked()), this , SLOT(focusLineEdit2()));
    connect(ui->toolButton_4,SIGNAL(clicked()), this , SLOT(focusLineEdit2()));

    connect(&checkPort, SIGNAL(portDisconnected()), this, SLOT(closeSerialPort()));

    //    onovlennyaTimer=new QTimer(this);
    //   connect(onovlennyaTimer, SIGNAL(timeout()), this, SLOT(onOnovlTimer()));
    //    onovlennyaTimer->start(1500);
}
コード例 #3
0
GraphicsPortItem::GraphicsPortItem(GraphicsClientItemsClient *client_, const QString &fullPortName_, int style_, QFont font_, int padding, QGraphicsItem *parent) :
    QGraphicsPathItem(parent),
    client(client_),
    fullPortName(fullPortName_),
    shortPortName(fullPortName.split(":")[1]),
    dataType(client->getPortType(fullPortName)),
    isInput(client->getPortFlags(fullPortName) & JackPortIsInput),
    style(style_),
    font(font_),
    showMenu(false)
{
    bool gradient = false;
    QColor captionColor(0xfc, 0xf9, 0xc2);
    setPen(QPen(QBrush(Qt::black), 2));
    setBrush(QBrush(captionColor));
    setFlags(QGraphicsItem::ItemSendsScenePositionChanges);
    setCursor(Qt::ArrowCursor);
    font.setStyleStrategy(QFont::PreferAntialias);
    QFontMetrics fontMetrics(font);
    int portPadding = padding;

    QGraphicsSimpleTextItem *portTextItem = new QGraphicsSimpleTextItem(shortPortName, this);
    portTextItem->setFont(font);
    portTextItem->setPos(portPadding, 0);
    portRect = portTextItem->boundingRect().adjusted(-portPadding, -portPadding, portPadding, portPadding).translated(portTextItem->pos());

    QPainterPath portPath;
    if (style == 0) {
        portPath = portPath.united(EllipsePath(portRect));
    } else if (style == 1) {
        portPath = portPath.united(SpeechBubblePath(portRect, portRect.height() / 4, portRect.height() / 4, Qt::AbsoluteSize));
    } else if (style == 2) {
        portPath = portPath.united(RoundedRectanglePath(portRect, portPadding + fontMetrics.height() / 2, portPadding + fontMetrics.height() / 2));
    } else if (style == 3) {
        portPath = portPath.united(RectanglePath(portRect));
    }
    setPath(portPath);

    // register the port registration callback at the jack server:
    QObject::connect(client, SIGNAL(portRegistered(QString,QString,int)), this, SLOT(onPortRegistered(QString,QString,int)), Qt::QueuedConnection);
    QObject::connect(client, SIGNAL(portUnregistered(QString,QString,int)), this, SLOT(onPortUnregistered(QString,QString,int)), Qt::QueuedConnection);
    QObject::connect(client, SIGNAL(portConnected(QString,QString)), this, SLOT(onPortConnected(QString,QString)), Qt::QueuedConnection);
    QObject::connect(client, SIGNAL(portDisconnected(QString,QString)), this, SLOT(onPortDisconnected(QString,QString)), Qt::QueuedConnection);

    if (gradient) {
        QLinearGradient gradient(portRect.topLeft(), portRect.bottomRight());
        gradient.setColorAt(0, Qt::white);
        gradient.setColorAt(1, QColor("wheat"));
        setBrush(QBrush(gradient));
    }

    // create the context menu:
    connectMenu = contextMenu.addMenu("Connect");
    disconnectMenu = contextMenu.addMenu("Disconnect");
    // create the entries in connect- and disconnect-menus, as well as graphical representations of existing connections:
    QStringList connectedPorts = client->getConnectedPorts(fullPortName);
    QSet<QString> connectedPortsSet;
    for (int i = 0; i < connectedPorts.size(); i++) {
        // create an entry in the disconnect-menu:
        QAction *action = disconnectMenu->addAction(connectedPorts[i]);
        action->setData(connectedPorts[i]);
        QObject::connect(action, SIGNAL(triggered()), this, SLOT(onDisconnectAction()));
        mapPortNamesToActions[connectedPorts[i]] = action;
        connectedPortsSet.insert(connectedPorts[i]);
        // create a graphical representation of the connection:
        if (isInput) {
            client->getPortConnectionItem(connectedPorts[i], fullPortName)->setPos(fullPortName, getConnectionScenePos());
        } else {
            client->getPortConnectionItem(fullPortName, connectedPorts[i])->setPos(fullPortName, getConnectionScenePos());
        }
    }
    // get all available ports that can be connected to this:
    QStringList connectablePorts = client->getPorts(0, dataType.toAscii().data(), isInput ? JackPortIsOutput : JackPortIsInput);
    for (int i = 0; i < connectablePorts.size(); i++) {
        // skip ports that are already connected:
        if (!connectedPortsSet.contains(connectablePorts[i])) {
            // create an entry in the connect-menu:
            QAction *action = connectMenu->addAction(connectablePorts[i]);
            action->setData(connectablePorts[i]);
            QObject::connect(action, SIGNAL(triggered()), this, SLOT(onConnectAction()));
            mapPortNamesToActions[connectablePorts[i]] = action;
        }
    }
    disconnectMenu->setEnabled(disconnectMenu->actions().size());
    connectMenu->setEnabled(connectMenu->actions().size());
}