void FileManager::create_menu() { layout_->addWidget(menuBar() ); file_ = new QPopupMenu( this ); menuBar()->insertItem( tr( "File" ), file_ ); INIT_FO_POPUP(file_, this); view_ = new QPopupMenu( this ); menuBar()->insertItem( tr( "View" ), view_ ); dirtree_idx_=view_->insertItem(tr("list"),this, SLOT(show_dirtree())); cout << "id : " << dirtree_idx_ << endl; image_idx_=view_->insertItem(tr("image"),this, SLOT(show_image())); status_idx_ = view_->insertItem(tr("status bar"),this, SLOT(show_status_bar())); view_->setItemChecked(status_idx_, true); options_ = new QPopupMenu( this ); menuBar()->insertItem( tr( "Options" ), options_ ); options_->insertItem(tr("Font"),this, SLOT(select_font())); options_->insertItem(tr("encode"),this, SLOT(show_encode_dialog())); up_ = new QToolButton(menuBar(),"up"); left_ = new QToolButton(0,"left"); right_ = new QToolButton(0,"right"); init_tool_button(menuBar(),up_,"up.png"); init_tool_button(menuBar(),left_,"left.png"); init_tool_button(menuBar(),right_,"right.png"); connect(up_, SIGNAL(clicked() ) , this, SLOT(cd_up())); connect(left_, SIGNAL(clicked() ) , this, SLOT(screen_off())); connect(right_, SIGNAL(clicked() ) , this, SLOT(screen_on())); }
FileManager::FileManager(QWidget * parent , const char * name , WFlags f ):QMainWindow(parent,name,f) { QVBoxLayout *layout = new QVBoxLayout( this ); layout->setSpacing(2); layout->setMargin(2); h_box_ = new QHBox(this); dirtree_view_ = new DirTreeView(h_box_); //dirtree_view_->hide(); dir_content_ = new DirContent(h_box_); //dir_content_->hide(); //image_widget_ = new ImageWidget(h_box_); //setCentralWidget(h_box_); font_selector_ = new FontSelector(); dirtree_view_->setGeometry(0,0,width(),height()*2); dir_content_->setGeometry(width(),0,width(),height()*2); //image_widget_->setGeometry(0,0,width(),height()*3); le_on_dirtree_ = new RenameLineEdit(dirtree_view_); le_on_dirtree_ -> hide(); le_on_dir_content_ = new RenameLineEdit(dir_content_); le_on_dir_content_ -> hide(); connect(le_on_dirtree_, SIGNAL( lost_focus() ), SLOT( rename() ) ); connect(le_on_dirtree_, SIGNAL(returnPressed()), this, SLOT(rename())); connect(le_on_dir_content_, SIGNAL( lost_focus() ), SLOT( rename() ) ); connect(le_on_dir_content_, SIGNAL(returnPressed()), this, SLOT(rename())); QObject::connect(dirtree_view_, SIGNAL(clicked ( QListViewItem *) ), dir_content_, SLOT(get_content(QListViewItem *) )); connect(dirtree_view_,SIGNAL(currentChanged ( QListViewItem *)), dir_content_, SLOT(get_content(QListViewItem *) ) ); QObject::connect(dir_content_, SIGNAL(cur_dir ( const std::string &) ), this, SLOT(modify_caption(const std::string &) )); QMenuBar *menubar = new QMenuBar(this); //QPEToolBar* toolBar = new QPEToolBar( this ); //toolBar->setHorizontalStretchable( TRUE ); //QPEMenuBar* menuBar = new QPEMenuBar( toolBar ); //layout->addWidget(toolBar); layout->addWidget(menubar); file_ = new QPopupMenu( this ); menubar->insertItem( tr( "File" ), file_ ); INIT_FO_POPUP(file_, this); view_ = new QPopupMenu( this ); menubar->insertItem( tr( "View" ), view_ ); view_->insertItem(tr("status bar"),this, SLOT(show_status_bar())); //view_->setCheckable(true); view_->setItemChecked(view_->idAt(0),false); options_ = new QPopupMenu( this ); menubar->insertItem( tr( "Options" ), options_ ); options_->insertItem("Font",this, SLOT(select_font())); up_ = new QToolButton(0,"up"); left_ = new QToolButton(0,"left"); right_ = new QToolButton(0,"right"); init_tool_button(menubar,up_,"up.png"); init_tool_button(menubar,left_,"left.png"); init_tool_button(menubar,right_,"right.png"); connect(up_, SIGNAL(clicked() ) , this, SLOT(cd_up())); connect(left_, SIGNAL(clicked() ) , this, SLOT(screen_off())); connect(right_, SIGNAL(clicked() ) , this, SLOT(screen_on())); QHBox *line_box = new QHBox( this ); layout->addWidget(line_box); layout->addWidget(h_box_); select_dir_ = new QComboBox(line_box); select_dir_->insertItem("/"); select_dir_->insertItem("/home/"); select_dir_->insertItem("/etc/"); select_dir_->insertItem("/mnt"); select_dir_->insertItem("/root"); select_dir_->insertItem("/home/descent/12/"); select_dir_->insertItem("/home/descent/aaa/"); connect(select_dir_, SIGNAL(activated ( const QString &) ), this, SLOT(change_dirtreeview_item(const QString & )) ); connect(dir_content_, SIGNAL( opendir ( const std::string &) ), this, SLOT(change_dirtreeview_item(const std::string & )) ); status_bar_ = statusBar (); if (status_bar_!=0) { qDebug("have status bar"); layout->addWidget(status_bar_); } else qDebug("don't have status bar"); //status_bar = new QStatusBar(this); //#endif }
/* * game_loop * DESCRIPTION: Main event loop for the adventure game. * INPUTS: none * OUTPUTS: none * RETURN VALUE: GAME_QUIT if the player quits, or GAME_WON if they have won * SIDE EFFECTS: drives the display, etc. */ static game_condition_t game_loop () { /* * Variables used to carry information between event loop ticks; see * initialization below for explanations of purpose. */ struct timeval start_time, tick_time; struct timeval cur_time; /* current time (during tick) */ cmd_t cmd; /* command issued by input control */ int time_cur; /* Record the starting time--assume success. */ (void)gettimeofday (&start_time, NULL); /* Calculate the time at which the first event loop tick should occur. */ tick_time = start_time; if ((tick_time.tv_usec += TICK_USEC) > 1000000) { tick_time.tv_sec++; tick_time.tv_usec -= 1000000; } /* The player has just entered the first room. */ enter_room = 1; /* The main event loop. */ while (1) { /* * Update the screen, preparing the VGA palette and photo-drawing * routines and drawing a new room photo first if the player has * entered a new room, then showing the screen (and status bar, * once you have it working). */ if (enter_room) { /* Reset the view window to (0,0). */ game_info.map_x = game_info.map_y = 0; set_view_window (game_info.map_x, game_info.map_y); /* Discard any partially-typed command. */ reset_typed_command (); /* Adjust colors and photo drawing for the current room photo. */ prep_room (game_info.where); /* Draw the room (calls show. */ redraw_room (); /* Only draw once on entry. */ enter_room = 0; /*reset the background*/ show_status_bar (" ", 3); } /*begin of the critical section*/ (void)pthread_mutex_lock (&msg_lock); /*check if the input has changed*/ if(strcmp(last_type, get_typed_command())) { show_status_bar (" ", 3); strcpy(last_type, get_typed_command()); } /*check if we need to print the status message*/ if(status_msg[0] != '\0') { show_status_bar (status_msg, 0); status_just_gone = 1; } else { /*check if the status message has just disappeared, i.e. need to reset the background*/ if(status_just_gone) { show_status_bar (" ", 3); status_just_gone = 0; } /*show the room name*/ show_status_bar (room_name (game_info.where), 1); /*get the latest command*/ const char * cmd = get_typed_command (); while (' ' == *cmd) { cmd++; } if ('\0' != *cmd) show_status_bar (get_typed_command (), 2); else show_status_bar ("_", 2); } (void)pthread_mutex_unlock (&msg_lock); /*end of the critical section*/ show_screen (); /* * Wait for tick. The tick defines the basic timing of our * event loop, and is the minimum amount of time between events. */ do { if (gettimeofday (&cur_time, NULL) != 0) { /* Panic! (should never happen) */ clear_mode_X (); shutdown_input (); perror ("gettimeofday"); exit (3); } } while (!time_is_after (&cur_time, &tick_time)); /* * Advance the tick time. If we missed one or more ticks completely, * i.e., if the current time is already after the time for the next * tick, just skip the extra ticks and advance the clock to the one * that we haven't missed. */ do { if ((tick_time.tv_usec += TICK_USEC) > 1000000) { tick_time.tv_sec++; tick_time.tv_usec -= 1000000; } } while (time_is_after (&cur_time, &tick_time)); /* * Handle asynchronous events. These events use real time rather * than tick counts for timing, although the real time is rounded * off to the nearest tick by definition. */ /* (none right now...) */ time_cur = tick_time.tv_sec - start_time.tv_sec; if(time_cur != prev_time) { //display_time_on_tux(time_cur); display_time_on_tux(time_cur); prev_time = time_cur; } /* * Handle synchronous events--in this case, only player commands. * Note that typed commands that move objects may cause the room * to be redrawn. */ (void)pthread_mutex_lock (&cmd_lock); cmd = get_command (); switch (cmd) { case CMD_UP: move_photo_down (); break; case CMD_RIGHT: move_photo_left (); break; case CMD_DOWN: move_photo_up (); break; case CMD_LEFT: move_photo_right (); break; case CMD_MOVE_LEFT: enter_room = (TC_CHANGE_ROOM == try_to_move_left (&game_info.where)); break; case CMD_ENTER: enter_room = (TC_CHANGE_ROOM == try_to_enter (&game_info.where)); break; case CMD_MOVE_RIGHT: enter_room = (TC_CHANGE_ROOM == try_to_move_right (&game_info.where)); break; case CMD_QUIT: return GAME_QUIT; default: break; } (void)pthread_mutex_unlock (&cmd_lock); //case CMD_TYPED: if (cmd == CMD_TYPED) { if(handle_typing ()) { enter_room = 1; } } /* If player wins the game, their room becomes NULL. */ if (NULL == game_info.where) { return GAME_WON; } /*If the palyer quits the game.*/ if(game == GAME_QUIT) { return GAME_QUIT; } } /* end of the main event loop */ }
void toggle_status_bar(){ if(bshow_status_bar == 1) hide_status_bar(); else show_status_bar(); }