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
autoscaledtokeyboardgraphicsview.cpp
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright 2015 Haye Hinrichsen, Christoph Wick
3  *
4  * This file is part of Entropy Piano Tuner.
5  *
6  * Entropy Piano Tuner is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * Entropy Piano Tuner is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * Entropy Piano Tuner. If not, see http://www.gnu.org/licenses/.
18  *****************************************************************************/
19 
21 #include "../core/system/eptexception.h"
22 #include "keyboardgraphicsview.h"
23 
25  : GraphicsViewAdapterForQt(parent, drawer, QRectF()),
26  mKeyboardGraphicsView(nullptr) {
27 
28  setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
29  setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
30 }
31 
33 {
34 
35 }
36 
38  mKeyboardGraphicsView = keyboardgraphicsview;
40  setSceneRect(mKeyboardGraphicsView->sceneRect());
41 }
42 
43 
46  if (item) {
47  delete item;
48  item = nullptr;
49  }
50  if (key >= 0) {
51  int numberOfKeys = mKeyboardGraphicsView->getKeyboard()->getNumberOfKeys();
52  float deltaX = 1.f / numberOfKeys;
54  if (item) {
55  // key is not out of range
56  item->setZOrder(-1);
58  }
59  }
60 }
61 
63  fitInView(mKeyboardGraphicsView->getVisibleContentsRect(), Qt::IgnoreAspectRatio);
64 
65  QGraphicsView::showEvent(event);
66 }
67 
69  fitInView(mKeyboardGraphicsView->getVisibleContentsRect(), Qt::IgnoreAspectRatio);
70 
71  QGraphicsView::resizeEvent(event);
72 }
KeyboardGraphicsView * mKeyboardGraphicsView
Pointer to the KeyboardGraphicsView.
Implementation of the GraphicsViewAdapter in Qt using QGraphicsView.
const Keyboard * getKeyboard() const
Getter for mKeyboard.
virtual void setZOrder(double z)
Set the z order of the element (here implemented without function)
Definition: graphicsitem.h:138
virtual GraphicsItem * drawFilledRect(double x, double y, double w, double h, PenType pen, FillTypes fill) override
Abstract function: Draw a filled rectangle.
AutoScaledToKeyboardGraphicsView(QWidget *parent, DrawerBase *drawer)
Constructor.
void addAutoScaledGraphicsView(AutoScaledToKeyboardGraphicsView *view)
Function to add a AutoScaledToKeyboardGraphicsView.
void resizeEvent(QResizeEvent *event) override
Reimplemented to keep the visible view with the KeyboardGraphicsView.
void setSceneRect(const QRectF &rect)
Setter function for the scene rectangle.
Class for a single item in a graphics view.
Definition: graphicsitem.h:55
Viewer for the keyboard.
GraphicsItem * getGraphicItemByRole(RoleType role)
Get the first of all graphics elements with a given role.
void setKeyIndexAndItemRole(int index, RoleType role)
Short function for setting the key index and the role.
int getNumberOfKeys() const
Definition: keyboard.h:72
void highlightKey(int key)
Function that will highlight the given key.
void setKeyboard(KeyboardGraphicsView *keyboardgraphicsview)
Setter function for the keyboard.
void showEvent(QShowEvent *event) override
Reimplemented to keep the visible view with the KeyboardGraphicsView.
Abstract base class for drawing 2d graphics.
Definition: drawerbase.h:40
QRectF getVisibleContentsRect() const