ads_globals.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2020 Uwe Kindler
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of Qt Creator.
  7. **
  8. ** Commercial License Usage
  9. ** Licensees holding valid commercial Qt licenses may use this file in
  10. ** accordance with the commercial license agreement provided with the
  11. ** Software or, alternatively, in accordance with the terms contained in
  12. ** a written agreement between you and The Qt Company. For licensing terms
  13. ** and conditions see https://www.qt.io/terms-conditions. For further
  14. ** information use the contact form at https://www.qt.io/contact-us.
  15. **
  16. ** GNU Lesser General Public License Usage
  17. ** Alternatively, this file may be used under the terms of the GNU Lesser
  18. ** General Public License version 2.1 or (at your option) any later version.
  19. ** The licenses are as published by the Free Software Foundation
  20. ** and appearing in the file LICENSE.LGPLv21 included in the packaging
  21. ** of this file. Please review the following information to ensure
  22. ** the GNU Lesser General Public License version 2.1 requirements
  23. ** will be met: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 3 or (at your option) any later version
  28. ** approved by the KDE Free Qt Foundation. The licenses are as published by
  29. ** the Free Software Foundation and appearing in the file LICENSE.GPL3
  30. ** included in the packaging of this file. Please review the following
  31. ** information to ensure the GNU General Public License requirements will
  32. ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
  33. **
  34. ****************************************************************************/
  35. #include "ads_globals.h"
  36. #include "dockmanager.h"
  37. #include "docksplitter.h"
  38. #include "iconprovider.h"
  39. #include "utils/hostosinfo.h"
  40. #include <QAbstractButton>
  41. #include <QPainter>
  42. #include <QVariant>
  43. namespace ADS {
  44. namespace internal {
  45. void replaceSplitterWidget(QSplitter *splitter, QWidget *from, QWidget *to)
  46. {
  47. int index = splitter->indexOf(from);
  48. from->setParent(nullptr);
  49. splitter->insertWidget(index, to);
  50. }
  51. DockInsertParam dockAreaInsertParameters(DockWidgetArea area)
  52. {
  53. switch (area) {
  54. case TopDockWidgetArea:
  55. return DockInsertParam(Qt::Vertical, false);
  56. case RightDockWidgetArea:
  57. return DockInsertParam(Qt::Horizontal, true);
  58. case CenterDockWidgetArea:
  59. case BottomDockWidgetArea:
  60. return DockInsertParam(Qt::Vertical, true);
  61. case LeftDockWidgetArea:
  62. return DockInsertParam(Qt::Horizontal, false);
  63. default:
  64. DockInsertParam(Qt::Vertical, false);
  65. }
  66. return DockInsertParam(Qt::Vertical, false);
  67. }
  68. QPixmap createTransparentPixmap(const QPixmap &source, qreal opacity)
  69. {
  70. QPixmap transparentPixmap(source.size());
  71. transparentPixmap.fill(Qt::transparent);
  72. QPainter painter(&transparentPixmap);
  73. painter.setOpacity(opacity);
  74. painter.drawPixmap(0, 0, source);
  75. return transparentPixmap;
  76. }
  77. void hideEmptyParentSplitters(DockSplitter *splitter)
  78. {
  79. while (splitter && splitter->isVisible()) {
  80. if (!splitter->hasVisibleContent()) {
  81. splitter->hide();
  82. }
  83. splitter = internal::findParent<DockSplitter *>(splitter);
  84. }
  85. }
  86. void setButtonIcon(QAbstractButton* button,
  87. QStyle::StandardPixmap standarPixmap,
  88. ADS::eIcon customIconId)
  89. {
  90. // First we try to use custom icons if available
  91. QIcon icon = DockManager::iconProvider().customIcon(customIconId);
  92. if (!icon.isNull()) {
  93. button->setIcon(icon);
  94. return;
  95. }
  96. if (Utils::HostOsInfo::isLinuxHost()) {
  97. button->setIcon(button->style()->standardIcon(standarPixmap));
  98. } else {
  99. // The standard icons does not look good on high DPI screens so we create
  100. // our own "standard" icon here.
  101. QPixmap normalPixmap = button->style()->standardPixmap(standarPixmap, nullptr, button);
  102. icon.addPixmap(internal::createTransparentPixmap(normalPixmap, 0.25), QIcon::Disabled);
  103. icon.addPixmap(normalPixmap, QIcon::Normal);
  104. button->setIcon(icon);
  105. }
  106. }
  107. } // namespace internal
  108. } // namespace ADS