Exemple #1
0
void PiecesTable::mouseMoveEvent(TQMouseEvent* e)
{
    QtTableView::mouseMoveEvent(e);

    // highlight on mouse over
    int row = findRow(e->y());
    int col = findCol(e->x());

    int oldrow = _activeRow;
    int oldcol = _activeCol;

    if(row >= numRows()
       || col >= numCols()
       || row < 0
       || col < 0) {
        _activeRow = -1;
        _activeCol = -1;
    }
    else {
        _activeRow = row;
        _activeCol = col;
    }

    updateCell(oldrow, oldcol, false);
    updateCell(row, col, false);
}
Exemple #2
0
void TableHead::mouseReleaseEvent(QMouseEvent *e)
{
    if (e->button() == Qt::LeftButton) // Returns the button that caused the
                                       // event.
    {
        int col = findCol(e->x());
        if (col < 0)
            col = (e->x() < 0) ? 0 : htable->ncols - 1; // good!

        if (!dragging and col == click_col)
        {
            // htable->emit_click_signal(col); // just click no drag
            emit htable->titleClicked(col);
        }

        if (dragging)
        {
            int vcol = findColNoMinus(e->x() - drag_offset);
            if (click_col >= 0)
            {
                htable->moveCol(click_col, vcol); // call
                                                  // Pstable::moveCol(int
                                                  // col, int place)
                                                  // should emit !!
                // emit colMoved(click_col, vcol);
            }
            ///	printf(" vcol2=%d \n",vcol);
        }
        dragging = false;
        floatHead->hide();
        // vp->hide();
    }
}
Exemple #3
0
// TEST
void TableHead::checkProfile()
{
    QRect viewR = viewRect();
    // if(viewR.y()!=0) printf(" qps: ooooohss....\n");
    int maxViewCol = findCol(viewR.width());
    if (maxViewCol < 0)
        maxViewCol = numCols();
    tablecache.setCol(maxViewCol);
    tablecache.setRow(1);
}
Exemple #4
0
/* processTbl:
 * Convert parser representation of cells into final form.
 * Find column and row positions of cells.
 * Recursively size cells.
 * Return 1 if problem sizing a cell.
 */
static int processTbl(graph_t *g, htmltbl_t * tbl, htmlenv_t * env)
{
    pitem *rp;
    pitem *cp;
    Dt_t *cdict;
    int r, c, cnt;
    htmlcell_t *cellp;
    htmlcell_t **cells;
    Dt_t *rows = tbl->u.p.rows;
    int rv = 0;
    int n_rows = 0;
    int n_cols = 0;
    PointSet *ps = newPS();

    rp = (pitem *) dtflatten(rows);
    cnt = 0;
    while (rp) {
	cdict = rp->u.rp;
	cp = (pitem *) dtflatten(cdict);
	while (cp) {
	    cellp = cp->u.cp;
	    cnt++;
	    cp = (pitem *) dtlink(cdict, (Dtlink_t *) cp);
	}
	rp = (pitem *) dtlink(rows, (Dtlink_t *) rp);
    }

    cells = tbl->u.n.cells = N_NEW(cnt + 1, htmlcell_t *);
    rp = (pitem *) dtflatten(rows);
    r = 0;
    while (rp) {
	cdict = rp->u.rp;
	cp = (pitem *) dtflatten(cdict);
	c = 0;
	while (cp) {
	    cellp = cp->u.cp;
	    *cells++ = cellp;
	    rv |= size_html_cell(g, cellp, tbl, env);
	    c = findCol(ps, r, c, cellp);
	    cellp->row = r;
	    cellp->col = c;
	    c += cellp->cspan;
	    n_cols = MAX(c, n_cols);
	    n_rows = MAX(r + cellp->rspan, n_rows);
	    cp = (pitem *) dtlink(cdict, (Dtlink_t *) cp);
	}
	rp = (pitem *) dtlink(rows, (Dtlink_t *) rp);
	r++;
    }
    tbl->rc = n_rows;
    tbl->cc = n_cols;
    dtclose(rows);
    freePS(ps);
    return rv;
}
Exemple #5
0
void Sheet::deleteColumn(const ColId& colId)
{
  const int index = findCol(colId);

  Q_ASSERT(index >= 0);

  if (index >= 0)
  {
    delete m_columns[index]; //destroy column

    m_columns.erase(m_columns.begin() + index);
  }
}
Exemple #6
0
void Sheet::insertColumn(Column* newCol, const ColId& colId /*= ColId()*/)
{
  Q_ASSERT(newCol && !newCol->id().isNull());

  const int index = colId == ColId() ? m_columns.size() : findCol(colId);
  Q_ASSERT(index >= 0);

  if (index >= 0)
  {
    newCol->createCells(); //initialize column

    m_columns.insert(index, newCol);
  }
}
Exemple #7
0
void TableBody::mouseMoveEvent(QMouseEvent *e)
{
    if (numRows() == 0)
        return; // *** prevent out of range

    // DRAFT CODE !
    // Signal : find row, col(field name) emit flyOnEvent Signal
    int row = findRow(e->y());
    int col = findCol(e->x());

    if (row < 0 or col < 0)
    {
        emit htable->outOfCell(); // if...
        return;
    }

    emit htable->flyOnCell(row, col);

    if (e->buttons() == Qt::NoButton)
        return;
    if (e->buttons() == Qt::RightButton)
        return;

    if (e->buttons() & Qt::ControlModifier || gadget_click)
        return;

    if (row != prev_drag_row)
    {
        if (row == -1)
        {
            if (!autoscrolling)
            {
                // dragging outside table, cause scrolling
                scrolldir = (e->y() < 0) ? UP : DOWN;
                //	killTimers();
                //	startTimer(scroll_delay);
                autoscrolling = true;
            }
        }
        else
        {
            ////killTimers();
            autoscrolling = false;
            dragSelectTo(row);
        }
    }
    //	repaintRow(row);
    //	view->update();
    repaintChanged();
}
Exemple #8
0
// TESt
void TableBody::checkProfile()
{
    htable->checkTableModel(); // important

    QRect viewR = viewRect();
    if (viewR.y() != 0)
        printf(" qps: ooooophss....\n");
    int maxViewRow = findRow(viewR.height());
    if (maxViewRow < 0)
        maxViewRow = numRows();
    int maxViewCol = findCol(viewR.width());
    if (maxViewCol < 0)
        maxViewCol = numCols();
    tablecache.setCol(maxViewCol);
    tablecache.setRow(maxViewRow);
}
Exemple #9
0
void TableHead::mousePressEvent(QMouseEvent *e)
{
    int col = findCol(e->x());
    //	printf("col=%d\n",col);
    if (col == -1)
        return;
    click_col = col;

    if (e->button() == Qt::RightButton)
    // && htable->options & HTBL_HEADING_CONTEXT_MENU)
    {
        emit rightClicked(e->globalPos(), col);
        return;
    }

    if (e->button() == Qt::LeftButton)
    {
        press = e->pos();
    }
}
Exemple #10
0
void KIconEditGrid::mousePressEvent( QMouseEvent *e )
{
  if(!e || (e->button() != LeftButton))
    return;

  int row = findRow( e->pos().y() );
  int col = findCol( e->pos().x() );
  //int cell = row * numCols() + col;

  if(!img->valid(col, row))
    return;

  btndown = true;
  start.setX(col);
  start.setY(row);

  if(ispasting)
  {
    ispasting = false;
    editPaste(true);
  }

  if(isselecting)
  {
    QPointArray a(pntarray.copy());
    pntarray.resize(0);
    drawPointArray(a, Mark);
    emit selecteddata(false);
  }

  switch( tool )
  {
    case SelectRect:
    case SelectCircle:
      isselecting = true;
      break;
    default:
      break;
  }

}
Exemple #11
0
void TodoView::doMouseEvent(QMouseEvent *e)
{
  editor->hide();
  priList->hide();
  editingFlag = FALSE;
  int c, r;

  c = findCol(e->x());
  if (count()==0) 
      r=-1;
  else
      r = findRow(e->y());
  // BL: workaround a bug in KTabListBox -- no !!!
  
  if (e->button() == RightButton)
    doPopup(r,c);
  else {
    //if ((y >= 0) && (x >= 0))
    // updateItem(y,x);
    ;
  }
}
Exemple #12
0
void PiecesTable::mousePressEvent(TQMouseEvent* e)
{
    QtTableView::mousePressEvent(e);

    if (e->button() == Qt::RightButton) {
        // execute RMB popup and check result
        _menu->exec(mapToGlobal(e->pos()));
        e->accept();
        return;
    }
    else {
        // GAME LOGIC

        // find the free position
        int pos = _map.find(15);
        if(pos < 0) return;

        int frow = pos / numCols();
        int fcol = pos - frow * numCols();

        // find click position
        int row = findRow(e->y());
        int col = findCol(e->x());

        // sanity check
        if (row < 0 || row >= numRows()) return;
        if (col < 0 || col >= numCols()) return;

        // valid move?
        if(row != frow && col != fcol) return;

        // rows match -> shift pieces
        if(row == frow) {

            if (col < fcol) {
                for(int c = fcol; c > col; c--) {
                    _map[c + row * numCols()] = _map[ c-1 + row *numCols()];
                    updateCell(row, c, false);
                }
            }
            else if (col > fcol) {
                for(int c = fcol; c < col; c++) {
                    _map[c + row * numCols()] = _map[ c+1 + row *numCols()];
                    updateCell(row, c, false);
                }
            }
        }
        // cols match -> shift pieces
        else if (col == fcol) {

            if (row < frow) {
                for(int r = frow; r > row; r--) {
                    _map[col + r * numCols()] = _map[ col + (r-1) *numCols()];
                    updateCell(r, col, false);
                }
            }
            else if (row > frow) {
                for(int r = frow; r < row; r++) {
                    _map[col + r * numCols()] = _map[ col + (r+1) *numCols()];
                    updateCell(r, col, false);
                }
            }
        }
        // move free cell to click position
        _map[col + row * numCols()] = 15;
        updateCell(row, col, false);

        // check if the player wins with this move
        chectwin();
    }
}
void MyLocalDirPanel::loadFromFile(QFile & file)
{
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
        return;

    CsvStream in(&file);
    bool saveSorting = m_table->isSortingEnabled();

    QStringList headers = in.readRecords();
    int firstNameCol = findCol(headers, QStringList()
                               << "firstname"
                               << tr("First Name")
                               << QString("First Name") );
    int lastNameCol = findCol(headers, QStringList()
                              << "lastname"
                              << tr("Last Name")
                              << QString("Last Name") );
    int maxCol = qMax(firstNameCol, lastNameCol);
    int phonenumberCol = findCol(headers, QStringList()
                                 << "phonenumber"
                                 << tr("Phone Number")
                                 << QString("Phone Number")
                                 << tr("Number")
                                 << QString("Number") );
    maxCol = qMax(maxCol, phonenumberCol);
    int emailCol = findCol(headers, QStringList()
                           << "emailaddress"
                           << tr("Email Address")
                           << tr("E-mail Address")
                           << tr("Email")
                           << QString("Email Address")
                           << QString("E-mail Address")
                           << QString("Email")
                           << QString("Primary Email") );
    maxCol = qMax(maxCol, emailCol);
    int companyCol = findCol(headers, QStringList()
                             << "company"
                             << tr("Company")
                             << QString("Company") );
    maxCol = qMax(maxCol, companyCol);
    int faxnumberCol = findCol(headers, QStringList()
                               << "faxnumber"
                               << tr("Fax Number")
                               << tr("Fax")
                               << QString("Fax Number")
                               << QString("Fax") );
    maxCol = qMax(maxCol, faxnumberCol);
    int mobilenumberCol = findCol(headers, QStringList()
                                  << "mobilenumber"
                                  << tr("Mobile Number")
                                  << tr("Mobile")
                                  << QString("Mobile Number")
                                  << QString("Mobile") );
    maxCol = qMax(maxCol, mobilenumberCol);
    qDebug() << Q_FUNC_INFO
             << firstNameCol << lastNameCol << phonenumberCol
             << emailCol << companyCol << faxnumberCol << mobilenumberCol;
    if(maxCol < 0) {
        // no header recognized... exiting
        return;
    }
    m_table->setSortingEnabled( false );
    while (!in.atEnd())
    {
        QStringList record = in.readRecords();
        if(record.size() <= maxCol)
            continue;
        int row = m_table->rowCount();
        m_table->setRowCount( row + 1 );
        if(firstNameCol >= 0)
        {
            QTableWidgetItem * itemFirstName = new QTableWidgetItem( record[firstNameCol] );
            m_table->setItem( row, 0, itemFirstName );
        }
        if(lastNameCol >= 0)
        {
            QTableWidgetItem * itemLastName = new QTableWidgetItem( record[lastNameCol] );
            m_table->setItem( row, 1, itemLastName );
        }
        if(phonenumberCol >= 0)
        {
            QTableWidgetItem * itemPhoneNumber = new QTableWidgetItem( record[phonenumberCol] );
            m_table->setItem( row, 2, itemPhoneNumber );
        }
        if(emailCol >= 0)
        {
            QTableWidgetItem * itemEmail = new QTableWidgetItem( record[emailCol] );
            m_table->setItem( row, 3, itemEmail );
        }
        if(companyCol >= 0)
        {
            QTableWidgetItem * itemCompany = new QTableWidgetItem( record[companyCol] );
            m_table->setItem( row, 4, itemCompany );
        }
        if(faxnumberCol >= 0)
        {
            QTableWidgetItem * itemFaxNumber = new QTableWidgetItem( record[faxnumberCol] );
            m_table->setItem( row, 5, itemFaxNumber );
        }
        if(mobilenumberCol >= 0)
        {
            QTableWidgetItem * itemMobileNumber = new QTableWidgetItem( record[mobilenumberCol] );
            m_table->setItem( row, 6, itemMobileNumber );
        }
    }
    m_table->setSortingEnabled( saveSorting );
}
Exemple #14
0
void TableHead::mouseMoveEvent(QMouseEvent *e)
{
    //	printf("mouseMoveEvent()\n");
    int col = findCol(e->x());
    if (col < 0)
    {
        emit htable->outOfHCell();
        return;
    }
    //	if( !dragging) return;
    emit htable->flyOnHCell(col);

    int thold = abs(press.x() - e->pos().x());

    if (e->buttons() == Qt::LeftButton //  Button state
        and htable->options & HTBL_REORDER_COLS)
    {
        {

            if (!dragging and thold > 5)
            {
                dragging = true;
                drag_offset =
                    press.x() - htable->colOffset(click_col) + xOffset();
                floatHead->setTitle(htable->title(click_col),
                                    cellWidth(click_col), height());
                floatHead->show();
                // vp->show();
            }

            if (dragging)
            {
                //	htable->body->drawGhostCol(drag_pos -
                // drag_offset, w);
                floatHead->move(e->x() - drag_offset, 0);

                int vcol = findColNoMinus(e->x() - drag_offset);
                int vcol_offx = htable->colOffset(vcol);
                static int old_pos = -1;
                //	printf("vcol=%d\n",vcol);

                // virtual Pointer move!
                if (old_pos != vcol_offx)
                {
                    QWidget *p = parentWidget(); // htable
                    //	vp->setMovable(htable->columnMovable(htable->columnMovable(vcol)
                    // and htable->columnMovable(click_col)
                    // ));
                    //	vp->move(vcol_offx -
                    // p->geometry().x()
                    //,p->geometry().y() -
                    // 13);
                    // vp->move(e->x()	,10);
                    old_pos = vcol_offx;
                }
                drag_pos = e->x(); // save old pos

                return;
            }
        }
    }

    if (col != -1) // ToolTip
    {
        //	for(int i=0;i<1024*1024;i++)	htable->tipText(col);
        //// memory leak
        // test
        QString s = htable->tipText(col);

        if (!s.isEmpty())
            QToolTip::showText(e->globalPos(), s);
    }
}
Exemple #15
0
void PiecesTable::mousePressEvent(QMouseEvent* e)
{
  QTableView::mousePressEvent(e);

  if (e->button() == RightButton) {

    // setup RMB pupup menu
    if(!_menu) {
      _menu = new QPopupMenu(this);
      _menu->insertItem(tr("R&andomize Pieces"), mRandomize);
      _menu->insertItem(tr("&Reset Pieces"), mReset);
      _menu->adjustSize();
    }

    // execute RMB popup and check result
    switch(_menu->exec(mapToGlobal(e->pos()))) {
    case mRandomize:
      randomizeMap();
      break;
    case mReset:
      initMap();
      repaint();
      break;
    default:
      break;
    }
  }
  else {
    // GAME LOGIC
    int cols = numCols();
    int rows = numRows();
    int item = cols*rows -1;

    // find the free position
    int pos = _map.find(item);
    if(pos < 0) return;

    int frow = pos / cols;
    int fcol = pos - frow * cols;

    // find click position
    int row = findRow(e->y());
    int col = findCol(e->x());

    // sanity check
    if (row < 0 || row >= rows) return;
    if (col < 0 || col >= cols) return;
    if ( row != frow && col != fcol ) return;

    // valid move?
    if(row != frow && col != fcol) return;

    // rows match -> shift pieces
    if(row == frow) {

      if (col < fcol) {
	for(int c = fcol; c > col; c--) {
	  _map[c + row * cols] = _map[ c-1 + row *cols];
	  updateCell(row, c, false);
	}
      }
      else if (col > fcol) {
	for(int c = fcol; c < col; c++) {
	  _map[c + row * cols] = _map[ c+1 + row *cols];
	  updateCell(row, c, false);
	}
      }
    }
    // cols match -> shift pieces
    else if (col == fcol) {

      if (row < frow) {
	for(int r = frow; r > row; r--) {
	  _map[col + r * cols] = _map[ col + (r-1) *cols];
	  updateCell(r, col, false);
	}
      }
      else if (row > frow) {
	for(int r = frow; r < row; r++) {
	  _map[col + r * cols] = _map[ col + (r+1) *cols];
	  updateCell(r, col, false);
	}
      }
    }
    // move free cell to click position
    _map[col + row * cols] = item;
    updateCell(row, col, false);

    // check if the player wins with this move
    checkwin();
  }
}
Exemple #16
0
/*!
  Returns the actual index of the section at position \a c, or -1 if outside.
 */
int QHeader::cellAt( int c ) const
{
    int i = ( orient == Horizontal ) ?  findCol( c ) :  findRow( c );
    return i >= count() ? -1 : i;
}
Exemple #17
0
void KIconEditGrid::mouseReleaseEvent( QMouseEvent *e )
{
  if(!e || (e->button() != LeftButton))
    return;

  int row = findRow( e->pos().y() );
  int col = findCol( e->pos().x() );
  btndown = false;
  end.setX(col);
  end.setY(row);
  int cell = row * numCols() + col;

  switch( tool )
  {
    case Eraser:
      currentcolor = TRANSPARENT;
    case Freehand:
    {
      if(!img->valid(col, row))
        return;
      setColor( cell, currentcolor );
      //if ( selected != cell )
      //{
        //modified = true;
        int prevSel = selected;
        selected = cell;
        repaint((prevSel%numCols())*cellsize,(prevSel/numCols())*cellsize, cellsize, cellsize, false);
        repaint(col*cellsize,row*cellsize, cellsize, cellsize, false);
        //updateCell( prevSel/numCols(), prevSel%numCols(), FALSE );
        //updateCell( row, col, FALSE );
        *((uint*)img->scanLine(row) + col) = colorAt(cell);
        p = *img;
      //}
      break;
    }
    case Ellipse:
    case Circle:
    case FilledEllipse:
    case FilledCircle:
    {
      drawEllipse(true);
      break;
    }
    case FilledRect:
    case Rect:
    {
      drawRect(true);
      break;
    }
    case Line:
    {
      drawLine(true);
      break;
    }
    case Spray:
    {
      drawSpray(QPoint(col, row));
      break;
    }
    case FloodFill:
    {
      QApplication::setOverrideCursor(waitCursor);
      drawFlood(col, row, colorAt(cell));
      QApplication::restoreOverrideCursor();
      updateColors();
      emit needPainting();
      p = *img;
      break;
    }
    case Find:
    {
      currentcolor = colorAt(cell);
      if ( selected != cell )
      {
        int prevSel = selected;
        selected = cell;
        repaint((prevSel%numCols())*cellsize,(prevSel/numCols())*cellsize, cellsize, cellsize, false);
        repaint(col*cellsize,row*cellsize, cellsize, cellsize, false);
        //updateCell( prevSel/numCols(), prevSel%numCols(), FALSE );
        //updateCell( row, col, FALSE );
      }

      break;
    }
    default:
      break;
  }
  emit changed(QPixmap(p));
  //emit colorschanged(numColors(), data());
}
Exemple #18
0
void KIconEditGrid::mouseMoveEvent( QMouseEvent *e )
{
  if(!e)
    return;

  int row = findRow( e->pos().y() );
  int col = findCol( e->pos().x() );
  int cell = row * numCols() + col;

  QPoint tmpp(col, row);
  if(tmpp == end)
    return;

  if(img->valid(col, row))
  {
    //debug("%d X %d", col, row);
    emit poschanged(col, row);
    emit xposchanged((col*scaling())+scaling()/2); // for the rulers
    emit yposchanged((row*scaling())+scaling()/2);
  }

  if(ispasting && !btndown && img->valid(col, row))
  {
    if( (col + cbsize.width()) > (numCols()-1) )
      insrect.setX(numCols()-insrect.width());
    else
      insrect.setX(col);
    if( (row + cbsize.height()) > (numRows()-1) )
      insrect.setY(numRows()-insrect.height());
    else
      insrect.setY(row);
    insrect.setSize(cbsize);
    //debug("Moving: %d x %d", insrect.width(), insrect.height());
    start = insrect.topLeft();
    end = insrect.bottomRight();
    drawRect(false);
    return;
  }

  if(!img->valid(col, row) || !btndown)
    return;

  end.setX(col);
  end.setY(row);

  if(isselecting)
  {
    if(tool == SelectRect)
      drawRect(false);
    else
      drawEllipse(false);
    return;
  }

  switch( tool )
  {
    case Eraser:
      currentcolor = TRANSPARENT;
    case Freehand:
    {
      setColor( cell, currentcolor );
  //img.setPixel(col, row, currentcolor.pixel());

      if ( selected != cell )
      {
        modified = true;
        int prevSel = selected;
        selected = cell;
        repaint((prevSel%numCols())*cellsize,(prevSel/numCols())*cellsize, cellsize, cellsize, false);
        repaint(col*cellsize,row*cellsize, cellsize, cellsize, false);
        //updateCell( prevSel/numCols(), prevSel%numCols(), FALSE );
        //updateCell( row, col, FALSE );
        *((uint*)img->scanLine(row) + col) = (colorAt(cell));
      }
      break;
    }
    case Find:
    {
      iconcolors.closestMatch(colorAt(cell));
      if ( selected != cell )
      {
        int prevSel = selected;
        selected = cell;
        repaint((prevSel%numCols())*cellsize,(prevSel/numCols())*cellsize, cellsize, cellsize, false);
        repaint(col*cellsize,row*cellsize, cellsize, cellsize, false);
        //updateCell( prevSel/numCols(), prevSel%numCols(), FALSE );
        //updateCell( row, col, FALSE );
      }
      break;
    }
    case Ellipse:
    case Circle:
    case FilledEllipse:
    case FilledCircle:
    {
      drawEllipse(false);
      break;
    }
    //case Select:
    case FilledRect:
    case Rect:
    {
      drawRect(false);
      break;
    }
    case Line:
    {
      drawLine(false);
      break;
    }
    case Spray:
    {
      drawSpray(QPoint(col, row));
      modified = true;
      break;
    }
    default:
      break;
  }

  p = *img;

  emit changed(QPixmap(p));
  //emit colorschanged(numColors(), data());
}