// // Programmer: Craig Stuart Sapp // Creation Date: Mon Dec 6 15:58:31 PST 1999 // Last Modified: Mon Dec 6 15:58:34 PST 1999 // Filename: ...improv/doc/gui/linux/qt/examples/midiscope/MainWidget.cpp // Syntax: C++; qt 2.02; improv 2.2.7 // #include "MainWidget.h" // #include "MainWidget.moc" #include #include #include ////////////////////////////// // // MainWidget::MainWidget -- sets up initial widget states for the // main window of the program. // MainWidget::MainWidget(QWidget* parent, const char* name) { // (1): creating the widgets in the main window. // Currently, there are only three LCD displays // in the main window. Note that these widgets do not // have to be deleted by MainWidget's deconstructor since // Qt will be keeping track of them. lcd[0] = new QLCDNumber(2, this, "command"); QToolTip::add(lcd[0], "command"); lcd[1] = new QLCDNumber(2, this, "p1"); QToolTip::add(lcd[1], "p1"); lcd[2] = new QLCDNumber(2, this, "p2"); QToolTip::add(lcd[2], "p2"); // (2): adjusting the layout of the widgets in the main window: setMinimumSize(280, 100); adjustSize(); // (3): adjusting style of LCD's and other stuff for (int i=0; i<3; i++) { // lcd[i]->setPalette(QPalette(QColor(0x0, 0x0, 0x0))); lcd[i]->setHexMode(); lcd[i]->setSegmentStyle(QLCDNumber::Flat); lcd[i]->display(0); } } ////////////////////////////// // // MainWidget::adjustSize -- adjust the contents of MainWidget when it // changes size. The user can only control the width of the // MainWidget, and the height of the MainWidget will be calculated // from the width (This is done with the setFixedHeight function). // void MainWidget::adjustSize(void) { setFixedHeight(width()/6); double digitsize = (width()-40)/6.0; // there are 6 digits to display lcd[0]->move(10, 10); lcd[0]->resize(2 * digitsize, height() - 25); lcd[1]->move(20 + 2 * digitsize, 10); lcd[1]->resize(2 * digitsize, height() - 25); lcd[2]->move(30 + 4 * digitsize, 10); lcd[2]->resize(2 * digitsize, height() - 25); } ////////////////////////////// // // MainWidget::midi -- what to do with a new MIDI message. // void MainWidget::midi(int byte1, int byte2, int byte3) { int byte[3]; static char buffer[8] = {0}; byte[0] = byte1; byte[1] = byte2; byte[2] = byte3; for (int i=0; i<3; i++) { if (byte[i] < 0x10 && byte[i] >= 0) { buffer[0] = '0'; if (byte[i] < 10) { buffer[1] = '0' + byte[i]; } else { buffer[1] = 'a' + byte[i] - 10; } buffer[2] = '\0'; lcd[i]->display(buffer); } else { lcd[i]->display(byte[i]); } lcd[i]->repaint(); } } /////////////////////////////////////////////////////////////////////////// // // Event-handling functions: // ////////////////////////////// // // MainWidget::resizeEvent -- a virtual function which is called // when the user resizes the MainWidget. void MainWidget::resizeEvent(QResizeEvent* event) { adjustSize(); }