Пример #1
0
bool PMenuData::menuMessageHandler(int fd, PukeMessage *pm)
{
    PukeMessage pmRet;
    int id = 0;
  switch(pm->iCommand){
  case PUKE_MENUDATA_INSERT_TEXT:
    {
      QPopupMenu *widget = (QPopupMenu *) child->widget();
      id = widget->insertItem(pm->cArg);
      if(pm->iArg > 0){
          widget->setAccel(pm->iArg, id);
      }

      pmRet.iCommand = PUKE_MENUDATA_INSERT_TEXT_ACK;
      pmRet.iWinId = pm->iWinId;
      pmRet.iArg = id;
      pmRet.cArg = 0;
      emit outputMessage(fd, &pmRet);
      break;
    }
  case PUKE_MENUDATA_INSERT_PIXMAP:
    {
      QPopupMenu *widget = (QPopupMenu *) child->widget();
      id = widget->insertItem(QPixmap(pm->cArg));
      if(pm->iArg > 0){
          widget->setAccel(pm->iArg, id);
      }
    
      pmRet.iCommand = PUKE_MENUDATA_INSERT_PIXMAP_ACK;
      pmRet.iWinId = pm->iWinId;
      pmRet.iArg = id;
      pmRet.cArg = 0;
      emit outputMessage(fd, &pmRet);
      break;
    }
  case PUKE_MENUDATA_REMOVE_ITEM:
    {
      QPopupMenu *widget = (QPopupMenu *) child->widget();
      widget->removeItem(pm->iArg);
    
      pmRet.iCommand = PUKE_MENUDATA_REMOVE_ITEM_ACK;
      pmRet.iWinId = pm->iWinId;
      pmRet.iArg = pm->iArg;
      pmRet.cArg = 0;
      emit outputMessage(fd, &pmRet);
      break;
    }

  default:
    return FALSE;
  }
  return TRUE;
}
Пример #2
0
QPopupMenu *KLineEdit::createPopupMenu()
{
    enum { IdUndo, IdRedo, IdSep1, IdCut, IdCopy, IdPaste, IdClear, IdSep2, IdSelectAll };

    QPopupMenu *popup = QLineEdit::createPopupMenu();

      int id = popup->idAt(0);
      popup->changeItem( id - IdUndo, SmallIconSet("undo"), popup->text( id - IdUndo) );
      popup->changeItem( id - IdRedo, SmallIconSet("redo"), popup->text( id - IdRedo) );
      popup->changeItem( id - IdCut, SmallIconSet("editcut"), popup->text( id - IdCut) );
      popup->changeItem( id - IdCopy, SmallIconSet("editcopy"), popup->text( id - IdCopy) );
      popup->changeItem( id - IdPaste, SmallIconSet("editpaste"), popup->text( id - IdPaste) );
      popup->changeItem( id - IdClear, SmallIconSet("editclear"), popup->text( id - IdClear) );

    // If a completion object is present and the input
    // widget is not read-only, show the Text Completion
    // menu item.
    if ( compObj() && !isReadOnly() && kapp->authorize("lineedit_text_completion") )
    {
        QPopupMenu *subMenu = new QPopupMenu( popup );
        connect( subMenu, SIGNAL( activated( int ) ),
                 this, SLOT( completionMenuActivated( int ) ) );

        popup->insertSeparator();
        popup->insertItem( SmallIconSet("completion"), i18n("Text Completion"),
                           subMenu );

        subMenu->insertItem( i18n("None"), NoCompletion );
        subMenu->insertItem( i18n("Manual"), ShellCompletion );
        subMenu->insertItem( i18n("Automatic"), AutoCompletion );
        subMenu->insertItem( i18n("Dropdown List"), PopupCompletion );
        subMenu->insertItem( i18n("Short Automatic"), ShortAutoCompletion );
        subMenu->insertItem( i18n("Dropdown List && Automatic"), PopupAutoCompletion );

        subMenu->setAccel( KStdAccel::completion(), ShellCompletion );

        KGlobalSettings::Completion mode = completionMode();
        subMenu->setItemChecked( NoCompletion,
                                 mode == KGlobalSettings::CompletionNone );
        subMenu->setItemChecked( ShellCompletion,
                                 mode == KGlobalSettings::CompletionShell );
        subMenu->setItemChecked( PopupCompletion,
                                 mode == KGlobalSettings::CompletionPopup );
        subMenu->setItemChecked( AutoCompletion,
                                 mode == KGlobalSettings::CompletionAuto );
        subMenu->setItemChecked( ShortAutoCompletion,
                                 mode == KGlobalSettings::CompletionMan );
        subMenu->setItemChecked( PopupAutoCompletion,
                                 mode == KGlobalSettings::CompletionPopupAuto );
        if ( mode != KGlobalSettings::completionMode() )
        {
            subMenu->insertSeparator();
            subMenu->insertItem( i18n("Default"), Default );
        }
    }
Пример #3
0
MenuExample::MenuExample( QWidget *parent, const char *name )
    : QWidget( parent, name )
{
    QPixmap p1( p1_xpm );
    QPixmap p2( p2_xpm );
    QPixmap p3( p3_xpm );

    QPopupMenu *print = new QPopupMenu( this );
    CHECK_PTR( print );
    print->insertTearOffHandle();
    print->insertItem( "&Print to printer", this, SLOT(printer()) );
    print->insertItem( "Print to &file", this, SLOT(file()) );
    print->insertItem( "Print to fa&x", this, SLOT(fax()) );
    print->insertSeparator();
    print->insertItem( "Printer &Setup", this, SLOT(printerSetup()) );

    QPopupMenu *file = new QPopupMenu( this );
    CHECK_PTR( file );
    file->insertItem( p1, "&Open",  this, SLOT(open()), CTRL+Key_O );
    file->insertItem( p2, "&New", this, SLOT(news()), CTRL+Key_N );
    file->insertItem( p3, "&Save", this, SLOT(save()), CTRL+Key_S );
    file->insertItem( "&Close", this, SLOT(closeDoc()), CTRL+Key_W );
    file->insertSeparator();
    file->insertItem( "&Print", print, CTRL+Key_P );
    file->insertSeparator();
    file->insertItem( "E&xit",  qApp, SLOT(quit()), CTRL+Key_Q );

    QPopupMenu *edit = new QPopupMenu( this );
    CHECK_PTR( edit );
    int undoID = edit->insertItem( "&Undo", this, SLOT(undo()) );
    int redoID = edit->insertItem( "&Redo", this, SLOT(redo()) );
    edit->setItemEnabled( undoID, FALSE );
    edit->setItemEnabled( redoID, FALSE );

    QPopupMenu* options = new QPopupMenu( this );
    CHECK_PTR( options );
    options->insertTearOffHandle();
    options->setCaption("Options");
    options->insertItem( "&Normal Font", this, SLOT(normal()) );
    options->insertSeparator();

    options->polish(); // adjust system settings
    QFont f = options->font();
    f.setBold( TRUE );
    boldID = options->insertItem( new MyMenuItem( "Bold", f ) );
    options->setAccel( CTRL+Key_B, boldID );
    options->connectItem( boldID, this, SLOT(bold()) );
    f = font();
    f.setUnderline( TRUE );
    underlineID = options->insertItem( new MyMenuItem( "Underline", f ) );
    options->setAccel( CTRL+Key_U, underlineID );
    options->connectItem( underlineID, this, SLOT(underline()) );

    isBold = FALSE;
    isUnderline = FALSE;
    options->setCheckable( TRUE );


    QPopupMenu *help = new QPopupMenu( this );
    CHECK_PTR( help );
    help->insertItem( "&About", this, SLOT(about()), CTRL+Key_H );
    help->insertItem( "About &Qt", this, SLOT(aboutQt()) );

    menu = new QMenuBar( this );
    CHECK_PTR( menu );
    menu->insertItem( "&File", file );
    menu->insertItem( "&Edit", edit );
    menu->insertItem( "&Options", options );
    menu->insertSeparator();
    menu->insertItem( "&Help", help );
    menu->setSeparator( QMenuBar::InWindowsStyle );

    label = new QLabel( this );
    CHECK_PTR( label );
    label->setGeometry( 20, rect().center().y()-20, width()-40, 40 );
    label->setFrameStyle( QFrame::Box | QFrame::Raised );
    label->setLineWidth( 1 );
    label->setAlignment( AlignCenter );

    connect( this,  SIGNAL(explain(const QString&)),
             label, SLOT(setText(const QString&)) );

    setMinimumSize( 100, 80 );
}
Пример #4
0
KBBGame::KBBGame() : KTopLevelWidget()     
{
  int i;

  setCaption(QString("KBlackBox ")+KBVERSION);

  menu                = new KMenuBar(this, "menu");
  QPopupMenu *game    = new QPopupMenu;
  QPopupMenu *file    = new QPopupMenu;
  sizesm  = new QPopupMenu;
  ballsm  = new QPopupMenu;
  QPopupMenu *help = new QPopupMenu;
  options = new QPopupMenu;
 
  CHECK_PTR( file );
  CHECK_PTR( game );
  CHECK_PTR( help );
  CHECK_PTR( sizesm );
  CHECK_PTR( ballsm );
  CHECK_PTR( options );
  CHECK_PTR( menu );

  help->insertItem( trans->translate("&Help"), ID_HELP );
  help->setAccel( CTRL+Key_H, ID_HELP );
  help->insertSeparator();
  help->insertItem( trans->translate("&About KBlackBox"), ID_ABOUT );
  help->setAccel( CTRL+Key_A, ID_ABOUT );
  help->insertItem( trans->translate("About &Qt"), ID_ABOUT_QT );

		    
  file->insertItem( trans->translate("&Quit"), ID_QUIT );
  file->setAccel( CTRL+Key_Q, ID_QUIT );

  game->insertItem( trans->translate("&New"), ID_NEW );
  game->insertItem( trans->translate("&Give up"), ID_GIVEUP );
  game->insertItem( trans->translate("&Done"), ID_DONE );
  game->insertSeparator();
  game->insertItem( trans->translate("&Resize"), ID_RESIZE );

  sizes1id = sizesm->insertItem( "  8 x 8  ", this, SLOT(size1()) );
  sizes2id = sizesm->insertItem( " 10 x 10 ", this, SLOT(size2()) );
  sizes3id = sizesm->insertItem( " 12 x 12 ", this, SLOT(size3()) );
  sizesm->setCheckable( TRUE );

  balls1id = ballsm->insertItem( " 4 ", this, SLOT(balls1()) );
  balls2id = ballsm->insertItem( " 6 ", this, SLOT(balls2()) );
  balls3id = ballsm->insertItem( " 8 ", this, SLOT(balls3()) );
  ballsm->setCheckable( TRUE );

  options->insertItem( trans->translate("&Size"), sizesm );  
  options->insertItem( trans->translate("&Balls"), ballsm );
  tut1id = options->insertItem( trans->translate("&Tutorial"),
				this, SLOT(tutorialSwitch()) );
  options->setCheckable( TRUE );

  connect( file, SIGNAL(activated(int)), SLOT(callBack(int)) );
  connect( help, SIGNAL(activated(int)), SLOT(callBack(int)) );
  connect( game, SIGNAL(activated(int)), SLOT(callBack(int)) );
 
  menu->insertItem( trans->translate("&File"), file );
  menu->insertItem( trans->translate("&Game"), game );
  menu->insertItem( trans->translate("&Options"), options );
  menu->insertSeparator();
  menu->insertItem( trans->translate("&Help"), help );

  menu->show(); 
  setMenu( menu );

  KIconLoader *loader = kapp->getIconLoader();
  QPixmap **pix = new QPixmap*[NROFTYPES];
  pix[0] = new QPixmap();
  *pix[0] = loader->loadIcon( pFNames[0] );
  if (!pix[0]->isNull()) {
    debug( "Pixmap \"%s\" loaded.", pFNames[0] );
    for (i = 1; i < NROFTYPES; i++) {
      pix[i] = new QPixmap;
      *pix[i] = loader->loadIcon( pFNames[i] );
      if (!pix[i]->isNull()) {
	debug( "Pixmap \"%s\" loaded.", pFNames[i] );
      } else {
	pix[i] = pix[i-1];
	pix[i]->detach();
	debug( "Cannot find pixmap \"%s\". Using previous one.", pFNames[i] );
      }
    }
  } else {
    debug( "Cannot find pixmap \"%s\". Pixmaps will not be loaded.",
	   pFNames[0] );
    delete pix[0];
    delete pix;
    pix = NULL;
  }
  gr = new KBBGraphic( pix, this );
  connect( gr, SIGNAL(inputAt(int,int,int)),
	  this, SLOT(gotInputAt(int,int,int)) );
  connect( this, SIGNAL(gameRuns(bool)),
	  gr, SLOT(setInputAccepted(bool)) );
  connect( gr, SIGNAL(endMouseClicked()),
	  this, SLOT(gameFinished()) );
  
  /*
  QToolTip::add( doneButton, trans->translate(
		 "Click here when you think you placed all the balls.") );
		 */

  QString tmps;
  stat = new KStatusBar( this );
  tmps.sprintf( "aaaaaaaa" );
  stat->insertItem( (const char *) tmps, SSCORE );
  tmps.sprintf( "aaaaaaaaaaa" );
  stat->insertItem( (const char *) tmps, SBALLS );
  tmps.sprintf( "aaaaaaa" );
  stat->insertItem( (const char *) tmps, SRUN );
  tmps.sprintf( "aaaaaaaaaa" );
  stat->insertItem( (const char *) tmps, SSIZE );
  setStatusBar( stat );

  tool = new KToolBar( this );
  tool->insertButton( loader->loadIcon("exit.xpm"),
		      ID_QUIT, TRUE, trans->translate("Quit") );
  tool->insertButton( loader->loadIcon("reload.xpm"),
		      ID_NEW, TRUE, trans->translate("New") );
  tool->insertButton( loader->loadIcon("giveup.xpm"),
		      ID_GIVEUP, TRUE, trans->translate("Give up") );
  tool->insertButton( loader->loadIcon("done.xpm"),
		      ID_DONE, TRUE, trans->translate("Done") );
  tool->insertSeparator();
  tool->insertButton( loader->loadIcon("help.xpm"), ID_HELP, TRUE,
		      trans->translate("Help") );
  connect( tool, SIGNAL(clicked(int)), SLOT(callBack(int)) );
  addToolBar( tool );
  tool->setBarPos( KToolBar::Top );
  tool->show();
  
  /*
     Game initializations
  */
  running = FALSE;
  gameBoard = NULL;

  KConfig *kConf;
  int j;
  kConf = KApplication::getKApplication()->getConfig();
  kConf->setGroup( "KBlackBox Setup" );
  if (kConf->hasKey( "Balls" )) {
    i = kConf->readNumEntry( "Balls" );
    balls = i;
    switch (i) {
    case 4: ballsm->setItemChecked( balls1id, TRUE ); break;
    case 6: ballsm->setItemChecked( balls2id, TRUE ); break;
    case 8: ballsm->setItemChecked( balls3id, TRUE ); break;
    }
  } else {
    balls = 4;
    ballsm->setItemChecked( balls1id, TRUE );
  }
  if ((kConf->hasKey( "Width" )) &&
      (kConf->hasKey( "Balls" ))) {
    i = kConf->readNumEntry( "Width" );
    j = kConf->readNumEntry( "Height" );
    gr->setSize( i+4, j+4 ); // +4 is the space for "lasers" and an edge...
    gameBoard = new RectOnArray( gr->numC(), gr->numR() );
    switch (i) {
    case 8: sizesm->setItemChecked( sizes1id, TRUE ); break;
    case 10: sizesm->setItemChecked( sizes2id, TRUE ); break;
    case 12: sizesm->setItemChecked( sizes3id, TRUE ); break;
    }
  } else {
    gr->setSize( 8+4, 8+4 ); // +4 is the space for "lasers" and an edge...
    gameBoard = new RectOnArray( gr->numC(), gr->numR() );
    sizesm->setItemChecked( sizes1id, TRUE );
  }
  if (kConf->hasKey( "tutorial" )) {
    tutorial = (bool) kConf->readNumEntry( "tutorial" );
  } else tutorial = FALSE;
  options->setItemChecked( tut1id, tutorial );

  QString s, s1;
  int pos;
  setMinSize();
  gameResize();
  if (kConf->hasKey( "appsize" )) {
    s = kConf->readEntry( "appsize" );
    debug("%s", (const char *) s);
    pos = s.find( 'x' );
    s1 = s.right( s.length() - pos - 1 );
    s.truncate( pos - 1 );
    //    debug("%s", (const char *) s);
    //    debug("%s", (const char *) s1);
    resize( s.toInt(), s1.toInt() );
  }

  setScore( 0 );
  ballsPlaced = 0;
  updateStats();

  setView( gr );

  newGame();
}