⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cgridview.cpp

📁 Gambas is a graphical development environment based on a Basic interpreter, like Visual Basic. It us
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************  CGridView.cpp  (c) 2000-2003 Beno� Minisini <gambas@users.sourceforge.net>  This program is free software; you can redistribute it and/or modify  it under the terms of the GNU General Public License as published by  the Free Software Foundation; either version 1, or (at your option)  any later version.  This program is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  GNU General Public License for more details.  You should have received a copy of the GNU General Public License  along with this program; if not, write to the Free Software  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.***************************************************************************/#define __CGRIDVIEW_CPP#include <qapplication.h>#include <qheader.h>#include "gambas.h"#include "CWidget.h"#include "CPicture.h"#include "CGridView.h"//static long EVENT_Change;    /* selection change */static long EVENT_Click;     /* simple click */static long EVENT_Activate;  /* double click */static long EVENT_Scroll;/***************************************************************************  class MyTableItem***************************************************************************/MyTableItem::MyTableItem(QTable *table): QTableItem(table, QTableItem::Never, 0){  picture = NULL;  key = NULL;  align = AlignLeft | SingleLine;}MyTableItem::~MyTableItem(){  GB.Unref((void **)&picture);}void MyTableItem::setPicture(GB_OBJECT *pict){  SET_PIXMAP(setPixmap, &picture, pict);}int MyTableItem::alignment() const{  return align | AlignVCenter;}/***************************************************************************  class MyTable***************************************************************************/MyTable::MyTable(QWidget *parent) :QTable(0, 0, parent){}void MyTable::paintFocus( QPainter *p, const QRect &r ){}QSize MyTable::tableSize() const{  return QSize( columnPos( numCols() - 1 ) + columnWidth( numCols() - 1 ),    rowPos( numRows() - 1 ) + rowHeight( numRows() - 1 ) );}/*void MyTable::columnWidthChanged( int col ){  updateContents( columnPos( col ), 0, contentsWidth(), contentsHeight() );  QSize s(tableSize());  int w = contentsWidth();  resizeContents( s.width(), s.height() );  if ( contentsWidth() < w )	  repaintContents( s.width(), 0, w - s.width() + 1, contentsHeight(), TRUE );  else	  repaintContents( w, 0, s.width() - w + 1, contentsHeight(), FALSE );  setLeftMargin(0); // updateGeometries();  for ( int j = col; j < numCols(); ++j )  {  	for ( int i = 0; i < numRows(); ++i )    {	    QWidget *w = cellWidget( i, j );	    if ( !w )		    continue;	    moveChild( w, columnPos( j ), rowPos( i ) );	    w->resize( columnWidth( j ) - 1, rowHeight( i ) - 1 );	  }  }}void MyTable::rowHeightChanged( int row ){  updateContents( 0, rowPos( row ), contentsWidth(), contentsHeight() );  QSize s( tableSize() );  int h = contentsHeight();  resizeContents( s.width(), s.height() );  if ( contentsHeight() < h )  	repaintContents( 0, contentsHeight(), contentsWidth(), h - s.height() + 1, TRUE );  else	  repaintContents( 0, h, contentsWidth(), s.height() - h + 1, FALSE );  setLeftMargin(0); // updateGeometries();  for ( int j = row; j < numRows(); ++j )  {	  for ( int i = 0; i < numCols(); ++i )    {	    QWidget *w = cellWidget( j, i );	    if ( !w )		    continue;	    moveChild( w, columnPos( i ), rowPos( j ) );	    w->resize( columnWidth( i ) - 1, rowHeight( j ) - 1 );	  }  }}*/void MyTable::setRowHeight(int row, long height){  if (height < 0)    adjustRow(row);  else    QTable::setRowHeight(row, height);}void MyTable::setColumnWidth(int col, long width){  if (width < 0)    adjustColumn(col);  else    QTable::setColumnWidth(col, width);}void MyTable::fontChange(const QFont &f){  int i;  int h;  //qDebug("font change");  h = fontMetrics().lineSpacing() + 2;  for (i = 0; i < numRows(); i++)    QTable::setRowHeight(i, h);  QTable::fontChange(f);}/***************************************************************************  GridView***************************************************************************/BEGIN_METHOD(CGRIDVIEW_new, GB_OBJECT parent)  MyTable *wid = new MyTable(CONTAINER(VARG(parent)));  //QObject::connect(wid, SIGNAL(currentChanged(int, int)), MANAGER, SLOT(changed()));  QObject::connect(wid, SIGNAL(doubleClicked(int, int, int, const QPoint &)), MANAGER, SLOT(activated()));  QObject::connect(wid, SIGNAL(clicked(int, int, int, const QPoint &)), MANAGER, SLOT(clicked()));  QObject::connect(wid, SIGNAL(contentsMoving(int, int)), MANAGER, SLOT(scrolled()));  CWIDGET_new(wid, (void *)_object, "GridView");  THIS->row = -1;  THIS->col = -1;  wid->setSelectionMode(QTable::NoSelection);  wid->setTopMargin(0);  wid->verticalHeader()->hide();  wid->setLeftMargin(0);  wid->horizontalHeader()->hide();  wid->show();END_METHODBEGIN_PROPERTY(CGRIDVIEW_row)  if (READ_PROPERTY)    GB.ReturnInteger(WIDGET->currentRow());  else    WIDGET->setCurrentCell(VPROP(GB_INTEGER), WIDGET->currentColumn());END_PROPERTYBEGIN_PROPERTY(CGRIDVIEW_column)  if (READ_PROPERTY)    GB.ReturnInteger(WIDGET->currentColumn());  else    WIDGET->setCurrentCell(WIDGET->currentRow(), VPROP(GB_INTEGER));END_PROPERTYBEGIN_METHOD_VOID(CGRIDVIEW_clear)  long rows = WIDGET->numRows();  WIDGET->setNumRows(0);  WIDGET->setNumRows(rows);  CGridView::fillItems(WIDGET);END_METHODBEGIN_METHOD(CGRIDVIEW_get, GB_INTEGER row; GB_INTEGER col)  long row = VARG(row);  long col = VARG(col);  if (CGridView::check(WIDGET, row, col))    return;  THIS->row = row;  THIS->col = col;  RETURN_SELF();END_METHODBEGIN_PROPERTY(CGRIDVIEW_current)  THIS->row = WIDGET->currentRow();  THIS->col = WIDGET->currentColumn();  RETURN_SELF();END_PROPERTYBEGIN_PROPERTY(CGRIDVIEW_self)  THIS->row = -1;  THIS->col = -1;  RETURN_SELF();END_PROPERTYBEGIN_PROPERTY(CGRIDVIEW_grid)  if (READ_PROPERTY)    GB.ReturnBoolean(WIDGET->showGrid());  else    WIDGET->setShowGrid(VPROP(GB_BOOLEAN));END_PROPERTYBEGIN_PROPERTY(CGRIDVIEW_client_width)  WIDGET->updateScrollBars();  GB.ReturnInteger(WIDGET->clipper()->width());END_PROPERTYBEGIN_PROPERTY(CGRIDVIEW_client_height)  WIDGET->updateScrollBars();  GB.ReturnInteger(WIDGET->clipper()->height());END_PROPERTY/***************************************************************************  GridItem***************************************************************************/BEGIN_PROPERTY(CGRIDITEM_x)  GB.ReturnInteger(WIDGET->columnPos(THIS->col) - WIDGET->contentsX());END_PROPERTYBEGIN_PROPERTY(CGRIDITEM_y)  GB.ReturnInteger(WIDGET->rowPos(THIS->row) - WIDGET->contentsY());END_PROPERTYBEGIN_PROPERTY(CGRIDITEM_width)  GB.ReturnInteger(WIDGET->columnWidth(THIS->col));END_PROPERTYBEGIN_PROPERTY(CGRIDITEM_height)  GB.ReturnInteger(WIDGET->rowHeight(THIS->row));END_PROPERTYBEGIN_PROPERTY(CGRIDITEM_text)  if (READ_PROPERTY)    GB.ReturnNewZeroString(TO_UTF8(ITEM->text()));  else  {    ITEM->setText(QSTRING_PROP());    WIDGET->updateCell(THIS->row, THIS->col);  }END_PROPERTYBEGIN_PROPERTY(CGRIDITEM_alignment)  if (READ_PROPERTY)    GB.ReturnInteger(ITEM->align);  else  {    ITEM->align = VPROP(GB_INTEGER);    WIDGET->updateCell(THIS->row, THIS->col);  }END_PROPERTYBEGIN_PROPERTY(CGRIDITEM_picture)  if (READ_PROPERTY)    GB.ReturnObject(ITEM->picture);  else  {    ITEM->setPicture(PROP(GB_OBJECT));    WIDGET->updateCell(THIS->row, THIS->col);  }END_PROPERTYBEGIN_METHOD_VOID(CGRIDITEM_ensure_visible)  WIDGET->ensureCellVisible(THIS->row, THIS->col);END_METHODBEGIN_METHOD_VOID(CGRIDITEM_clear)  WIDGET->clearCell(THIS->row, THIS->col);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -