mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-06 00:10:59 +00:00
fix style issues as posted + removal of the static pixmap, no Assert()
though. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5431 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
2b62b66d31
commit
5a601958b2
@ -1,3 +1,8 @@
|
||||
|
||||
2002-10-17 André Pönitz <poenitz@lyx.org>
|
||||
|
||||
* QBrowseBox.[Ch]: fix style issues
|
||||
|
||||
2002-10-16 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* ui/moc/Makefile.am:
|
||||
|
@ -2,7 +2,7 @@
|
||||
* \file QBrowseBox.C
|
||||
*
|
||||
* Original file taken from klyx 0.10 sources:
|
||||
* $Id: QBrowseBox.C,v 1.3 2002/10/15 18:29:01 larsbj Exp $
|
||||
* $Id: QBrowseBox.C,v 1.4 2002/10/17 09:51:18 poenitz Exp $
|
||||
*
|
||||
* \author Kalle Dalheimer ?
|
||||
*
|
||||
@ -29,23 +29,23 @@ QBrowseBox::QBrowseBox(int rows, int cols, QWidget * parent,
|
||||
char const * name, WFlags fl)
|
||||
: QGridView()
|
||||
{
|
||||
setNumRows( rows );
|
||||
setNumCols( cols );
|
||||
setCellWidth( width()/cols );
|
||||
setCellHeight( height()/rows );
|
||||
setNumRows(rows);
|
||||
setNumCols(cols);
|
||||
setCellWidth(width()/cols);
|
||||
setCellHeight(height()/rows);
|
||||
|
||||
_texts = new QString[rows * cols];
|
||||
_pixmaps = new QPixmap[rows * cols];
|
||||
texts_ = new QString[rows * cols];
|
||||
pixmaps_ = new QPixmap[rows * cols];
|
||||
|
||||
_activecell.setX( 0 );
|
||||
_activecell.setY( 0 );
|
||||
updateCell(0,0);
|
||||
setMouseTracking( true );
|
||||
activecell_.setX(0);
|
||||
activecell_.setY(0);
|
||||
updateCell(0, 0);
|
||||
setMouseTracking(true);
|
||||
|
||||
if( style().inherits( "QWindowsStyle" ) )
|
||||
setFrameStyle( QFrame::WinPanel | QFrame::Raised );
|
||||
if (style().inherits("QWindowsStyle"))
|
||||
setFrameStyle(QFrame::WinPanel | QFrame::Raised);
|
||||
else
|
||||
setFrameStyle( QFrame::Panel | QFrame::Raised );
|
||||
setFrameStyle(QFrame::Panel | QFrame::Raised);
|
||||
|
||||
setFocusPolicy(QWidget::StrongFocus);
|
||||
}
|
||||
@ -54,83 +54,88 @@ QBrowseBox::QBrowseBox(int rows, int cols, QWidget * parent,
|
||||
|
||||
QBrowseBox::~QBrowseBox()
|
||||
{
|
||||
delete [] _texts;
|
||||
delete [] _pixmaps;
|
||||
delete [] texts_;
|
||||
delete [] pixmaps_;
|
||||
}
|
||||
|
||||
|
||||
int QBrowseBox::coordsToIndex( int row, int col )
|
||||
int QBrowseBox::coordsToIndex(int row, int col)
|
||||
{
|
||||
if( col<0 || col>numCols() || row<0 || row>numRows() )
|
||||
qDebug( "coordsToIndex: invalid coords (%d, %d)\n", row, col );
|
||||
|
||||
return row + col*numCols();
|
||||
if (col < 0 || col > numCols() || row < 0 || row > numRows())
|
||||
qDebug("coordsToIndex: invalid coords (%d, %d)\n", row, col);
|
||||
return row + col * numCols();
|
||||
}
|
||||
|
||||
|
||||
void QBrowseBox::insertItem( const QString& text, int row, int col )
|
||||
void QBrowseBox::insertItem(QString const & text, int row, int col)
|
||||
{
|
||||
_texts[ coordsToIndex( row, col ) ] = text;
|
||||
texts_[coordsToIndex(row, col)] = text;
|
||||
}
|
||||
|
||||
|
||||
void QBrowseBox::insertItem( QPixmap pixmap, int row, int col )
|
||||
void QBrowseBox::insertItem(char const * text, int x, int y)
|
||||
{
|
||||
_pixmaps[ coordsToIndex( row, col ) ] = pixmap;
|
||||
insertItem(QString(text), x, y);
|
||||
}
|
||||
|
||||
|
||||
void QBrowseBox::insertItem(QPixmap pixmap, int row, int col)
|
||||
{
|
||||
pixmaps_[coordsToIndex(row, col)] = pixmap;
|
||||
}
|
||||
|
||||
|
||||
void QBrowseBox::insertItem( QPixmap pixmap)
|
||||
{
|
||||
int w = (pixmap.width()/numCols());
|
||||
int h = (pixmap.height()/numRows());
|
||||
int w = pixmap.width() / numCols();
|
||||
int h = pixmap.height() / numRows();
|
||||
|
||||
for( int row = 0; row < numRows(); row++ )
|
||||
for( int col = 0; col < numCols(); col++ )
|
||||
{
|
||||
for (int row = 0; row < numRows(); ++row)
|
||||
for (int col = 0; col < numCols(); ++col) {
|
||||
QPixmap small(w,h);
|
||||
bitBlt(&small,0,0,&pixmap,col*w,row*h,w,h,Qt::CopyROP,false);
|
||||
insertItem(small, row, col );
|
||||
insertItem(small, row, col);
|
||||
}
|
||||
|
||||
resize(pixmap.width() + (numCols()+1)*frameWidth(),
|
||||
pixmap.height() +(numRows()+1)*frameWidth());
|
||||
resize(pixmap.width() + (numCols() + 1) * frameWidth(),
|
||||
pixmap.height() + (numRows() + 1) * frameWidth());
|
||||
}
|
||||
|
||||
void QBrowseBox::removeItem( int row, int col )
|
||||
|
||||
void QBrowseBox::removeItem(int row, int col)
|
||||
{
|
||||
_texts[ coordsToIndex( row, col ) ] = "";
|
||||
_pixmaps[ coordsToIndex( row, col ) ].resize( 0, 0 );
|
||||
texts_[coordsToIndex(row, col)] = "";
|
||||
pixmaps_[coordsToIndex(row, col)].resize(0, 0);
|
||||
}
|
||||
|
||||
|
||||
void QBrowseBox::clear()
|
||||
{
|
||||
for( int row = 0; row < numRows(); row++ )
|
||||
for( int col = 0; col < numCols(); col++ )
|
||||
removeItem( row, col );
|
||||
for (int row = 0; row < numRows(); ++row)
|
||||
for (int col = 0; col < numCols(); ++col)
|
||||
removeItem(row, col);
|
||||
}
|
||||
|
||||
|
||||
QString QBrowseBox::text( int row, int col )
|
||||
QString QBrowseBox::text(int row, int col)
|
||||
{
|
||||
if( col<0 || col >= numCols() || row<0 || row >= numRows() )
|
||||
if (col < 0 || col >= numCols() || row < 0 || row >= numRows())
|
||||
return "";
|
||||
return _texts[ coordsToIndex( row, col ) ];
|
||||
return texts_[coordsToIndex(row, col)];
|
||||
}
|
||||
|
||||
|
||||
QPixmap QBrowseBox::pixmap( int row, int col )
|
||||
QPixmap QBrowseBox::pixmap(int row, int col)
|
||||
{
|
||||
static QPixmap empty;
|
||||
|
||||
if( col<0 || col>=numCols() || row<0 || row>=numRows() )
|
||||
return empty;
|
||||
return _pixmaps[ coordsToIndex( row, col ) ];
|
||||
if (col < 0 || col >= numCols() || row < 0 || row >= numRows())
|
||||
return QPixmap();
|
||||
return pixmaps_[coordsToIndex(row, col)];
|
||||
}
|
||||
|
||||
void QBrowseBox::keyPressEvent( QKeyEvent* e )
|
||||
|
||||
void QBrowseBox::keyPressEvent(QKeyEvent * e)
|
||||
{
|
||||
switch( e->key()){
|
||||
switch(e->key()) {
|
||||
case Key_Up:
|
||||
moveUp();
|
||||
break;
|
||||
@ -144,67 +149,67 @@ void QBrowseBox::keyPressEvent( QKeyEvent* e )
|
||||
moveRight();
|
||||
break;
|
||||
case Key_Return:
|
||||
emit selected( _activecell.x(), _activecell.y());
|
||||
emit selected(activecell_.x(), activecell_.y());
|
||||
break;
|
||||
default:
|
||||
e->ignore();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void QBrowseBox::mouseReleaseEvent( QMouseEvent* e )
|
||||
|
||||
void QBrowseBox::mouseReleaseEvent(QMouseEvent * e)
|
||||
{
|
||||
qWarning("mouse release");
|
||||
emit selected( _activecell.x(), _activecell.y());
|
||||
emit selected( activecell_.x(), activecell_.y());
|
||||
}
|
||||
|
||||
//void QBrowseBox::closeEvent( QCloseEvent* e)
|
||||
|
||||
//void QBrowseBox::closeEvent(QCloseEvent * e)
|
||||
//{
|
||||
// e->accept();
|
||||
// qApp->exit_loop();
|
||||
//}
|
||||
|
||||
void QBrowseBox::paintCell( class QPainter * painter, int row, int col )
|
||||
void QBrowseBox::paintCell(QPainter * painter, int row, int col)
|
||||
{
|
||||
painter->setClipRect(cellGeometry(row,col));//, QPainter::CoordPainter);
|
||||
bool ispixmap = false;
|
||||
|
||||
if( ! _pixmaps[coordsToIndex(row,col)].isNull() ) {
|
||||
painter->drawPixmap(0,0,_pixmaps[coordsToIndex(row,col)]);
|
||||
if (!pixmaps_[coordsToIndex(row,col)].isNull()) {
|
||||
painter->drawPixmap(0,0,pixmaps_[coordsToIndex(row, col)]);
|
||||
ispixmap = true;
|
||||
}
|
||||
|
||||
if( (_activecell.x()==row) && (_activecell.y()==col) ) {
|
||||
if( ispixmap )
|
||||
qDrawShadeRect( painter, 0, 0, cellWidth(),
|
||||
cellHeight(), colorGroup(), false, 1 );
|
||||
if (activecell_.x() == row && activecell_.y() == col) {
|
||||
if (ispixmap)
|
||||
qDrawShadeRect(painter, 0, 0, cellWidth(),
|
||||
cellHeight(), colorGroup(), false, 1);
|
||||
else
|
||||
qDrawShadePanel( painter, 0, 0, cellWidth(),
|
||||
cellHeight(), colorGroup(), false, 1 );
|
||||
qDrawShadePanel(painter, 0, 0, cellWidth(),
|
||||
cellHeight(), colorGroup(), false, 1);
|
||||
} else {
|
||||
qDrawPlainRect( painter, 0, 0, cellWidth(),
|
||||
cellHeight(), colorGroup().background(), 1 );
|
||||
qDrawPlainRect(painter, 0, 0, cellWidth(),
|
||||
cellHeight(), colorGroup().background(), 1);
|
||||
}
|
||||
|
||||
if( ! _texts[ coordsToIndex( row, col ) ].isEmpty() ) {
|
||||
painter->drawText( 0, 0, cellWidth(),
|
||||
if (!texts_[coordsToIndex(row, col)].isEmpty()) {
|
||||
painter->drawText(0, 0, cellWidth(),
|
||||
cellHeight(), AlignLeft,
|
||||
_texts[ coordsToIndex( row, col ) ] );
|
||||
texts_[coordsToIndex(row, col)]);
|
||||
}
|
||||
painter->setClipping(false);
|
||||
}
|
||||
|
||||
|
||||
void QBrowseBox::resizeEvent( QResizeEvent* e )
|
||||
void QBrowseBox::resizeEvent(QResizeEvent * e)
|
||||
{
|
||||
QGridView::resizeEvent(e);
|
||||
setCellWidth( contentsRect().width()/numCols() );
|
||||
setCellHeight( contentsRect().height()/numRows() );
|
||||
setCellWidth(contentsRect().width() / numCols());
|
||||
setCellHeight(contentsRect().height() / numRows());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void QBrowseBox::mouseMoveEvent( QMouseEvent* e )
|
||||
void QBrowseBox::mouseMoveEvent(QMouseEvent * e)
|
||||
{
|
||||
qWarning("mouseMoveEvent");
|
||||
int x = e->pos().x();
|
||||
@ -213,70 +218,77 @@ void QBrowseBox::mouseMoveEvent( QMouseEvent* e )
|
||||
int cellx;
|
||||
int celly;
|
||||
|
||||
if( x < 0 || y < 0 || x > width() || y > height() ) {
|
||||
if (x < 0 || y < 0 || x > width() || y > height()) {
|
||||
// outside the box
|
||||
cellx = -1;
|
||||
celly = -1;
|
||||
} else {
|
||||
#ifdef WITH_WARNINGS
|
||||
#warning Is the switch of x and y intended here? (Andre)
|
||||
#endif
|
||||
celly = (int)floor( ((double)x) / ((double)cellWidth()) );
|
||||
cellx = (int)floor( ((double)y) / ((double)cellHeight()) );
|
||||
}
|
||||
|
||||
if( (_activecell.x() != cellx) || (_activecell.y() != celly) )
|
||||
{
|
||||
if (activecell_.x() != cellx || activecell_.y() != celly) {
|
||||
qWarning("update");
|
||||
// mouse has been moved to another cell
|
||||
int oldactivecellx = _activecell.x();
|
||||
int oldactivecelly = _activecell.y();
|
||||
_activecell.setX( cellx );
|
||||
_activecell.setY( celly );
|
||||
int oldactivecellx = activecell_.x();
|
||||
int oldactivecelly = activecell_.y();
|
||||
activecell_.setX(cellx);
|
||||
activecell_.setY(celly);
|
||||
// remove old highlighting
|
||||
updateCell( oldactivecellx, oldactivecelly );
|
||||
updateCell(oldactivecellx, oldactivecelly);
|
||||
// set new highlighting
|
||||
updateCell( _activecell.x(), _activecell.y() );
|
||||
updateCell(activecell_.x(), activecell_.y());
|
||||
}
|
||||
}
|
||||
|
||||
void QBrowseBox::moveLeft( )
|
||||
|
||||
void QBrowseBox::moveLeft()
|
||||
{
|
||||
int const y = _activecell.y();
|
||||
int const y = activecell_.y();
|
||||
|
||||
if (y>0)
|
||||
_activecell.setY(y-1);
|
||||
activecell_.setY(y - 1);
|
||||
|
||||
updateCell(_activecell.x(), y);
|
||||
updateCell(_activecell.x(), _activecell.y());
|
||||
updateCell(activecell_.x(), y);
|
||||
updateCell(activecell_.x(), activecell_.y());
|
||||
}
|
||||
|
||||
void QBrowseBox::moveRight( )
|
||||
|
||||
void QBrowseBox::moveRight()
|
||||
{
|
||||
int const y = _activecell.y();
|
||||
int const y = activecell_.y();
|
||||
|
||||
if (y<numCols()-1)
|
||||
_activecell.setY(y+1);
|
||||
if (y < numCols() - 1)
|
||||
activecell_.setY(y+1);
|
||||
|
||||
updateCell(_activecell.x(), y);
|
||||
updateCell(_activecell.x(),_activecell.y());
|
||||
updateCell(activecell_.x(), y);
|
||||
updateCell(activecell_.x(), activecell_.y());
|
||||
}
|
||||
|
||||
void QBrowseBox::moveUp( )
|
||||
|
||||
void QBrowseBox::moveUp()
|
||||
{
|
||||
int const x = _activecell.x();
|
||||
int const x = activecell_.x();
|
||||
|
||||
if (x>0)
|
||||
_activecell.setX(x-1);
|
||||
if (x > 0)
|
||||
activecell_.setX(x - 1);
|
||||
|
||||
updateCell(x, _activecell.y());
|
||||
updateCell(_activecell.x(),_activecell.y());
|
||||
updateCell(x, activecell_.y());
|
||||
updateCell(activecell_.x(), activecell_.y());
|
||||
}
|
||||
|
||||
void QBrowseBox::moveDown( )
|
||||
|
||||
void QBrowseBox::moveDown()
|
||||
{
|
||||
int const x = _activecell.x();
|
||||
int const x = activecell_.x();
|
||||
|
||||
if (x<numRows()-1)
|
||||
_activecell.setX(x+1);
|
||||
if (x < numRows() - 1)
|
||||
activecell_.setX(x + 1);
|
||||
|
||||
updateCell(x, _activecell.y());
|
||||
updateCell(_activecell.x(),_activecell.y());
|
||||
updateCell(x, activecell_.y());
|
||||
updateCell(activecell_.x(), activecell_.y());
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
* \file QBrowseBox.h
|
||||
*
|
||||
* Original file taken from klyx 0.10 sources:
|
||||
* $Id: QBrowseBox.h,v 1.1 2002/10/09 08:59:02 leuven Exp $
|
||||
* $Id: QBrowseBox.h,v 1.2 2002/10/17 09:51:18 poenitz Exp $
|
||||
*
|
||||
* \author Kalle Dalheimer ?
|
||||
*
|
||||
@ -16,7 +16,6 @@
|
||||
#include "qgridview.h"
|
||||
|
||||
#include <qwidget.h>
|
||||
#include <qarray.h>
|
||||
|
||||
|
||||
class QString;
|
||||
@ -28,45 +27,49 @@ class QBrowseBox : public QGridView
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QBrowseBox( int rows , int cols, QWidget* parent = 0 , const char* name=0 , WFlags f =0 );
|
||||
QBrowseBox(int rows, int cols, QWidget * parent = 0,
|
||||
char const * name = 0, WFlags f = 0);
|
||||
~QBrowseBox();
|
||||
|
||||
void insertItem( const QString& text, int x, int y );
|
||||
void insertItem( const char* text, int x, int y ) { insertItem( QString( text ), x, y ); }
|
||||
void insertItem( QPixmap pixmap, int x, int y );
|
||||
void insertItem( QPixmap pixmap);
|
||||
void removeItem( int x, int y );
|
||||
void insertItem(QString const & text, int x, int y);
|
||||
void insertItem(char const * text, int x, int y);
|
||||
void insertItem(QPixmap pixmap, int x, int y);
|
||||
void insertItem(QPixmap pixmap);
|
||||
void removeItem(int x, int y);
|
||||
void clear();
|
||||
|
||||
QString text( int x, int y );
|
||||
QPixmap pixmap( int x, int y);
|
||||
QString text(int x, int y);
|
||||
QPixmap pixmap(int x, int y);
|
||||
|
||||
// int exec( const QPoint& pos );
|
||||
// int exec( int x, int y );
|
||||
// int exec( const QWidget* trigger );
|
||||
// int exec(QPoint const & pos);
|
||||
// int exec(int x, int y);
|
||||
// int exec(QWidget * trigger);
|
||||
|
||||
signals:
|
||||
signals:
|
||||
void selected(int, int);
|
||||
|
||||
protected:
|
||||
virtual void keyPressEvent( QKeyEvent* e );
|
||||
virtual void resizeEvent( QResizeEvent* e );
|
||||
virtual void mouseReleaseEvent( QMouseEvent* e );
|
||||
// virtual void closeEvent( QCloseEvent* e );
|
||||
virtual void mouseMoveEvent( QMouseEvent* e );
|
||||
virtual void paintCell( QPainter *, int, int );
|
||||
virtual void keyPressEvent(QKeyEvent * e);
|
||||
virtual void resizeEvent(QResizeEvent * e);
|
||||
virtual void mouseReleaseEvent(QMouseEvent * e);
|
||||
// virtual void closeEvent(QCloseEvent * e);
|
||||
virtual void mouseMoveEvent(QMouseEvent * e);
|
||||
virtual void paintCell(QPainter *, int x, int y);
|
||||
|
||||
private:
|
||||
// make sure the automatically generated one is not used
|
||||
QBrowseBox & operator=(QBrowseBox const &);
|
||||
|
||||
void moveLeft();
|
||||
void moveRight();
|
||||
void moveUp();
|
||||
void moveDown();
|
||||
|
||||
int coordsToIndex( int x, int y );
|
||||
int coordsToIndex(int x, int y);
|
||||
|
||||
QString* _texts;
|
||||
QPixmap* _pixmaps;
|
||||
QPoint _activecell;
|
||||
QString * texts_;
|
||||
QPixmap* pixmaps_;
|
||||
QPoint activecell_;
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user