ctkCmdLineModuleExplorerUtils.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #include "ctkCmdLineModuleExplorerUtils.h"
  16. #include "ctkCmdLineModuleRunException.h"
  17. #include <QPainter>
  18. #include <QObject>
  19. #include <QWidget>
  20. #include <QApplication>
  21. #include <QMessageBox>
  22. QPixmap ctkCmdLineModuleExplorerUtils::createIconOverlay(const QPixmap &base, const QPixmap &overlay)
  23. {
  24. QPixmap result(base.width(), base.height());
  25. result.fill(Qt::transparent);
  26. QPainter painter(&result);
  27. painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
  28. painter.drawPixmap(0, 0, base);
  29. painter.drawPixmap(base.width()/2, base.height()/2,
  30. overlay.scaled(base.width()/2, base.height()/2, Qt::KeepAspectRatio));
  31. return result;
  32. }
  33. void ctkCmdLineModuleExplorerUtils::messageBoxModuleRegistration(const QFuture<ctkCmdLineModuleReference>& moduleRefsFuture,
  34. ctkCmdLineModuleManager::ValidationMode validationMode)
  35. {
  36. QString errorMsg;
  37. QFutureIterator<ctkCmdLineModuleReference> futureIter(moduleRefsFuture);
  38. while(futureIter.hasNext())
  39. {
  40. try
  41. {
  42. const ctkCmdLineModuleReference& moduleRef = futureIter.next();
  43. if (!moduleRef)
  44. {
  45. errorMsg += QObject::tr("Failed to register ") + moduleRef.location().toString() + "\n\n";
  46. }
  47. else if (!moduleRef.xmlValidationErrorString().isEmpty() &&
  48. validationMode == ctkCmdLineModuleManager::STRICT_VALIDATION)
  49. {
  50. errorMsg += QObject::tr("Failed to register ") + moduleRef.location().toString() + ":\n" + moduleRef.xmlValidationErrorString() + "\n\n";
  51. }
  52. }
  53. catch (const ctkCmdLineModuleRunException& e)
  54. {
  55. errorMsg += QObject::tr("Failed to register module ") + e.location().toString() + ":\n" + e.message() + "\n\\n";
  56. }
  57. catch (const std::exception& e)
  58. {
  59. errorMsg += QObject::tr("Failed to register module:\n") + e.what() + "\n\n";
  60. }
  61. }
  62. if (!errorMsg.isEmpty())
  63. {
  64. QWidget* widget = QApplication::activeModalWidget();
  65. if (widget == NULL) widget = QApplication::activeWindow();
  66. QMessageBox::critical(widget, QObject::tr("Failed to register modules"), errorMsg);
  67. }
  68. }