示例#1
0
void WidgetQuit::handleEvents() {
	Events &events = *_vm->_events;
	Talk &talk = *_vm->_talk;
	Common::Point mousePos = events.mousePos();
	Common::Rect yesRect(_bounds.left, _bounds.top + (_surface.fontHeight() + 4) * 2 + 3, _bounds.right,
		_bounds.top + (_surface.fontHeight() + 4) * 2 + 3 + _surface.fontHeight() + 7);
	Common::Rect noRect(_bounds.left, _bounds.top + (_surface.fontHeight() + 4) * 2 + _surface.fontHeight() + 10,
		_bounds.right, _bounds.top + (_surface.fontHeight() + 4) * 2 + 10 + _surface.fontHeight() * 2 + 7);

	if (talk._talkToAbort)
		return;

	// Determine the highlighted item
	_select = -1;
	if (yesRect.contains(mousePos))
		_select = 1;
	else if (noRect.contains(mousePos))
		_select = 0;

	if (events.kbHit()) {
		Common::KeyState keyState = events.getKey();

		switch (keyState.keycode) {
		case Common::KEYCODE_TAB:
			// If the mouse is not over any of the options, move the mouse so that it points to the first option
			if (_select == -1)
				events.warpMouse(Common::Point(_bounds.right - 10, _bounds.top + (_surface.fontHeight() + 4) * 2
					+ 3 + _surface.fontHeight() + 1));
			else if (_select == 1)
				events.warpMouse(Common::Point(mousePos.x, _bounds.top + (_surface.fontHeight() + 4) * 2
					+ 3 + _surface.fontHeight() * 2 + 11));
			else
				events.warpMouse(Common::Point(mousePos.x, _bounds.top + (_surface.fontHeight() + 4) * 2
					+ 3 + _surface.fontHeight() + 1));
			break;

		case Common::KEYCODE_ESCAPE:
		case Common::KEYCODE_n:
			close();
			return;

		case Common::KEYCODE_y:
			close();
			_vm->quitGame();
			break;

		default:
			break;
		}
	}

	// Check for change of the highlighted item
	if (_select != _oldSelect) {
		byte color = (_select == 1) ? COMMAND_HIGHLIGHTED : INFO_TOP;
		int yp = (_surface.fontHeight() + 4) * 2 + 8;
		_surface.writeString(FIXED(Yes), Common::Point((_surface.width() - _surface.stringWidth(FIXED(Yes))) / 2, yp), color);

		color = (_select == 0) ? COMMAND_HIGHLIGHTED : INFO_TOP;
		yp += (_surface.fontHeight() + 7);
		_surface.writeString(FIXED(No), Common::Point((_surface.width() - _surface.stringWidth(FIXED(No))) / 2, yp), color);
	}
	_oldSelect = _select;

	// Flag is they started pressing outside of the menu
	if (events._firstPress && !_bounds.contains(mousePos))
		_outsideMenu = true;

	if (events._released || events._rightReleased) {
		events.clearEvents();
		close();
		if (_select == 1)
			// Yes selected
			_vm->quitGame();
	}
}
示例#2
0
文件: scandialog.cpp 项目: KDE/kooka
bool ScanDialog::setup()
{
   if( ! m_device )
   {
      good_scan_connect = false;
      return(false);
   }
   // The scan device is now closed on closing the scan dialog. That means
   // that more work to open it needs to be done in the setup slot like opening
   // the selector if necessary etc.

   if( m_scanParams )
   {
      /* if m_scanParams exist it means, that the dialog is already open */
      return true;
   }

   m_scanParams = new ScanParams( splitter );
   connect( m_previewer->getImageCanvas(), SIGNAL( newRect(QRect)),
	    m_scanParams, SLOT(slCustomScanSize(QRect)));
   connect( m_previewer->getImageCanvas(), SIGNAL( noRect()),
	    m_scanParams, SLOT(slMaximalScanSize()));

   connect( m_scanParams, SIGNAL( scanResolutionChanged( int, int )),
	    m_previewer, SLOT( slNewScanResolutions( int, int )));


   /* continue to attach a real scanner */
   /* first, get the list of available devices from libkscan */
   QStringList scannerNames;
   QStrList backends = m_device->getDevices();;
   QStrListIterator it( backends );

   while ( it.current() ) {
      scannerNames.append( m_device->getScannerName( it.current() ));
      ++it;
   }

   /* ..if there are devices.. */
   QCString configDevice;
   good_scan_connect = true;
   if( scannerNames.count() > 0 )
   {
      /* allow the user to select one */
      DeviceSelector ds( this, backends, scannerNames );
      configDevice = ds.getDeviceFromConfig( );

      if( configDevice.isEmpty() || configDevice.isNull() )
      {
	 kdDebug(29000) << "configDevice is not valid - starting selector!" << configDevice << endl;
	 if ( ds.exec() == QDialog::Accepted )
	 {
	    configDevice = ds.getSelectedDevice();
	 }
      }

      /* If a device was selected, */
      if( ! configDevice.isNull() )
      {
	 /* ..open it (init sane with that) */
	 m_device->openDevice( configDevice );

	 /* ..and connect to the gui (create the gui) */
	 if ( !m_scanParams->connectDevice( m_device ) )
	 {
	    kdDebug(29000) << "ERR: Could not connect scan device" << endl;
	    good_scan_connect = false;
	 }
      }
   }

   if( configDevice.isNull() || configDevice.isEmpty() )
   {
      /* No scanner found, open with information */
      m_scanParams->connectDevice( 0L );
      good_scan_connect = false;
      /* Making the previewer gray */
      /* disabling is much better than hiding for 'advertising' ;) */
   }

   /* Move the scan params to the left, for backward compatibility.
    * However, having it on the right looks a bit better IMHO */
   if( splitter && m_scanParams )
      splitter->moveToFirst( m_scanParams );

   if( good_scan_connect )
   {
      m_previewer->setEnabled( true );
      m_previewer->setPreviewImage( m_device->loadPreviewImage() );
      m_previewer->connectScanner( m_device );
   }

    /* set initial sizes */
    setInitialSize( configDialogSize( GROUP_STARTUP ));

    KConfig *kfg = KGlobal::config();
    if( kfg )
    {
       QRect r = KGlobalSettings::desktopGeometry(this);

       kfg->setGroup( GROUP_STARTUP );
       /* Since this is a vertical splitter, only the width is important */
       QString key = QString::fromLatin1( SCANDIA_SPLITTER_SIZES ).arg( r.width());
       kdDebug(29000) << "Read Splitter-Sizes " << key  << endl;
       splitter->setSizes( kfg->readIntListEntry( key ));
    }

   return true;
}