コード例 #1
0
ファイル: main.cpp プロジェクト: moslemezzati/IPC
int main(int argc, char *argv[])
{
    cppdb::session sql("sqlite3:db=db.db");
    sql << "DROP TABLE IF EXISTS test" << cppdb::exec;

    sql<<   "CREATE TABLE test ( "
            "   id   INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "
            "   name    TEXT"
            ")  " << cppdb::exec;
    qDebug() << "DB created!";

    QApplication a(argc, argv);
    PosServer server;

    if(!server.listen(QHostAddress::LocalHost, 6142)){
        std::cerr << "Failed to bind to port" << std::endl;
        return 1;
    }

    QPushButton quitButton("&Quit");
    quitButton.setWindowTitle("Pos server");
    QObject::connect(&quitButton, SIGNAL(clicked()), &a, SLOT(quit()));
    quitButton.show();

    return a.exec();

}
コード例 #2
0
ファイル: moc_SFLPhone.cpp プロジェクト: max3903/SFLphone
int SFLPhone::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = KXmlGuiWindow::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: on_view_statusMessageChangeAsked((*reinterpret_cast< const QString(*)>(_a[1]))); break;
        case 1: on_view_windowTitleChangeAsked((*reinterpret_cast< const QString(*)>(_a[1]))); break;
        case 2: on_view_enabledActionsChangeAsked((*reinterpret_cast< const bool*(*)>(_a[1]))); break;
        case 3: on_view_actionIconsChangeAsked((*reinterpret_cast< const QString*(*)>(_a[1]))); break;
        case 4: on_view_actionTextsChangeAsked((*reinterpret_cast< const QString*(*)>(_a[1]))); break;
        case 5: on_view_transferCheckStateChangeAsked((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 6: on_view_recordCheckStateChangeAsked((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 7: on_view_addressBookEnableAsked((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 8: on_view_screenChanged((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 9: on_view_incomingCall((*reinterpret_cast< const Call*(*)>(_a[1]))); break;
        case 10: updateScreen((*reinterpret_cast< QAction*(*)>(_a[1]))); break;
        case 11: quitButton(); break;
        default: ;
        }
        _id -= 12;
    }
    return _id;
}
コード例 #3
0
ファイル: main.cpp プロジェクト: ifhw/study
int main(int argc, char* argv[ ])
{
    QApplication app(argc, argv);

    QPushButton button("State Machine");
    QPushButton quitButton("Quit");
    QPushButton interruptButton("interrupt");

    QStateMachine machine;
    QState *s1 = new QState(&machine);
    QState *s11 = new QState(s1);
    QState *s12 = new QState(s1);
    QState *s13 = new QState(s1);
    s1->setInitialState(s11);

    s11->assignProperty(&button, "geometry", QRect(100, 100, 100, 50));
    s12->assignProperty(&button, "geometry", QRect(300, 100, 100, 50));
    s13->assignProperty(&button, "geometry", QRect(200, 200, 100, 50));

    QSignalTransition *transition1 = s11->addTransition(&button,
                                                       SIGNAL(clicked()), s12);
    QSignalTransition *transition2 = s12->addTransition(&button,
                                                       SIGNAL(clicked()), s13);
    QSignalTransition *transition3 = s13->addTransition(&button,
                                                       SIGNAL(clicked()), s11);

    QPropertyAnimation *animation = new QPropertyAnimation(&button, "geometry");
    transition1->addAnimation(animation);
    transition2->addAnimation(animation);
    transition3->addAnimation(animation);

    QObject::connect(s13, SIGNAL(entered()), &button, SLOT(showMinimized()));

    QFinalState *s2 = new QFinalState(&machine);
    s1->addTransition(&quitButton, SIGNAL(clicked()), s2);
    QObject::connect(&machine, SIGNAL(finished()), qApp, SLOT(quit()));

    QHistoryState *s1h = new QHistoryState(s1);

    QState *s3 = new QState(&machine);
    QMessageBox mbox;
    mbox.addButton(QMessageBox::Ok);
    mbox.setText("Interrupted!");
    mbox.setIcon(QMessageBox::Information);
    QObject::connect(s3, SIGNAL(entered()), &mbox, SLOT(exec()));
    s3->addTransition(s1h);

    s1->addTransition(&interruptButton, SIGNAL(clicked()), s3);

    machine.setInitialState(s1);
    machine.start();

    button.show();
    quitButton.move(300, 300);
    quitButton.show();
    interruptButton.show();

    return app.exec();
}
コード例 #4
0
ファイル: main.cpp プロジェクト: marsimunovic/QTGui
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    TripServer server;
    if (!server.listen(QHostAddress::Any, 6178)) {
        std::cerr << "Failed to bind to port" << std::endl;
        return 1;
    }
    QPushButton quitButton(QObject::tr("&Quit"));
    quitButton.setWindowTitle(QObject::tr("Trip Server"));
    QObject::connect(&quitButton, SIGNAL(clicked()),
    &app, SLOT(quit()));
    quitButton.show();
    return app.exec();
}
コード例 #5
0
ファイル: GameMenu.cpp プロジェクト: xephoran/GameProjects
int GameMenu::RunMenu(sf::RenderWindow& window)
{
	std::cout << "\nhas entered game menu class";
	//sets up rectangles for buttons
	// resume button has following Left:86, Top:58, Width:329, Height, 110
	sf::IntRect resumeButton(441, 275, 194, 56);
	// options button has following Left:86, Top:231, Width:392, Height:110
	sf::IntRect optionsButton(442, 352, 194, 56);
	// quit button has following Top:420m Left: 86, width 329, height 110
	sf::IntRect quitButton(442, 426, 194, 56);
	
	//creates the menu here
	sf::Texture menutexture;
	if (!menutexture.loadFromFile("images/gamemenu.png"))
	{
		std::cout << "\n\n\n\n\n\n-------ERROR COUDLNT LOAD MENU TEXTURE-----------\n\n\n\n\n\n\n\n";
		//error
	}

	if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
	{
		if (quitButton.contains(sf::Mouse::getPosition(window)) == true)
		{
			return 1;
		}
		if (optionsButton.contains(sf::Mouse::getPosition(window)) == true)
		{
			return 2;
		}
		if (resumeButton.contains(sf::Mouse::getPosition(window)) == true)
		{
			return 3;
		}
	}

	sf::Sprite menu;
	menu.setTexture(menutexture);
	window.draw(menu);
	window.display();
	std::cout << "should have drawn the menu";
	return 0;
}
コード例 #6
0
ファイル: main.cpp プロジェクト: rymarchik/QtLearning
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QLabel lbl("0");

    Counter counter;

    QSignalMapper* mapper = new QSignalMapper();
    QObject::connect(mapper, SIGNAL(mapped(const QString&)), &counter, SLOT(slotInc(const QString&)));

    QPushButton* but1 = new QPushButton("Button1");
    QObject::connect(but1, SIGNAL(clicked()), mapper, SLOT(map()));
    mapper->setMapping(but1, "Button1 Action");

    QPushButton* but2 = new QPushButton("Button2");
    QObject::connect(but2, SIGNAL(clicked()), mapper, SLOT(map()));
    mapper->setMapping(but2, "Button2 Action");

    QPushButton quitButton("Quit");

    QVBoxLayout layout;
    layout.addWidget(&lbl);
    layout.addWidget(but1);
    layout.addWidget(but2);
    layout.addWidget(&quitButton);

    QWidget window;
    window.setLayout(&layout);
    window.show();

    QObject::connect(&counter, SIGNAL(counterChanged(int)), &lbl, SLOT(setNum(int)));
    QObject::connect(&counter, SIGNAL(goodbye()), &app, SLOT(quit()));
    QObject::connect(&quitButton, SIGNAL(clicked(bool)), &app, SLOT(quit()));

    return app.exec();
}
コード例 #7
0
ScreenOption::ScreenOption(unsigned int _button)
:m_character_array(0),
 m_gravityType(NoSliding),
 m_nbButton(_button),
 m_quit(false)
{

   m_window = sfg::Window::Create();
   m_window->SetTitle( "Option" );

   m_box = sfg::Box::Create(sfg::Box::Orientation::VERTICAL, 10.0f);
   m_boxClose = sfg::Box::Create(sfg::Box::Orientation::VERTICAL);
   m_layoutPhysics = sfg::Box::Create( sfg::Box::Orientation::HORIZONTAL);
   m_layoutCharacter = sfg::Box::Create( sfg::Box::Orientation::HORIZONTAL);

   m_framePhysics = sfg::Frame::Create("Gravity Type");
   m_frameCharacter = sfg::Frame::Create("Select a character");

   m_background.setTexture(*TextureManager::getTextureManager()->getResource(std::string(FilenameBackGroundMenu)));
   m_background.setColor(sf::Color(backgroundColor,backgroundColor,backgroundColor));

    for ( unsigned int i = 0 ; i < m_nbButton ; i++)
    {
        std::ostringstream oss;

        oss << i + 1;
        ChoiceCharacter temp = ChoiceCharacter(i+1);
        m_character_array.push_back(temp);
        sfg::Button::Ptr button (sfg::Button::Create("Character_" + oss.str()));

        button->GetSignal( sfg::Widget::OnLeftClick ).Connect( std::bind(&ChoiceCharacter::defineCharacter , &(m_character_array.at(i))));
        m_layoutCharacter->Pack(button);

    }

    sfg::RadioButton::Ptr radio1(sfg::RadioButton::Create("Sliging"));
    sfg::RadioButton::Ptr radio2(sfg::RadioButton::Create("No Sliding", radio1->GetGroup()));
    radio1->GetSignal(sfg::Widget::OnLeftClick).Connect(std::bind(&ScreenOption::activateSliding, this));
    radio2->GetSignal(sfg::Widget::OnLeftClick).Connect(std::bind(&ScreenOption::desactivateSliding, this));

    sfg::Button::Ptr saveButton(sfg::Button::Create("Save"));
    saveButton->GetSignal(sfg::Widget::OnLeftClick).Connect(std::bind(&ScreenOption::save, this));

    sfg::Button::Ptr quitButton(sfg::Button::Create("Go back main menu"));
    quitButton->GetSignal(sfg::Widget::OnLeftClick).Connect(std::bind(&ScreenOption::quit, this));
    quitButton->SetId("quitButton");

    m_layoutPhysics->Pack(radio1);
    m_layoutPhysics->Pack(radio2);

    m_frameCharacter->Add(m_layoutCharacter);
    m_framePhysics->Add(m_layoutPhysics);

    m_box->Pack(m_frameCharacter);
    m_box->Pack(m_framePhysics);
    m_box->Pack(saveButton);
    m_box->Pack(quitButton);

	m_window->Add(m_box);

    //m_desktop.LoadThemeFromFile(FilenameTheme);
    m_desktop.Add(m_window);


}
コード例 #8
0
void Window::handleButton()
{
    m_button->setText("Quit");
    m_button->resize(150,150);
    connect(m_button, SIGNAL (released()), this, SLOT (quitButton()));
}
コード例 #9
0
ファイル: main.cpp プロジェクト: Splime/ChapShmup
int main() {
    //RNG
    srand((unsigned int)time(NULL));

	//Load up our textures
	loadGlobalTextures();
	//Load Our Font
	loadGlobalFonts();

	//Load up the Game
	mainWindow.create(sf::VideoMode(WINDOW_WIDTH,WINDOW_HEIGHT), windowName);
	Game theGame;

	//Frame Clock
	sf::Clock frameClock;
	frameClock.restart();

	//Menu Stuff - TODO, make separate class?
	sf::Texture splashTex;
	if (EXTERNAL_FILE_MODE)
		splashTex.loadFromFile(PROJECT_DIRECTORY + SPLASH_IMAGE);
	else
		splashTex.loadFromFile(SPLASH_IMAGE);
	sf::Sprite splashBox(splashTex);
	//New Game
	TextButton newGameButton("New Game", 64, sf::Color::Green);
    newGameButton.setSelectedColor(sf::Color::Red);
    newGameButton.text.setPosition(WINDOW_WIDTH/2 - newGameButton.text.getGlobalBounds().width/2, 160);
	//Load Game
	TextButton loadGameButton("Load Game", 64, sf::Color::Green);
    loadGameButton.setSelectedColor(sf::Color::Red);
    loadGameButton.text.setPosition(WINDOW_WIDTH/2 - loadGameButton.text.getGlobalBounds().width/2, 260);
	//Instant Play
    TextButton playButton("Instant Play", 64, sf::Color::Green);
    playButton.setSelectedColor(sf::Color::Red);
    playButton.text.setPosition(WINDOW_WIDTH/2 - playButton.text.getGlobalBounds().width/2, 360);
	//Settings Button
	TextButton settingsButton("Settings", 64, sf::Color::Green);
	settingsButton.setSelectedColor(sf::Color::Red);
    settingsButton.text.setPosition(WINDOW_WIDTH/2 - settingsButton.text.getGlobalBounds().width/2, 460);
	//Quit Button
	TextButton quitButton("Quit Game", 64, sf::Color::Green);
	quitButton.setSelectedColor(sf::Color::Red);
    quitButton.text.setPosition(WINDOW_WIDTH/2 - quitButton.text.getGlobalBounds().width/2, 560);
	//Logo
	sf::Text logo = createText("Chap Shmup", 96, sf::Color::Green, FONT_2);
	logo.setPosition(WINDOW_WIDTH/2 - logo.getGlobalBounds().width/2, 16);

	//Settings Screen
	//Title
	sf::Text settingsTitle = createText("Settings", 96, sf::Color::Green, FONT_2);
	settingsTitle.setPosition(WINDOW_WIDTH/2 - settingsTitle.getGlobalBounds().width/2, 16);
	//TODO
	//Actual Settings
	//Back
	TextButton backButton("Back", 64, sf::Color::Green);
	backButton.setSelectedColor(sf::Color::Red);
    backButton.text.setPosition(WINDOW_WIDTH/2 - backButton.text.getGlobalBounds().width/2, 560);

    //New Game Screen
    //Title
    sf::Text newGameTitle = createText("New Game", 96, sf::Color::Green, FONT_2);
	newGameTitle.setPosition(WINDOW_WIDTH/2 - newGameTitle.getGlobalBounds().width/2, 16);
	//Story Blurb
	sf::Text storyText = createText("2:00am, 21 Dec 2712", 32, sf::Color::Green);
	storyText.setPosition(WINDOW_WIDTH/4 - storyText.getGlobalBounds().width/2, 160);

	//Character Input
	sf::Text charInputText = createText("Character Info:", 32, sf::Color::Green);
	charInputText.setPosition(3*WINDOW_WIDTH/4 - charInputText.getGlobalBounds().width/2, 160);
	sf::Text nameInputText = createText("Your Name:", 32, sf::Color::Green);
	nameInputText.setPosition(3*WINDOW_WIDTH/4 - nameInputText.getGlobalBounds().width, 260);

	//Next Button
	TextButton nextButton("Next", 64, sf::Color::Green);
	nextButton.setSelectedColor(sf::Color::Red);
    nextButton.text.setPosition(WINDOW_WIDTH/2 - nextButton.text.getGlobalBounds().width/2, 560);

	//Run the window
	while (mainWindow.isOpen()) {
		//Get elapsed time
		sf::Time elapsedTime = frameClock.restart();
		sf::Event e;
		while(mainWindow.pollEvent(e))
		{
			if (e.type == sf::Event::Closed)
            {
				mainWindow.close();
			}
			if (e.type == sf::Event::KeyPressed && e.key.code == sf::Keyboard::Escape) {
                if (GAME_MODE == "Main Menu")
                {
                    mainWindow.close();
                }
                else
                {
                    GAME_MODE = "Main Menu";
                }
			}
			if (e.type == sf::Event::MouseButtonPressed)
			{
				if (GAME_MODE == "Main Menu")
				{
					//Buttons!
					if (mouseWithin(newGameButton.text))
					{
						GAME_MODE = "New Game";
					}
					else if (mouseWithin(loadGameButton.text))
					{
						GAME_MODE = "Load Game";
					}
					else if (mouseWithin(playButton.text))
					{
						GAME_MODE = "Play Level";
						theGame.start();
					}
					else if (mouseWithin(settingsButton.text))
					{
						GAME_MODE = "Settings";
					}
					else if (mouseWithin(quitButton.text))
					{
						mainWindow.close();
					}
				}
				else if (GAME_MODE == "Settings")
                {
                    if (mouseWithin(backButton.text))
					{
						GAME_MODE = "Main Menu";
					}
                }
                else if (GAME_MODE == "New Game")
                {
                    if (mouseWithin((nextButton.text)))
                    {
                        GAME_MODE = "Play Level";
						theGame.start();
                    }
                }
			}
		}
		//GAME_MODE: Main Menu
		if (GAME_MODE == "Main Menu")
        {
		    //Updating
		    playButton.update(elapsedTime.asSeconds());
		    settingsButton.update(elapsedTime.asSeconds());
		    quitButton.update(elapsedTime.asSeconds());
		    newGameButton.update(elapsedTime.asSeconds());
		    loadGameButton.update(elapsedTime.asSeconds());

		    //Drawing
			mainWindow.clear();
			playButton.draw(mainWindow);
			settingsButton.draw(mainWindow);
			quitButton.draw(mainWindow);
			loadGameButton.draw(mainWindow);
			newGameButton.draw(mainWindow);
			mainWindow.draw(logo);
			mainWindow.display();
		}
		//GAME_MODE: Play Game
		else if (GAME_MODE == "Play Level")
        {
			//Updating
			theGame.update(elapsedTime.asSeconds());

			//Drawing
			mainWindow.clear();
			theGame.draw(mainWindow);
			mainWindow.display();

			//Game ended?
			if (theGame.isLevelOver())
                GAME_MODE = "Main Menu";
		}
		//GAME_MODE: Settings
		else if (GAME_MODE == "Settings")
        {
            //Updating
            backButton.update(elapsedTime.asSeconds());

            //Drawing
			mainWindow.clear();
			mainWindow.draw(settingsTitle);
			backButton.draw(mainWindow);
			mainWindow.display();
		}
		else if (GAME_MODE == "New Game")
        {
            //Update
            nextButton.update(elapsedTime.asSeconds());

            //Draw
            mainWindow.clear();
            mainWindow.draw(newGameTitle);
            mainWindow.draw(storyText);
            mainWindow.draw(charInputText);
            mainWindow.draw(nameInputText);
            nextButton.draw(mainWindow);
            mainWindow.display();
        }
        else if (GAME_MODE == "Load Game")
        {
            //Update


            //Draw
            mainWindow.clear();
            mainWindow.draw(splashBox);
            mainWindow.display();
        }

		//Try to keep approx 60 fps
		sf::Time timeToPause = sf::milliseconds(16) - frameClock.getElapsedTime();
		sf::sleep(timeToPause);
	}

	//Terminate
	//system("pause");
	return EXIT_SUCCESS;
}
コード例 #10
0
ファイル: Main.cpp プロジェクト: MORTAL2000/SnakeFML
int main()
{
	//state
	enum gameState
	{
		MENU,
		INGAME,
		EXITING
	} currentState(MENU); //launch into menu

	//window and framerate control
	sf::RenderWindow window(sf::VideoMode(800, 800), "SnakeFML");
	window.setFramerateLimit(60);
	sf::Image icon;
	icon.loadFromFile("Icon.png");
	window.setIcon(icon.getSize().x, icon.getSize().y, icon.getPixelsPtr());
	sf::Clock	dtClock;

	//Objects
	Score			score("KBZipaDeeDooDah.ttf");
	World			world("Grass.png", { 1000,1000 });
	Snake			snake(window,world,score,"SnakeHead.png");
	MouseSpawner	spawner(&window,"Mouse.png", snake);
	Button			playButton([&]() {currentState = INGAME; }, "PlayButton.png");
	Button			quitButton([&]() {currentState = EXITING; }, "QuitButton.png");
	Menu			menu(window,{ playButton, quitButton });



	while (window.isOpen())
	{
		if (currentState == EXITING)
		{
			window.close();
			continue;
		}
		auto dt(dtClock.restart().asSeconds());
		sf::Event event;
		while (window.pollEvent(event))
		{
			if (event.type == sf::Event::Closed)
			{
				currentState = EXITING;
			}

			switch (currentState)
			{
			case MENU:
				menu.handleEvent(event);
				break;
			case INGAME:
				if (event.type == sf::Event::KeyPressed)
				{
					switch (event.key.code)
					{
						//escape to pause
					case sf::Keyboard::Escape:
						currentState = MENU;
						break;
					default:
						break;
					}
				}
				break;
			default:
				break;
			}
		}

		window.clear(sf::Color(50,150, 255));	//because Sea!

		if (currentState == INGAME)
		{
			//update objects if in game (i.e. not paused)
			snake.update(dt);
			spawner.checkCollisions();
			spawner.spawn();
		}

		//draw the essentials (with the correct view)
		window.setView(snake.getView());
		window.draw(world);
		spawner.draw();
		window.draw(snake);

		//default view for score (and menu, if needed)
		window.setView(window.getDefaultView());
		window.draw(score);

		if (currentState == MENU)
			window.draw(menu);

		window.display();
		sf::sleep(sf::seconds(0));
	}
	window.close();

	return 0;
};