1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649
|
// -*- c-basic-offset: 4 -*-
/*
Rosegarden-4
A sequencer and musical notation editor.
This program is Copyright 2000-2005
Guillaume Laurent <glaurent@telegraph-road.org>,
Chris Cannam <cannam@all-day-breakfast.com>,
Richard Bown <bownie@bownie.com>
The moral right of the authors to claim authorship of this work
has been asserted.
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 (at your option) any later version. See the file
COPYING included with this distribution for more information.
*/
#include <kconfig.h>
#include <kstdaction.h>
#include <kaction.h>
#include <kstddirs.h>
#include <qvbox.h>
#include <qlayout.h>
#include <qtooltip.h>
#include <qlineedit.h>
#include <qspinbox.h>
#include <qlabel.h>
#include <qaccel.h>
#include <qiconset.h>
#include "markereditor.h"
#include "rosegardenguidoc.h"
#include "rosedebug.h"
#include "rosestrings.h"
#include "editcommands.h"
#include "widgets.h"
// ------- MarkerEditorViewItem --------
//
//
class MarkerEditorViewItem : public QListViewItem
{
public:
MarkerEditorViewItem(QListView * parent, QString label1,
QString label2 = QString::null,
QString label3 = QString::null,
QString label4 = QString::null,
QString label5 = QString::null,
QString label6 = QString::null,
QString label7 = QString::null,
QString label8 = QString::null):
QListViewItem(parent, label1, label2, label3, label4,
label5, label6, label7, label8) { ; }
virtual int compare(QListViewItem * i, int col, bool ascending) const;
void setRawTime(Rosegarden::timeT rawTime) { m_rawTime = rawTime; }
Rosegarden::timeT getRawTime() const { return m_rawTime; }
protected:
Rosegarden::timeT m_rawTime;
};
int
MarkerEditorViewItem::compare(QListViewItem * i, int col, bool ascending) const
{
MarkerEditorViewItem *ei =
dynamic_cast<MarkerEditorViewItem *>(i);
if (!ei) return QListViewItem::compare(i, col, ascending);
// Raw time sorting on time column
//
if (col == 0) {
if (m_rawTime < ei->getRawTime()) return -1;
else if (ei->getRawTime() < m_rawTime) return 1;
else return 0;
} else {
return QListViewItem::compare(i, col, ascending);
}
}
// -------- MarkerEditorDialog --------
//
//
MarkerEditorDialog::MarkerEditorDialog(QWidget *parent,
RosegardenGUIDoc *doc):
KMainWindow(parent, "markereditordialog"),
m_doc(doc),
m_modified(false)
{
QVBox* mainFrame = new QVBox(this);
setCentralWidget(mainFrame);
setCaption(i18n("Manage Markers"));
m_listView = new KListView(mainFrame);
m_listView->addColumn(i18n("Marker time "));
m_listView->addColumn(i18n("Marker name "));
m_listView->addColumn(i18n("Marker description "));
// Align centrally
for (int i = 0; i < 3; ++i)
m_listView->setColumnAlignment(i, Qt::AlignHCenter);
QGroupBox *posGroup = new QGroupBox(2, Horizontal,
i18n("Pointer position"), mainFrame);
new QLabel(i18n("Absolute time:"), posGroup);
m_absoluteTime = new QLabel(posGroup);
new QLabel(i18n("Real time:"), posGroup);
m_realTime = new QLabel(posGroup);
new QLabel(i18n("In measure:"), posGroup);
m_barTime = new QLabel(posGroup);
QFrame* btnBox = new QFrame(mainFrame);
btnBox->setSizePolicy(
QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed));
QHBoxLayout* layout = new QHBoxLayout(btnBox, 4, 10);
m_addButton = new QPushButton(i18n("Add"), btnBox);
m_deleteButton = new QPushButton(i18n("Delete"), btnBox);
m_deleteAllButton = new QPushButton(i18n("Delete All"), btnBox);
m_closeButton = new QPushButton(i18n("Close"), btnBox);
QToolTip::add(m_addButton,
i18n("Add a Marker"));
QToolTip::add(m_deleteButton,
i18n("Delete a Marker"));
QToolTip::add(m_deleteAllButton,
i18n("Delete All Markers"));
QToolTip::add(m_closeButton,
i18n("Close the Marker Editor"));
layout->addStretch(10);
layout->addWidget(m_addButton);
layout->addWidget(m_deleteButton);
layout->addWidget(m_deleteAllButton);
layout->addSpacing(30);
layout->addWidget(m_closeButton);
layout->addSpacing(5);
connect(m_addButton, SIGNAL(released()),
SLOT(slotAdd()));
connect(m_deleteButton, SIGNAL(released()),
SLOT(slotDelete()));
connect(m_closeButton, SIGNAL(released()),
SLOT(slotClose()));
connect(m_deleteAllButton, SIGNAL(released()),
SLOT(slotDeleteAll()));
setupActions();
m_doc->getCommandHistory()->attachView(actionCollection());
connect(m_doc->getCommandHistory(), SIGNAL(commandExecuted()),
this, SLOT(slotUpdate()));
connect(m_listView, SIGNAL(doubleClicked(QListViewItem *)),
SLOT(slotEdit(QListViewItem *)));
connect(m_listView, SIGNAL(pressed(QListViewItem *)),
this, SLOT(slotItemClicked(QListViewItem *)));
// Highlight all columns - enable extended selection mode
//
m_listView->setAllColumnsShowFocus(true);
m_listView->setSelectionMode(QListView::Extended);
m_listView->setItemsRenameable(true);
initDialog();
setAutoSaveSettings(MarkerEditorConfigGroup, true);
m_accelerators = new QAccel(this);
}
void
MarkerEditorDialog::updatePosition()
{
Rosegarden::timeT pos = m_doc->getComposition().getPosition();
m_absoluteTime->setText(QString("%1").arg(pos));
Rosegarden::RealTime rT = m_doc->getComposition().getElapsedRealTime(pos);
long hours = rT.sec / (60 * 60);
long mins = rT.sec / 60;
long secs = rT.sec;
long msecs = rT.msec();
QString realTime, secsStr;
if (hours) realTime += QString("%1h ").arg(hours);
if (mins) realTime += QString("%1m ").arg(hours);
secsStr.sprintf("%ld.%03lds", secs, msecs);
realTime += secsStr;
// only update if we need to to try and avoid flickering
if (m_realTime->text() != realTime) m_realTime->setText(realTime);
QString barTime =
QString("%1").arg(m_doc->getComposition().getBarNumber(pos) + 1);
// again only update if needed
if (m_barTime->text() != barTime) m_barTime->setText(barTime);
/*
// Don't allow us to add another marker if there's already one
// at the current position.
//
if (m_doc->getComposition().
isMarkerAtPosition(m_doc->getComposition().getPosition()))
m_addButton->setEnabled(false);
else
m_addButton->setEnabled(true);
*/
}
MarkerEditorDialog::~MarkerEditorDialog()
{
RG_DEBUG << "MarkerEditorDialog::~MarkerEditorDialog" << endl;
m_listView->saveLayout(kapp->config(), MarkerEditorConfigGroup);
if (m_doc)
m_doc->getCommandHistory()->detachView(actionCollection());
}
void
MarkerEditorDialog::initDialog()
{
RG_DEBUG << "MarkerEditorDialog::initDialog" << endl;
slotUpdate();
}
void
MarkerEditorDialog::slotUpdate()
{
RG_DEBUG << "MarkerEditorDialog::slotUpdate" << endl;
//QPtrList<QListViewItem> selection = m_listView->selectedItems();
MarkerEditorViewItem *item;
m_listView->clear();
Rosegarden::Composition::markercontainer markers =
m_doc->getComposition().getMarkers();
Rosegarden::Composition::markerconstiterator it;
kapp->config()->setGroup(MarkerEditorConfigGroup);
int timeMode = kapp->config()->readNumEntry("timemode", 0);
for (it = markers.begin(); it != markers.end(); ++it)
{
QString timeString = makeTimeString((*it)->getTime(), timeMode);
item = new
MarkerEditorViewItem(m_listView,
timeString,
strtoqstr((*it)->getName()),
strtoqstr((*it)->getDescription()));
// Set this for the MarkerEditorDialog
//
item->setRawTime((*it)->getTime());
m_listView->insertItem(item);
}
if (m_listView->childCount() == 0)
{
QListViewItem *item =
new MarkerEditorViewItem(m_listView, i18n("<none>"));
m_listView->insertItem(item);
m_listView->setSelectionMode(QListView::NoSelection);
}
else
{
m_listView->setSelectionMode(QListView::Extended);
}
updatePosition();
}
void
MarkerEditorDialog::slotDeleteAll()
{
RG_DEBUG << "MarkerEditorDialog::slotDeleteAll" << endl;
KMacroCommand *command = new KMacroCommand(i18n("Remove all markers"));
QListViewItem *item = m_listView->firstChild();
do
{
RemoveMarkerCommand *rc =
new RemoveMarkerCommand(&m_doc->getComposition(),
item->text(0).toInt(),
qstrtostr(item->text(1)),
qstrtostr(item->text(2)));
command->addCommand(rc);
}
while((item = item->nextSibling()));
addCommandToHistory(command);
}
void
MarkerEditorDialog::slotAdd()
{
RG_DEBUG << "MarkerEditorDialog::slotAdd" << endl;
AddMarkerCommand *command =
new AddMarkerCommand(&m_doc->getComposition(),
m_doc->getComposition().getPosition(),
std::string("new marker"),
std::string("no description"));
addCommandToHistory(command);
}
void
MarkerEditorDialog::slotDelete()
{
RG_DEBUG << "MarkerEditorDialog::slotDelete" << endl;
QListViewItem *item = m_listView->currentItem();
if (!item) return;
RemoveMarkerCommand *command =
new RemoveMarkerCommand(&m_doc->getComposition(),
item->text(0).toInt(),
qstrtostr(item->text(1)),
qstrtostr(item->text(2)));
addCommandToHistory(command);
}
void
MarkerEditorDialog::slotClose()
{
RG_DEBUG << "MarkerEditorDialog::slotClose" << endl;
if (m_doc) m_doc->getCommandHistory()->detachView(actionCollection());
m_doc = 0;
close();
}
void
MarkerEditorDialog::setupActions()
{
KAction* close = KStdAction::close(this,
SLOT(slotClose()),
actionCollection());
m_closeButton->setText(close->text());
connect(m_closeButton, SIGNAL(released()), this, SLOT(slotClose()));
// some adjustments
new KToolBarPopupAction(i18n("Und&o"),
"undo",
KStdAccel::key(KStdAccel::Undo),
actionCollection(),
KStdAction::stdName(KStdAction::Undo));
new KToolBarPopupAction(i18n("Re&do"),
"redo",
KStdAccel::key(KStdAccel::Redo),
actionCollection(),
KStdAction::stdName(KStdAction::Redo));
QString pixmapDir = KGlobal::dirs()->findResource("appdata", "pixmaps/");
kapp->config()->setGroup(MarkerEditorConfigGroup);
int timeMode = kapp->config()->readNumEntry("timemode", 0);
KRadioAction *action;
QCanvasPixmap pixmap(pixmapDir + "/toolbar/time-musical.xpm");
QIconSet icon(pixmap);
action = new KRadioAction(i18n("&Musical Times"), icon, 0, this,
SLOT(slotMusicalTime()),
actionCollection(), "time_musical");
action->setExclusiveGroup("timeMode");
if (timeMode == 0) action->setChecked(true);
pixmap.load(pixmapDir + "/toolbar/time-real.xpm");
icon = QIconSet(pixmap);
action = new KRadioAction(i18n("&Real Times"), icon, 0, this,
SLOT(slotRealTime()),
actionCollection(), "time_real");
action->setExclusiveGroup("timeMode");
if (timeMode == 1) action->setChecked(true);
pixmap.load(pixmapDir + "/toolbar/time-raw.xpm");
icon = QIconSet(pixmap);
action = new KRadioAction(i18n("Ra&w Times"), icon, 0, this,
SLOT(slotRawTime()),
actionCollection(), "time_raw");
action->setExclusiveGroup("timeMode");
if (timeMode == 2) action->setChecked(true);
createGUI("markereditor.rc");
}
void
MarkerEditorDialog::addCommandToHistory(KCommand *command)
{
getCommandHistory()->addCommand(command);
setModified(false);
}
MultiViewCommandHistory*
MarkerEditorDialog::getCommandHistory()
{
return m_doc->getCommandHistory();
}
void
MarkerEditorDialog::setModified(bool modified)
{
RG_DEBUG << "MarkerEditorDialog::setModified(" << modified << ")" << endl;
if (modified)
{
}
else
{
}
m_modified = modified;
}
void
MarkerEditorDialog::checkModified()
{
RG_DEBUG << "MarkerEditorDialog::checkModified(" << m_modified << ")"
<< endl;
}
void
MarkerEditorDialog::slotEdit(QListViewItem *i)
{
RG_DEBUG << "MarkerEditorDialog::slotEdit" << endl;
if (m_listView->selectionMode() == QListView::NoSelection) {
// The marker list is empty, so we shouldn't allow editing the
// <none> placeholder
return;
}
// Need to get the raw time from the ListViewItem
//
MarkerEditorViewItem *item =
dynamic_cast<MarkerEditorViewItem*>(i);
if (!item) return;
MarkerModifyDialog dialog(this,
&m_doc->getComposition(),
item->getRawTime(),
item->text(1),
item->text(2));
if (dialog.exec() == QDialog::Accepted)
{
ModifyMarkerCommand *command =
new ModifyMarkerCommand(&m_doc->getComposition(),
dialog.getOriginalTime(),
dialog.getTime(),
qstrtostr(dialog.getName()),
qstrtostr(dialog.getDescription()));
addCommandToHistory(command);
}
}
void
MarkerEditorDialog::closeEvent(QCloseEvent *e)
{
emit closing();
KMainWindow::closeEvent(e);
}
// Reset the document
//
void
MarkerEditorDialog::setDocument(RosegardenGUIDoc *doc)
{
// reset our pointers
m_doc = doc;
m_modified = false;
slotUpdate();
}
MarkerModifyDialog::MarkerModifyDialog(QWidget *parent,
Rosegarden::Composition *composition,
int time,
const QString &name,
const QString &des):
KDialogBase(parent, 0, true, i18n("Edit Marker"), Ok | Cancel),
m_originalTime(time)
{
QVBox *vbox = makeVBoxMainWidget();
m_timeEdit = new RosegardenTimeWidget(i18n("Marker Time"), vbox, composition,
time);
/*!!!
layout->addWidget(new QLabel(i18n("Absolute Time:"), frame), 0, 0);
m_timeEdit = new QSpinBox(frame);
layout->addWidget(m_timeEdit, 0, 1);
m_timeEdit->setMinValue(INT_MIN);
m_timeEdit->setMaxValue(INT_MAX);
m_timeEdit->setLineStep(
Rosegarden::Note(Rosegarden::Note::Shortest).getDuration());
m_timeEdit->setValue(time);
*/
QGroupBox *groupBox = new QGroupBox
(1, Horizontal, i18n("Marker Properties"), vbox);
QFrame *frame = new QFrame(groupBox);
QGridLayout *layout = new QGridLayout(frame, 2, 2, 5, 5);
layout->addWidget(new QLabel(i18n("Name:"), frame), 0, 0);
m_nameEdit = new QLineEdit(name, frame);
layout->addWidget(m_nameEdit, 0, 1);
layout->addWidget(new QLabel(i18n("Description:"), frame), 1, 0);
m_desEdit = new QLineEdit(des, frame);
layout->addWidget(m_desEdit, 1, 1);
}
void
MarkerEditorDialog::slotItemClicked(QListViewItem *item)
{
RG_DEBUG << "MarkerEditorDialog::slotItemClicked" << endl;
if (item)
{
RG_DEBUG << "MarkerEditorDialog::slotItemClicked - "
<< "jump to marker at " << item->text(0).toInt() << endl;
emit jumpToMarker(Rosegarden::timeT(item->text(0).toInt()));
}
}
QString
MarkerEditorDialog::makeTimeString(Rosegarden::timeT time, int timeMode)
{
switch (timeMode) {
case 0: // musical time
{
int bar, beat, fraction, remainder;
m_doc->getComposition().getMusicalTimeForAbsoluteTime
(time, bar, beat, fraction, remainder);
++bar;
return QString("%1%2%3-%4%5-%6%7-%8%9 ")
.arg(bar/100)
.arg((bar%100)/10)
.arg(bar%10)
.arg(beat/10)
.arg(beat%10)
.arg(fraction/10)
.arg(fraction%10)
.arg(remainder/10)
.arg(remainder%10);
}
case 1: // real time
{
Rosegarden::RealTime rt =
m_doc->getComposition().getElapsedRealTime(time);
return QString("%1 ").arg(rt.toString().c_str());
}
default:
return QString("%1 ").arg(time);
}
}
void
MarkerEditorDialog::slotMusicalTime()
{
kapp->config()->setGroup(MarkerEditorConfigGroup);
kapp->config()->writeEntry("timemode", 0);
slotUpdate();
}
void
MarkerEditorDialog::slotRealTime()
{
kapp->config()->setGroup(MarkerEditorConfigGroup);
kapp->config()->writeEntry("timemode", 1);
slotUpdate();
}
void
MarkerEditorDialog::slotRawTime()
{
kapp->config()->setGroup(MarkerEditorConfigGroup);
kapp->config()->writeEntry("timemode", 2);
slotUpdate();
}
const char* const MarkerEditorDialog::MarkerEditorConfigGroup = "Marker Editor";
|