/launcher/ui/promolabel.cpp

https://github.com/syntheticpp/GammaRay · C++ · 79 lines · 45 code · 11 blank · 23 comment · 7 complexity · b0ef2020164743bbae3d9b895f567329 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-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
  6. Author: Volker Krause <volker.krause@kdab.com>
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation, either version 2 of the License, or
  10. (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "promolabel.h"
  19. #include <QDesktopServices>
  20. #include <QUrl>
  21. #include <QDebug>
  22. #include <QMouseEvent>
  23. using namespace GammaRay;
  24. PromoLabel::PromoLabel(QWidget *parent, Qt::WindowFlags f)
  25. : QLabel(parent, f)
  26. {
  27. updatePixmap();
  28. setCursor(QCursor(Qt::PointingHandCursor));
  29. setToolTip(tr("Visit KDAB Website"));
  30. }
  31. bool PromoLabel::event(QEvent *e)
  32. {
  33. if (e->type() == QEvent::PaletteChange) {
  34. updatePixmap();
  35. }
  36. return QLabel::event(e);
  37. }
  38. void PromoLabel::mouseReleaseEvent(QMouseEvent *ev)
  39. {
  40. if (ev->button() == Qt::LeftButton && ev->modifiers() == Qt::NoModifier) {
  41. QDesktopServices::openUrl(QUrl("http://www.kdab.com"));
  42. ev->accept();
  43. return;
  44. }
  45. QLabel::mouseReleaseEvent(ev);
  46. }
  47. QImage PromoLabel::tintedImage(const QString &image, const QColor &color)
  48. {
  49. QImage img(image);
  50. img = img.alphaChannel();
  51. QColor newColor = color;
  52. for (int i = 0; i < img.colorCount(); ++i) {
  53. newColor.setAlpha(qGray(img.color(i)));
  54. img.setColor(i, newColor.rgba());
  55. }
  56. return img;
  57. }
  58. void PromoLabel::updatePixmap()
  59. {
  60. // load image and adapt it to user's foreground color
  61. setPixmap(QPixmap::fromImage(tintedImage(QString(":gammaray/kdabproducts.png"),
  62. palette().foreground().color())));
  63. }