/urledit.cpp

https://github.com/torrent-file-editor/torrent-file-editor · C++ · 84 lines · 54 code · 10 blank · 20 comment · 1 complexity · 58b64d1abd99735314fb657d089ac73c MD5 · raw file

  1. /*
  2. * This is an open source non-commercial project. Dear PVS-Studio, please check it.
  3. * PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
  4. *
  5. * Copyright (C) 2014 Ivan Romanov <drizt72@zoho.eu>
  6. *
  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 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. #include "urledit.h"
  22. #include <QUrl>
  23. #include <QPushButton>
  24. #include <QDesktopServices>
  25. #include <QApplication>
  26. #include <QClipboard>
  27. UrlEdit::UrlEdit(QWidget *parent)
  28. : LineEditWidget(parent)
  29. , _pbOpenUrl(new QPushButton(this))
  30. , _pbCopyUrl(new QPushButton(this))
  31. {
  32. _pbCopyUrl->setObjectName(QStringLiteral("pbCopyUrl"));
  33. _pbCopyUrl->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
  34. _pbCopyUrl->setContentsMargins(0, 0, 0, 0);
  35. _pbCopyUrl->setFocusPolicy(Qt::NoFocus);
  36. _pbCopyUrl->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
  37. _pbCopyUrl->setAutoFillBackground(true);
  38. _pbCopyUrl->setCursor(Qt::PointingHandCursor);
  39. _pbCopyUrl->resize(0, 0);
  40. _pbCopyUrl->setFlat(true);
  41. _pbCopyUrl->setMinimumWidth(24);
  42. _pbCopyUrl->setMaximumWidth(24);
  43. addWidget(_pbCopyUrl);
  44. connect(_pbCopyUrl, SIGNAL(clicked()), SLOT(copyAll()));
  45. _pbOpenUrl->setObjectName(QStringLiteral("pbOpenUrl"));
  46. _pbOpenUrl->setIcon(QIcon::fromTheme(QStringLiteral("applications-internet")));
  47. _pbOpenUrl->setContentsMargins(0, 0, 0, 0);
  48. _pbOpenUrl->setFocusPolicy(Qt::NoFocus);
  49. _pbOpenUrl->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
  50. _pbOpenUrl->setAutoFillBackground(true);
  51. _pbOpenUrl->setCursor(Qt::PointingHandCursor);
  52. _pbOpenUrl->resize(0, 0);
  53. _pbOpenUrl->setFlat(true);
  54. _pbOpenUrl->setMinimumWidth(24);
  55. _pbOpenUrl->setMaximumWidth(24);
  56. addWidget(_pbOpenUrl);
  57. connect(_pbOpenUrl, SIGNAL(clicked()), SLOT(openUrl()));
  58. retranslateUi();
  59. }
  60. void UrlEdit::openUrl()
  61. {
  62. QUrl url(text());
  63. if (url.isValid())
  64. QDesktopServices::openUrl(url);
  65. }
  66. void UrlEdit::copyAll()
  67. {
  68. qApp->clipboard()->setText(text());
  69. }
  70. void UrlEdit::retranslateUi()
  71. {
  72. _pbCopyUrl->setToolTip(QLineEdit::tr("&Copy").remove(QLatin1Char('&')));
  73. _pbOpenUrl->setToolTip(tr("Open in internet browser"));
  74. }