| 1 |
/* |
| 2 |
* Copyright (C) 2021 Rerrah |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person |
| 5 |
* obtaining a copy of this software and associated documentation |
| 6 |
* files (the "Software"), to deal in the Software without |
| 7 |
* restriction, including without limitation the rights to use, |
| 8 |
* copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 |
* copies of the Software, and to permit persons to whom the |
| 10 |
* Software is furnished to do so, subject to the following |
| 11 |
* conditions: |
| 12 |
* |
| 13 |
* The above copyright notice and this permission notice shall be |
| 14 |
* included in all copies or substantial portions of the Software. |
| 15 |
* |
| 16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 17 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
| 18 |
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 20 |
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 21 |
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 22 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 23 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 24 |
*/ |
| 25 |
|
| 26 |
#include "pan_macro_editor.hpp" |
| 27 |
#include <QPainter> |
| 28 |
|
| 29 |
namespace |
| 30 |
{ |
| 31 |
const QString MML_DISP[4] = { "n", "r", "l", "c" }; |
| 32 |
} |
| 33 |
|
| 34 |
PanMacroEditor::PanMacroEditor(QWidget* parent) |
| 35 |
: VisualizedInstrumentMacroEditor(parent) |
| 36 |
{ |
| 37 |
setMaximumDisplayedRowCount(2); |
| 38 |
setDefaultRow(3); |
| 39 |
AddRow(tr("Right"), false); |
| 40 |
AddRow(tr("Left"), false); |
| 41 |
autoFitLabelWidth(); |
| 42 |
} |
| 43 |
|
| 44 |
PanMacroEditor::~PanMacroEditor() = default; |
| 45 |
|
| 46 |
void PanMacroEditor::drawField() |
| 47 |
{ |
| 48 |
QPainter painter(&pixmap_); |
| 49 |
painter.setFont(font_); |
| 50 |
|
| 51 |
int textOffset = fontAscend_ - fontHeight_ + fontLeading_ / 2; |
| 52 |
|
| 53 |
// Row label |
| 54 |
painter.setPen(palette_->instSeqTagColor); |
| 55 |
painter.drawText(1, rowHeights_[0] + textOffset, labels_[1]); |
| 56 |
painter.drawText(1, rowHeights_[0] + rowHeights_[1] + textOffset, labels_[0]); |
| 57 |
|
| 58 |
for (size_t i = 1; i < cols_.size(); i += 2) { |
| 59 |
painter.fillRect(labWidth_ |
| 60 |
+ std::accumulate(colWidths_.begin(), colWidths_.begin() + static_cast<int>(i), 0), |
| 61 |
0, |
| 62 |
colWidths_[i], fieldHeight_, |
| 63 |
palette_->instSeqOddColColor); |
| 64 |
} |
| 65 |
|
| 66 |
// Sequence |
| 67 |
painter.setPen(palette_->instSeqCellTextColor); |
| 68 |
for (size_t i = 0; i < cols_.size(); ++i) { |
| 69 |
int v = cols_[i].row; |
| 70 |
int x = labWidth_ + std::accumulate(colWidths_.begin(), colWidths_.begin() + static_cast<int>(i), 0); |
| 71 |
if (v & 0b10) { // Left |
| 72 |
painter.fillRect(x, 0, colWidths_[i], rowHeights_[0], palette_->instSeqCellColor); |
| 73 |
} |
| 74 |
if (v & 0b01) { // Right |
| 75 |
painter.fillRect(x, rowHeights_[0], colWidths_[i], rowHeights_[1], palette_->instSeqCellColor); |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
if (hovCol_ >= 0 && hovRow_ >= 0) { |
| 80 |
painter.fillRect(labWidth_ + std::accumulate(colWidths_.begin(), colWidths_.begin() + hovCol_, 0), |
| 81 |
std::accumulate(rowHeights_.begin(), rowHeights_.begin() + hovRow_, 0), |
| 82 |
colWidths_[static_cast<size_t>(hovCol_)], rowHeights_[static_cast<size_t>(hovRow_)], |
| 83 |
palette_->instSeqHovColor); |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
int PanMacroEditor::detectRowNumberForMouseEvent(int col, int internalRow) const |
| 88 |
{ |
| 89 |
int lrFlag = internalRow ? 0b01 /* Right */ : 0b10; /* Left */ |
| 90 |
return cols_.at(static_cast<size_t>(col)).row ^ lrFlag; |
| 91 |
} |
| 92 |
|
| 93 |
int PanMacroEditor::maxInMML() const |
| 94 |
{ |
| 95 |
return 3; |
| 96 |
} |
| 97 |
|
| 98 |
QString PanMacroEditor::convertSequenceDataUnitToMML(Column col) |
| 99 |
{ |
| 100 |
return MML_DISP[col.row]; |
| 101 |
} |
| 102 |
|
| 103 |
bool PanMacroEditor::interpretDataInMML(QString& text, int& cnt, std::vector<Column>& column) |
| 104 |
{ |
| 105 |
auto c = text.left(1); |
| 106 |
for (int i = 0; i < 4; ++i) { |
| 107 |
if (c == MML_DISP[i]) { |
| 108 |
column.push_back({ i, -1, "" }); |
| 109 |
++cnt; |
| 110 |
text.remove(0, 1); |
| 111 |
return true; |
| 112 |
} |
| 113 |
} |
| 114 |
return false; |
| 115 |
} |