Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonzqt/spreadsheetviewer.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/gutil.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/tframehandle.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <qkeyevent></qkeyevent>
Toshihiro Shimizu 890ddd
#include <qwheelevent></qwheelevent>
Toshihiro Shimizu 890ddd
#include <qlabel></qlabel>
Campbell Barton d0e335
#include <qscrollbar></qscrollbar>
Toshihiro Shimizu 890ddd
#include <qpainter></qpainter>
Toshihiro Shimizu 890ddd
#include <qgridlayout></qgridlayout>
Toshihiro Shimizu 890ddd
#include <qpaintevent></qpaintevent>
Toshihiro Shimizu 890ddd
#include <qtooltip></qtooltip>
Toshihiro Shimizu 890ddd
#include <assert.h></assert.h>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <qmainwindow></qmainwindow>
Toshihiro Shimizu 890ddd
#include <qdockwidget></qdockwidget>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace Spreadsheet
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
FrameScroller::FrameScroller()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FrameScroller::~FrameScroller()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FrameScroller::connectScroller(FrameScroller *scroller)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (scroller != this && !m_connectedScrollers.contains(scroller)) {
Toshihiro Shimizu 890ddd
		m_connectedScrollers.append(scroller);
Toshihiro Shimizu 890ddd
		scroller->connectScroller(this);
Toshihiro Shimizu 890ddd
		QScrollBar *sb0 = getFrameScrollArea()->verticalScrollBar();
Toshihiro Shimizu 890ddd
		QScrollBar *sb1 = scroller->getFrameScrollArea()->verticalScrollBar();
Toshihiro Shimizu 890ddd
		QObject::connect(sb0, SIGNAL(valueChanged(int)), sb1, SLOT(setValue(int)));
Toshihiro Shimizu 890ddd
		QObject::connect(sb1, SIGNAL(valueChanged(int)), sb0, SLOT(setValue(int)));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FrameScroller::disconnectScroller(FrameScroller *scroller)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_connectedScrollers.contains(scroller)) {
Toshihiro Shimizu 890ddd
		m_connectedScrollers.removeAll(scroller);
Toshihiro Shimizu 890ddd
		scroller->disconnectScroller(this);
Toshihiro Shimizu 890ddd
		QScrollBar *sb0 = getFrameScrollArea()->verticalScrollBar();
Toshihiro Shimizu 890ddd
		QScrollBar *sb1 = scroller->getFrameScrollArea()->verticalScrollBar();
Toshihiro Shimizu 890ddd
		QObject::disconnect(sb0, SIGNAL(valueChanged(int)), sb1, SLOT(setValue(int)));
Toshihiro Shimizu 890ddd
		QObject::disconnect(sb1, SIGNAL(valueChanged(int)), sb0, SLOT(setValue(int)));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool FrameScroller::isScrollerConnected(FrameScroller *scroller)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return m_connectedScrollers.contains(scroller);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
static QList<framescroller *=""> frameScrollers;</framescroller>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FrameScroller::registerFrameScroller()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!frameScrollers.contains(this)) {
Toshihiro Shimizu 890ddd
		for (int i = 0; i < frameScrollers.size(); i++)
Toshihiro Shimizu 890ddd
			connectScroller(frameScrollers[i]);
Toshihiro Shimizu 890ddd
		frameScrollers.append(this);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FrameScroller::unregisterFrameScroller()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (frameScrollers.contains(this)) {
Toshihiro Shimizu 890ddd
		frameScrollers.removeAll(this);
Toshihiro Shimizu 890ddd
		for (int i = 0; i < frameScrollers.size(); i++)
Toshihiro Shimizu 890ddd
			disconnectScroller(frameScrollers[i]);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FrameScroller::prepareToScroll(int dy)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (dy == 0)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	for (int i = 0; i < frameScrollers.size(); i++)
Toshihiro Shimizu 890ddd
		if (frameScrollers[i] != this)
Toshihiro Shimizu 890ddd
			frameScrollers[i]->onPrepareToScroll(dy);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SetFrameDragTool::click(int row, int col, QMouseEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_frameHandle->setFrame(row);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SetFrameDragTool::drag(int row, int col, QMouseEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (row < 0)
Toshihiro Shimizu 890ddd
		row = 0;
Toshihiro Shimizu 890ddd
	m_frameHandle->setFrame(row);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SetFrameDragTool::release(int row, int col, QMouseEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// SelectionDragTool
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
SelectionDragTool::SelectionDragTool(SpreadsheetViewer *viewer)
Toshihiro Shimizu 890ddd
	: m_viewer(viewer), m_firstRow(-1), m_firstCol(-1)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SelectionDragTool::click(int row, int col, QMouseEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_firstCol = col;
Toshihiro Shimizu 890ddd
	m_firstRow = row;
Toshihiro Shimizu 890ddd
	QRect selectedCells(col, row, 1, 1);
Toshihiro Shimizu 890ddd
	m_viewer->selectCells(selectedCells);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SelectionDragTool::drag(int row, int col, QMouseEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int r0 = qMin(row, m_firstRow);
Toshihiro Shimizu 890ddd
	int r1 = qMax(row, m_firstRow);
Toshihiro Shimizu 890ddd
	int c0 = qMin(col, m_firstCol);
Toshihiro Shimizu 890ddd
	int c1 = qMax(col, m_firstCol);
Toshihiro Shimizu 890ddd
	QRect selectedCells(c0, r0, c1 - c0 + 1, r1 - r0 + 1);
Toshihiro Shimizu 890ddd
	m_viewer->selectCells(selectedCells);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SelectionDragTool::release(int row, int col, QMouseEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
PanTool::PanTool(Spreadsheet::GenericPanel *panel)
Toshihiro Shimizu 890ddd
	: m_panel(panel), m_viewer(panel->getViewer()), m_lastPos()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void PanTool::click(int row, int col, QMouseEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_lastPos = e->pos(); // m_panel->mapToGlobal(e->pos());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
void PanTool::drag(int row, int col, QMouseEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QPoint pos = e->pos(); // m_panel->mapToGlobal(e->pos());
Toshihiro Shimizu 890ddd
	//QPoint delta = p - m_lastPos;
Toshihiro Shimizu 890ddd
	//m_lastPos = p;
Toshihiro Shimizu 890ddd
	// QToolTip::showText(p,"delta="+QString::number(delta.x())+","+QString::number(delta.y()));
Toshihiro Shimizu 890ddd
	m_viewer->scroll(m_lastPos - pos);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
void PanTool::release(int row, int col, QMouseEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	//QToolTip::hideText();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#if QT_VERSION >= 0x050500
Toshihiro Shimizu 890ddd
ScrollArea::ScrollArea(QWidget *parent, Qt::WindowFlags flags)
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
ScrollArea::ScrollArea(QWidget *parent, Qt::WFlags flags)
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
	: QScrollArea(parent)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	setFrameStyle(QFrame::Panel | QFrame::Raised);
Toshihiro Shimizu 890ddd
	setLineWidth(6);
Toshihiro Shimizu 890ddd
	setContentsMargins(10, 10, 10, 10);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ScrollArea::~ScrollArea()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ScrollArea::keyPressEvent(QKeyEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	e->ignore();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ScrollArea::wheelEvent(QWheelEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	e->ignore();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
GenericPanel::GenericPanel(SpreadsheetViewer *viewer)
Toshihiro Shimizu 890ddd
	: QWidget(viewer), m_viewer(viewer), m_dragTool(0)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	setFocusPolicy(Qt::NoFocus);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
GenericPanel::~GenericPanel()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void GenericPanel::paintEvent(QPaintEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QPainter p(this);
Toshihiro Shimizu 890ddd
	p.setPen(m_viewer->getLightLineColor());
Toshihiro Shimizu 890ddd
	for (int c = 0;; c++) {
Toshihiro Shimizu 890ddd
		int x = getViewer()->columnToX(c);
Toshihiro Shimizu 890ddd
		if (x > width())
Toshihiro Shimizu 890ddd
			break;
Toshihiro Shimizu 890ddd
		p.drawLine(x, 0, x, height());
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	for (int r = 0;; r++) {
Toshihiro Shimizu 890ddd
		int y = getViewer()->rowToY(r);
Toshihiro Shimizu 890ddd
		if (y > height())
Toshihiro Shimizu 890ddd
			break;
Toshihiro Shimizu 890ddd
		p.drawLine(0, y, width(), y);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	p.setPen(Qt::magenta);
Toshihiro Shimizu 890ddd
	p.drawLine(e->rect().topLeft(), e->rect().bottomRight());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void GenericPanel::mousePressEvent(QMouseEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(!m_dragTool);
Toshihiro Shimizu 890ddd
	if (e->button() == Qt::MidButton)
Toshihiro Shimizu 890ddd
		m_dragTool = new PanTool(this);
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		m_dragTool = createDragTool(e);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int row = getViewer()->yToRow(e->pos().y());
Toshihiro Shimizu 890ddd
	int col = getViewer()->xToColumn(e->pos().x());
Toshihiro Shimizu 890ddd
	if (m_dragTool)
Toshihiro Shimizu 890ddd
		m_dragTool->click(row, col, e);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void GenericPanel::mouseReleaseEvent(QMouseEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int row = getViewer()->yToRow(e->pos().y());
Toshihiro Shimizu 890ddd
	int col = getViewer()->xToColumn(e->pos().x());
Toshihiro Shimizu 890ddd
	m_viewer->stopAutoPan();
Toshihiro Shimizu 890ddd
	if (m_dragTool) {
Toshihiro Shimizu 890ddd
		m_dragTool->release(row, col, e);
Toshihiro Shimizu 890ddd
		delete m_dragTool;
Toshihiro Shimizu 890ddd
		m_dragTool = 0;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void GenericPanel::mouseMoveEvent(QMouseEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int row = getViewer()->yToRow(e->pos().y());
Toshihiro Shimizu 890ddd
	int col = getViewer()->xToColumn(e->pos().x());
Toshihiro Shimizu 890ddd
	if (e->buttons() != 0 && m_dragTool != 0) {
Toshihiro Shimizu 890ddd
		if ((e->buttons() & Qt::LeftButton) != 0 && !visibleRegion().contains(e->pos())) {
Toshihiro Shimizu 890ddd
			QRect bounds = visibleRegion().boundingRect();
Toshihiro Shimizu 890ddd
			m_viewer->setAutoPanSpeed(bounds, e->pos());
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			m_viewer->stopAutoPan();
Toshihiro Shimizu 890ddd
		m_dragTool->drag(row, col, e);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
RowPanel::RowPanel(SpreadsheetViewer *viewer)
Toshihiro Shimizu 890ddd
	: GenericPanel(viewer), m_xa(12)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
DragTool *RowPanel::createDragTool(QMouseEvent *)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TFrameHandle *frameHandle = getViewer()->getFrameHandle();
Toshihiro Shimizu 890ddd
	if (frameHandle)
Toshihiro Shimizu 890ddd
		return new SetFrameDragTool(frameHandle);
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void RowPanel::drawRows(QPainter &p, int r0, int r1)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
#ifdef WIN32
Toshihiro Shimizu 890ddd
	static QFont font("Arial", 9, QFont::Bold);
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
	static QFont font("Helvetica", 9, QFont::Bold);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
	p.setFont(font);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QRect visibleRect = visibleRegion().boundingRect();
Toshihiro Shimizu 890ddd
	int x0 = visibleRect.left();
Toshihiro Shimizu 890ddd
	int x1 = visibleRect.right();
Toshihiro Shimizu 890ddd
	int y0 = visibleRect.top();
Toshihiro Shimizu 890ddd
	int y1 = visibleRect.bottom();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int r;
Toshihiro Shimizu 890ddd
	for (r = r0; r <= r1; r++) {
Toshihiro Shimizu 890ddd
		int y = getViewer()->rowToY(r);
Toshihiro Shimizu 890ddd
		//draw horizontal line
Toshihiro Shimizu 890ddd
		QColor color = (getViewer()->isMarkRow(r)) ? getViewer()->getMarkerLineColor() : getViewer()->getLightLineColor();
Toshihiro Shimizu 890ddd
		p.setPen(color);
Toshihiro Shimizu 890ddd
		p.drawLine(x0, y, x1, y);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		//draw numbers
Toshihiro Shimizu 890ddd
		p.setPen(getViewer()->getTextColor());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		QString number = QString::number(r + 1);
Toshihiro Shimizu 890ddd
		p.drawText(QRect(x0, y + 1, width(), 18), Qt::AlignHCenter | Qt::AlignBottom, number);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	// erase the marker interval at upper-end
Toshihiro Shimizu 890ddd
	if (r0 == 0) {
Toshihiro Shimizu 890ddd
		p.setPen(getViewer()->getLightLineColor());
Toshihiro Shimizu 890ddd
		p.drawLine(x0, getViewer()->rowToY(0), x1, getViewer()->rowToY(0));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void RowPanel::drawCurrentRowGadget(QPainter &p, int r0, int r1)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int currentRow = getViewer()->getCurrentRow();
Toshihiro Shimizu 890ddd
	int y = getViewer()->rowToY(currentRow);
Toshihiro Shimizu 890ddd
	if (currentRow < r0 || r1 < currentRow)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	p.fillRect(1, y + 1, width() - 2, 19, getViewer()->getCurrentRowBgColor());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void RowPanel::paintEvent(QPaintEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QRect toBeUpdated = e->rect();
Toshihiro Shimizu 890ddd
	QPainter p(this);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// range di righe visibili
Toshihiro Shimizu 890ddd
	int r0 = getViewer()->yToRow(toBeUpdated.top());
Toshihiro Shimizu 890ddd
	int r1 = getViewer()->yToRow(toBeUpdated.bottom());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	p.setClipRect(toBeUpdated);
Toshihiro Shimizu 890ddd
	p.fillRect(toBeUpdated, QBrush(getViewer()->getLightLightBGColor()));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	drawCurrentRowGadget(p, r0, r1);
Toshihiro Shimizu 890ddd
	drawRows(p, r0, r1);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ColumnPanel::ColumnPanel(SpreadsheetViewer *viewer)
Toshihiro Shimizu 890ddd
	: GenericPanel(viewer)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
CellPanel::CellPanel(SpreadsheetViewer *viewer)
Toshihiro Shimizu 890ddd
	: GenericPanel(viewer)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
DragTool *CellPanel::createDragTool(QMouseEvent *)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	// FunctionSheetCellViewer::createDragTool is called instead
Toshihiro Shimizu 890ddd
	// when clicking on the CellPanel in NumericalColumns
Toshihiro Shimizu 890ddd
	return new SelectionDragTool(getViewer());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CellPanel::paintEvent(QPaintEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QPainter painter(this);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QRect toBeUpdated = e->rect();
Toshihiro Shimizu 890ddd
	painter.setClipRect(toBeUpdated);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int x0 = toBeUpdated.left() - 1;
Toshihiro Shimizu 890ddd
	int y0 = toBeUpdated.top();
Toshihiro Shimizu 890ddd
	int x1 = toBeUpdated.right(), y1 = toBeUpdated.bottom();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// visible rows range
Toshihiro Shimizu 890ddd
	int r0 = getViewer()->yToRow(y0);
Toshihiro Shimizu 890ddd
	int r1 = getViewer()->yToRow(y1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// visible columns range
Toshihiro Shimizu 890ddd
	int c0 = getViewer()->xToColumn(x0);
Toshihiro Shimizu 890ddd
	int c1 = getViewer()->xToColumn(x1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// cambia colore alle celle prima di rowCount()
Toshihiro Shimizu 890ddd
	int rowCount = getViewer()->getRowCount();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//fill with bg color
Toshihiro Shimizu 890ddd
	painter.fillRect(toBeUpdated, getViewer()->getLightLightBGColor());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//scene range bg
Toshihiro Shimizu 890ddd
	int yLast = getViewer()->rowToY(rowCount);
Toshihiro Shimizu 890ddd
	if (yLast < y1)
Toshihiro Shimizu 890ddd
		painter.fillRect(x0, y0, x1 - x0, yLast - y0, getViewer()->getBGColor());
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		painter.fillRect(toBeUpdated, getViewer()->getBGColor());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//draw cells
Toshihiro Shimizu 890ddd
	drawCells(painter, r0, c0, r1, c1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// draw columns
Toshihiro Shimizu 890ddd
	painter.setPen(getViewer()->getVerticalLineColor());
Toshihiro Shimizu 890ddd
	for (int col = c0; col <= c1; col++) {
Toshihiro Shimizu 890ddd
		int x = getViewer()->columnToX(col);
Toshihiro Shimizu 890ddd
		painter.drawLine(x, y0, x, y1);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// draw rows
Toshihiro Shimizu 890ddd
	int currentRow = getViewer()->getCurrentRow();
Toshihiro Shimizu 890ddd
	for (int r = r0; r <= r1; r++) {
Toshihiro Shimizu 890ddd
		int y = getViewer()->rowToY(r);
Toshihiro Shimizu 890ddd
		QColor color = getViewer()->isMarkRow(r) ? getViewer()->getMarkerLineColor() : getViewer()->getLightLineColor();
Toshihiro Shimizu 890ddd
		painter.setPen(color);
Toshihiro Shimizu 890ddd
		painter.drawLine(x0, y, x1, y);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	// erase the marker interval at upper-end
Toshihiro Shimizu 890ddd
	painter.setPen(getViewer()->getLightLineColor());
Toshihiro Shimizu 890ddd
	painter.drawLine(x0, 0, x1, 0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} // namespace Spreadsheet
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
SpreadsheetViewer::SpreadsheetViewer(QWidget *parent)
Toshihiro Shimizu 890ddd
	: QFrame(parent), m_columnScrollArea(0), m_rowScrollArea(0), m_cellScrollArea(0), m_frameHandle(0), m_columnWidth(50), m_rowHeight(20), m_timerId(0), m_autoPanSpeed(0, 0), m_lastAutoPanPos(0, 0), m_rowCount(0), m_columnCount(0), m_currentRow(0), m_markRowDistance(6), m_markRowOffset(0), m_isComputingSize(false)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	setFocusPolicy(Qt::NoFocus);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	setFrameStyle(QFrame::StyledPanel);
Toshihiro Shimizu 890ddd
	setObjectName("Viewer");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//column header
Toshihiro Shimizu 890ddd
	m_columnScrollArea = new Spreadsheet::ScrollArea;
Toshihiro Shimizu 890ddd
	m_columnScrollArea->setObjectName("ScrollArea");
Toshihiro Shimizu 890ddd
	m_columnScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
Toshihiro Shimizu 890ddd
	m_columnScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
Toshihiro Shimizu 890ddd
	m_columnScrollArea->setFocusPolicy(Qt::NoFocus);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//row area
Toshihiro Shimizu 890ddd
	m_rowScrollArea = new Spreadsheet::ScrollArea;
Toshihiro Shimizu 890ddd
	m_rowScrollArea->setObjectName("ScrollArea");
Toshihiro Shimizu 890ddd
	m_rowScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
Toshihiro Shimizu 890ddd
	m_rowScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
Toshihiro Shimizu 890ddd
	m_rowScrollArea->setFocusPolicy(Qt::NoFocus);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//cell area
Toshihiro Shimizu 890ddd
	m_cellScrollArea = new Spreadsheet::ScrollArea;
Toshihiro Shimizu 890ddd
	m_cellScrollArea->setObjectName("ScrollArea");
Toshihiro Shimizu 890ddd
	m_cellScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
Toshihiro Shimizu 890ddd
	m_cellScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
Toshihiro Shimizu 890ddd
	m_cellScrollArea->horizontalScrollBar()->setObjectName("XsheetScrollBar");
Toshihiro Shimizu 890ddd
	m_cellScrollArea->verticalScrollBar()->setObjectName("XsheetScrollBar");
Toshihiro Shimizu 890ddd
	m_cellScrollArea->setFocusPolicy(Qt::NoFocus);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_columnScrollArea->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed));
Toshihiro Shimizu 890ddd
	m_rowScrollArea->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Ignored));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_rowScrollArea->setFixedWidth(30);
Toshihiro Shimizu 890ddd
	m_columnScrollArea->setFixedHeight(m_rowHeight * 3 - 3);
Toshihiro Shimizu 890ddd
	//m_columnScrollArea->setFixedHeight(m_rowHeight * 3 + 60 - 63);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//---- layout
Toshihiro Shimizu 890ddd
	QGridLayout *layout = new QGridLayout();
Toshihiro Shimizu 890ddd
	layout->setMargin(0);
Toshihiro Shimizu 890ddd
	layout->setSpacing(0);
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		layout->addWidget(m_columnScrollArea, 0, 1);
Toshihiro Shimizu 890ddd
		layout->addWidget(m_rowScrollArea, 1, 0);
Toshihiro Shimizu 890ddd
		layout->addWidget(m_cellScrollArea, 1, 1, 2, 2);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		//upper-right
Toshihiro Shimizu 890ddd
		QWidget *w = new QWidget(this);
Toshihiro Shimizu 890ddd
		w->setFixedSize(QSize(20, m_rowHeight * 3 + 60 - 63));
Toshihiro Shimizu 890ddd
		layout->addWidget(w, 0, 2);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		//lower-left
Toshihiro Shimizu 890ddd
		w = new QWidget(this);
Toshihiro Shimizu 890ddd
		w->setFixedSize(QSize(30, 20));
Toshihiro Shimizu 890ddd
		layout->addWidget(w, 2, 0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		layout->setColumnStretch(0, 0);
Toshihiro Shimizu 890ddd
		layout->setColumnStretch(1, 1);
Toshihiro Shimizu 890ddd
		layout->setColumnStretch(2, 0);
Toshihiro Shimizu 890ddd
		layout->setRowStretch(0, 0);
Toshihiro Shimizu 890ddd
		layout->setRowStretch(1, 1);
Toshihiro Shimizu 890ddd
		layout->setRowStretch(2, 0);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	setLayout(layout);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//---signal-slot connections
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// vertical slider: cell <=> row
Toshihiro Shimizu 890ddd
	connect(m_rowScrollArea->verticalScrollBar(), SIGNAL(valueChanged(int)),
Toshihiro Shimizu 890ddd
			m_cellScrollArea->verticalScrollBar(), SLOT(setValue(int)));
Toshihiro Shimizu 890ddd
	connect(m_cellScrollArea->verticalScrollBar(), SIGNAL(valueChanged(int)),
Toshihiro Shimizu 890ddd
			m_rowScrollArea->verticalScrollBar(), SLOT(setValue(int)));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// horizontal slider: cell <=> column
Toshihiro Shimizu 890ddd
	connect(m_columnScrollArea->horizontalScrollBar(), SIGNAL(valueChanged(int)),
Toshihiro Shimizu 890ddd
			m_cellScrollArea->horizontalScrollBar(), SLOT(setValue(int)));
Toshihiro Shimizu 890ddd
	connect(m_cellScrollArea->horizontalScrollBar(), SIGNAL(valueChanged(int)),
Toshihiro Shimizu 890ddd
			m_columnScrollArea->horizontalScrollBar(), SLOT(setValue(int)));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	connect(m_cellScrollArea->verticalScrollBar(), SIGNAL(valueChanged(int)),
Toshihiro Shimizu 890ddd
			SLOT(onVSliderChanged(int)));
Toshihiro Shimizu 890ddd
	connect(m_cellScrollArea->horizontalScrollBar(), SIGNAL(valueChanged(int)),
Toshihiro Shimizu 890ddd
			SLOT(onHSliderChanged(int)));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
SpreadsheetViewer::~SpreadsheetViewer()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SpreadsheetViewer::setFrameHandle(TFrameHandle *frameHandle)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_frameHandle == frameHandle)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	if (m_frameHandle)
Toshihiro Shimizu 890ddd
		m_frameHandle->disconnect(this);
Toshihiro Shimizu 890ddd
	m_frameHandle = frameHandle;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (isVisible() && m_frameHandle) {
Toshihiro Shimizu 890ddd
		connect(m_frameHandle, SIGNAL(frameSwitched()), this, SLOT(onFrameSwitched()));
Toshihiro Shimizu 890ddd
		update();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SpreadsheetViewer::setRowsPanel(Spreadsheet::RowPanel *rows)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_rowScrollArea->setWidget(rows);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SpreadsheetViewer::setColumnsPanel(Spreadsheet::ColumnPanel *columns)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_columnScrollArea->setWidget(columns);
Toshihiro Shimizu 890ddd
	// columns->setFixedHeight(200);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SpreadsheetViewer::setCellsPanel(Spreadsheet::CellPanel *cells)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_cellScrollArea->setWidget(cells);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SpreadsheetViewer::setRowCount(int rowCount)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_rowCount != rowCount) {
Toshihiro Shimizu 890ddd
		m_rowCount = rowCount;
Toshihiro Shimizu 890ddd
		refreshContentSize(0, 0);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SpreadsheetViewer::setColumnCount(int columnCount)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_columnCount != columnCount) {
Toshihiro Shimizu 890ddd
		m_columnCount = columnCount;
Toshihiro Shimizu 890ddd
		refreshContentSize(0, 0);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SpreadsheetViewer::scroll(QPoint delta)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	refreshContentSize(delta.x(), delta.y());
Toshihiro Shimizu 890ddd
	prepareToScroll(delta.y());
Toshihiro Shimizu 890ddd
	if (delta.y() != 0) {
Toshihiro Shimizu 890ddd
		QScrollBar *vSc = m_cellScrollArea->verticalScrollBar();
Toshihiro Shimizu 890ddd
		vSc->setValue(vSc->value() + delta.y());
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (delta.x() != 0) {
Toshihiro Shimizu 890ddd
		QScrollBar *hSc = m_cellScrollArea->horizontalScrollBar();
Toshihiro Shimizu 890ddd
		hSc->setValue(hSc->value() + delta.x());
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SpreadsheetViewer::setAutoPanSpeed(const QPoint &speed)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	bool wasAutoPanning = isAutoPanning();
Toshihiro Shimizu 890ddd
	m_autoPanSpeed = speed;
Toshihiro Shimizu 890ddd
	if (isAutoPanning() && !wasAutoPanning && m_timerId == 0)
Toshihiro Shimizu 890ddd
		m_timerId = startTimer(40);
Toshihiro Shimizu 890ddd
	else if (!isAutoPanning() && wasAutoPanning && m_timerId != 0) {
Toshihiro Shimizu 890ddd
		killTimer(m_timerId);
Toshihiro Shimizu 890ddd
		m_timerId = 0;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int getAutoPanSpeed(int pixels)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int f = 40;
Toshihiro Shimizu 890ddd
	return tmin(100, (f - 1 + pixels * f) / 100);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SpreadsheetViewer::setAutoPanSpeed(const QRect &widgetBounds, const QPoint &mousePos)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QPoint speed;
Toshihiro Shimizu 890ddd
	int limit = 100, factor = 30;
Toshihiro Shimizu 890ddd
	if (mousePos.x() < widgetBounds.left())
Toshihiro Shimizu 890ddd
		speed.setX(-getAutoPanSpeed(widgetBounds.left() - mousePos.x()));
Toshihiro Shimizu 890ddd
	else if (mousePos.x() > widgetBounds.right())
Toshihiro Shimizu 890ddd
		speed.setX(getAutoPanSpeed(mousePos.x() - widgetBounds.right()));
Toshihiro Shimizu 890ddd
	if (mousePos.y() < widgetBounds.top())
Toshihiro Shimizu 890ddd
		speed.setY(-getAutoPanSpeed(widgetBounds.top() - mousePos.y()));
Toshihiro Shimizu 890ddd
	else if (mousePos.y() > widgetBounds.bottom())
Toshihiro Shimizu 890ddd
		speed.setY(getAutoPanSpeed(mousePos.y() - widgetBounds.bottom()));
Toshihiro Shimizu 890ddd
	setAutoPanSpeed(speed);
Toshihiro Shimizu 890ddd
	m_lastAutoPanPos = mousePos;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!Shift is a consequence of style sheet border.*/
Toshihiro Shimizu 890ddd
int SpreadsheetViewer::xToColumn(int x) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return (x + 1) / m_columnWidth;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!Shift is a consequence of style sheet border.*/
Toshihiro Shimizu 890ddd
int SpreadsheetViewer::columnToX(int col) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return (col * m_columnWidth) - 1;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!Shift is a consequence of style sheet border.*/
Toshihiro Shimizu 890ddd
int SpreadsheetViewer::yToRow(int y) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return (y + 1) / m_rowHeight;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!Shift is a consequence of style sheet border.*/
Toshihiro Shimizu 890ddd
int SpreadsheetViewer::rowToY(int row) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return (row * m_rowHeight) - 1;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool SpreadsheetViewer::refreshContentSize(int scrollDx, int scrollDy)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QSize viewportSize = m_cellScrollArea->viewport()->size();
Toshihiro Shimizu 890ddd
	QPoint offset = m_cellScrollArea->widget()->pos();
Toshihiro Shimizu 890ddd
	offset = QPoint(qMin(0, offset.x() - scrollDx), qMin(0, offset.y() - scrollDy));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QSize contentSize(columnToX(m_columnCount + 1), rowToY(m_rowCount + 1));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QSize actualSize(contentSize);
Toshihiro Shimizu 890ddd
	int x = viewportSize.width() - offset.x();
Toshihiro Shimizu 890ddd
	int y = viewportSize.height() - offset.y();
Toshihiro Shimizu 890ddd
	if (x > actualSize.width())
Toshihiro Shimizu 890ddd
		actualSize.setWidth(x);
Toshihiro Shimizu 890ddd
	if (y > actualSize.height())
Toshihiro Shimizu 890ddd
		actualSize.setHeight(y);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (actualSize == m_cellScrollArea->widget()->size())
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
	else {
Toshihiro Shimizu 890ddd
		m_isComputingSize = true;
Toshihiro Shimizu 890ddd
		m_cellScrollArea->widget()->setFixedSize(actualSize);
Toshihiro Shimizu 890ddd
		m_rowScrollArea->widget()->setFixedSize(
Toshihiro Shimizu 890ddd
			m_rowScrollArea->viewport()->width(),
Toshihiro Shimizu 890ddd
			actualSize.height());
Toshihiro Shimizu 890ddd
		m_columnScrollArea->widget()->setFixedSize(
Toshihiro Shimizu 890ddd
			actualSize.width(),
Toshihiro Shimizu 890ddd
			m_columnScrollArea->viewport()->height());
Toshihiro Shimizu 890ddd
		m_isComputingSize = false;
Toshihiro Shimizu 890ddd
		return true;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SpreadsheetViewer::showEvent(QShowEvent *)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int viewportHeight = m_cellScrollArea->height();
Toshihiro Shimizu 890ddd
	int contentHeight = rowToY(m_rowCount * 0 + 50);
Toshihiro Shimizu 890ddd
	QScrollBar *vSc = m_cellScrollArea->verticalScrollBar();
Toshihiro Shimizu 890ddd
	int actualContentHeight = qMax(contentHeight, vSc->value() + viewportHeight);
Toshihiro Shimizu 890ddd
	m_rowScrollArea->widget()->setFixedHeight(actualContentHeight);
Toshihiro Shimizu 890ddd
	m_cellScrollArea->widget()->setFixedHeight(actualContentHeight);
Toshihiro Shimizu 890ddd
	if (m_frameHandle)
Toshihiro Shimizu 890ddd
		connect(m_frameHandle, SIGNAL(frameSwitched()), this, SLOT(onFrameSwitched()));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// updateAreasSize();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SpreadsheetViewer::hideEvent(QHideEvent *)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_frameHandle)
Toshihiro Shimizu 890ddd
		m_frameHandle->disconnect(this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SpreadsheetViewer::resizeEvent(QResizeEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QFrame::resizeEvent(e);
Toshihiro Shimizu 890ddd
	refreshContentSize(0, 0);
Toshihiro Shimizu 890ddd
	/*
Toshihiro Shimizu 890ddd
	int w = width();
Toshihiro Shimizu 890ddd
	int h = height();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  int hSpacing = 4;
Toshihiro Shimizu 890ddd
  int vSpacing = 4;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  int x = m_rowScrollAreaWidth + hSpacing;
Toshihiro Shimizu 890ddd
  int y = m_columnScrollAreaHeight + vSpacing;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_cellScrollArea->setGeometry(x,y, w-x, h-y);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  int sh = m_cellScrollArea->horizontalScrollBar()->height();
Toshihiro Shimizu 890ddd
  int sw = m_cellScrollArea->verticalScrollBar()->width();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_columnScrollArea->setGeometry(x, 0, w-x-sw, m_columnScrollAreaHeight);
Toshihiro Shimizu 890ddd
  m_rowScrollArea->setGeometry(0, y, m_rowScrollAreaWidth, h-y-sh);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  updateSizeToScroll(0,0); //Non updateAreeSize() perche' si deve tener conto degli scrollbar.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SpreadsheetViewer::wheelEvent(QWheelEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	scroll(QPoint(0, -e->delta()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SpreadsheetViewer::timerEvent(QTimerEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!isAutoPanning())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	scroll(m_autoPanSpeed);
Toshihiro Shimizu 890ddd
	m_lastAutoPanPos += m_autoPanSpeed;
Toshihiro Shimizu 890ddd
	/*
Toshihiro Shimizu 890ddd
  if(m_dragTool)
Toshihiro Shimizu 890ddd
  {
Toshihiro Shimizu 890ddd
    QMouseEvent mouseEvent(QEvent::MouseMove, m_lastAutoPanPos, Qt::NoButton, 0, 0);
Toshihiro Shimizu 890ddd
    m_dragTool->onDrag(&mouseEvent);
Toshihiro Shimizu 890ddd
  }
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SpreadsheetViewer::keyPressEvent(QKeyEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int frameCount = m_rowCount;
Toshihiro Shimizu 890ddd
	int row = m_frameHandle->getFrame();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (e->key() == Qt::Key_Up && row > 0) { //Row = frame precedente a quello settato
Toshihiro Shimizu 890ddd
		m_frameHandle->setFrame(row - 1);
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	} else if (e->key() == Qt::Key_Down) { //Row = frame successivo a quello settato
Toshihiro Shimizu 890ddd
		m_frameHandle->setFrame(row + 1);
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	} else if (e->key() == '0') {
Toshihiro Shimizu 890ddd
		QWidget *panel = parentWidget();
Toshihiro Shimizu 890ddd
		QWidget *panelParent = panel->parentWidget();
Toshihiro Shimizu 890ddd
		while (panelParent != 0 && dynamic_cast<qmainwindow *="">(panelParent) == 0) {</qmainwindow>
Toshihiro Shimizu 890ddd
			panel = panelParent;
Toshihiro Shimizu 890ddd
			panelParent = panel->parentWidget();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		if (panelParent) {
Toshihiro Shimizu 890ddd
			QList<qdockwidget *=""> panels = panelParent->findChildren<qdockwidget *="">();</qdockwidget></qdockwidget>
Toshihiro Shimizu 890ddd
			for (int i = 0; i < panels.size(); i++) {
Toshihiro Shimizu 890ddd
				QWidget *w = panels[i];
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int y = 0;
Toshihiro Shimizu 890ddd
	QRect visibleRect = m_cellScrollArea->widget()->visibleRegion().boundingRect();
Toshihiro Shimizu 890ddd
	int visibleRowCount = visibleRect.height() / m_rowHeight;
Toshihiro Shimizu 890ddd
	if (e->key() == Qt::Key_PageUp) //Setto la visualizzazione della pagina precedente
Toshihiro Shimizu 890ddd
		y = visibleRect.top() - (visibleRowCount + 1) * m_rowHeight;
Toshihiro Shimizu 890ddd
	else if (e->key() == Qt::Key_PageDown) //Setto la visualizzazione della pagina successiva
Toshihiro Shimizu 890ddd
		y = visibleRect.bottom() + (visibleRowCount + 1) * m_rowHeight;
Toshihiro Shimizu 890ddd
	else if (e->key() == Qt::Key_Home)
Toshihiro Shimizu 890ddd
		y = 0;
Toshihiro Shimizu 890ddd
	else if (e->key() == Qt::Key_End)
Toshihiro Shimizu 890ddd
		y = (frameCount + 1) * m_rowHeight;
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int deltaY = 0;
Toshihiro Shimizu 890ddd
	if (y < visibleRect.top())
Toshihiro Shimizu 890ddd
		deltaY = y - visibleRect.top();
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		deltaY = y - visibleRect.bottom();
Toshihiro Shimizu 890ddd
	scroll(QPoint(0, deltaY));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SpreadsheetViewer::frameSwitched()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
void SpreadsheetViewer::updateAllAree()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SpreadsheetViewer::updateCellColumnAree()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SpreadsheetViewer::updateCellRowAree()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SpreadsheetViewer::updateAreas()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SpreadsheetViewer::onVSliderChanged(int)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_isComputingSize)
Toshihiro Shimizu 890ddd
		refreshContentSize(0, 0);
Toshihiro Shimizu 890ddd
	/*
Toshihiro Shimizu 890ddd
  QScrollBar *vSc = m_cellScrollArea->verticalScrollBar();
Toshihiro Shimizu 890ddd
  int h = qMax(vSc->value() + m_cellScrollArea->height(), rowToY(getRowCount()));
Toshihiro Shimizu 890ddd
  if(m_cellScrollArea->widget())
Toshihiro Shimizu 890ddd
    m_cellScrollArea->widget()->setFixedHeight(h);
Toshihiro Shimizu 890ddd
  if(m_rowScrollArea->widget())
Toshihiro Shimizu 890ddd
    m_rowScrollArea->widget()->setFixedHeight(h);
Toshihiro Shimizu 890ddd
    */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*
Toshihiro Shimizu 890ddd
  int viewportHeight = m_cellScrollArea->height();
Toshihiro Shimizu 890ddd
  int contentHeight = rowToY(m_rowCount*0 + 50);
Toshihiro Shimizu 890ddd
  QScrollBar *vSc = m_cellScrollArea->verticalScrollBar();
Toshihiro Shimizu 890ddd
  int actualContentHeight = qMax(contentHeight, vSc->value() + viewportHeight);
Toshihiro Shimizu 890ddd
  m_rowScrollArea->widget()->setFixedHeight(actualContentHeight);
Toshihiro Shimizu 890ddd
  m_cellScrollArea->widget()->setFixedHeight(actualContentHeight);
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SpreadsheetViewer::onHSliderChanged(int)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_isComputingSize)
Toshihiro Shimizu 890ddd
		refreshContentSize(0, 0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SpreadsheetViewer::ensureVisibleCol(int col)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int x = columnToX(col) + m_columnWidth / 2;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int vertValue = m_cellScrollArea->verticalScrollBar()->value();
Toshihiro Shimizu 890ddd
	m_cellScrollArea->ensureVisible(x, vertValue, m_columnWidth / 2, 0);
Toshihiro Shimizu 890ddd
}