/launcher/ui/promolabel.cpp

https://github.com/KDAB/GammaRay · C++ · 71 lines · 34 code · 9 blank · 28 comment · 6 complexity · 06e0539d3b5fc3fb3d54a24aca36a84f MD5 · raw file

  1. /*
  2. mainwindow.cpp
  3. This file is part of GammaRay, the Qt application inspection and
  4. manipulation tool.
  5. Copyright (C) 2010-2022 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
  6. Author: Volker Krause <volker.krause@kdab.com>
  7. Licensees holding valid commercial KDAB GammaRay licenses may use this file in
  8. accordance with GammaRay Commercial License Agreement provided with the Software.
  9. Contact info@kdab.com if any conditions of this licensing are not clear to you.
  10. This program is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation, either version 2 of the License, or
  13. (at your option) any later version.
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. GNU General Public License for more details.
  18. You should have received a copy of the GNU General Public License
  19. along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include "promolabel.h"
  22. #include <ui/uiresources.h>
  23. #include <QDesktopServices>
  24. #include <QUrl>
  25. #include <QDebug>
  26. #include <QMouseEvent>
  27. using namespace GammaRay;
  28. PromoLabel::PromoLabel(QWidget *parent, Qt::WindowFlags f)
  29. : ThemedImageLabel(parent, f)
  30. {
  31. setCursor(QCursor(Qt::PointingHandCursor));
  32. setToolTip(tr("Visit KDAB Website"));
  33. setThemeFileName(QStringLiteral("kdab-products.png"));
  34. }
  35. bool PromoLabel::event(QEvent *e)
  36. {
  37. if (e->type() == QEvent::PaletteChange)
  38. updatePixmap();
  39. return ThemedImageLabel::event(e);
  40. }
  41. void PromoLabel::mouseReleaseEvent(QMouseEvent *ev)
  42. {
  43. if (ev->button() == Qt::LeftButton && ev->modifiers() == Qt::NoModifier) {
  44. QDesktopServices::openUrl(QUrl(QStringLiteral("https://www.kdab.com")));
  45. ev->accept();
  46. return;
  47. }
  48. ThemedImageLabel::mouseReleaseEvent(ev);
  49. }
  50. void PromoLabel::updatePixmap()
  51. {
  52. // load image and adapt it to user's foreground color
  53. const QImage image = UIResources::themedImage(themeFileName(), this);
  54. setPixmap(UIResources::tintedPixmap(image, palette().windowText().color()));
  55. }