2017-02-27 21:15:20 +08:00
|
|
|
/*******************************************************************************
|
2017-06-10 04:04:02 +08:00
|
|
|
** Qt Advanced Docking System
|
2017-02-27 21:15:20 +08:00
|
|
|
** Copyright (C) 2017 Uwe Kindler
|
2018-05-06 18:45:46 +08:00
|
|
|
**
|
2017-06-10 04:04:02 +08:00
|
|
|
** This library is free software; you can redistribute it and/or
|
|
|
|
** modify it under the terms of the GNU Lesser General Public
|
|
|
|
** License as published by the Free Software Foundation; either
|
|
|
|
** version 2.1 of the License, or (at your option) any later version.
|
2018-05-06 18:45:46 +08:00
|
|
|
**
|
2017-06-10 04:04:02 +08:00
|
|
|
** This library is distributed in the hope that it will be useful,
|
2017-02-27 21:15:20 +08:00
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2017-06-10 04:04:02 +08:00
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
** Lesser General Public License for more details.
|
2018-05-06 18:45:46 +08:00
|
|
|
**
|
2017-06-10 04:04:02 +08:00
|
|
|
** You should have received a copy of the GNU Lesser General Public
|
|
|
|
** License along with this library; If not, see <http://www.gnu.org/licenses/>.
|
2017-02-27 21:15:20 +08:00
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
2017-02-25 05:44:02 +08:00
|
|
|
//============================================================================
|
|
|
|
/// \file ads_globals.cpp
|
|
|
|
/// \author Uwe Kindler
|
|
|
|
/// \date 24.02.2017
|
2017-02-27 21:15:20 +08:00
|
|
|
/// \brief Implementation of
|
2017-02-25 05:44:02 +08:00
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// INCLUDES
|
|
|
|
//============================================================================
|
|
|
|
#include <QVariant>
|
2018-11-08 17:04:29 +08:00
|
|
|
#include <QPainter>
|
2020-02-05 15:57:57 +08:00
|
|
|
#include <QAbstractButton>
|
2020-05-11 01:30:34 +08:00
|
|
|
#include <QStyle>
|
2017-02-25 05:44:02 +08:00
|
|
|
|
2017-03-24 17:18:25 +08:00
|
|
|
#include "DockSplitter.h"
|
2020-02-05 15:57:57 +08:00
|
|
|
#include "DockManager.h"
|
|
|
|
#include "IconProvider.h"
|
2017-02-27 01:13:56 +08:00
|
|
|
#include "ads_globals.h"
|
|
|
|
|
2017-03-24 17:18:25 +08:00
|
|
|
|
2017-02-25 05:44:02 +08:00
|
|
|
namespace ads
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace internal
|
|
|
|
{
|
2017-03-01 21:09:56 +08:00
|
|
|
//============================================================================
|
|
|
|
void replaceSplitterWidget(QSplitter* Splitter, QWidget* From, QWidget* To)
|
|
|
|
{
|
|
|
|
int index = Splitter->indexOf(From);
|
2019-01-26 00:28:36 +08:00
|
|
|
From->setParent(nullptr);
|
2017-03-01 21:09:56 +08:00
|
|
|
Splitter->insertWidget(index, To);
|
|
|
|
}
|
|
|
|
|
2017-02-27 01:13:56 +08:00
|
|
|
//============================================================================
|
2017-03-01 05:41:34 +08:00
|
|
|
CDockInsertParam dockAreaInsertParameters(DockWidgetArea Area)
|
2017-02-27 01:13:56 +08:00
|
|
|
{
|
|
|
|
switch (Area)
|
|
|
|
{
|
2018-05-06 18:45:46 +08:00
|
|
|
case TopDockWidgetArea: return CDockInsertParam(Qt::Vertical, false);
|
|
|
|
case RightDockWidgetArea: return CDockInsertParam(Qt::Horizontal, true);
|
2017-02-27 01:13:56 +08:00
|
|
|
case CenterDockWidgetArea:
|
2018-05-06 18:45:46 +08:00
|
|
|
case BottomDockWidgetArea: return CDockInsertParam(Qt::Vertical, true);
|
|
|
|
case LeftDockWidgetArea: return CDockInsertParam(Qt::Horizontal, false);
|
|
|
|
default: CDockInsertParam(Qt::Vertical, false);
|
2017-02-27 01:13:56 +08:00
|
|
|
} // switch (Area)
|
|
|
|
|
2017-03-01 05:41:34 +08:00
|
|
|
return CDockInsertParam(Qt::Vertical, false);
|
2017-02-27 01:13:56 +08:00
|
|
|
}
|
|
|
|
|
2018-11-08 17:04:29 +08:00
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
QPixmap createTransparentPixmap(const QPixmap& Source, qreal Opacity)
|
|
|
|
{
|
|
|
|
QPixmap TransparentPixmap(Source.size());
|
|
|
|
TransparentPixmap.fill(Qt::transparent);
|
|
|
|
QPainter p(&TransparentPixmap);
|
|
|
|
p.setOpacity(Opacity);
|
|
|
|
p.drawPixmap(0, 0, Source);
|
|
|
|
return TransparentPixmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-03 19:52:57 +08:00
|
|
|
//============================================================================
|
|
|
|
void hideEmptyParentSplitters(CDockSplitter* Splitter)
|
|
|
|
{
|
|
|
|
while (Splitter && Splitter->isVisible())
|
|
|
|
{
|
|
|
|
if (!Splitter->hasVisibleContent())
|
|
|
|
{
|
|
|
|
Splitter->hide();
|
|
|
|
}
|
|
|
|
Splitter = internal::findParent<CDockSplitter*>(Splitter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-05 15:57:57 +08:00
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void setButtonIcon(QAbstractButton* Button, QStyle::StandardPixmap StandarPixmap,
|
|
|
|
ads::eIcon CustomIconId)
|
|
|
|
{
|
|
|
|
// First we try to use custom icons if available
|
|
|
|
QIcon Icon = CDockManager::iconProvider().customIcon(CustomIconId);
|
|
|
|
if (!Icon.isNull())
|
|
|
|
{
|
|
|
|
Button->setIcon(Icon);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef Q_OS_LINUX
|
|
|
|
Button->setIcon(Button->style()->standardIcon(StandarPixmap));
|
|
|
|
#else
|
|
|
|
// The standard icons does not look good on high DPI screens so we create
|
|
|
|
// our own "standard" icon here.
|
|
|
|
QPixmap normalPixmap = Button->style()->standardPixmap(StandarPixmap, 0, Button);
|
|
|
|
Icon.addPixmap(internal::createTransparentPixmap(normalPixmap, 0.25), QIcon::Disabled);
|
|
|
|
Icon.addPixmap(normalPixmap, QIcon::Normal);
|
|
|
|
Button->setIcon(Icon);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-05-11 01:30:34 +08:00
|
|
|
|
|
|
|
//============================================================================
|
2020-06-07 23:19:07 +08:00
|
|
|
void repolishStyle(QWidget* w, eRepolishChildOptions Options)
|
2020-05-11 01:30:34 +08:00
|
|
|
{
|
|
|
|
if (!w)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
w->style()->unpolish(w);
|
|
|
|
w->style()->polish(w);
|
2020-06-07 23:19:07 +08:00
|
|
|
|
|
|
|
if (RepolishIgnoreChildren == Options)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<QWidget*> Children = w->findChildren<QWidget*>(QString(),
|
|
|
|
(RepolishDirectChildren == Options) ? Qt::FindDirectChildrenOnly: Qt::FindChildrenRecursively);
|
|
|
|
for (auto Widget : Children)
|
|
|
|
{
|
|
|
|
Widget->style()->unpolish(Widget);
|
|
|
|
Widget->style()->polish(Widget);
|
|
|
|
}
|
2020-05-11 01:30:34 +08:00
|
|
|
}
|
|
|
|
|
2017-02-25 05:44:02 +08:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace ads
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// EOF ads_globals.cpp
|