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
36 #include "ads_globals.h"
37
38 #include "dockmanager.h"
39 #include "docksplitter.h"
40 #include "iconprovider.h"
41
42 #include <QAbstractButton>
43 #include <QPainter>
44 #include <QStyle>
45 #include <QVariant>
46
47 namespace ADS {
48
49 namespace internal {
50
replaceSplitterWidget(QSplitter * splitter,QWidget * from,QWidget * to)51 void replaceSplitterWidget(QSplitter *splitter, QWidget *from, QWidget *to)
52 {
53 int index = splitter->indexOf(from);
54 from->setParent(nullptr);
55 splitter->insertWidget(index, to);
56 }
57
dockAreaInsertParameters(DockWidgetArea area)58 DockInsertParam dockAreaInsertParameters(DockWidgetArea area)
59 {
60 switch (area) {
61 case TopDockWidgetArea:
62 return DockInsertParam(Qt::Vertical, false);
63 case RightDockWidgetArea:
64 return DockInsertParam(Qt::Horizontal, true);
65 case CenterDockWidgetArea:
66 case BottomDockWidgetArea:
67 return DockInsertParam(Qt::Vertical, true);
68 case LeftDockWidgetArea:
69 return DockInsertParam(Qt::Horizontal, false);
70 default:
71 DockInsertParam(Qt::Vertical, false);
72 }
73
74 return DockInsertParam(Qt::Vertical, false);
75 }
76
createTransparentPixmap(const QPixmap & source,qreal opacity)77 QPixmap createTransparentPixmap(const QPixmap &source, qreal opacity)
78 {
79 QPixmap transparentPixmap(source.size());
80 transparentPixmap.fill(Qt::transparent);
81 QPainter painter(&transparentPixmap);
82 painter.setOpacity(opacity);
83 painter.drawPixmap(0, 0, source);
84 return transparentPixmap;
85 }
86
hideEmptyParentSplitters(DockSplitter * splitter)87 void hideEmptyParentSplitters(DockSplitter *splitter)
88 {
89 while (splitter && splitter->isVisible()) {
90 if (!splitter->hasVisibleContent()) {
91 splitter->hide();
92 }
93 splitter = internal::findParent<DockSplitter *>(splitter);
94 }
95 }
96
setButtonIcon(QAbstractButton * button,QStyle::StandardPixmap standarPixmap,ADS::eIcon customIconId)97 void setButtonIcon(QAbstractButton *button,
98 QStyle::StandardPixmap standarPixmap,
99 ADS::eIcon customIconId)
100 {
101 // First we try to use custom icons if available
102 QIcon icon = DockManager::iconProvider().customIcon(customIconId);
103 if (!icon.isNull()) {
104 button->setIcon(icon);
105 return;
106 }
107
108 if (Utils::HostOsInfo::isLinuxHost()) {
109 button->setIcon(button->style()->standardIcon(standarPixmap));
110 } else {
111 // The standard icons does not look good on high DPI screens so we create
112 // our own "standard" icon here.
113 QPixmap normalPixmap = button->style()->standardPixmap(standarPixmap, nullptr, button);
114 icon.addPixmap(internal::createTransparentPixmap(normalPixmap, 0.25), QIcon::Disabled);
115 icon.addPixmap(normalPixmap, QIcon::Normal);
116 button->setIcon(icon);
117 }
118 }
119
repolishStyle(QWidget * widget,eRepolishChildOptions options)120 void repolishStyle(QWidget *widget, eRepolishChildOptions options)
121 {
122 if (!widget)
123 return;
124
125 widget->style()->unpolish(widget);
126 widget->style()->polish(widget);
127
128 if (RepolishIgnoreChildren == options)
129 return;
130
131 QList<QWidget*> children = widget->findChildren<QWidget *>(QString(),
132 (RepolishDirectChildren == options) ? Qt::FindDirectChildrenOnly : Qt::FindChildrenRecursively);
133 for (auto w : children)
134 {
135 w->style()->unpolish(w);
136 w->style()->polish(w);
137 }
138 }
139
140 } // namespace internal
141 } // namespace ADS
142