comparison layer/ImageLayer.cpp @ 586:1ae54a29e59e

Merge from debug-output branch
author Chris Cannam
date Tue, 14 Jun 2011 14:48:29 +0100
parents f4960f8ce798
children 4806715f7a19
comparison
equal deleted inserted replaced
583:4c484636d5ec 586:1ae54a29e59e
125 ImageModel::PointList 125 ImageModel::PointList
126 ImageLayer::getLocalPoints(View *v, int x, int y) const 126 ImageLayer::getLocalPoints(View *v, int x, int y) const
127 { 127 {
128 if (!m_model) return ImageModel::PointList(); 128 if (!m_model) return ImageModel::PointList();
129 129
130 // std::cerr << "ImageLayer::getLocalPoints(" << x << "," << y << "):"; 130 // DEBUG << "ImageLayer::getLocalPoints(" << x << "," << y << "):";
131 const ImageModel::PointList &points(m_model->getPoints()); 131 const ImageModel::PointList &points(m_model->getPoints());
132 132
133 ImageModel::PointList rv; 133 ImageModel::PointList rv;
134 134
135 for (ImageModel::PointList::const_iterator i = points.begin(); 135 for (ImageModel::PointList::const_iterator i = points.begin();
153 // this image is a candidate, test it properly 153 // this image is a candidate, test it properly
154 154
155 int width = 32; 155 int width = 32;
156 if (m_scaled[v].find(p.image) != m_scaled[v].end()) { 156 if (m_scaled[v].find(p.image) != m_scaled[v].end()) {
157 width = m_scaled[v][p.image].width(); 157 width = m_scaled[v][p.image].width();
158 // std::cerr << "scaled width = " << width << std::endl; 158 // DEBUG << "scaled width = " << width << endl;
159 } 159 }
160 160
161 if (x >= px && x < px + width) { 161 if (x >= px && x < px + width) {
162 rv.insert(p); 162 rv.insert(p);
163 } 163 }
498 //!!! how to reap no-longer-used images? 498 //!!! how to reap no-longer-used images?
499 499
500 bool 500 bool
501 ImageLayer::getImageOriginalSize(QString name, QSize &size) const 501 ImageLayer::getImageOriginalSize(QString name, QSize &size) const
502 { 502 {
503 // std::cerr << "getImageOriginalSize: \"" << name.toStdString() << "\"" << std::endl; 503 // std::cerr << "getImageOriginalSize: \"" << name << "\"" << std::endl;
504 504
505 QMutexLocker locker(&m_imageMapMutex); 505 QMutexLocker locker(&m_imageMapMutex);
506 if (m_images.find(name) == m_images.end()) { 506 if (m_images.find(name) == m_images.end()) {
507 // std::cerr << "don't have, trying to open local" << std::endl; 507 // std::cerr << "don't have, trying to open local" << std::endl;
508 m_images[name] = QImage(getLocalFilename(name)); 508 m_images[name] = QImage(getLocalFilename(name));
519 QImage 519 QImage
520 ImageLayer::getImage(View *v, QString name, QSize maxSize) const 520 ImageLayer::getImage(View *v, QString name, QSize maxSize) const
521 { 521 {
522 bool need = false; 522 bool need = false;
523 523
524 // std::cerr << "ImageLayer::getImage(" << v << ", " << name.toStdString() << ", (" 524 // DEBUG << "ImageLayer::getImage(" << v << ", " << name << ", ("
525 // << maxSize.width() << "x" << maxSize.height() << "))" << std::endl; 525 // << maxSize.width() << "x" << maxSize.height() << "))" << endl;
526 526
527 if (!m_scaled[v][name].isNull() && 527 if (!m_scaled[v][name].isNull() &&
528 ((m_scaled[v][name].width() == maxSize.width() && 528 ((m_scaled[v][name].width() == maxSize.width() &&
529 m_scaled[v][name].height() <= maxSize.height()) || 529 m_scaled[v][name].height() <= maxSize.height()) ||
530 (m_scaled[v][name].width() <= maxSize.width() && 530 (m_scaled[v][name].width() <= maxSize.width() &&
556 } 556 }
557 557
558 void 558 void
559 ImageLayer::drawStart(View *v, QMouseEvent *e) 559 ImageLayer::drawStart(View *v, QMouseEvent *e)
560 { 560 {
561 // std::cerr << "ImageLayer::drawStart(" << e->x() << "," << e->y() << ")" << std::endl; 561 // DEBUG << "ImageLayer::drawStart(" << e->x() << "," << e->y() << ")" << endl;
562 562
563 if (!m_model) { 563 if (!m_model) {
564 std::cerr << "ImageLayer::drawStart: no model" << std::endl; 564 DEBUG << "ImageLayer::drawStart: no model" << endl;
565 return; 565 return;
566 } 566 }
567 567
568 long frame = v->getFrameForX(e->x()); 568 long frame = v->getFrameForX(e->x());
569 if (frame < 0) frame = 0; 569 if (frame < 0) frame = 0;
580 } 580 }
581 581
582 void 582 void
583 ImageLayer::drawDrag(View *v, QMouseEvent *e) 583 ImageLayer::drawDrag(View *v, QMouseEvent *e)
584 { 584 {
585 // std::cerr << "ImageLayer::drawDrag(" << e->x() << "," << e->y() << ")" << std::endl; 585 // DEBUG << "ImageLayer::drawDrag(" << e->x() << "," << e->y() << ")" << endl;
586 586
587 if (!m_model || !m_editing) return; 587 if (!m_model || !m_editing) return;
588 588
589 long frame = v->getFrameForX(e->x()); 589 long frame = v->getFrameForX(e->x());
590 if (frame < 0) frame = 0; 590 if (frame < 0) frame = 0;
596 } 596 }
597 597
598 void 598 void
599 ImageLayer::drawEnd(View *v, QMouseEvent *) 599 ImageLayer::drawEnd(View *v, QMouseEvent *)
600 { 600 {
601 // std::cerr << "ImageLayer::drawEnd(" << e->x() << "," << e->y() << ")" << std::endl; 601 // DEBUG << "ImageLayer::drawEnd(" << e->x() << "," << e->y() << ")" << endl;
602 if (!m_model || !m_editing) return; 602 if (!m_model || !m_editing) return;
603 603
604 bool ok = false; 604 bool ok = false;
605 605
606 ImageDialog dialog(tr("Select image"), "", ""); 606 ImageDialog dialog(tr("Select image"), "", "");
625 bool 625 bool
626 ImageLayer::addImage(long frame, QString url) 626 ImageLayer::addImage(long frame, QString url)
627 { 627 {
628 QImage image(getLocalFilename(url)); 628 QImage image(getLocalFilename(url));
629 if (image.isNull()) { 629 if (image.isNull()) {
630 std::cerr << "Failed to open image from url \"" << url.toStdString() << "\" (local filename \"" << getLocalFilename(url).toStdString() << "\"" << std::endl; 630 std::cerr << "Failed to open image from url \"" << url << "\" (local filename \"" << getLocalFilename(url) << "\"" << std::endl;
631 delete m_fileSources[url]; 631 delete m_fileSources[url];
632 m_fileSources.erase(url); 632 m_fileSources.erase(url);
633 return false; 633 return false;
634 } 634 }
635 635
642 } 642 }
643 643
644 void 644 void
645 ImageLayer::editStart(View *v, QMouseEvent *e) 645 ImageLayer::editStart(View *v, QMouseEvent *e)
646 { 646 {
647 // std::cerr << "ImageLayer::editStart(" << e->x() << "," << e->y() << ")" << std::endl; 647 // DEBUG << "ImageLayer::editStart(" << e->x() << "," << e->y() << ")" << endl;
648 648
649 if (!m_model) return; 649 if (!m_model) return;
650 650
651 ImageModel::PointList points = getLocalPoints(v, e->x(), e->y()); 651 ImageModel::PointList points = getLocalPoints(v, e->x(), e->y());
652 if (points.empty()) return; 652 if (points.empty()) return;
684 } 684 }
685 685
686 void 686 void
687 ImageLayer::editEnd(View *, QMouseEvent *) 687 ImageLayer::editEnd(View *, QMouseEvent *)
688 { 688 {
689 // std::cerr << "ImageLayer::editEnd(" << e->x() << "," << e->y() << ")" << std::endl; 689 // DEBUG << "ImageLayer::editEnd(" << e->x() << "," << e->y() << ")" << endl;
690 if (!m_model || !m_editing) return; 690 if (!m_model || !m_editing) return;
691 691
692 if (m_editingCommand) { 692 if (m_editingCommand) {
693 finish(m_editingCommand); 693 finish(m_editingCommand);
694 } 694 }
904 } 904 }
905 905
906 void 906 void
907 ImageLayer::checkAddSource(QString img) const 907 ImageLayer::checkAddSource(QString img) const
908 { 908 {
909 std::cerr << "ImageLayer::checkAddSource(" << img.toStdString() << "): yes, trying..." << std::endl; 909 DEBUG << "ImageLayer::checkAddSource(" << img << "): yes, trying..." << endl;
910 910
911 if (m_fileSources.find(img) != m_fileSources.end()) { 911 if (m_fileSources.find(img) != m_fileSources.end()) {
912 return; 912 return;
913 } 913 }
914 914
915 ProgressDialog dialog(tr("Opening image URL..."), true, 2000); 915 ProgressDialog dialog(tr("Opening image URL..."), true, 2000);
916 FileSource *rf = new FileSource(img, &dialog); 916 FileSource *rf = new FileSource(img, &dialog);
917 if (rf->isOK()) { 917 if (rf->isOK()) {
918 std::cerr << "ok, adding it (local filename = " << rf->getLocalFilename().toStdString() << ")" << std::endl; 918 std::cerr << "ok, adding it (local filename = " << rf->getLocalFilename() << ")" << std::endl;
919 m_fileSources[img] = rf; 919 m_fileSources[img] = rf;
920 connect(rf, SIGNAL(ready()), this, SLOT(fileSourceReady())); 920 connect(rf, SIGNAL(ready()), this, SLOT(fileSourceReady()));
921 } else { 921 } else {
922 delete rf; 922 delete rf;
923 } 923 }
936 } 936 }
937 937
938 void 938 void
939 ImageLayer::fileSourceReady() 939 ImageLayer::fileSourceReady()
940 { 940 {
941 // std::cerr << "ImageLayer::fileSourceReady" << std::endl; 941 // DEBUG << "ImageLayer::fileSourceReady" << endl;
942 942
943 FileSource *rf = dynamic_cast<FileSource *>(sender()); 943 FileSource *rf = dynamic_cast<FileSource *>(sender());
944 if (!rf) return; 944 if (!rf) return;
945 945
946 QString img; 946 QString img;
947 for (FileSourceMap::const_iterator i = m_fileSources.begin(); 947 for (FileSourceMap::const_iterator i = m_fileSources.begin();
948 i != m_fileSources.end(); ++i) { 948 i != m_fileSources.end(); ++i) {
949 if (i->second == rf) { 949 if (i->second == rf) {
950 img = i->first; 950 img = i->first;
951 // std::cerr << "it's image \"" << img.toStdString() << "\"" << std::endl; 951 // std::cerr << "it's image \"" << img << "\"" << std::endl;
952 break; 952 break;
953 } 953 }
954 } 954 }
955 if (img == "") return; 955 if (img == "") return;
956 956