Commit 40adefb9 authored by Marco Martin's avatar Marco Martin

Support for Global header

parent 9c7888d8
......@@ -33,6 +33,7 @@
#include <QLoggingCategory>
#include <QDesktopServices>
#include <QDialogButtonBox>
#include <QPainter>
#include <KPageWidget>
#include <KAuthorized>
......@@ -44,17 +45,86 @@
#include <KAboutData>
#include <KAuthObjectDecorator>
#include <KIconLoader>
#include <KTitleWidget>
#include <KSharedConfig>
#include <KColorScheme>
#include <KActivities/ResourceInstance>
#include <cmath>
#include "MenuItem.h"
class CustomTitle : public KTitleWidget {
public:
CustomTitle(QWidget *parent = nullptr);
protected:
void paintEvent(QPaintEvent *event);
void colorsChanged();
};
CustomTitle::CustomTitle(QWidget *parent)
: KTitleWidget(parent)
{
setContentsMargins(style()->pixelMetric(QStyle::PM_LayoutLeftMargin),
style()->pixelMetric(QStyle::PM_LayoutTopMargin),
style()->pixelMetric(QStyle::PM_LayoutRightMargin),
style()->pixelMetric(QStyle::PM_LayoutBottomMargin));
colorsChanged();
connect(qApp, &QApplication::paletteChanged, this, &CustomTitle::colorsChanged);
}
void CustomTitle::colorsChanged()
{
auto config = KSharedConfig::openConfig();
auto active = KColorScheme(QPalette::Active, KColorScheme::Header, config);
auto inactive = KColorScheme(QPalette::Inactive, KColorScheme::Header, config);
auto disabled = KColorScheme(QPalette::Disabled, KColorScheme::Header, config);
QPalette palette = KColorScheme::createApplicationPalette(config);
palette.setBrush(QPalette::Active, QPalette::Window, active.background());
palette.setBrush(QPalette::Active, QPalette::WindowText, active.foreground());
palette.setBrush(QPalette::Disabled, QPalette::Window, disabled.background());
palette.setBrush(QPalette::Disabled, QPalette::WindowText, disabled.foreground());
palette.setBrush(QPalette::Inactive, QPalette::Window, inactive.background());
palette.setBrush(QPalette::Inactive, QPalette::WindowText, inactive.foreground());
setPalette(palette);
}
void CustomTitle::paintEvent(QPaintEvent *event)
{
KTitleWidget::paintEvent(event);
auto linearlyInterpolateDouble = [](double one, double two, double factor) {
return one + (two - one) * factor;
};
QPainter p(this);
const QColor window = palette().color(QPalette::Window);
const QColor text = palette().color(QPalette::Text);
const qreal balance = 0.2;
const QColor separator = QColor::fromHsv(
std::fmod(linearlyInterpolateDouble(window.hue(), text.hue(), balance), 360.0),
qBound(0.0, linearlyInterpolateDouble(window.saturation(), text.saturation(), balance), 255.0),
qBound(0.0, linearlyInterpolateDouble(window.value(), text.value(), balance), 255.0),
qBound(0.0, linearlyInterpolateDouble(window.alpha(), text.alpha(), balance), 255.0)
);
p.fillRect(event->rect(), window);
p.fillRect(QRect(QPoint(0, height() - 1), QSize(width(), 1)), separator);
}
class ModuleView::Private {
public:
Private() {}
QMap<KPageWidgetItem*, KCModuleProxy*> mPages;
QMap<KPageWidgetItem*, KCModuleInfo*> mModules;
KPageWidget* mPageWidget = nullptr;
CustomTitle* mCustomHeader = nullptr;
QVBoxLayout* mLayout = nullptr;
QDialogButtonBox* mButtons = nullptr;
KAuth::ObjectDecorator* mApplyAuthorize = nullptr;
......@@ -71,14 +141,22 @@ ModuleView::ModuleView( QWidget * parent )
: QWidget( parent )
, d( new Private() )
{
QVBoxLayout *rootLayout = new QVBoxLayout(this);
rootLayout->setContentsMargins(0, 0, 0, 0);
// Configure a layout first
d->mLayout = new QVBoxLayout(this);
d->mLayout = new QVBoxLayout();
// Create the Page Widget
d->mPageWidget = new KPageWidget(this);
d->mCustomHeader = new CustomTitle(this);
rootLayout->addWidget(d->mCustomHeader);
rootLayout->addItem(d->mLayout);
//d->mPageWidget->setPageHeader(d->mCustomHeader);
d->mPageWidget->layout()->setContentsMargins(0, 0, 0, 0);
// Zero out only the horizontal spacing (the vertical spacing is fine)
QGridLayout *gridLayout = static_cast<QGridLayout*>(d->mPageWidget->layout());
gridLayout->setHorizontalSpacing(0);
d->mLayout->addWidget(d->mPageWidget);
// Create the dialog
d->mButtons = new QDialogButtonBox( Qt::Horizontal, this );
......@@ -220,16 +298,18 @@ void ModuleView::updatePageIconHeader( KPageWidgetItem * page, bool light )
page->setHeader( moduleInfo->moduleName() );
page->setIcon( QIcon::fromTheme( moduleInfo->icon() ) );
//HACK: not much other ways to detect is a qml kcm
if ( moduleProxy && moduleProxy->realModule()->inherits("KCModuleQml") ) {
page->setHeaderVisible(false);
}
//HACK: no other ways to detect is a qml kcm
d->mCustomHeader->setText(moduleInfo->moduleName());
d->mCustomHeader->setVisible(!moduleProxy || !moduleProxy->realModule()->inherits("KCModuleQml"));
page->setHeaderVisible(false);
if( light ) {
return;
}
if( moduleProxy && moduleProxy->realModule()->useRootOnlyMessage() ) {
page->setHeader( moduleInfo->moduleName() + QStringLiteral("<br><small>") + moduleProxy->realModule()->rootOnlyMessage() + QStringLiteral("</small>") );
d->mCustomHeader->setText( moduleInfo->moduleName() + QStringLiteral("<br><small>") + moduleProxy->realModule()->rootOnlyMessage() + QStringLiteral("</small>") );
}
}
......@@ -492,3 +572,17 @@ void ModuleView::moduleShowDefaultsIndicators(bool show)
activeModule->setDefaultsIndicatorsVisible(show);
}
}
void ModuleView::setHeaderHeight(qreal height)
{
if (height == d->mCustomHeader->minimumHeight()) {
return;
}
d->mCustomHeader->setMinimumHeight(height);
}
qreal ModuleView::headerHeight() const
{
return d->mCustomHeader->minimumHeight();
}
......@@ -142,6 +142,9 @@ public:
*/
void moduleShowDefaultsIndicators(bool show);
qreal headerHeight() const;
void setHeaderHeight(qreal height);
public Q_SLOTS:
/**
* Loads the module specified by menuItem.\n
......
......@@ -252,6 +252,7 @@ public:
int activeCategoryRow = -1;
int activeSubCategoryRow = -1;
int activeSearchRow = -1;
qreal headerHeight = 0;
bool m_actionMenuVisible = false;
void setActionMenuVisible(SidebarMode* sidebarMode, const bool &actionMenuVisible)
{
......@@ -635,6 +636,21 @@ void SidebarMode::setIntroPageVisible(const bool &introPageVisible)
emit introPageVisibleChanged();
}
void SidebarMode::setHeaderHeight(qreal height)
{
if (height == d->moduleView->headerHeight()) {
return;
}
d->moduleView->setHeaderHeight(height);
emit headerHeightChanged();
}
qreal SidebarMode::headerHeight() const
{
return d->moduleView->headerHeight();
}
void SidebarMode::toggleDefaultsIndicatorsVisibility()
{
d->m_defaultsIndicatorsVisible = !d->m_defaultsIndicatorsVisible;
......
......@@ -77,6 +77,7 @@ class SidebarMode : public BaseMode
Q_PROPERTY(bool actionMenuVisible READ actionMenuVisible NOTIFY actionMenuVisibleChanged)
Q_PROPERTY(bool introPageVisible READ introPageVisible WRITE setIntroPageVisible NOTIFY introPageVisibleChanged)
Q_PROPERTY(bool defaultsIndicatorsVisible READ defaultsIndicatorsVisible NOTIFY defaultsIndicatorsVisibleChanged)
Q_PROPERTY(qreal headerHeight READ headerHeight WRITE setHeaderHeight NOTIFY headerHeightChanged)
public:
SidebarMode(QObject * parent, const QVariantList &args );
......@@ -104,6 +105,9 @@ public:
bool introPageVisible() const;
void setIntroPageVisible(const bool &introPageVisible);
qreal headerHeight() const;
void setHeaderHeight(qreal height);
bool defaultsIndicatorsVisible() const;
Q_INVOKABLE void toggleDefaultsIndicatorsVisibility();
......@@ -134,6 +138,7 @@ Q_SIGNALS:
void widthChanged();
void actionMenuVisibleChanged();
void introPageVisibleChanged();
void headerHeightChanged();
void defaultsIndicatorsVisibleChanged();
private:
......
......@@ -33,6 +33,12 @@ Kirigami.ScrollablePage {
leftPadding: Kirigami.Units.smallSpacing
rightPadding: Kirigami.Units.smallSpacing
Binding {
target: systemsettings
property: "headerHeight"
value: mainColumn.header.height
}
contentItem: RowLayout {
anchors.fill: parent
spacing: Kirigami.Units.smallSpacing
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment