ctkCheckBoxTest1.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. // Qt includes
  15. #include <QApplication>
  16. #include <QDebug>
  17. #include <QFormLayout>
  18. #include <QProxyStyle>
  19. #include <QTimer>
  20. // CTK includes
  21. #include "ctkCheckBox.h"
  22. #include "ctkProxyStyle.h"
  23. // STD includes
  24. #include <cstdlib>
  25. #include <iostream>
  26. //-----------------------------------------------------------------------------
  27. int ctkCheckBoxTest1(int argc, char * argv [])
  28. {
  29. //QPlastiqueStyle* style = new QPlastiqueStyle;
  30. //QApplication::setStyle(style);
  31. QApplication app(argc, argv);
  32. QPixmap onPixmap =
  33. QApplication::style()->standardPixmap(QStyle::SP_DriveCDIcon);
  34. QPixmap offPixmap =
  35. QApplication::style()->standardPixmap(QStyle::SP_DesktopIcon);
  36. QIcon icon;
  37. icon.addPixmap(offPixmap,
  38. QIcon::Normal,
  39. QIcon::On);
  40. icon.addPixmap(onPixmap,
  41. QIcon::Normal,
  42. QIcon::Off);
  43. QWidget topLevel;
  44. ctkCheckBox* checkBoxWithoutIcon = new ctkCheckBox(0);
  45. checkBoxWithoutIcon->setIndicatorIcon(icon);
  46. ctkCheckBox* checkBoxWithIcon = new ctkCheckBox(0);
  47. checkBoxWithIcon->setIcon(QApplication::style()->standardIcon(QStyle::SP_FileIcon));
  48. ctkCheckBox* checkBoxWithIconAndText = new ctkCheckBox(0);
  49. checkBoxWithoutIcon->setIndicatorIcon(icon);
  50. // checkBoxWithoutIcon->setIndicatorIconSize(QSize(15,15));
  51. checkBoxWithIcon->setIndicatorIcon(icon);
  52. if (checkBoxWithIcon->indicatorIcon().isNull())
  53. {
  54. std::cerr << "Line " << __LINE__ << " - Problem with "
  55. << "the function indicatorIcon()" << std::endl;
  56. return EXIT_FAILURE;
  57. }
  58. icon.addPixmap(QApplication::style()->standardPixmap(QStyle::SP_FileLinkIcon),
  59. QIcon::Active,
  60. QIcon::On);
  61. checkBoxWithIcon->setIndicatorIcon(QIcon());
  62. checkBoxWithIconAndText->setIndicatorIcon(icon);
  63. checkBoxWithIconAndText->setIndicatorIconSize(QSize(25,25));
  64. checkBoxWithIconAndText->setText("Test1");
  65. checkBoxWithIconAndText->setIcon(QApplication::style()->standardIcon(QStyle::SP_FileIcon));
  66. ctkCheckBox* checkBoxWithoutIcon2 = new ctkCheckBox(0);
  67. ctkCheckBox* checkBoxWithIcon2 = new ctkCheckBox(0);
  68. checkBoxWithIcon2->setIcon(QApplication::style()->standardIcon(QStyle::SP_FileIcon));
  69. ctkCheckBox* checkBoxWithIconAndText2 = new ctkCheckBox(0);
  70. checkBoxWithIconAndText2->setText("Test1");
  71. checkBoxWithIconAndText2->setIcon(QApplication::style()->standardIcon(QStyle::SP_FileIcon));
  72. QFormLayout* layout = new QFormLayout(&topLevel);
  73. layout->addRow("Indicator:", checkBoxWithoutIcon);
  74. layout->addRow("Icon:", checkBoxWithIcon);
  75. layout->addRow("Indicator, Icon, Text:", checkBoxWithIconAndText);
  76. layout->addRow("Default:", checkBoxWithoutIcon2);
  77. layout->addRow("Icon:", checkBoxWithIcon2);
  78. layout->addRow("Icon, Text:", checkBoxWithIconAndText2);
  79. topLevel.setLayout(layout);
  80. topLevel.show();
  81. // Style check
  82. ctkProxyStyle* checkBoxStyle = qobject_cast<ctkProxyStyle*>(checkBoxWithoutIcon->style());
  83. if (!checkBoxStyle)
  84. {
  85. std::cerr << "Not a ctkProxyStyle" << std::endl;
  86. return EXIT_FAILURE;
  87. }
  88. checkBoxStyle->ensureBaseStyle();
  89. if (checkBoxStyle->baseStyle()->proxy() != checkBoxStyle)
  90. {
  91. std::cerr << "Wrong proxy: " << checkBoxStyle->baseStyle()->proxy() << std::endl;
  92. return EXIT_FAILURE;
  93. }
  94. if (argc < 2 || QString(argv[1]) != "-I" )
  95. {
  96. QTimer::singleShot(200, &app, SLOT(quit()));
  97. }
  98. return app.exec();
  99. }