|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- /*
- * DISTRHO Notes Plugin
- * Copyright (C) 2012-2013 Filipe Coelho <falktx@falktx.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * For a full copy of the GNU General Public License see the GPL.txt file
- */
-
- #include "DistrhoUINotes.hpp"
-
- #include <QtGui/QResizeEvent>
-
- START_NAMESPACE_DISTRHO
-
- #include "moc_DistrhoUINotes.cpp"
-
- // -------------------------------------------------
-
- DistrhoUINotes::DistrhoUINotes()
- : QtUI(),
- fCurPage(1),
- fSaveSizeNowChecker(-1),
- fSaveTextNowChecker(-1),
- fTextEdit(this),
- fButton(this),
- fProgressBar(this),
- fSpacer(this),
- fGridLayout(this)
- {
- fButton.setCheckable(true);
- fButton.setChecked(true);
- fButton.setText("Edit");
- fButton.setFixedSize(fButton.minimumSizeHint());
-
- fProgressBar.set_minimum(1);
- fProgressBar.set_maximum(100);
- fProgressBar.set_value(1);
-
- fSpacer.setText("");
- fSpacer.setFixedSize(5, 5);
-
- fTextEdit.setReadOnly(false);
-
- setLayout(&fGridLayout);
- fGridLayout.addWidget(&fTextEdit, 0, 0, 1, 3);
- fGridLayout.addWidget(&fButton, 1, 0, 1, 1);
- fGridLayout.addWidget(&fProgressBar, 1, 1, 1, 1);
- fGridLayout.addWidget(&fSpacer, 1, 2, 1, 1);
- fGridLayout.setContentsMargins(0, 0, 0, 0);
-
- connect(&fButton, SIGNAL(clicked(bool)), SLOT(buttonClicked(bool)));
- connect(&fProgressBar, SIGNAL(valueChangedFromBar(float)), SLOT(progressBarValueChanged(float)));
- connect(&fTextEdit, SIGNAL(textChanged()), SLOT(textChanged()));
-
- setSize(300, 200);
- }
-
- DistrhoUINotes::~DistrhoUINotes()
- {
- }
-
- void DistrhoUINotes::saveCurrentTextState()
- {
- QString pageKey = QString("pageText #%1").arg(fCurPage);
- QString pageValue = fTextEdit.toPlainText();
-
- if (pageValue != fNotes[fCurPage-1])
- {
- fNotes[fCurPage-1] = pageValue;
- d_setState(pageKey.toUtf8().constData(), pageValue.toUtf8().constData());
- }
- }
-
- // -------------------------------------------------
- // DSP Callbacks
-
- void DistrhoUINotes::d_parameterChanged(uint32_t index, float value)
- {
- if (index != 0)
- return;
-
- int nextCurPage = value;
-
- if (nextCurPage != fCurPage && nextCurPage >= 1 && nextCurPage <= 100)
- {
- saveCurrentTextState();
- fCurPage = nextCurPage;
-
- fTextEdit.setPlainText(fNotes[fCurPage-1]);
- fProgressBar.set_value(fCurPage);
- fProgressBar.update();
- }
- }
-
- void DistrhoUINotes::d_stateChanged(const char* key, const char* value)
- {
- if (std::strcmp(key, "guiWidth") == 0)
- {
- bool ok;
- int width = QString(value).toInt(&ok);
-
- if (ok && width > 0)
- setSize(width, height());
- }
-
- else if (std::strcmp(key, "guiHeight") == 0)
- {
- bool ok;
- int height = QString(value).toInt(&ok);
-
- if (ok && height > 0)
- setSize(width(), height);
- }
-
- else if (std::strncmp(key, "pageText #", 10) == 0)
- {
- bool ok;
- int pageIndex = QString(key+10).toInt(&ok);
-
- if (ok && pageIndex >= 1 && pageIndex <= 100)
- {
- fNotes[pageIndex-1] = QString(value);
-
- if (pageIndex == fCurPage)
- fTextEdit.setPlainText(fNotes[pageIndex-1]);
- }
- }
-
- else if (strcmp(key, "readOnly") == 0)
- {
- bool readOnly = !strcmp(value, "yes");
- fButton.setChecked(!readOnly);
- fTextEdit.setReadOnly(readOnly);
- }
- }
-
- // -------------------------------------------------
- // UI Callbacks
-
- void DistrhoUINotes::d_uiIdle()
- {
- if (fSaveSizeNowChecker == 11)
- {
- d_setState("guiWidth", QString::number(width()).toUtf8().constData());
- d_setState("guiHeight", QString::number(height()).toUtf8().constData());
- fSaveSizeNowChecker = -1;
- }
-
- if (fSaveTextNowChecker == 11)
- {
- saveCurrentTextState();
- fSaveTextNowChecker = -1;
- }
-
- if (fSaveSizeNowChecker >= 0)
- fSaveSizeNowChecker++;
-
- if (fSaveTextNowChecker >= 0)
- fSaveTextNowChecker++;
- }
-
- void DistrhoUINotes::resizeEvent(QResizeEvent* event)
- {
- fSaveSizeNowChecker = 0;
- QtUI::resizeEvent(event);
- }
-
- // -------------------------------------------------
-
- void DistrhoUINotes::buttonClicked(bool click)
- {
- bool readOnly = !click;
- fTextEdit.setReadOnly(readOnly);
-
- d_setState("readOnly", readOnly ? "yes" : "no");
- }
-
- void DistrhoUINotes::progressBarValueChanged(float value)
- {
- value = rint(value);
-
- if (fCurPage == (int)value)
- return;
-
- // maybe save current text before changing page
- if (fSaveTextNowChecker >= 0 && value >= 1.0f && value <= 100.0f)
- {
- saveCurrentTextState();
- fSaveTextNowChecker = -1;
- }
-
- // change current page
- d_parameterChanged(0, value);
-
- // tell host about this change
- d_setParameterValue(0, value);
- }
-
- void DistrhoUINotes::textChanged()
- {
- fSaveTextNowChecker = 0;
- }
-
- // -------------------------------------------------
-
- UI* createUI()
- {
- return new DistrhoUINotes;
- }
-
- // -------------------------------------------------
-
- END_NAMESPACE_DISTRHO
|