Milo  0.1
Milo:EquationManipulationProgram
Static Public Attributes | Private Attributes | Static Private Attributes | List of all members
UI::EqnPanel Class Reference

#include <panel.h>

Inheritance diagram for UI::EqnPanel:
Inheritance graph
[legend]
Collaboration diagram for UI::EqnPanel:
Collaboration graph
[legend]

Public Types

EqnPanel function pointer declerations.
using key_handler = bool(*)(EqnPanel &, const KeyEvent &)
 
using mouse_handler = bool(*)(EqnPanel &, const MouseEvent &)
 
using menu_handler = bool(*)(EqnPanel &)
 

Public Member Functions

Constructors and Virtual Desctructor
 EqnPanel ()
 
 EqnPanel (std::istream &is)
 
 EqnPanel (const std::string &eq)
 
 ~EqnPanel ()
 Virtual desctructor.
 
Virtual Public Member Functions
void doKey (const KeyEvent &key)
 
void doMouse (const MouseEvent &mouse)
 
bool doMenu (const std::string &menuFunctionName)
 
void doDraw ()
 
void pushUndo ()
 
void popUndo ()
 
void saveState (std::ostream &fs)
 
void loadState (std::istream &is)
 
bool blink ()
 
void getCursorOrig (int &x, int &y)
 
Helper Public Member functions
Equation & getEqn ()
 
Equation & newEqn (std::string eq)
 
Equation & newEqn (std::istream &is)
 
void set_refresh (bool refresh)
 
- Public Member Functions inherited from UI::MiloPanel
 MiloPanel ()
 
 ~MiloPanel ()
 
void saveState (const std::string &filename)
 
void loadState (const std::string &filename)
 

Static Public Attributes

static const std::string name = "equation"
 Name of this panel.
 

Private Member Functions

Private member functions to handle UI events
bool do_alphaNumber (const KeyEvent &event)
 
bool do_backspace (const KeyEvent &event)
 
bool do_left (const KeyEvent &event)
 
bool do_right (const KeyEvent &event)
 
bool do_shift_left (const KeyEvent &event)
 
bool do_shift_right (const KeyEvent &event)
 
bool do_up (const KeyEvent &event)
 
bool do_down (const KeyEvent &event)
 
bool do_shift_up (const KeyEvent &event)
 
bool do_shift_down (const KeyEvent &event)
 
bool do_enter (const KeyEvent &event)
 
bool do_tab (const KeyEvent &event)
 
bool do_plus_minus (const KeyEvent &event)
 
bool do_divide (const KeyEvent &event)
 
bool do_power (const KeyEvent &event)
 
bool do_left_parenthesis (const KeyEvent &event)
 
bool do_space (const KeyEvent &event)
 
bool do_mouse_pressed (const MouseEvent &mouse)
 
bool do_mouse_released (const MouseEvent &mouse)
 
bool do_mouse_clicked (const MouseEvent &mouse)
 
bool do_mouse_double (const MouseEvent &mouse)
 
bool do_mouse_position (const MouseEvent &mouse)
 

Static Private Member Functions

Static member functions
static bool do_init ()
 
static bool emit_key (EqnPanel &panel, const KeyEvent &key)
 

Private Attributes

EqnPtr m_eqn
 Shared pointer to current equation.
 
EqnUndoList m_eqns
 Equation undo stack.
 
bool m_fRefresh = true
 Refresh on very draw by default.
 
Node * m_start_select = nullptr
 If not null, node is selected.
 
int m_start_mouse_x = -1
 Horiz coord of start of mouse drag.
 
int m_start_mouse_y = -1
 Vertical coord of start of mouse drag.
 

Static Private Attributes

static bool init = EqnPanel::do_init()
 Should be true after static initilization.
 
Static member objects
static const std::unordered_map< MouseEvent, mouse_handler > mouse_event_map
 
static const std::unordered_map< KeyEvent, key_handler > key_event_map
 
static const std::unordered_map< std::string, menu_handler > menu_map
 

Additional Inherited Members

- Static Public Member Functions inherited from UI::MiloPanel
static MiloPanelPtr makePanel (const std::string &name, const std::string &init)
 
- Static Protected Attributes inherited from UI::MiloPanel
static std::unordered_map< std::string, panel_factory > panel_map
 Map of name to panel create functions.
 

Detailed Description

Panel class for Equation class.

Member Typedef Documentation

using UI::EqnPanel::key_handler = bool (*)(EqnPanel&, const KeyEvent&)

Function pointer to handle key event. Pointer to event passed as argument. Return true, if event changed equation.

Function pointer to handle mouse event. Return true, if event changed equation.

using UI::EqnPanel::mouse_handler = bool (*)(EqnPanel&, const MouseEvent&)

Function pointer to handle mouse event. Pointer to event passed as argument. Return true, if event changed equation.

Constructor & Destructor Documentation

UI::EqnPanel::EqnPanel ( )
inline

Default Constructor for EqnPanel initializing Equation with single input.

UI::EqnPanel::EqnPanel ( std::istream &  is)
inline

Constructor for EqnPanel initializing Equation with text stream.

UI::EqnPanel::EqnPanel ( const std::string &  eq)
inline

Constructor for EqnPanel initializing Equation with string.

Member Function Documentation

bool EqnPanel::blink ( )
virtual

Check where there is an active input in this equation object.

Returns
If true, there is an active input.

Implements UI::MiloPanel.

bool EqnPanel::do_alphaNumber ( const KeyEvent &  event)
private

Handle letter or number key event. Insert letter or number key into equation if there is a current input or selection.

Parameters
eventKey event.
Returns
True if key event is processed.
bool EqnPanel::do_backspace ( const KeyEvent &  event)
private

Handle backspace key event. Erase selection if it exists, or previous factor before current input.

Parameters
eventKey event.
Returns
True if backspace is processed.
bool EqnPanel::do_divide ( const KeyEvent &  event)
private

Insert divide term.

Parameters
eventKey event.
Returns
True if successful.
bool EqnPanel::do_down ( const KeyEvent &  event)
private

Handle down arrow key event. Transverse the entire equation tree to the right of the selection or the current input. Select last node if there is no selection or input.

Parameters
eventKey event.
Returns
Always true.
bool EqnPanel::do_enter ( const KeyEvent &  event)
private

Handle enter key event. Either disable current input or replace current selection with a new input.

Parameters
eventKey event.
Returns
True if enter is proccessed.
bool EqnPanel::do_init ( )
staticprivate

Static initialization for class.

bool EqnPanel::do_left ( const KeyEvent &  event)
private

Handle left arrow key event. Move to node to the left of selection or current input.

Parameters
eventKey event.
Returns
True if left arrow proccessed.
bool EqnPanel::do_left_parenthesis ( const KeyEvent &  event)
private

Handle left parenthesis key event. Add "(*)". Side effect will be to add any functions that matches or an expression as a new factor.

Parameters
eventKey event.
Returns
True if successful.
bool EqnPanel::do_mouse_clicked ( const MouseEvent &  mouse)
private

Handle mouse click. If mouse clicks on node select it or activate input.

Parameters
mouseMouse Event
Returns
True if node selected.
bool EqnPanel::do_mouse_double ( const MouseEvent &  mouse)
private

Handle mouse double click. If no node found, return false. Otherwise activate if input selected or add input before selected node.

Parameters
mouseMouse Event
Returns
True, if node found.
bool EqnPanel::do_mouse_position ( const MouseEvent &  mouse)
private

Handle mouse position reports, Update part of equation selected by mouse dragging.

Parameters
mouseMouse Event
Returns
Always false.
bool EqnPanel::do_mouse_pressed ( const MouseEvent &  mouse)
private

Handle mouse press event. If node has been selected, remember it and mouse coordinates.

Parameters
mouseMouse Event
Returns
Always false.
bool EqnPanel::do_mouse_released ( const MouseEvent &  mouse)
private

Handle mouse release event. If mouse released where it was pressed, select node. Otherwise, end mouse dragging state.

Parameters
mouseMouse Event
Returns
Always true.
bool EqnPanel::do_plus_minus ( const KeyEvent &  event)
private

Handle +/- key event. Add a new term with a new input. New term is positive or negative depending on whether character is +/-.

Parameters
eventKey event.
Returns
True if input is active.
bool EqnPanel::do_power ( const KeyEvent &  event)
private

Insert power factor.

Parameters
eventKey event.
Returns
True if successfull.
bool EqnPanel::do_right ( const KeyEvent &  event)
private

Handle right arrow key event. Move to node to the right of selection or current input.

Parameters
eventKey event.
Returns
True if right arrow proccessed.
bool EqnPanel::do_shift_down ( const KeyEvent &  event)
private

Handle down arrow with shift key event. Select the expression to the right of the current input or add it to the existing selection.

Parameters
eventKey event.
Returns
True if down arrow with shift is processed.
bool EqnPanel::do_shift_left ( const KeyEvent &  event)
private

Handle left arrow with shift key event. Either add factor on the left to selection or select factor to left of cursor.

Parameters
eventKey event.
Returns
True if shift left arrow is processed.
bool EqnPanel::do_shift_right ( const KeyEvent &  event)
private

Handle right arrow with shift key event. Either add factor on the right to selection or select factor to right of cursor.

Parameters
eventKey event.
Returns
True if shift right arrow is processed.
bool EqnPanel::do_shift_up ( const KeyEvent &  event)
private

Handle up arrow with shift key event. Select the expression to the left of the current input or add it to the existing selection.

Parameters
eventKey event.
Returns
True if up arrow with shift is processed.
bool EqnPanel::do_space ( const KeyEvent &  event)
private

Handle space key event. Either select factor at input or select one level higher.

Parameters
eventKey event.
Returns
True if successful.
bool EqnPanel::do_tab ( const KeyEvent &  event)
private

Handle tab key event. Move to next input. If shift down move to previous input.

Parameters
eventKey event.
Returns
Always true
bool EqnPanel::do_up ( const KeyEvent &  event)
private

Handle up arrow key event. Transverse the entire equation tree to the left of the selection or the current input. Select first node if there is no selection or input.

Parameters
eventKey event.
Returns
Always true.
void EqnPanel::doDraw ( )
virtual

Handle redraw event

Implements UI::MiloPanel.

void EqnPanel::doKey ( const KeyEvent &  key)
virtual

Handle key event for panel

Parameters
keyKey event

Implements UI::MiloPanel.

bool EqnPanel::doMenu ( const std::string &  menuFunctionName)
virtual

Execute panel specific function based on its name. Used for menu handling.

Parameters
menuFunctionNameName of menu function to be executed.
Returns
True if menuFunctionName found.

Implements UI::MiloPanel.

void EqnPanel::doMouse ( const MouseEvent &  mouse)
virtual

Handle mouse event for panel

Implements UI::MiloPanel.

bool EqnPanel::emit_key ( EqnPanel &  panel,
const KeyEvent &  key 
)
staticprivate

Static function to emit a key event to a panel.

Parameters
panelEqnPanel to handle key event.
keyKey event.
Returns
True if key event was handled.
void EqnPanel::getCursorOrig ( int &  x,
int &  y 
)
virtual

Get coordinates of current active input.

Parameters
[out]xHorizontal origin of curosr.
[out]yVertical origin cursor.

Implements UI::MiloPanel.

Equation& UI::EqnPanel::getEqn ( )
inline

Get reference to current equation.

Returns
Reference to current equation.
void EqnPanel::loadState ( std::istream &  is)
virtual

Load panel from XML stream.

Parameters
filenameName of file

Implements UI::MiloPanel.

Equation& UI::EqnPanel::newEqn ( std::string  eq)
inline

New equation from string such as 'a+b/c'

Parameters
eqString containing equation to be created.
Returns
Refrence to new equation
Equation& UI::EqnPanel::newEqn ( std::istream &  is)
inline

New equation from xml stream.

Parameters
isInput stream containing xml.
Returns
Refrence to new equation
void EqnPanel::popUndo ( )
virtual

Restore state of panel on top of undo stack.

Implements UI::MiloPanel.

void EqnPanel::pushUndo ( )
virtual

Push state of panel to undo stack.

Implements UI::MiloPanel.

void EqnPanel::saveState ( std::ostream &  fs)
virtual

Save panel to XML stream

Parameters

Implements UI::MiloPanel.

void UI::EqnPanel::set_refresh ( bool  refresh)
inline

Set drawing refresh state for panel

Parameters
refreshIf true, refresh on every draw

Member Data Documentation

const unordered_map< KeyEvent, EqnPanel::key_handler > EqnPanel::key_event_map
staticprivate

Map of events to functions that handle key events.

const unordered_map< string, EqnPanel::menu_handler > EqnPanel::menu_map
staticprivate
Initial value:
= {
{ string("simplify"), [](EqnPanel& p) { return p.getEqn().simplify(); } },
{ string("normalize"), [](EqnPanel& p) { p.getEqn().normalize(); return true; } },
}

Map of names to functions that handle menu calls.

const unordered_map< MouseEvent, EqnPanel::mouse_handler > EqnPanel::mouse_event_map
staticprivate
Initial value:
= {
{ MouseEvent(Mouse::RELEASED, 1), [](EqnPanel& p, const MouseEvent& m) { return p.do_mouse_released(m); } },
{ MouseEvent(Mouse::PRESSED, 1), [](EqnPanel& p, const MouseEvent& m) { return p.do_mouse_pressed(m); } },
{ MouseEvent(Mouse::CLICKED, 1), [](EqnPanel& p, const MouseEvent& m) { return p.do_mouse_clicked(m); } },
{ MouseEvent(Mouse::DOUBLE, 1), [](EqnPanel& p, const MouseEvent& m) { return p.do_mouse_double(m); } },
{ MouseEvent(Mouse::POSITION, 0), [](EqnPanel& p, const MouseEvent& m) { return p.do_mouse_position(m); } }
}

Map of events to functions that handle mouse events.


The documentation for this class was generated from the following files: