Entropy Piano Tuner  1.1.3 (documentation not yet complete)
An open-source experimental software for piano tuning by entropy minimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
KeyboardGraphicsView Class Reference

Viewer for the keyboard. More...

#include <keyboardgraphicsview.h>

+ Inheritance diagram for KeyboardGraphicsView:
+ Collaboration diagram for KeyboardGraphicsView:

Signals

void selectionChanged (int8_t key)
 Signal beeing emitted if the selected key changed. More...
 

Public Member Functions

 KeyboardGraphicsView (QWidget *parent)
 Constructor. More...
 
 ~KeyboardGraphicsView ()
 
const QGraphicsScene & getScene () const
 Getter for mScene. More...
 
void setKeyboard (const Keyboard *kb)
 Setter for mKeyboard. More...
 
const KeyboardgetKeyboard () const
 Getter for mKeyboard. More...
 
int8_t getSelectedKeyIndex () const
 Getter for mSelectedKey. More...
 
const KeygetSelectedKey () const
 
KeyState getSelectedKeyState () const
 Getter for mSelectedKeyState. More...
 
int8_t getPreliminaryKey () const
 Getter for mPreliminaryKey. More...
 
void setSelection (int key, KeyState state, int preliminary)
 Function to set the current selection. More...
 
void centerOnKey (int8_t key)
 This function will center the view on the given key. More...
 
void addAutoScaledGraphicsView (AutoScaledToKeyboardGraphicsView *view)
 Function to add a AutoScaledToKeyboardGraphicsView. More...
 
void selectKey (int8_t key0, KeyState keyState, bool notifyMessageListeners=true)
 Function to select or deselect a key. More...
 
QRectF getVisibleContentsRect () const
 
- Public Member Functions inherited from MessageListener
 MessageListener (bool defaultActivation=true)
 
virtual ~MessageListener ()
 
bool isMessageListenerActive () const
 
void activateMessageListener ()
 
void deactivateMessageListener ()
 

Static Public Attributes

static const qreal GLOBAL_SCALING = 1
 A global scaling factor. More...
 
static const qreal PEN_THIN_LINE = 1 * KeyboardGraphicsView::GLOBAL_SCALING
 Thin pen line width. More...
 
static const qreal PEN_MEDIUM_LINE = 2 * KeyboardGraphicsView::GLOBAL_SCALING
 Medium pen line width. More...
 
static const qreal KEY_WIDTH = 10 * KeyboardGraphicsView::GLOBAL_SCALING
 Width of a single key. More...
 
static const qreal KEY_HEIGHT = 80 * KeyboardGraphicsView::GLOBAL_SCALING
 Height of a single key. More...
 
static const qreal KEY_SPACING_TO_MARKERS = KeyboardGraphicsView::KEY_WIDTH + 2 * KeyboardGraphicsView::GLOBAL_SCALING
 Space between keys and markers. More...
 
static const qreal KEY_MARKERS_MARGIN = 1 * KeyboardGraphicsView::GLOBAL_SCALING
 Margin of a single marker. More...
 
static const qreal TOTAL_HEIGHT = KeyboardGraphicsView::KEY_HEIGHT + KeyboardGraphicsView::KEY_SPACING_TO_MARKERS
 Total height of the view. More...
 
static const qreal KEY_BLACK_TO_WHITE_RATIO = 0.6
 Size ratio of black and white keys. More...
 
static const qreal KEY_WHITE_KEY_SIZE = KeyboardGraphicsView::KEY_WIDTH * 12.0 / 7.0
 Size of a white key (a bit bigger than KEY_WIDTH) More...
 
static const QColor KEY_PRELIMINARY_COLOR = Qt::gray
 Color of the preliminary key. More...
 
static const QColor KEY_SELECTED_RECORDED_COLOR
 Color of the selected key if it is recorded. More...
 
static const QColor KEY_SELECTED_UNRECORDED_COLOR
 Color of the selected key if it is not recorded. More...
 
static const qreal KEY_FORCED_FACTOR = 0.5
 Color scaling if the key is forced. More...
 
static const QColor KEY_PRELIMINARY_AND_SELECTED_COLOR
 Color if the preliminary key equates the selected key. More...
 
static const int NO_KEY = -1
 No key selection constant. More...
 

Protected Member Functions

virtual QSize sizeHint () const overridefinal
 
virtual QSize minimumSizeHint () const overridefinal
 
void showEvent (QShowEvent *event) override
 Reimplemented to keep the complete scene rect in the view. More...
 
void resizeEvent (QResizeEvent *event) override
 Reimplemented to keep the complete scene rect in the view. More...
 
virtual void scrollContentsBy (int dx, int dy) overridefinal
 
void mousePressEvent (QMouseEvent *event) override
 The mouse press will select the klicked key. More...
 
void mouseMoveEvent (QMouseEvent *event) override
 
void keyPressEvent (QKeyEvent *event) override
 Handler for key presses. More...
 
void handleMessage (MessagePtr m) override
 Message handling. More...
 
int heightForWidth (int w) const override
 Get the height for a given view width. More...
 

Private Types

using KeyState = piano::KeyState
 
using KeyColor = piano::KeyColor
 

Private Slots

void selectNext ()
 Slot that will select the next key. More...
 
void selectPrevious ()
 Slot that will select the previous key. More...
 
void deselectKey (bool notifyListeners=true)
 Slot to deselect a key. More...
 

Private Member Functions

void resetKey (int8_t key)
 Function to reset the key and marker color to the unselected state. More...
 
void setKeyColor (int8_t key)
 Function to set the key color of key. More...
 
void selectPreliminaryKey (int8_t key0)
 Function to change the prelimary key stored in mPreliminaryKey. More...
 
void redrawAllMarkers ()
 Force all markers to update its state. More...
 
void updateColorMarker (int8_t key0)
 Function to update a single color marker. More...
 
QPixmap getPixmapForKeyRecordingState (bool recorded)
 Function to get the QPixmap for the given recording state. More...
 
QColor getKeyColor (piano::KeyColor color, bool selected, KeyState keyState, bool recorded)
 Function to get the key color. More...
 
QRectF keyShape (int8_t key0)
 Returns a QRectF as shape of the given key. More...
 
void changeTotalNumberOfKeys (int keys, int keyA)
 Function to change the total number of keys and the key number of A. More...
 
void fitAllInView ()
 Fit the complete scene rect in the given view. More...
 
int getKeyAtPosition (const QPoint &pos)
 Function to get the key index at the given position. More...
 

Private Attributes

int mResizeBlocked = 0
 
const KeyboardmKeyboard
 Pointer to the keyboard that is displayed. More...
 
QGraphicsScene mScene
 The QGraphicsScene in which the elements will be drawed. More...
 
std::vector
< QGraphicsPixmapItem * > 
mMarkerPixmapItems
 List of all marker items. More...
 
std::vector< QGraphicsRectItem * > mKeysGraphicsItems
 List of all key items. More...
 
int8_t mCenterOnKey
 Index of the key to center on. More...
 
int8_t mSelectedKey
 The selected key. More...
 
KeyState mSelectedKeyState
 The key state of the selected key. More...
 
int8_t mPreliminaryKey
 The preliminary key. More...
 
int mKeyNumberOfA
 The keynumber of A of the given mKeyboard. More...
 
QList
< AutoScaledToKeyboardGraphicsView * > 
mAutoScaledGraphicsViews
 List of other graphic views that are scaled along this keyboard view. More...
 

Detailed Description

Viewer for the keyboard.

This class will draw the keyboard into the QGraphicsView.

The class can be set to a different KeyboardMode depending on how it should react on a mouse click. A MODE_NORMAL just selects the clicked key. A MODE_CLICK_RAISES_FULLSCREEN will open a FullScreenKeyboardDialog to display a keyboard in MODE_FULLSCREEN. If MODE_SCROLLBAR is set, the keyboard will display a scrollbar. The window will have a fixed width-height ratio defined by heightForWidth(int).

Definition at line 47 of file keyboardgraphicsview.h.

Member Typedef Documentation

Definition at line 75 of file keyboardgraphicsview.h.

Definition at line 74 of file keyboardgraphicsview.h.

Constructor & Destructor Documentation

KeyboardGraphicsView::KeyboardGraphicsView ( QWidget *  parent)

Constructor.

Parameters
parent: The parent widget
mode: The KeyboadMode

Definition at line 65 of file keyboardgraphicsview.cpp.

+ Here is the call graph for this function:

KeyboardGraphicsView::~KeyboardGraphicsView ( )

Definition at line 103 of file keyboardgraphicsview.cpp.

Member Function Documentation

void KeyboardGraphicsView::addAutoScaledGraphicsView ( AutoScaledToKeyboardGraphicsView view)
inline

Function to add a AutoScaledToKeyboardGraphicsView.

Parameters
viewThe view to add

Definition at line 152 of file keyboardgraphicsview.h.

void KeyboardGraphicsView::centerOnKey ( int8_t  key)

This function will center the view on the given key.

Parameters
key: The key to center or -1

Definition at line 120 of file keyboardgraphicsview.cpp.

void KeyboardGraphicsView::changeTotalNumberOfKeys ( int  keys,
int  keyA 
)
private

Function to change the total number of keys and the key number of A.

Parameters
keys: Number of keys
keyA: Index of A

This function will also recreate all elements.

Definition at line 419 of file keyboardgraphicsview.cpp.

+ Here is the call graph for this function:

void KeyboardGraphicsView::deselectKey ( bool  notifyListeners = true)
privateslot

Slot to deselect a key.

Definition at line 550 of file keyboardgraphicsview.cpp.

+ Here is the call graph for this function:

void KeyboardGraphicsView::fitAllInView ( )
private

Fit the complete scene rect in the given view.

Definition at line 510 of file keyboardgraphicsview.cpp.

+ Here is the call graph for this function:

int KeyboardGraphicsView::getKeyAtPosition ( const QPoint &  pos)
private

Function to get the key index at the given position.

Parameters
pos: The position to search for a key
Returns
The index of the key or -1 if none was found

This function is usually called by a mousePressEvent(QMouseEvent*) to select the clicked key.

Definition at line 517 of file keyboardgraphicsview.cpp.

const Keyboard* KeyboardGraphicsView::getKeyboard ( ) const
inline

Getter for mKeyboard.

Returns
mKeyboard.

Definition at line 106 of file keyboardgraphicsview.h.

QColor KeyboardGraphicsView::getKeyColor ( piano::KeyColor  color,
bool  selected,
KeyState  keyState,
bool  recorded 
)
private

Function to get the key color.

Parameters
colorThe color of the key.
selectedIs the key selected?
keyStateThe state of the key.
recordedIs the key recorded?
Returns
A QColor for the key

Definition at line 380 of file keyboardgraphicsview.cpp.

QPixmap KeyboardGraphicsView::getPixmapForKeyRecordingState ( bool  recorded)
private

Function to get the QPixmap for the given recording state.

Parameters
recorded: The recording state
Returns
The QPixmap that is connected to the recording state

Definition at line 372 of file keyboardgraphicsview.cpp.

int8_t KeyboardGraphicsView::getPreliminaryKey ( ) const
inline

Getter for mPreliminaryKey.

Returns
mPreliminaryKey

Definition at line 129 of file keyboardgraphicsview.h.

const QGraphicsScene& KeyboardGraphicsView::getScene ( ) const
inline

Getter for mScene.

Returns
mScene

Definition at line 92 of file keyboardgraphicsview.h.

const Key* KeyboardGraphicsView::getSelectedKey ( ) const
inline

Definition at line 115 of file keyboardgraphicsview.h.

+ Here is the call graph for this function:

int8_t KeyboardGraphicsView::getSelectedKeyIndex ( ) const
inline

Getter for mSelectedKey.

Returns
mSelectedKey

Definition at line 113 of file keyboardgraphicsview.h.

KeyState KeyboardGraphicsView::getSelectedKeyState ( ) const
inline

Getter for mSelectedKeyState.

Returns
mSelectedKeyState.

Definition at line 122 of file keyboardgraphicsview.h.

QRectF KeyboardGraphicsView::getVisibleContentsRect ( ) const

Definition at line 555 of file keyboardgraphicsview.cpp.

void KeyboardGraphicsView::handleMessage ( MessagePtr  m)
overrideprotectedvirtual

Message handling.

Parameters
m: The message

Implements MessageListener.

Definition at line 203 of file keyboardgraphicsview.cpp.

+ Here is the call graph for this function:

int KeyboardGraphicsView::heightForWidth ( int  w) const
overrideprotected

Get the height for a given view width.

Parameters
w: The width
Returns
Height with a fixed ratio.

Definition at line 160 of file keyboardgraphicsview.cpp.

void KeyboardGraphicsView::keyPressEvent ( QKeyEvent *  event)
overrideprotected

Handler for key presses.

Parameters
event: The key event

Pressing return will set the current selected key to forced mode.

Definition at line 195 of file keyboardgraphicsview.cpp.

+ Here is the call graph for this function:

QRectF KeyboardGraphicsView::keyShape ( int8_t  key0)
private

Returns a QRectF as shape of the given key.

Parameters
key0: The key index
Returns
The key shape

Definition at line 400 of file keyboardgraphicsview.cpp.

+ Here is the call graph for this function:

virtual QSize KeyboardGraphicsView::minimumSizeHint ( ) const
inlinefinaloverrideprotectedvirtual

Definition at line 170 of file keyboardgraphicsview.h.

void KeyboardGraphicsView::mouseMoveEvent ( QMouseEvent *  event)
overrideprotected

Definition at line 184 of file keyboardgraphicsview.cpp.

+ Here is the call graph for this function:

void KeyboardGraphicsView::mousePressEvent ( QMouseEvent *  event)
overrideprotected

The mouse press will select the klicked key.

Parameters
event: The mouse event

In in MODE_CLICK_RAISES_FULLSCREEN, this will open a FullScreenKeyboardDialog

Definition at line 167 of file keyboardgraphicsview.cpp.

+ Here is the call graph for this function:

void KeyboardGraphicsView::redrawAllMarkers ( )
private

Force all markers to update its state.

E.g. this function is called when a new piano was loaded.

Definition at line 353 of file keyboardgraphicsview.cpp.

+ Here is the call graph for this function:

void KeyboardGraphicsView::resetKey ( int8_t  key)
private

Function to reset the key and marker color to the unselected state.

Parameters
key: The key index

Definition at line 247 of file keyboardgraphicsview.cpp.

+ Here is the call graph for this function:

void KeyboardGraphicsView::resizeEvent ( QResizeEvent *  event)
overrideprotected

Reimplemented to keep the complete scene rect in the view.

Parameters
event: The resize event

Definition at line 131 of file keyboardgraphicsview.cpp.

+ Here is the call graph for this function:

void KeyboardGraphicsView::scrollContentsBy ( int  dx,
int  dy 
)
finaloverrideprotectedvirtual

Definition at line 150 of file keyboardgraphicsview.cpp.

+ Here is the call graph for this function:

void KeyboardGraphicsView::selectionChanged ( int8_t  key)
signal

Signal beeing emitted if the selected key changed.

Parameters
keyThe newly selected key index
void KeyboardGraphicsView::selectKey ( int8_t  key0,
piano::KeyState  keyState,
bool  notifyMessageListeners = true 
)

Function to select or deselect a key.

Parameters
key0The key index to select or -1.
keyStateThe state of the key.
notifyMessageListenersNotiy the message listeners by sending a message

The current selected key is stored in mSelectedKey and its state in mSelectedKeyState.

Definition at line 297 of file keyboardgraphicsview.cpp.

+ Here is the call graph for this function:

void KeyboardGraphicsView::selectNext ( )
privateslot

Slot that will select the next key.

Definition at line 540 of file keyboardgraphicsview.cpp.

+ Here is the call graph for this function:

void KeyboardGraphicsView::selectPreliminaryKey ( int8_t  key0)
private

Function to change the prelimary key stored in mPreliminaryKey.

Parameters
key0: The new preliminary key

Definition at line 334 of file keyboardgraphicsview.cpp.

+ Here is the call graph for this function:

void KeyboardGraphicsView::selectPrevious ( )
privateslot

Slot that will select the previous key.

Definition at line 545 of file keyboardgraphicsview.cpp.

+ Here is the call graph for this function:

void KeyboardGraphicsView::setKeyboard ( const Keyboard kb)

Setter for mKeyboard.

Parameters
kb: The Keyboard

Definition at line 108 of file keyboardgraphicsview.cpp.

+ Here is the call graph for this function:

void KeyboardGraphicsView::setKeyColor ( int8_t  key)
private

Function to set the key color of key.

Parameters
key The key index

Depending on mSelectedKey, mPreliminaryKey and mSelectedKeyState this function will chose the correct color and apply it to the key.

Definition at line 261 of file keyboardgraphicsview.cpp.

+ Here is the call graph for this function:

void KeyboardGraphicsView::setSelection ( int  key,
KeyState  state,
int  preliminary 
)

Function to set the current selection.

Parameters
key: The selected key or -1
state: The selected KeyState
preliminary: The preliminary key or -1

Definition at line 115 of file keyboardgraphicsview.cpp.

+ Here is the call graph for this function:

void KeyboardGraphicsView::showEvent ( QShowEvent *  event)
overrideprotected

Reimplemented to keep the complete scene rect in the view.

Parameters
event: The show event

Definition at line 127 of file keyboardgraphicsview.cpp.

virtual QSize KeyboardGraphicsView::sizeHint ( ) const
inlinefinaloverrideprotectedvirtual

Definition at line 169 of file keyboardgraphicsview.h.

void KeyboardGraphicsView::updateColorMarker ( int8_t  key0)
private

Function to update a single color marker.

Parameters
key0: The index of the marker

This function will read the current state of the key in the mKeyboard and adjust the QPixmap of the marker

Definition at line 361 of file keyboardgraphicsview.cpp.

+ Here is the call graph for this function:

Member Data Documentation

const qreal KeyboardGraphicsView::GLOBAL_SCALING = 1
static

A global scaling factor.

Definition at line 52 of file keyboardgraphicsview.h.

const qreal KeyboardGraphicsView::KEY_BLACK_TO_WHITE_RATIO = 0.6
static

Size ratio of black and white keys.

Definition at line 60 of file keyboardgraphicsview.h.

const qreal KeyboardGraphicsView::KEY_FORCED_FACTOR = 0.5
static

Color scaling if the key is forced.

Definition at line 67 of file keyboardgraphicsview.h.

const qreal KeyboardGraphicsView::KEY_HEIGHT = 80 * KeyboardGraphicsView::GLOBAL_SCALING
static

Height of a single key.

Definition at line 56 of file keyboardgraphicsview.h.

const qreal KeyboardGraphicsView::KEY_MARKERS_MARGIN = 1 * KeyboardGraphicsView::GLOBAL_SCALING
static

Margin of a single marker.

Definition at line 58 of file keyboardgraphicsview.h.

const QColor KeyboardGraphicsView::KEY_PRELIMINARY_AND_SELECTED_COLOR
static

Color if the preliminary key equates the selected key.

Definition at line 68 of file keyboardgraphicsview.h.

const QColor KeyboardGraphicsView::KEY_PRELIMINARY_COLOR = Qt::gray
static

Color of the preliminary key.

Definition at line 64 of file keyboardgraphicsview.h.

const QColor KeyboardGraphicsView::KEY_SELECTED_RECORDED_COLOR
static

Color of the selected key if it is recorded.

Definition at line 65 of file keyboardgraphicsview.h.

const QColor KeyboardGraphicsView::KEY_SELECTED_UNRECORDED_COLOR
static

Color of the selected key if it is not recorded.

Definition at line 66 of file keyboardgraphicsview.h.

const qreal KeyboardGraphicsView::KEY_SPACING_TO_MARKERS = KeyboardGraphicsView::KEY_WIDTH + 2 * KeyboardGraphicsView::GLOBAL_SCALING
static

Space between keys and markers.

Definition at line 57 of file keyboardgraphicsview.h.

const qreal KeyboardGraphicsView::KEY_WHITE_KEY_SIZE = KeyboardGraphicsView::KEY_WIDTH * 12.0 / 7.0
static

Size of a white key (a bit bigger than KEY_WIDTH)

Definition at line 61 of file keyboardgraphicsview.h.

const qreal KeyboardGraphicsView::KEY_WIDTH = 10 * KeyboardGraphicsView::GLOBAL_SCALING
static

Width of a single key.

Definition at line 55 of file keyboardgraphicsview.h.

QList<AutoScaledToKeyboardGraphicsView*> KeyboardGraphicsView::mAutoScaledGraphicsViews
private

List of other graphic views that are scaled along this keyboard view.

Definition at line 376 of file keyboardgraphicsview.h.

int8_t KeyboardGraphicsView::mCenterOnKey
private

Index of the key to center on.

This variable is needed in the fullscreen keyboard to center on the key that was pressed in the small size keyboard view.

Definition at line 361 of file keyboardgraphicsview.h.

const Keyboard* KeyboardGraphicsView::mKeyboard
private

Pointer to the keyboard that is displayed.

Definition at line 343 of file keyboardgraphicsview.h.

int KeyboardGraphicsView::mKeyNumberOfA
private

The keynumber of A of the given mKeyboard.

Definition at line 373 of file keyboardgraphicsview.h.

std::vector<QGraphicsRectItem *> KeyboardGraphicsView::mKeysGraphicsItems
private

List of all key items.

Definition at line 352 of file keyboardgraphicsview.h.

std::vector<QGraphicsPixmapItem *> KeyboardGraphicsView::mMarkerPixmapItems
private

List of all marker items.

Definition at line 349 of file keyboardgraphicsview.h.

int8_t KeyboardGraphicsView::mPreliminaryKey
private

The preliminary key.

Definition at line 370 of file keyboardgraphicsview.h.

int KeyboardGraphicsView::mResizeBlocked = 0
private

Definition at line 341 of file keyboardgraphicsview.h.

QGraphicsScene KeyboardGraphicsView::mScene
private

The QGraphicsScene in which the elements will be drawed.

Definition at line 346 of file keyboardgraphicsview.h.

int8_t KeyboardGraphicsView::mSelectedKey
private

The selected key.

Definition at line 364 of file keyboardgraphicsview.h.

KeyState KeyboardGraphicsView::mSelectedKeyState
private

The key state of the selected key.

Definition at line 367 of file keyboardgraphicsview.h.

const int KeyboardGraphicsView::NO_KEY = -1
static

No key selection constant.

Definition at line 70 of file keyboardgraphicsview.h.

const qreal KeyboardGraphicsView::PEN_MEDIUM_LINE = 2 * KeyboardGraphicsView::GLOBAL_SCALING
static

Medium pen line width.

Definition at line 54 of file keyboardgraphicsview.h.

const qreal KeyboardGraphicsView::PEN_THIN_LINE = 1 * KeyboardGraphicsView::GLOBAL_SCALING
static

Thin pen line width.

Definition at line 53 of file keyboardgraphicsview.h.

const qreal KeyboardGraphicsView::TOTAL_HEIGHT = KeyboardGraphicsView::KEY_HEIGHT + KeyboardGraphicsView::KEY_SPACING_TO_MARKERS
static

Total height of the view.

Definition at line 59 of file keyboardgraphicsview.h.


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