tahoma2d/toonz/sources/toonzfarm/tfarmclient/tgrid.h

132 lines
3.3 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef TGRID_H
#define TGRID_H
#include "tcolumnset.h"
#include "tw/tw.h"
#include "tw/scrollbar.h"
//-------------------------------------------------------------------
//-------------------------------------------------------------------
//-------------------------------------------------------------------
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class TGenericGridAction {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
virtual ~TGenericGridAction() {}
virtual void sendCommand(int item) = 0;
2016-03-19 06:57:51 +13:00
};
//-------------------------------------------------------------------
template <class T>
2016-06-15 18:43:10 +12:00
class TGridAction : public TGenericGridAction {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
typedef void (T::*Method)(int item);
TGridAction(T *target, Method method) : m_target(target), m_method(method) {}
void sendCommand(int item) { (m_target->*m_method)(item); }
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
T *m_target;
Method m_method;
2016-03-19 06:57:51 +13:00
};
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class TGridCell {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TGridCell() {}
TGridCell(const string &text) : m_text(text) {}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
string m_text;
2016-03-19 06:57:51 +13:00
};
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class TGridColumn : public TColumnHeader {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
enum Alignment { LeftAlignment, CenterAlignment, RightAlignment };
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TGridColumn(const string &name = "", Alignment alignment = CenterAlignment);
~TGridColumn();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
static TGridColumn *createEmpty();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int getRowCount() const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
const TGridCell &getCell(int row) const;
void setCell(int row, const TGridCell &cell);
void setCell(int row, const string &text) { setCell(row, TGridCell(text)); }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void getCells(int row, int rowCount, TGridCell cells[]);
void setCells(int row, int rowCount, const TGridCell cells[]);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void insertEmptyCells(int row, int rowCount = 1);
void removeCells(int row, int rowCount = 1);
void clearCells(int row, int rowCount = 1);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
string getName() const;
Alignment getAlignment() const;
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
class Imp;
Imp *m_imp;
2016-03-19 06:57:51 +13:00
};
typedef TSmartPointerT<TGridColumn> TGridColumnP;
//-------------------------------------------------------------------
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class TGrid : public TWidget {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TGrid(TWidget *parent, string name = "grid");
~TGrid();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void addColumn(const string &name, int width,
TGridColumn::Alignment align = TGridColumn::CenterAlignment);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void addRow();
void removeRow(int row);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int getColIndex(const string &colName);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setCell(int row, int col, const string &text);
string getCell(int row, int col);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int getColCount() const;
int getRowCount() const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int getSelectedRowCount() const;
int getSelectedRowIndex(
int i) const; // returns the index of the i-th item selected
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void select(int row, bool on);
void unselectAll();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool isSelected(int row) const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setSelAction(TGenericGridAction *action);
void setDblClickAction(TGenericGridAction *action);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void draw();
void configureNotify(const TDimension &d);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void leftButtonDown(const TMouseEvent &e);
void leftButtonDrag(const TMouseEvent &e);
void leftButtonUp(const TMouseEvent &e);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
/*
void leftButtonDoubleClick(const TMouseEvent &e);
void keyDown(int key, unsigned long mod, const TPoint &);
2016-03-19 06:57:51 +13:00
*/
2016-06-15 18:43:10 +12:00
void scrollTo(int y);
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
class Data;
Data *m_data;
2016-03-19 06:57:51 +13:00
};
#endif