Esempio n. 1
0
//private
void GameWindow::setGame(QSharedPointer<ReversiGame> game)
{
    if (game.isNull())
        return;

    //Force us to update the game's AI options
    this->handleAIOptionChange(this->options);

    this->ui->widget->setBoard(game->getBoard());

    ReversiGame * raw = game.data();
    connect(this->ui->widget,
            SIGNAL(cellClicked(BoardPos)),
            raw,
            SLOT(handleCellClicked(BoardPos)));
    connect(raw,
            SIGNAL(gameOver(CELL_STATE)),
            this,
            SLOT(handleGameOver(CELL_STATE)));
            this->game = game;
    connect(raw,
            SIGNAL(scoreChanged(quint16,quint16)),
            this,
            SLOT(handleCountChange(quint16,quint16)));
}
DbTable::DbTable(list<ColumnConfig> cc,const litesql::Expr & expr,Wt::WContainerWidget * parent):
    Wt::Ext::TableView(parent),
    _column_config(cc),
    _sql(sql) {
    setBorder(false);
    model=new DbTableModel(cc,expr,parent);
    setModel(model);
    setAlternatingRowColors(true);
    resizeColumnsToContents(true);
    setHighlightMouseOver(true);
    setSelectionBehavior(Wt::SelectRows);
    setSelectionMode(Wt::SingleSelection);
    std::list<ColumnConfig>::iterator confit=cc.begin();
    for(int a=0; confit!=cc.end(); confit++, a++) {
//          enableColumnHiding(a, true);
//          setColumnSortable(a, true);
        setColumnWidth(a,(*confit).getWidth());
    }
    _clickCount=0;
    cellClicked().connect(SLOT(this,DbTable::itemSelected));
    doubleClickTimer=new Wt::WTimer(this);
    doubleClickTimer->setInterval(200);
    doubleClickTimer->timeout().connect(SLOT(this, DbTable::emitClickCount));

}
Esempio n. 3
0
void BoardWidget::onClicked(const QPoint &point)
{
    for (int i = 0; i < 19; ++i) {
        for (int j = 0; j < 19; ++j) {
            if (isInsideCell(i, j, point)) {
                emit cellClicked(i, j);
                break;
            }
        }
    }
}
ExtendedTableWidget::ExtendedTableWidget(QWidget* parent) :
    QTableView(parent)
{
    setHorizontalScrollMode(ExtendedTableWidget::ScrollPerPixel);

    connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(vscrollbarChanged(int)));
    connect(this, SIGNAL(clicked(QModelIndex)), this, SLOT(cellClicked(QModelIndex)));

    // Set up filter row
    m_tableHeader = new FilterTableHeader(this);
    setHorizontalHeader(m_tableHeader);
}
Esempio n. 5
0
void MineField::contentsMouseReleaseEvent( QMouseEvent* e )
{
    int c = e->pos().x() / cellSize;
    int r = e->pos().y() / cellSize;
    if ( onBoard( r, c ) && c == currCol && r == currRow )
	cellClicked( r, c );


    if ( flagAction == FlagNext ) {
	flagAction = NoAction;
    }
}
Esempio n. 6
0
void ClsBaseQStateArrayView::mouseHandle( const QPointF &_pos ) {
#ifdef DEBUG_CLSBASEQSTATEARRAYVIEW
    cout << "ClsBaseQStateArrayView::mouseHandle( const QPointF &_pos )" << endl;
#endif
    int iX = pos2index2( _pos.x() );
    int iY = pos2index2( _pos.y() );

    if(iSelectionMode == ClsBaseQStateArrayView::SINGLE){
	clear();
    }
    setValue(fFixedValue, iX, iY);
    emit cellClicked( iX, iY);
}
Esempio n. 7
0
bool MainWindow::eventFilter(QObject *object, QEvent *event)
{
  if (event->type() == QEvent::KeyPress) {
    QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
    switch (keyEvent->key()) {
      case Qt::Key_Up : 
      case Qt::Key_2:
           board[selected]->setSelected(false);
           if (selected - BoardSize < 0) {
             selected += BoardSize*(BoardSize-1);
           } else
             selected -= BoardSize;
           board[selected]->setSelected(true);
           return true;
      case Qt::Key_Down : 
      case Qt::Key_8:
           board[selected]->setSelected(false);
           if (selected + BoardSize >= BoardSize*BoardSize) {
             selected -= BoardSize*(BoardSize-1);
           } else 
             selected += BoardSize;
           board[selected]->setSelected(true);
           return true;
      case Qt::Key_Left : 
      case Qt::Key_4:
           board[selected]->setSelected(false);
           if (selected  % BoardSize == 0) {
             selected += BoardSize - 1;
           } else
             selected -= 1;
           board[selected]->setSelected(true);
           return true;
      case Qt::Key_Right : 
      case Qt::Key_6:
           board[selected]->setSelected(false);
           if ((selected + 1) % BoardSize == 0) {
             selected -= BoardSize - 1;
           } else
             selected += 1;
           board[selected]->setSelected(true);
           return true;
      case Qt::Key_Return :
      case Qt::Key_5:
      case Qt::Key_NumberSign:
      case Qt::Key_Asterisk:
           emit cellClicked(selected);
           return true;
    }
  }
  return false;
}
Esempio n. 8
0
void Cell::mousePressEvent(QMouseEvent* e)
{
  /*if(e->button() == Qt::LeftButton)
    emit lClicked(iindex);
  else if(e->button() == Qt::RightButton)
    emit rClicked(iindex);
  */
/*  if (e->x()<e->y() )
    emit lClicked(iindex);
  else
    emit rClicked(iindex);*/

    emit cellClicked(iindex);
}
ExtendedTableWidget::ExtendedTableWidget(QWidget* parent) :
    QTableView(parent)
{
    setHorizontalScrollMode(ExtendedTableWidget::ScrollPerPixel);
    // Force ScrollPerItem, so scrolling shows all table rows
    setVerticalScrollMode(ExtendedTableWidget::ScrollPerItem);

    connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(vscrollbarChanged(int)));
    connect(this, SIGNAL(clicked(QModelIndex)), this, SLOT(cellClicked(QModelIndex)));

    // Set up filter row
    m_tableHeader = new FilterTableHeader(this);
    setHorizontalHeader(m_tableHeader);

    // Set up vertical header context menu
    verticalHeader()->setContextMenuPolicy(Qt::CustomContextMenu);

    // Set up table view context menu
    m_contextMenu = new QMenu(this);
    QAction* nullAction = new QAction(tr("Set to NULL"), m_contextMenu);
    QAction* copyAction = new QAction(QIcon(":/icons/copy"), tr("Copy"), m_contextMenu);
    QAction* pasteAction = new QAction(QIcon(":/icons/paste"), tr("Paste"), m_contextMenu);
    m_contextMenu->addAction(nullAction);
    m_contextMenu->addSeparator();
    m_contextMenu->addAction(copyAction);
    m_contextMenu->addAction(pasteAction);
    setContextMenuPolicy(Qt::CustomContextMenu);

    // Set up context menu actions
    connect(this, static_cast<void(QTableView::*)(const QPoint&)>(&QTableView::customContextMenuRequested),
            [=](const QPoint& pos)
    {
        // Try to find out whether the current view is editable and (de)activate menu options according to that
        bool editable = editTriggers() != QAbstractItemView::NoEditTriggers;
        nullAction->setEnabled(editable);
        pasteAction->setEnabled(editable);

        // Show menu
        m_contextMenu->popup(viewport()->mapToGlobal(pos));
    });
    connect(nullAction, &QAction::triggered, [&]() {
        foreach(const QModelIndex& index, selectedIndexes())
            model()->setData(index, QVariant());
    });
Esempio n. 10
0
void MainWindow::newGame()
{
  if(soundaction->isChecked())
    startsound->play();

  for(int i = 0; i < BoardSize * BoardSize; i++)
  {
    board[i]->setDirs(Cell::None);
    board[i]->setConnected(false);
    board[i]->setRoot(false);
    board[i]->setSelected(false);
  }

  start = true;
  int shoots = (skill+ 2) * BoardSize / 2;

  while(cellsCount() == 0)
    for(int i = 0; i < shoots; i++) {
      const int row = rand() % BoardSize;
      const int col = rand() % BoardSize;
      cellClicked(row * BoardSize + col);
    }

  lcd->display(shoots + 3);
  cellsLcd->display(cellsCount());

  start = false;
  for(int i = 0; i < BoardSize * BoardSize; i++)
  {
    if (!board[i]->isConnected())
	continue;

    //qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
    QTimer::singleShot(20, board[i], SLOT(update()));
    //qApp->processEvents(QEventLoop::ExcludeUserInputEvents | QEventLoop::WaitForMoreEvents);
  }
}
Esempio n. 11
0
void OpenNIC::cellDoubleClicked ( int row, int col )
{
	cellClicked(row,col);
}
ExtendedTableWidget::ExtendedTableWidget(QWidget* parent) :
    QTableView(parent)
{
    setHorizontalScrollMode(ExtendedTableWidget::ScrollPerPixel);
    // Force ScrollPerItem, so scrolling shows all table rows
    setVerticalScrollMode(ExtendedTableWidget::ScrollPerItem);

    connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(vscrollbarChanged(int)));
    connect(this, SIGNAL(clicked(QModelIndex)), this, SLOT(cellClicked(QModelIndex)));

    // Set up filter row
    m_tableHeader = new FilterTableHeader(this);
    setHorizontalHeader(m_tableHeader);

    // Set up vertical header context menu
    verticalHeader()->setContextMenuPolicy(Qt::CustomContextMenu);

    // Set up table view context menu
    m_contextMenu = new QMenu(this);
    QAction* nullAction = new QAction(tr("Set to NULL"), m_contextMenu);
    QAction* copyAction = new QAction(QIcon(":/icons/copy"), tr("Copy"), m_contextMenu);
    QAction* copyWithHeadersAction = new QAction(QIcon(":/icons/special_copy"), tr("Copy with Headers"), m_contextMenu);
    QAction* pasteAction = new QAction(QIcon(":/icons/paste"), tr("Paste"), m_contextMenu);
    QAction* filterAction = new QAction(tr("Use as Filter"), m_contextMenu);
    m_contextMenu->addAction(filterAction);
    m_contextMenu->addSeparator();
    m_contextMenu->addAction(nullAction);
    m_contextMenu->addSeparator();
    m_contextMenu->addAction(copyAction);
    m_contextMenu->addAction(copyWithHeadersAction);
    m_contextMenu->addAction(pasteAction);
    setContextMenuPolicy(Qt::CustomContextMenu);

    // Create and set up delegate
    m_editorDelegate = new ExtendedTableWidgetEditorDelegate(this);
    setItemDelegate(m_editorDelegate);

    // This is only for displaying the shortcut in the context menu.
    // An entry in keyPressEvent is still needed.
    nullAction->setShortcut(QKeySequence(tr("Alt+Del")));
    copyAction->setShortcut(QKeySequence::Copy);
    copyWithHeadersAction->setShortcut(QKeySequence(tr("Ctrl+Shift+C")));
    pasteAction->setShortcut(QKeySequence::Paste);

    // Set up context menu actions
    connect(this, &QTableView::customContextMenuRequested,
            [=](const QPoint& pos)
    {
        // Deactivate context menu options if there is no model set
        bool enabled = model();
        filterAction->setEnabled(enabled);
        copyAction->setEnabled(enabled);
        copyWithHeadersAction->setEnabled(enabled);

        // Try to find out whether the current view is editable and (de)activate menu options according to that
        bool editable = editTriggers() != QAbstractItemView::NoEditTriggers;
        nullAction->setEnabled(enabled && editable);
        pasteAction->setEnabled(enabled && editable);

        // Show menu
        m_contextMenu->popup(viewport()->mapToGlobal(pos));
    });
    connect(filterAction, &QAction::triggered, [&]() {
        useAsFilter();
    });
    connect(nullAction, &QAction::triggered, [&]() {
        for(const QModelIndex& index : selectedIndexes())
            model()->setData(index, QVariant());
    });
    connect(copyAction, &QAction::triggered, [&]() {
       copy(false);
    });
    connect(copyWithHeadersAction, &QAction::triggered, [&]() {
       copy(true);
    });
    connect(pasteAction, &QAction::triggered, [&]() {
       paste();
    });
}