Ejemplo n.º 1
0
Game::Game() :  KTopLevelWidget()
{
    setCaption( kapp->getCaption() );

    setIcon(klocale->translate("Snake Race"));

    conf = kapp->getConfig();
    if(conf == NULL) {
	printf(klocale->translate("KConfig error ??\n"));
	kapp->quit();
    }

    levels = new Levels();
    score  = new Score;
    menu();
    checkMenuItems();

    View *view = new View(this);
    rattler = view->rattler;
    rattler->setFocus();

    connect(rattler, SIGNAL(setPoints(int)), view->lcd, SLOT(display(int)));
    connect(rattler, SIGNAL(setTrys(int)), view->trys, SLOT(set(int)));
    connect(rattler, SIGNAL(rewind()), view->pg, SLOT(rewind()));
    connect(rattler, SIGNAL(advance()), view->pg, SLOT(advance()));
    connect(view->pg, SIGNAL(restart()), rattler, SLOT(restartTimer()));

    connect(rattler, SIGNAL(togglePaused()), this, SLOT(togglePaused()));
    connect(rattler, SIGNAL(setScore(int)), score, SLOT(setScore(int)));

    menubar->show();
    setMenu(menubar);
    view->show();
    setView(view);
}
Ejemplo n.º 2
0
Kpacman::Kpacman(QWidget *parent, const char *name, WFlags fl)
        : KTMainWindow(parent, name,fl)
{
    schemesPopup = new QList<QPopupMenu>;
    schemesPopup->setAutoDelete(TRUE);

    menu();

	m_view = new QWidget( this, "m_view" );
    m_view->setBackgroundColor( black );
	m_layout = new QGridLayout( m_view );
	m_layout->setMargin( 7 );

	view = new KpacmanWidget( this, QString(name)+"widget");
	m_layout->addWidget( view, 0, 0 );

    setCaption( tr("KPacman") );

    view->referee->setFocus();

    connect(view->referee, SIGNAL(setScore(int,int)),
            view->score, SLOT(setScore(int,int)));
    connect(view->referee, SIGNAL(setPoints(int)),
            view->score, SLOT(set(int)));
    connect(view->referee, SIGNAL(setLifes(int)),
            view->status, SLOT(setLifes(int)));
    connect(view->referee, SIGNAL(setLevel(int)),
            view->status, SLOT(setLevel(int)));
    connect(view->referee, SIGNAL(forcedHallOfFame(bool)),
            this, SLOT(forcedHallOfFame(bool)));
    connect(view->referee, SIGNAL(togglePaused()), this, SLOT(togglePaused()));
    connect(view->referee, SIGNAL(toggleNew()), this, SLOT(toggleNew()));

    connect(view->score, SIGNAL(toggleNew()), this, SLOT(toggleNew()));
    connect(view->score, SIGNAL(forcedHallOfFame(bool)),
            this, SLOT(forcedHallOfFame(bool)));

    APP_CONFIG_BEGIN( cfg );
    focusOutPause = !cfg->readBoolEntry("FocusOutPause", TRUE);
    focusInContinue = !cfg->readBoolEntry("FocusInContinue", TRUE);
    hideMouseCursor = !cfg->readBoolEntry("HideMouseCursor", TRUE);
    APP_CONFIG_END( cfg );

    toggleFocusOutPause();
    toggleFocusInContinue();
    toggleHideMouseCursor();

    setCentralWidget( m_view );
}
Ejemplo n.º 3
0
Images::Images(QWidget *parent) 
: QWidget(parent)
{
    setWindowTitle(tr("Image loading and scaling example"));
    resize(800, 600);

    imageScaling = new QFutureWatcher<QImage>(this);
    connect(imageScaling, SIGNAL(resultReadyAt(int)), SLOT(showImage(int)));
    connect(imageScaling, SIGNAL(finished()), SLOT(finished()));

    openButton = new QPushButton(tr("Open Images"));
    connect(openButton, SIGNAL(clicked()), SLOT(open()));

    cancelButton = new QPushButton(tr("Cancel"));
    cancelButton->setEnabled(false);
    connect(cancelButton, SIGNAL(clicked()), imageScaling, SLOT(cancel()));
   
    pauseButton = new QPushButton(tr("Pause/Resume"));
    pauseButton->setEnabled(false);
    connect(pauseButton, SIGNAL(clicked()), imageScaling, SLOT(togglePaused()));
   
    QHBoxLayout *buttonLayout = new QHBoxLayout();
    buttonLayout->addWidget(openButton);
    buttonLayout->addWidget(cancelButton);
    buttonLayout->addWidget(pauseButton);
    buttonLayout->addStretch();

    imagesLayout = new QGridLayout();

    mainLayout = new QVBoxLayout();
    mainLayout->addLayout(buttonLayout);
    mainLayout->addLayout(imagesLayout);
    mainLayout->addStretch();
    setLayout(mainLayout);
}
void ofxCvInputManager::keyPressed(ofKeyEventArgs & e){
		switch (e.key) {
			case OF_KEY_LEFT:
				ePrevFrame = true;
				bPlay = true;
				break;
			case OF_KEY_RIGHT:
				eNextFrame = true;
				bPlay = true;
				break;
			case OF_KEY_UP:
				setPaused(true);
				inputIdx = (inputIdx + 1) % inputs.size();
				setPaused(false);
				break;
			case 'p':
				togglePaused();
				break;
			case 'o':
				bChangeSettings = !bChangeSettings;
				break;
			case 'r':
				if(inputs[inputIdx]->type == TYPE_VideoPlayer){
					((ofxCvVideoInput*)inputs[inputIdx])->firstFrame();
				}
				setPaused(false);
				break;
			case 'i':
				bStopable = !bStopable;
				break;
			default:
				break;
		}

		//TODO draw/explain interface
}
TimelineWidget::TimelineWidget(QWidget* parent) :
    QWidget(parent),
    m_timelineView(NULL),
    m_timeRate(1.0),
    m_paused(true)
{
    m_timelineView = new TimelineView(this);
    connect(m_timelineView, SIGNAL(currentTimeChanged(double)), this, SIGNAL(currentTimeChanged(double)));
    
    QWidget* controls = new QWidget(this);
    controls->setContentsMargins(0, 0, 0, 0);
    QHBoxLayout* controlsLayout = new QHBoxLayout(controls);
    
    QLabel* zoomLabel = new QLabel(controls);
    zoomLabel->setText("Zoom: "
                       "<a href=\"0.04167\">1h</a> "
                       "<a href=\"0.08333\">6h</a> "
                       "<a href=\"0.5\">12h</a> "
                       "<a href=\"1\">1d</a> "
                       "<a href=\"5\">5d</a> "
                       "<a href=\"10\">10d</a> "
                       "<a href=\"30\">1m</a> "
                       "<a href=\"180\">6m</a> "
                       "<a href=\"365\">1y</a> "
                       "<a href=\"all\">all</a>");

    QToolBar* toolbar = new QToolBar(controls);
    toolbar->setIconSize(QSize(24, 24));
    toolbar->setMaximumHeight(24);
    toolbar->setMovable(false);
    toolbar->setFloatable(false);
    toolbar->setContentsMargins(0, 0, 0, 0);
    
    QAction* reverseTimeAction = new QAction(QIcon(":/icons/timeline-reverse.png"),
                                             tr("Reverse time"), toolbar);
    QAction* slowTimeAction = new QAction(QIcon(":/icons/timeline-slower.png"),
                                          tr("10x slower"), toolbar);
    QAction* halfTimeAction = new QAction(QIcon(":/icons/timeline-half.png"),
                                          tr("2x slower"), toolbar);
    QAction* pauseAction = new QAction(QIcon(":/icons/timeline-pause.png"),
                                       tr("Pause time"), toolbar);
    QAction* realTimeAction = new QAction(QIcon(":/icons/timeline-realtime.png"),
                                          tr("Real time"), toolbar);
    QAction* doubleTimeAction = new QAction(QIcon(":/icons/timeline-double.png"),
                                            tr("2x faster"), toolbar);
    QAction* fastTimeAction = new QAction(QIcon(":/icons/timeline-faster.png"),
                                          tr("10x faster"), toolbar);
    
    connect(reverseTimeAction, SIGNAL(triggered()), this, SLOT(reverseTime()));
    toolbar->addAction(reverseTimeAction);
    
    connect(slowTimeAction, SIGNAL(triggered()), this, SLOT(slowerTime()));
    toolbar->addAction(slowTimeAction);
    
    connect(halfTimeAction, SIGNAL(triggered()), this, SLOT(halfTime()));
    toolbar->addAction(halfTimeAction);
    
    connect(pauseAction, SIGNAL(triggered()), this, SLOT(togglePaused()));
    toolbar->addAction(pauseAction);
    
    connect(realTimeAction, SIGNAL(triggered()), this, SLOT(realTime()));
    toolbar->addAction(realTimeAction);
    
    connect(doubleTimeAction, SIGNAL(triggered()), this, SLOT(doubleTime()));
    toolbar->addAction(doubleTimeAction);
    
    connect(fastTimeAction, SIGNAL(triggered()), this, SLOT(fasterTime()));
    toolbar->addAction(fastTimeAction);
    
    
    controlsLayout->addWidget(toolbar);
    
    controlsLayout->addStretch(1);
    controlsLayout->addWidget(zoomLabel);
    controls->setLayout(controlsLayout);
    
    connect(zoomLabel, SIGNAL(linkActivated(const QString&)), this, SLOT(setZoom(const QString&)));
    
    QVBoxLayout* layout = new QVBoxLayout(this);
    
    layout->addWidget(m_timelineView);
    layout->addWidget(controls);
    //layout->addLayout(controlsLayout);
    layout->setContentsMargins(0, 0, 0, 0);
    
    this->setLayout(layout);
    this->show();
    
    m_timelineView->setTimeRange(0.0, 5.0);
}
Ejemplo n.º 6
0
void Clock::mousePressEvent(QMouseEvent* event) {
	QLabel::mousePressEvent(event);
	emit togglePaused();
}
Ejemplo n.º 7
0
Window::Window() {
    m_board = new Board(this);
    connect(m_board, &Board::finished, this, &Window::gameFinished);
    connect(m_board, &Board::started, this, &Window::gameStarted);
    connect(m_board, &Board::pauseChanged, this, &Window::gamePauseChanged);

    QWidget* contents = new QWidget(this);
    setCentralWidget(contents);

    View* view = new View(m_board, contents);

    m_scores = new ScoreBoard(this);

    m_definitions = new Definitions(m_board->words(), this);
    connect(m_board, &Board::wordAdded, m_definitions, &Definitions::addWord);
    connect(m_board, &Board::wordSolved, m_definitions, &Definitions::solveWord);
    connect(m_board, &Board::wordSelected, m_definitions, &Definitions::selectWord);
    connect(m_board, &Board::loading, m_definitions, &Definitions::clear);

    // Create success message
    m_success = new QLabel(contents);
    m_success->setAttribute(Qt::WA_TransparentForMouseEvents);

    QFont f = font();
    f.setPointSize(24);
    QFontMetrics metrics(f);
    int width = metrics.width(tr("Success"));
    int height = metrics.height();
    int ratio = devicePixelRatio();
    QPixmap pixmap(QSize(width + height, height * 2) * ratio);
    pixmap.setDevicePixelRatio(ratio);
    pixmap.fill(QColor(0, 0, 0, 0));
    {
        QPainter painter(&pixmap);

        painter.setPen(Qt::NoPen);
        painter.setBrush(QColor(0, 0, 0, 200));
        painter.setRenderHint(QPainter::Antialiasing, true);
        painter.drawRoundedRect(0, 0, width + height, height * 2, 10, 10);

        painter.setFont(f);
        painter.setPen(Qt::white);
        painter.setRenderHint(QPainter::TextAntialiasing, true);
        painter.drawText(height / 2, height / 2 + metrics.ascent(), tr("Success"));
    }
    m_success->setPixmap(pixmap);
    m_success->hide();
    connect(m_board, &Board::loading, m_success, &QLabel::hide);

    // Create overlay background
    QLabel* overlay = new QLabel(this);

    f = font();
    f.setPixelSize(20);
    metrics = QFontMetrics(f);
    width = std::max(metrics.width(tr("Loading")), metrics.width(tr("Paused")));
    for (int i = 0; i < 10; ++i) {
        QString test(6, QChar(i + 48));
        test.insert(4, QLatin1Char(':'));
        test.insert(2, QLatin1Char(':'));
        width = std::max(width, metrics.width(test));
    }
    pixmap = QPixmap(QSize(width + 82, 32) * ratio);
    pixmap.setDevicePixelRatio(ratio);
    pixmap.fill(Qt::transparent);
    {
        QPainter painter(&pixmap);

        painter.setPen(Qt::NoPen);
        painter.setBrush(QColor(0, 0, 0, 200));
        painter.setRenderHint(QPainter::Antialiasing, true);
        painter.drawRoundedRect(0, -32, width + 82, 64, 5, 5);
    }
    overlay->setPixmap(pixmap);

    // Create overlay buttons
    m_definitions_button = new QLabel(overlay);
    m_definitions_button->setPixmap(QIcon(":/definitions.png").pixmap(24,24));
    m_definitions_button->setCursor(Qt::PointingHandCursor);
    m_definitions_button->setToolTip(tr("Definitions"));
    m_definitions_button->installEventFilter(this);

    m_hint_button = new QLabel(overlay);
    m_hint_button->setPixmap(QIcon(":/hint.png").pixmap(24,24));
    m_hint_button->setCursor(Qt::PointingHandCursor);
    m_hint_button->setToolTip(tr("Hint"));
    m_hint_button->setDisabled(true);
    m_hint_button->installEventFilter(this);
    connect(m_board, &Board::hintAvailable, m_hint_button, &QLabel::setEnabled);

    // Create clock
    m_clock = new Clock(overlay);
    m_clock->setDisabled(true);
    connect(m_clock, &Clock::togglePaused, m_board, &Board::togglePaused);
    connect(m_board, &Board::loading, m_clock, &Clock::setLoading);

    QHBoxLayout* overlay_layout = new QHBoxLayout(overlay);
    overlay_layout->setMargin(0);
    overlay_layout->setSpacing(0);
    overlay_layout->addSpacing(10);
    overlay_layout->addWidget(m_definitions_button);
    overlay_layout->addStretch();
    overlay_layout->addWidget(m_clock, 0, Qt::AlignCenter);
    overlay_layout->addStretch();
    overlay_layout->addWidget(m_hint_button);
    overlay_layout->addSpacing(10);

    // Lay out board
    QGridLayout* layout = new QGridLayout(contents);
    layout->setMargin(0);
    layout->setSpacing(0);
    layout->addWidget(view, 0, 0);
    layout->addWidget(m_success, 0, 0, Qt::AlignCenter);
    layout->addWidget(overlay, 0, 0, Qt::AlignHCenter | Qt::AlignTop);

    // Create menus
    QMenu* menu = menuBar()->addMenu(tr("&Game"));
    menu->addAction(tr("&New"), this, SLOT(newGame()), QKeySequence::New);
    menu->addAction(tr("&Choose..."), this, SLOT(chooseGame()));
    menu->addSeparator();
    m_pause_action = menu->addAction(tr("&Pause"), m_board, SLOT(togglePaused()), tr("P"));
    m_pause_action->setDisabled(true);
    QAction* action = menu->addAction(tr("&Hint"), m_board, SLOT(showHint()), tr("H"));
    action->setDisabled(true);
    connect(m_board, &Board::hintAvailable, action, &QAction::setEnabled);
    menu->addAction(tr("D&efinitions"), m_definitions, SLOT(selectWord()), tr("D"));
    menu->addSeparator();
    menu->addAction(tr("&Details"), this, SLOT(showDetails()));
    menu->addAction(tr("&Scores"), m_scores, SLOT(exec()));
    menu->addSeparator();
    action = menu->addAction(tr("&Quit"), qApp, SLOT(quit()), QKeySequence::Quit);
    action->setMenuRole(QAction::QuitRole);

    menu = menuBar()->addMenu(tr("&Settings"));
    menu->addAction(tr("Application &Language..."), this, SLOT(setLocale()));

    menu = menuBar()->addMenu(tr("&Help"));
    action = menu->addAction(tr("&About"), this, SLOT(about()));
    action->setMenuRole(QAction::AboutRole);
    action = menu->addAction(tr("About &Qt"), qApp, SLOT(aboutQt()));
    action->setMenuRole(QAction::AboutQtRole);

    // Restore window geometry
    QSettings settings;
    resize(800, 600);
    restoreGeometry(settings.value("Geometry").toByteArray());

    // Continue previous or start new game
    show();
    if (settings.contains("Current/Words") && (settings.value("Current/Version" ).toInt() == 4)) {
        m_board->openGame();
    } else {
        settings.remove("Current");
        newGame();
    }
}