Source: /app/hbasic/hbasic/lib_calc_sheet/sheet_editor.h


Annotated List
Files
Globals
Hierarchy
Index
/* **************************************************************************
 File: sheet_editor.h
 Desc: Designer widget to edit gui structures.
 ----------------------------------------------------------------------------
	copyright            : (C) 2001 HBasic project (Marcus Engels)
 ***************************************************************************/

/* **************************************************************************
 *                                                                         *
 *   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 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

/* ----------------------------------------------------------------------- */
/* Classlist: List of classes that will be defined in this source file.    */
/* ----------------------------------------------------------------------- */
/*
 * class CSheetEditor: Editor widget for calc sheets.
 */

/* ----------------------------------------------------------------------- */
/* Changelog: Description of important changes within this file.           */
/*            Please report with date, maintainer and change description.  */
/* ----------------------------------------------------------------------- */

#ifndef EDIT_SHEET_H
#define EDIT_SHEET_H

#include 
#include 
#include 

#include "structs.h"
#include "window_list.h"

/* types of item descriptions. */

#define TITEM_NONE 0
#define TITEM_INTEGER 1
#define TITEM_DOUBLE 2
#define TITEM_TEXT 3
#define TITEM_EXPR 4

#define OPR_ADD 1
#define OPR_SUB 2
#define OPR_MUL 3
#define OPR_DIV 4

#define SHEET_DEFAULT_SIZE 100

/* Types of selection */
#define SELECT_NONE 0
#define SELECT_RANGE 1
#define SELECT_EDIT 2

#define SENTRY_DEFAULT_HEIGHT 20
#define SENTRY_DEFAULT_WIDTH 100

class QString;
class MemoryBlock;
class QVBox;
class QLineEdit;
class HBSubList;
class HBSheetCellHeader;
class HBSheetCell;
class HBSheet;
class QHeader;
class QLabel;

void calculateExprValue( HBSheetCell *cell_ptr );

/* ##################################################################### */

class CSheetTableWidget : public QScrollView
{
Q_OBJECT

public:
	CSheetTableWidget( QWidget *parent, HBSheet *sheet_desc, QLineEdit *edit_line, QLineEdit *le_sel_current );
	void drawContents( QPainter *p, int x, int y, int w, int h );

	/* Notify about changes in property editor */
	void cellPropertyChanged( HBSheetCell *cell_ptr );
	void updateCurrentCell( void );

private:
	QLineEdit *le_inline;
	QLineEdit *le_sel_current;
	QLineEdit *sheet_edit_line;

	HBSheet *sheet_data;

	/* Selection entries */
	HBSheetCell *current_cell;
	short current_row;
	short current_column;

	/* Size of current cell: used especially if current_cell == NULL */
	short current_xstart;
	short current_ystart;
	short current_width;
	short current_height;
	HBSheetCellHeader *h_current_header;
	HBSheetCellHeader *v_current_header;

	/* Used when a block will be marked with a mouseclick */
	short mark_block_mode;

	/* Currently selected cells in sheet */
	short marked_xfrom;
	short marked_xto;
	short marked_yfrom;
	short marked_yto;

	/* Event position for mouse events */
	short evt_xpos;
	short evt_ypos;

	/* Has cursor been set for this widget */
	short global_cursor_set;

	/* How is the sheet currently selected */
	short select_state;
	short last_changed;

	/* Header size */
	int h_left_offset;
	int h_top_offset;
	HBSheetCellHeader *resize_header;

	void leaveEvent( QEvent *evt );
	void mousePressEvent( QMouseEvent *evt );
	void mouseReleaseEvent( QMouseEvent *evt );
	void mouseMoveEvent( QMouseEvent *evt );
	void mouseDoubleClickEvent( QMouseEvent *evt );
	void paintCell( QPainter *p, QString *cell_text, HBSheetCell *cell_data_ptr, const QRect &cr );
	void recalcSheet( void );
	long compileCellSource( char *start_source );
	char *getColumnName( int number );
//	void slotMouseClicked( int x, int y, int button, const QPoint &mouse_pos );

private slots:
	void slotReturnPressed( void );
	void slotTextChanged( const QString &);
	void slotCreateDiagram( void );
	void slotCreateRow( void );
	void slotCreateColumn( void );
	void slotDropRow( void );
	void slotDropColumn( void );
	void slotClearCells( void );
};

/* ##################################################################### */

class CCellLineEdit : public QLineEdit
{
public:
	CCellLineEdit( QWidget *parent );
	void drawContents( QPainter *painter );
};

/* ##################################################################### */

class CSheetItem : public QTableItem
{
public:
	CSheetItem( QTable *parent_table, QString text, HBSheetCell *cell_data );
	HBSheetCell *cell_data_ptr;
	void setEditorProperties( QLineEdit *e, HBSubList *prop_list );
	QWidget *createEditor();

private:
	void paint( QPainter *p, const QColorGroup &cg, const QRect &cd, bool selected );
};

/* ##################################################################### */
/* Derive from Qtable to implement our own paint function */

class CTableWidget : public QTable
{
public:
	CTableWidget( QWidget *parent );

private:
	void paintCell( QPainter *p, int row, int col,
		const QRect &cr, bool selected, const QColorGroup &cg );
};

/* ##################################################################### */

/**
 * class CSheetEditor: Editor widget for calc sheets.
 */

class CSheetEditor : public CWindowListChild
{
	Q_OBJECT

public:
	CSheetEditor( QWidget *parent, HBSheet *cell_data );

	QString name;
	CSourceEditData *cell_contents;

private:
	QVBox *main_container;
	QLineEdit *input_line;
	QLineEdit *le_disp_current;
	QLabel *la_func_img;
	CSheetTableWidget *table_wgt;

	HBSheet *cell_data;
	long prop_width_length;
	QString curr_old_text;

	/* Cell position currently selected for editing. */
	int current_row;
	int current_column;
	int current_changed;
	int input_line_changed;

	/* variables for expression parser. */
	char *parse_cptr;
	int parse_resulttype;
	long parse_int_result;
	double parse_dbl_result;
	char *parse_textresult;
	long int_value[20];    /* long value and string pointer */
	double dbl_value[20];
	int value_type[20];
	int value_pos;

	/* Stack to handle operations on expressions. */
	int oper_pos;
	int oper_stack[20];
	int oper_priority[20];

	void createNumberDesc( HBSheetCellHeader *row_ptr, HBSheetCell *item_ptr, char *cptr );
	void createExpressionDesc( HBSheetCellHeader *row_ptr, HBSheetCell *item_ptr, char *cptr );
	void createTextDesc( HBSheetCellHeader *row_ptr, HBSheetCell *item_ptr, char *cptr );

	void setEditLine( int row, int column );

	long compileCellSource( char *start_source );

	void replaceCellValue( HBSheetCellHeader *row_ptr, HBSheetCell *item_ptr, QString new_text );

	int getCellValue( int row, int column );

	void changeHeaderLabel( void );
	QString getItemText( HBSheetCell *item_ptr, short in_sheet );
	int read_number( int firstsign);
	void recalcSheet( void );
	void resizeEvent( QResizeEvent *evt );

private slots:
	void slotCurrentChanged( int, int );
	void slotValueChanged( int, int );
	void slotTextChanged( const QString &new_text );
	void slotReturnPressed( void );
};

#endif


Generated by: root on linux on Sun Jul 13 18:06:35 2003, using kdoc 2.0a54.