| 1 | /* |
| 2 | Copyright (C) 2011 Andres Cabrera |
| 3 | [email protected] |
| 4 | |
| 5 | This file is part of CsoundQt. |
| 6 | |
| 7 | CsoundQt is free software; you can redistribute it |
| 8 | and/or modify it under the terms of the GNU Lesser General Public |
| 9 | License as published by the Free Software Foundation; either |
| 10 | version 2.1 of the License, or (at your option) any later version. |
| 11 | |
| 12 | CsoundQt is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU Lesser General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU Lesser General Public |
| 18 | License along with Csound; if not, write to the Free Software |
| 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 20 | 02111-1307 USA |
| 21 | */ |
| 22 | |
| 23 | #include "scoreeditor.h" |
| 24 | #include <QHBoxLayout> |
| 25 | |
| 26 | ScoreEditor::ScoreEditor(QWidget *parent) : |
| 27 | QWidget(parent) |
| 28 | { |
| 29 | m_textEditor = new TextEditor(this); |
| 30 | m_textEditor->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); |
| 31 | m_sheet = new EventSheet(this); |
| 32 | m_textEditor->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); |
| 33 | setMode(1); // Text view by default |
| 34 | setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); |
| 35 | |
| 36 | connect(m_sheet, SIGNAL(modified()), this, SLOT(modified())); |
| 37 | connect(m_textEditor, SIGNAL(textChanged()), this, SLOT(modified())); |
| 38 | QHBoxLayout *layout = new QHBoxLayout; |
| 39 | layout->setContentsMargins (5,5,5,5); |
| 40 | layout->addWidget(m_textEditor); |
| 41 | layout->addWidget(m_sheet); |
| 42 | |
| 43 | setLayout(layout); |
| 44 | } |
| 45 | |
| 46 | void ScoreEditor::setMode(int mode) |
| 47 | { |
| 48 | m_mode = mode; |
| 49 | switch (m_mode) { |
| 50 | case 0: |
| 51 | m_textEditor->show(); |
| 52 | m_sheet->hide(); |
| 53 | this->setFocusProxy(m_textEditor); |
| 54 | break; |
| 55 | case 1: |
| 56 | m_sheet->show(); |
| 57 | m_textEditor->hide(); |
| 58 | this->setFocusProxy(m_sheet); |
| 59 | break; |
| 60 | default: |
| 61 | break; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | void ScoreEditor::setPlainText(QString text) |
| 66 | { |
| 67 | switch (m_mode) { |
| 68 | case 0: |
| 69 | m_textEditor->setPlainText(text); |
| 70 | break; |
| 71 | case 1: |
| 72 | m_sheet->clear(); |
| 73 | m_sheet->setFromText(text); |
| 74 | break; |
| 75 | default: |
| 76 | break; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | void ScoreEditor::setFontPointSize(float size) |
| 81 | { |
| 82 | m_textEditor->setFontPointSize(size); |
| 83 | } |
| 84 | |
| 85 | void ScoreEditor::setTabStopWidth(int width) |
| 86 | { |
| 87 | m_textEditor->setTabStopWidth(width); |
| 88 | } |
| 89 | |
| 90 | void ScoreEditor::setLineWrapMode(QTextEdit::LineWrapMode mode) |
| 91 | { |
| 92 | m_textEditor->setLineWrapMode(mode); |
| 93 | } |
| 94 | |
| 95 | QString ScoreEditor::getPlainText() |
| 96 | { |
| 97 | QString text; |
| 98 | switch (m_mode) { |
| 99 | case 0: |
| 100 | text = m_textEditor->toPlainText(); |
| 101 | break; |
| 102 | case 1: |
| 103 | text = m_sheet->getPlainText(); |
| 104 | break; |
| 105 | default: |
| 106 | break; |
| 107 | } |
| 108 | return text; |
| 109 | } |
| 110 | |
| 111 | QString ScoreEditor::getSelection() |
| 112 | { |
| 113 | QString text; |
| 114 | switch (m_mode) { |
| 115 | case 0: |
| 116 | text = m_textEditor->textCursor().selectedText(); |
| 117 | break; |
| 118 | case 1: |
| 119 | text = m_sheet->getPlainText(); |
| 120 | break; |
| 121 | default: |
| 122 | break; |
| 123 | } |
| 124 | return text; |
| 125 | } |
| 126 | |
| 127 | void ScoreEditor::clearUndoRedoStacks() |
| 128 | { |
| 129 | // TODO implement |
| 130 | } |
| 131 | |
| 132 | void ScoreEditor::modified() |
| 133 | { |
| 134 | emit textChanged(); |
| 135 | } |
| 136 | |
| 137 | void ScoreEditor::cut() |
| 138 | { |
| 139 | switch (m_mode) { |
| 140 | case 0: |
| 141 | m_textEditor->cut(); |
| 142 | break; |
| 143 | case 1: |
| 144 | m_sheet->cut(); |
| 145 | break; |
| 146 | default: |
| 147 | break; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | void ScoreEditor::copy() |
| 152 | { |
| 153 | switch (m_mode) { |
| 154 | case 0: |
| 155 | m_textEditor->copy(); |
| 156 | break; |
| 157 | case 1: |
| 158 | m_sheet->copy(); |
| 159 | break; |
| 160 | default: |
| 161 | break; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | void ScoreEditor::paste() |
| 166 | { |
| 167 | switch (m_mode) { |
| 168 | case 0: |
| 169 | m_textEditor->paste(); |
| 170 | break; |
| 171 | case 1: |
| 172 | m_sheet->paste(); |
| 173 | break; |
| 174 | default: |
| 175 | break; |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | void ScoreEditor::undo() |
| 180 | { |
| 181 | switch (m_mode) { |
| 182 | case 0: |
| 183 | m_textEditor->undo(); |
| 184 | break; |
| 185 | case 1: |
| 186 | m_sheet->undo(); |
| 187 | break; |
| 188 | default: |
| 189 | break; |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | void ScoreEditor::redo() |
| 194 | { |
| 195 | switch (m_mode) { |
| 196 | case 0: |
| 197 | m_textEditor->redo(); |
| 198 | break; |
| 199 | case 1: |
| 200 | m_sheet->redo(); |
| 201 | break; |
| 202 | default: |
| 203 | break; |
| 204 | } |
| 205 | } |