PageRenderTime 37ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/digikam-2.7.0/extra/kipi-plugins/debianscreenshots/kclickableimagelabel.cpp

#
C++ | 83 lines | 48 code | 13 blank | 22 comment | 3 complexity | e500ccff8f1714c834ca225acc06e1a3 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, LGPL-2.1, LGPL-3.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, GPL-3.0, GPL-2.0
  1. /* ============================================================
  2. *
  3. * This file is a part of kipi-plugins project
  4. * http://www.digikam.org
  5. *
  6. * Date : 2010-11-29
  7. * Description : a kipi plugin to export images to Debian Screenshots
  8. *
  9. * Copyright (C) 2010 by Pau Garcia i Quiles <pgquiles at elpauer dot org>
  10. *
  11. * This program is free software; you can redistribute it
  12. * and/or modify it under the terms of the GNU General
  13. * Public License as published by the Free Software Foundation;
  14. * either version 2, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * ============================================================ */
  22. #include "kclickableimagelabel.moc"
  23. // Qt includes
  24. #include <QDesktopServices>
  25. #include <QRect>
  26. #include <QCursor>
  27. #include <QDebug>
  28. namespace KIPIDebianScreenshotsPlugin
  29. {
  30. KClickableImageLabel::KClickableImageLabel(QWidget* parent, Qt::WindowFlags f)
  31. : QLabel(parent, f), m_url(QUrl())
  32. {
  33. setMouseTracking(true);
  34. }
  35. KClickableImageLabel::KClickableImageLabel(const QString& text, QWidget* parent, Qt::WindowFlags f)
  36. : QLabel(text, parent, f), m_url(QUrl())
  37. {
  38. }
  39. void KClickableImageLabel::setUrl(const QUrl& url)
  40. {
  41. m_url = url;
  42. }
  43. QUrl KClickableImageLabel::url() const
  44. {
  45. return m_url;
  46. }
  47. void KClickableImageLabel::mousePressEvent(QMouseEvent* /* ev */)
  48. {
  49. if(m_url.isEmpty())
  50. {
  51. return;
  52. }
  53. QDesktopServices::openUrl(m_url);
  54. }
  55. void KClickableImageLabel::mouseMoveEvent(QMouseEvent* /* ev */)
  56. {
  57. if(pixmap()->isNull())
  58. {
  59. return;
  60. }
  61. if( rect().contains(mapFromGlobal(QCursor::pos())) )
  62. {
  63. setCursor(Qt::PointingHandCursor);
  64. }
  65. else
  66. {
  67. setCursor(Qt::ArrowCursor);
  68. }
  69. }
  70. } // KIPIDebianScreenshotsPlugin