void GrpRadioButton::keyPressEvent(QKeyEvent *e) { switch (e->key()){ case Key_Down:{ QRadioButton *first = NULL; QRadioButton *next = NULL; QObjectList *l = parentWidget()->queryList("QRadioButton"); QObjectListIt it(*l); QObject *obj; while ((obj=it.current()) != NULL){ if (first == NULL) first = static_cast<QRadioButton*>(obj); if (obj == this){ ++it; if ((obj = it.current()) == NULL){ next = first; }else{ next = static_cast<QRadioButton*>(obj); } break; } ++it; } delete l; if (next){ next->setFocus(); next->setChecked(true); } return; } case Key_Up:{ QRadioButton *prev = NULL; QObjectList *l = parentWidget()->queryList("QRadioButton"); QObjectListIt it(*l); QObject *obj; while ((obj=it.current()) != NULL){ if ((obj == this) && prev) break; prev = static_cast<QRadioButton*>(obj); ++it; } delete l; if (prev){ prev->setFocus(); prev->setChecked(true); } return; } } QRadioButton::keyPressEvent(e); }
void UIVMCloseDialog::configure() { /* Get actual machine-state: */ KMachineState machineState = m_machine.GetState(); /* Assign pixmap: */ setPixmap(vboxGlobal().vmGuestOSTypeIcon(m_machine.GetOSTypeId())); /* Check which close-actions are resticted: */ bool fIsDetachAllowed = vboxGlobal().isSeparateProcess() && !(m_restictedCloseActions & MachineCloseAction_Detach); bool fIsStateSavingAllowed = !(m_restictedCloseActions & MachineCloseAction_SaveState); bool fIsACPIShutdownAllowed = !(m_restictedCloseActions & MachineCloseAction_Shutdown); bool fIsPowerOffAllowed = !(m_restictedCloseActions & MachineCloseAction_PowerOff); bool fIsPowerOffAndRestoreAllowed = fIsPowerOffAllowed && !(m_restictedCloseActions & MachineCloseAction_PowerOff_RestoringSnapshot); /* Make 'Detach' button visible/hidden depending on restriction: */ setDetachButtonVisible(fIsDetachAllowed); /* Make 'Detach' button enabled/disabled depending on machine-state: */ setDetachButtonEnabled(machineState != KMachineState_Stuck); /* Make 'Save state' button visible/hidden depending on restriction: */ setSaveButtonVisible(fIsStateSavingAllowed); /* Make 'Save state' button enabled/disabled depending on machine-state: */ setSaveButtonEnabled(machineState != KMachineState_Stuck); /* Make 'Shutdown' button visible/hidden depending on restriction: */ setShutdownButtonVisible(fIsACPIShutdownAllowed); /* Make 'Shutdown' button enabled/disabled depending on console and machine-state: */ setShutdownButtonEnabled(m_fIsACPIEnabled && machineState != KMachineState_Stuck); /* Make 'Power off' button visible/hidden depending on restriction: */ setPowerOffButtonVisible(fIsPowerOffAllowed); /* Make the Restore Snapshot checkbox visible/hidden depending on snapshot count & restrictions: */ setDiscardCheckBoxVisible(fIsPowerOffAndRestoreAllowed && m_machine.GetSnapshotCount() > 0); /* Assign Restore Snapshot checkbox text: */ if (!m_machine.GetCurrentSnapshot().isNull()) m_strDiscardCheckBoxText = m_machine.GetCurrentSnapshot().GetName(); /* Check which radio-button should be initially chosen: */ QRadioButton *pRadioButtonToChoose = 0; /* If choosing 'last choice' is possible: */ m_lastCloseAction = gEDataManager->lastMachineCloseAction(vboxGlobal().managedVMUuid()); if (m_lastCloseAction == MachineCloseAction_Detach && fIsDetachAllowed) { pRadioButtonToChoose = m_pDetachRadio; } else if (m_lastCloseAction == MachineCloseAction_SaveState && fIsStateSavingAllowed) { pRadioButtonToChoose = m_pSaveRadio; } else if (m_lastCloseAction == MachineCloseAction_Shutdown && fIsACPIShutdownAllowed && m_fIsACPIEnabled) { pRadioButtonToChoose = m_pShutdownRadio; } else if (m_lastCloseAction == MachineCloseAction_PowerOff && fIsPowerOffAllowed) { pRadioButtonToChoose = m_pPowerOffRadio; } else if (m_lastCloseAction == MachineCloseAction_PowerOff_RestoringSnapshot && fIsPowerOffAndRestoreAllowed) { pRadioButtonToChoose = m_pPowerOffRadio; m_pDiscardCheckBox->setChecked(true); } /* Else 'default choice' will be used: */ else { if (fIsDetachAllowed) pRadioButtonToChoose = m_pDetachRadio; else if (fIsStateSavingAllowed) pRadioButtonToChoose = m_pSaveRadio; else if (fIsACPIShutdownAllowed && m_fIsACPIEnabled) pRadioButtonToChoose = m_pShutdownRadio; else if (fIsPowerOffAllowed) pRadioButtonToChoose = m_pPowerOffRadio; } /* If some radio-button chosen: */ if (pRadioButtonToChoose) { /* Check and focus it: */ pRadioButtonToChoose->setChecked(true); pRadioButtonToChoose->setFocus(); sltUpdateWidgetAvailability(); m_fValid = true; } }
KDMShutdown::KDMShutdown( int mode, QWidget* _parent, const char* _name, const char* _shutdown, const char* _restart) : FDialog( _parent, _name, true) { shutdown = _shutdown; restart = _restart; int h = 10, w = 0; QFrame* winFrame = new QFrame( this); winFrame->setFrameStyle( QFrame::WinPanel | QFrame::Raised); QBoxLayout* box = new QBoxLayout( winFrame, QBoxLayout::TopToBottom, 10, 10); QString shutdownmsg = klocale->translate( "Shutdown or restart?"); if( mode == KDMConfig::RootOnly) { shutdownmsg += '\n'; shutdownmsg += klocale->translate( "(Enter Root Password)"); } label = new QLabel( shutdownmsg, winFrame); set_fixed( label); h += label->height() + 10; w = label->width(); box->addWidget( label, 0, AlignCenter); QFrame* sepFrame = new QFrame( this); sepFrame->setFrameStyle( QFrame::HLine| QFrame::Sunken); h += sepFrame->height(); box->addWidget( sepFrame); btGroup = new QButtonGroup( /* this */); QRadioButton *rb; rb = new QRadioButton( winFrame /*btGroup*/); rb->setText( klocale->translate("Shutdown")); set_min( rb); rb->setFocusPolicy( StrongFocus); // Default action rb->setChecked( true); rb->setFocus(); cur_action = shutdown; h += rb->height() + 10; w = QMAX( rb->width(), w); box->addWidget( rb); btGroup->insert( rb); rb = new QRadioButton( winFrame /*btGroup*/); rb->setText( klocale->translate("Shutdown and restart")); set_min( rb); rb->setFocusPolicy( StrongFocus); h += rb->height() + 10; w = QMAX( rb->width(), w); box->addWidget( rb); btGroup->insert( rb); rb = new QRadioButton( winFrame /*btGroup*/); rb->setText( klocale->translate("Restart X Server"));//better description set_min( rb); rb->setFocusPolicy( StrongFocus); h += rb->height() + 10; w = QMAX( rb->width(), w); box->addWidget( rb); btGroup->insert( rb); // Passwd line edit if( mode == KDMConfig::RootOnly) { pswdEdit = new QLineEdit( winFrame); //set_min( pswdEdit); pswdEdit->setMinimumHeight( pswdEdit->sizeHint().height()); pswdEdit->setEchoMode( QLineEdit::NoEcho); /*QColorGroup passwdColGroup( QApplication::palette()->normal().foreground(), QApplication::palette()->normal().background(), QApplication::palette()->normal().light(), QApplication::palette()->normal().dark(), QApplication::palette()->normal().mid(), QApplication::palette()->normal().base(), QApplication::palette()->normal().base()); QPalette passwdPalette( passwdColGroup, passwdColGroup, passwdColGroup); pswdEdit->setPalette( passwdPalette); */ pswdEdit->setFocusPolicy( StrongFocus); pswdEdit->setFocus(); h+= pswdEdit->height() + 10; box->addWidget( pswdEdit); } QBoxLayout* box3 = new QBoxLayout( QBoxLayout::LeftToRight, 10); box->addLayout( box3); okButton = new QPushButton( klocale->translate("OK"), winFrame); set_min( okButton); okButton->setFocusPolicy( StrongFocus); cancelButton = new QPushButton( klocale->translate("Cancel"), winFrame); set_min( cancelButton); //cancelButton->setDefault( true); cancelButton->setFocusPolicy( StrongFocus); h += cancelButton->height() + 10; w = QMAX( (okButton->width() + 10 + cancelButton->width()), w); box3->addWidget( okButton); box3->addWidget( cancelButton); // Connections connect( okButton, SIGNAL(clicked()), SLOT(bye_bye())); connect( cancelButton, SIGNAL(clicked()), SLOT(reject())); connect( btGroup, SIGNAL(clicked(int)), SLOT(rb_clicked(int))); if( mode == KDMConfig::RootOnly) { okButton->setEnabled( false); connect( pswdEdit, SIGNAL( returnPressed()), this, SLOT( pw_entered())); } else cancelButton->setFocus(); resize( 20 + w, h); winFrame->setGeometry( 0, 0, width(), height()); }