예제 #1
0
WindowManagerWindow::WindowManagerWindow( Window window ):
	_x11Window( window )
{
	_previousState = _state = Normal;

	_normalX = _normalY = 0;
	_normalWidth = _normalHeight = 600;

	_maximizedX = _maximizedY = 0;
	_maximizedWidth = XLibWrapper::getScreenWidth( XLibWrapper::getScreenForWindow(_x11Window) );
	_maximizedHeight = XLibWrapper::getScreenHeight( XLibWrapper::getScreenForWindow(_x11Window) );

	// init the titlebar
	_titleBar = new TitleBar();
	std::string windowName = XLibWrapper::getWindowName( _x11Window );
	_titleBar->setTitlebarText( windowName.c_str() );
	
	connect( _titleBar, SIGNAL(minimizeButton()), this, SLOT(minimize()) );
	connect( _titleBar, SIGNAL(maximizeButton()), this, SLOT(maximize()) );
	connect( _titleBar, SIGNAL(closeButton()), this, SLOT(close()) );
	connect( _titleBar, SIGNAL(titleDragged(int,int)), this, SLOT(move(int,int)) );

	// init the bottombar
	_bottomBar = new BottomBar();
	connect( _bottomBar, SIGNAL(reizeLeft(int,int)), this, SLOT(resizeLeft(int,int)) );	
	connect( _bottomBar, SIGNAL(reizeRight(int,int)), this, SLOT(resizeRight(int,int)) );	
}
예제 #2
0
/***********************************************************
	函数名称: state_trans()
	函数功能: 控制电梯的状态
	入口参数: 无
	出口参数: 无
	备 注: 使用到的全局变量
			buttonUp,buttonDown,buttonNumber,currentFloor,state,nextFloor,moveDirection
			其中nextFloor,moveDirection为只读 不可修改
			使用自动机模型 电梯运行速度2秒每层 电梯停靠时间为4秒
***********************************************************/
void state_trans()
{
    static int reopen = 0;//电梯关门时按下开门键的标示

    switch (state) //根据状态和事件,进行相应的处理
    {
        case
                IDLE: //电梯空闲状态
            if (openbutton == 1)
            {
                state = STOP;//电梯按下开门按钮进入停靠状态
            }

            if (moveDirection != STOP) //由control函数发现有不同层响应呼叫 电梯进入运行状态
            {
                state = RUN;//电梯进入运行状态
                startIDLE = 1;
            }
            else
                if (currentFloor == nextFloor) //由control函数发现有同层响应呼叫 电梯进入停靠状态
                {
                    state = STOP;
                    startIDLE = 1;
                }
                else
                {
                    if (Profile == C)
                    {
                        if (startIDLE == 1)
                        {
                            a = clock();
                            startIDLE = 0;
                        }
                        else
                        {
                            b = clock();
                            c = (double) (b - a) / CLOCKS_PER_SEC;

                            if (c > waitTime) //等待waitTime秒
                            {
                                if (currentFloor != 1)
                                {
                                    nextFloor = -1;
                                    moveDirection = DOWN;
                                    state = RUN;
                                    startIDLE = 1;
                                }

                            }
                        }
                    }
                    else
                    {
                        moveDirection = STOP;
                    }
                }

            break;

        case
                RUN://电梯运行状态
            if (currentFloor == ignore)//安全运行结束
            {
                ignore = 0;
            }

            if (nextFloor == -1 || profileCfindnextfloor == 1)
            {

                if (currentFloor != 1) //未到目标楼层
                {

                    if (startRUN == 1)//计时器开始计时
                    {
                        directa = ar = clock();
                        startRUN = 0;
                    }
                    else
                    {
                        directb = br = clock();
                        cr = (double) (br - ar) / CLOCKS_PER_SEC;
                        directc = (double) (directb - directa) / CLOCKS_PER_SEC;
                        elevatorMove((double)cr / velocity);//电梯运行动画

                        if (directc >= 0.05)
                        {
                            directa = clock();
                            showDirection_run(0);//指示灯动画
                        }

                        if (cr > velocity)//时间到velocity秒
                        {
                            currentFloor--;
                            profileCfindnextfloor = 0;
                            showFloor();
                            elevatorMove(0);
                            startRUN = 1;
                        }

                    }

                }

                if (currentFloor == 1) //电梯到达目标楼层
                {
                    nextFloor = 0;
                    state = IDLE;
                    moveDirection = STOP;
                    showDirection_stop();
                }

            }
            else//profileCfindnextfloor==0
            {

                if (startRun == 1)
                {
                    staticStart = clock();//统计计时
                    startRun = 0;
                }

                if (currentFloor != nextFloor || profileEFfindnextfloor == 1) //未到目标楼层
                {
                    if (startRUN == 1)
                    {
                        directa = ar = clock();
                        startRUN = 0;
                        profileEFfindnextfloor = 0;
                    }
                    else
                    {

                        if (profileEFfindnextfloor == 1)
                        {
                            static double temptime1, temptime = 0;

                            if (startRUNEF == 1)
                            {
                                br = clock();
                                temptime = (double) (br - ar) / CLOCKS_PER_SEC;
                                temptime1 = temptime;
                                ar = clock();
                                startRUNEF = 0;
                            }
                            else
                            {

                                directb = br = clock();
                                cr = (double) (br - ar) / CLOCKS_PER_SEC;
                                directc = (double) (directb - directa) / CLOCKS_PER_SEC;


                                temptime = temptime1 - cr;

                                if (temptime > 0)
                                {

                                    elevatorMove((double)(velocity - temptime) / velocity);

                                }

                                if (directc >= 0.05)
                                {
                                    directa = clock();
                                    showDirection_run(0);//指示灯动画
                                }

                                if (temptime < 0)
                                {

                                    showFloor();//显示当前楼层

                                    profileEFfindnextfloor = 0;
                                    elevatorMove(0);//电梯运行动画
                                    startRUNEF = 1;
                                    startRUN = 1;
                                    temptime = 0;
                                }


                            }


                        }

                        else

                        {
                            directb = br = clock();

                            cr = (double) (br - ar) / CLOCKS_PER_SEC;
                            directc = (double) (directb - directa) / CLOCKS_PER_SEC;

                            if (profileEFfindnextfloor == 0)
                            {
                                elevatorMove((double)cr / velocity);//电梯运行动画
                            }

                            if (directc >= 0.05)
                            {
                                directa = clock();
                                showDirection_run(0);//指示灯动画
                            }

                            if (cr > velocity)
                            {
                                currentFloor += moveDirection;
                                showFloor();//显示当前楼层

                                if (profileEFfindnextfloor == 0)
                                {
                                    elevatorMove(0);//电梯运行动画
                                }

                                startRUN = 1;
                            }
                        }


                    }
                }




                if ((currentFloor == nextFloor) && (profileEFfindnextfloor == 0)) //电梯到达目标楼层
                {
                    if (moveDirection == UP) //关闭相应的按钮 电梯进入停靠状态
                    {
                        if (Profile == B)//B策略单独处理
                        {
                            if (headPtr != NULL)
                            {
                                closeButton();
                                eachNumber[previousProfile]++;
                                deleteNode(headPtr->data);
                            }
                        }

                        else//关闭按钮
                        {
                            if((buttonUp[currentFloor] == 0) && (buttonNumber[currentFloor] == 0))
                            {
                                buttonDown[currentFloor] = 0;
                                deleteNode(listDown[currentFloor]);
                                lightOff(listDown[currentFloor]);

                                eachNumber[previousProfile]++;
                            }
                            else//关闭按钮
                            {
                                buttonUp[currentFloor] = 0;
                                buttonNumber[currentFloor] = 0;
                                lightOff(listUp[currentFloor]);
                                lightOff(listNumber[currentFloor]);

                                if (headPtr != NULL)
                                {
                                    eachNumber[previousProfile]++;
                                    deleteNode(listUp[currentFloor]);

                                    deleteNode(listNumber[currentFloor]);
                                }


                            }
                        }

                        state = STOP;
                        startRun = 1;
                        staticStop = clock();
                        totalTime[previousProfile] += (double) (staticStop - staticStart) / CLOCKS_PER_SEC;//统计时间

                    }

                    if (moveDirection == DOWN) //关闭相应的按钮 电梯进入停靠状态

                    {
                        if (Profile == B)//B策略需单独处理
                        {
                            if (headPtr != NULL)
                            {
                                closeButton();
                                deleteNode(headPtr->data);


                                eachNumber[previousProfile]++;
                            }
                        }
                        else//关闭按钮
                        {
                            if ((buttonDown[currentFloor] == 0) && (buttonNumber[currentFloor] == 0))
                            {
                                buttonUp[currentFloor] = 0;
                                lightOff(listUp[currentFloor]);
                                deleteNode(listUp[currentFloor]);

                                eachNumber[previousProfile]++;
                            }
                            else//关闭按钮
                            {

                                buttonDown[currentFloor] = 0;
                                buttonNumber[currentFloor] = 0;
                                lightOff(listDown[currentFloor]);
                                lightOff(listNumber[currentFloor]);

                                if (headPtr != NULL)
                                {
                                    eachNumber[previousProfile]++;
                                    deleteNode(listDown[currentFloor]);
                                    deleteNode(listNumber[currentFloor]);
                                }
                            }
                        }

                        state = STOP;//进入停靠
                        startRun = 1;
                        staticStop = clock();

                        totalTime[previousProfile] += (double) (staticStop - staticStart) / CLOCKS_PER_SEC;//统计时间

                    }

                    if (moveDirection == STOP) //如果电梯无运行方向 电梯进入停靠状态
                    {
                        state = STOP;
                        startRun = 1;
                        staticStop = clock();
                        //时间统计
                        totalTime[previousProfile] += (double) (staticStop - staticStart) / CLOCKS_PER_SEC;//统计时间
                    }
                }

            }

            break;

        case
                STOP: //电梯停靠状态

            if (startSTOP == 1)//刚开始停靠
            {
                DWORD ThreadIDa = 1, ThreadIDb = 2;
                HANDLE hReada, hReadb;
                as = clock();//计时器初始化

                if (reopen == 1)//判断是否开门
                {
                    reopen = 0;
                }
                else
                {
                    //开门动画,指示灯动画并且播放语音
                    hReada = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)arriveSound, NULL, 0, &ThreadIDa);
                    hReadb = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)showDirection_stop, NULL, 0, &ThreadIDb);
                    openDoor();

                    startSTOP = 0;
                }

            }
            else
            {

                if (openbutton == 1)//长按开门键则不关门
                {
                    as = clock();
                    restTime = stopTime;
                }
                else
                {
                    showDirection_stop();
                    bs = clock();
                    cs = (double) (bs - as) / CLOCKS_PER_SEC;
                    restTime = stopTime - cs;

                    if (cs > stopTime || Go == 1)//Go指令判断
                    {
                        startSTOP = 1;

                    }

                }

            }

            if (startSTOP == 1)
            {

                if (nextFloor == 0) //如果无目标楼层 电梯进入空闲状态
                {
                    if (closeDoor() == 1)
                    {
                        state = STOP;
                        startSTOP = 1;
                        reopen = 1;
                        break;
                    }

                    moveDirection = STOP;
                    state = IDLE;

                    if (Profile == B)
                    {
                        showDirection_stop();
                    }

                }
                else//有目标楼层则电梯进入运行状态
                {
                    if (closeDoor())
                    {
                        state = STOP;
                        startSTOP = 1;
                        reopen = 1;
                        break;
                    }

                    state = RUN;
                    control();
                    gosound();

                }

            }

            break;

    }//end of switch
}
예제 #3
0
/**
 * Parse a given XmlReader objest that represents the map.
 *
 * @param reader Reference to a XmlReader object representing a given XML file.
 */
void
Window::parse(XmlReader& reader)
{
    // parse attributes...
    XmlReader::AttributeIterator iter(reader);
    while(iter.next()) {
        const char* name = (const char*) iter.getName();
        const char* value = (const char*) iter.getValue();

        if(parseAttribute(name, value)) {
            continue;
        } else if(strcmp(name, "width") == 0) {
            if(sscanf(value, "%f", &width) != 1) {
                std::stringstream msg;
                msg << "Couldn't parse width attribute (" << value << ").";
                throw std::runtime_error(msg.str());
            }
        } else if(strcmp(name, "height") == 0) {
            if(sscanf(value, "%f", &height) != 1) {
                std::stringstream msg;
                msg << "Couldn't parse height attribute (" << value << ").";
                throw std::runtime_error(msg.str());
            }
        } else if(strcmp(name, "border") == 0) {
            if(sscanf(value, "%f", &border) != 1) {
                std::stringstream msg;
                msg << "Couldn't parse border attribute (" << value << ").";
                throw std::runtime_error(msg.str());
            }
        } else if(strcmp(name, "titlesize") == 0) {
            if(sscanf(value, "%f", &titlesize) != 1) {
                std::stringstream msg;
                msg << "Couldn't parse titlesize attribute (" << value << ").";
                throw std::runtime_error(msg.str());
            }
        } else {
            std::cerr << "Unknown attribute '" << name << "' skipped.\n";
        }
    }
    if(width <= 0 || height <= 0)
        throw std::runtime_error("Width or Height invalid");

    childs.assign(5, Child());

    int depth = reader.getDepth();
    while(reader.read() && reader.getDepth() > depth) {
        if(reader.getNodeType() == XML_READER_TYPE_ELEMENT) {
            std::string element = (const char*) reader.getName();
            if(element == "title") {
                resetChild(title(), parseEmbeddedComponent(reader));
            } else if(element == "closebutton") {
                std::auto_ptr<Button> button (new Button());
                button->parse(reader);
                resetChild(closeButton(), button.release());
            } else if(element == "contents") {
                resetChild(contents(), parseEmbeddedComponent(reader));
            } else if(element == "background") {
                resetChild(background(), parseEmbeddedComponent(reader));
            } else if(element == "title-background") {
                resetChild(title_background(), parseEmbeddedComponent(reader));
            } else {
                std::cerr << "Skipping unknown element '"
                    << element << "'.\n";
                reader.nextNode();
            }
        }
    }

    // layout
    float closeButtonHeight = 0;
    float closeButtonWidth = 0;
    float closeButtonBorder = 0;
    if(closeButton().getComponent() != 0) {
        closeButtonHeight = closeButton().getComponent()->getHeight();
        if(titlesize < closeButtonHeight) {
            titlesize = closeButtonHeight;
        }

        closeButtonWidth = closeButton().getComponent()->getWidth();
        closeButtonBorder = (titlesize - closeButtonHeight) / 2;
        closeButtonWidth += 2*closeButtonBorder;
        closeButtonHeight += 2*closeButtonBorder;
    }

    float compWidth = width - 2*border;
    float compHeight = height - 2*border;
    title().setPos(Vector2(border, border));
    title().getComponent()->resize(compWidth - closeButtonWidth, titlesize);
    if(title_background().getComponent() != 0) {
        title_background().setPos(title().getPos());
        title_background().getComponent()->resize(
                compWidth - closeButtonWidth, titlesize);
    }
    if(closeButton().getComponent() != 0) {
        closeButton().setPos(Vector2(
                    border + compWidth - closeButtonWidth + closeButtonBorder,
                    border + closeButtonBorder));
    }
    contents().setPos(Vector2(border, border + titlesize));
    contents().getComponent()->resize(compWidth, compHeight - titlesize);
    if(background().getComponent() != 0) {
        background().setPos(Vector2(0, 0));
        background().getComponent()->resize(width, height);
    }

    // connect signals...
    if(closeButton().getComponent() != 0) {
        Button* button = (Button*) closeButton().getComponent();
        button->clicked.connect(
                makeCallback(*this, &Window::closeButtonClicked));
    }
}
예제 #4
0
QgsAuthSslImportDialog::QgsAuthSslImportDialog( QWidget *parent )
    : QDialog( parent )
    , mSocket( nullptr )
    , mExecErrorsDialog( false )
    , mTimer( nullptr )
    , mSslErrors( QList<QSslError>() )
    , mTrustedCAs( QList<QSslCertificate>() )
    , mAuthNotifyLayout( nullptr )
    , mAuthNotify( nullptr )
{
  if ( QgsAuthManager::instance()->isDisabled() )
  {
    mAuthNotifyLayout = new QVBoxLayout;
    this->setLayout( mAuthNotifyLayout );
    mAuthNotify = new QLabel( QgsAuthManager::instance()->disabledMessage(), this );
    mAuthNotifyLayout->addWidget( mAuthNotify );
  }
  else
  {
    setupUi( this );
    QStyle *style = QApplication::style();
    lblWarningIcon->setPixmap( style->standardIcon( QStyle::SP_MessageBoxWarning ).pixmap( 48, 48 ) );
    lblWarningIcon->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );

    closeButton()->setDefault( false );
    saveButton()->setEnabled( false );

    leServer->setSelection( 0, leServer->text().size() );
    pteSessionStatus->setReadOnly( true );
    spinbxTimeout->setValue( 15 );

    grpbxServer->setCollapsed( false );
    radioServerImport->setChecked( true );
    frameServerImport->setEnabled( true );
    radioFileImport->setChecked( false );
    frameFileImport->setEnabled( false );

    connect( radioServerImport, SIGNAL( toggled( bool ) ),
             this, SLOT( radioServerImportToggled( bool ) ) );
    connect( radioFileImport, SIGNAL( toggled( bool ) ),
             this, SLOT( radioFileImportToggled( bool ) ) );

    connect( leServer, SIGNAL( textChanged( QString ) ),
             this, SLOT( updateEnabledState() ) );
    connect( btnConnect, SIGNAL( clicked() ),
             this, SLOT( secureConnect() ) );
    connect( leServer, SIGNAL( returnPressed() ),
             btnConnect, SLOT( click() ) );

    connect( buttonBox, SIGNAL( accepted() ),
             this, SLOT( accept() ) );
    connect( buttonBox, SIGNAL( rejected() ),
             this, SLOT( reject() ) );

    connect( wdgtSslConfig, SIGNAL( readyToSaveChanged( bool ) ),
             this, SLOT( widgetReadyToSaveChanged( bool ) ) );
    wdgtSslConfig->setEnabled( false );

    mTrustedCAs = QgsAuthManager::instance()->getTrustedCaCertsCache();
  }
}