ctkScreenshotDialog.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. #ifndef __ctkScreenshotDialog_h
  15. #define __ctkScreenshotDialog_h
  16. // Qt includes
  17. #include <QDialog>
  18. // CTK includes
  19. #include "ctkWidgetsExport.h"
  20. class ctkScreenshotDialogPrivate;
  21. /**
  22. \ingroup Widgets
  23. ctkScreenshotDialog is simple dialog allowing to grab the content
  24. of any widget and save it into a PNG file.
  25. It can be used as a tool and can take screenshots without being opened nor
  26. executed.
  27. \code
  28. ctkScreenshotDialog screenshot;
  29. screenshot.setWidgetToGrab(myWidget);
  30. screenshot.instantScreenshot();
  31. \endcode
  32. \sa ctkScreenshotDialog::setWidgetToGrab, QDialog
  33. */
  34. class CTK_WIDGETS_EXPORT ctkScreenshotDialog : public QDialog
  35. {
  36. Q_OBJECT
  37. Q_PROPERTY(QString baseFileName READ baseFileName WRITE setBaseFileName)
  38. Q_PROPERTY(QString directory READ directory WRITE setDirectory)
  39. Q_PROPERTY(int delay READ delay WRITE setDelay)
  40. public:
  41. typedef QDialog Superclass;
  42. ctkScreenshotDialog(QWidget* parent = 0);
  43. virtual ~ctkScreenshotDialog();
  44. /// Get widget to grab content from. If no widget is set, no screenshot will
  45. /// be taken.
  46. /// 0 by default.
  47. /// TODO: if widgetToGrab -> screenshot the entire application
  48. void setWidgetToGrab(QWidget* newWidgetToGrab);
  49. QWidget* widgetToGrab()const;
  50. /// Set screenshot base name used to generate unique file names to save the
  51. /// screenshot images. The base name doesn't contain the file extension
  52. /// (automatically set to ".png")
  53. /// "Untitled" by default
  54. void setBaseFileName(const QString& newImageName);
  55. QString baseFileName() const;
  56. /// Set directory where screenshot files are saved. If path is empty, the
  57. /// program's working directory, ("."), is used.
  58. /// Current working directory by default.
  59. void setDirectory(const QString& path);
  60. QString directory()const;
  61. /// Set the delay in seconds before the screenshot is taken.
  62. /// 0 seconds by default.
  63. void setDelay(int seconds);
  64. int delay()const;
  65. /// Disable scaling or output resolution control and take a fixed
  66. /// resolution screenshot. Default output resolution is (300,300)
  67. void enforceResolution(int width = 300, int height = 300);
  68. void enforceResolution(QSize size = QSize(300,300));
  69. /// Get the original widget size
  70. QSize widgetSize();
  71. /// Allow/Disallow transparency in the output screenshot
  72. void enableTransparency(bool enable = true);
  73. public Q_SLOTS:
  74. /// Instantanely grabs the content of \a widgetToGrag. Generates a
  75. /// png file into \a directory. It automatically increments the image name
  76. /// index suffix.
  77. void instantScreenshot();
  78. /// Calls instantScreenshot() after a countdown of \a delay seconds
  79. void saveScreenshot();
  80. protected:
  81. QScopedPointer<ctkScreenshotDialogPrivate> d_ptr;
  82. private:
  83. Q_DECLARE_PRIVATE(ctkScreenshotDialog);
  84. Q_DISABLE_COPY(ctkScreenshotDialog);
  85. };
  86. #endif