Commit 0ce396e6 authored by Alexander Lohnau's avatar Alexander Lohnau 💬

Run clang-format

If you want git blame to ignore formatting revisions run:
git config blame.ignoreRevsFile .git-blame-ignore-revs
parent bbd1a085
This diff is collapsed.
......@@ -20,28 +20,28 @@
#ifndef SETTINGS_BASE_H
#define SETTINGS_BASE_H
#include "MenuItem.h"
#include "BaseMode.h"
#include "MenuItem.h"
#include "tooltipmanager.h"
#include "ui_configDialog.h"
#include <QButtonGroup>
#include <QMap>
#include <QStackedWidget>
#include <QButtonGroup>
#include <KService>
#include <KLineEdit>
#include <KAboutApplicationDialog>
#include <KActionMenu>
#include <KConfigDialog>
#include <KLineEdit>
#include <KService>
#include <KXmlGuiWindow>
#include <KAboutApplicationDialog>
class SettingsBase : public KXmlGuiWindow
{
Q_OBJECT
public:
explicit SettingsBase(BaseMode::ApplicationMode mode, QWidget * parent = nullptr);
explicit SettingsBase(BaseMode::ApplicationMode mode, QWidget *parent = nullptr);
~SettingsBase() override;
bool queryClose() override;
......@@ -57,47 +57,47 @@ private Q_SLOTS:
void initToolBar();
void initHelpMenu();
void initConfig();
void initMenuList(MenuItem * parent);
void initMenuList(MenuItem *parent);
void configUpdated();
void configShow();
void about();
void changePlugin();
void viewChange(bool state);
void updateViewActions();
void changeToolBar( BaseMode::ToolBarItems toolbar );
void changeAboutMenu( const KAboutData * menuAbout, QAction * menuItem, const QString &fallback );
void changeToolBar(BaseMode::ToolBarItems toolbar);
void changeAboutMenu(const KAboutData *menuAbout, QAction *menuItem, const QString &fallback);
private:
// The plugins
QMap<QString, BaseMode *> possibleViews;
QList<ToolTipManager*> tooltipManagers;
BaseMode * activeView = nullptr;
QList<ToolTipManager *> tooltipManagers;
BaseMode *activeView = nullptr;
// The search bar
KLineEdit * searchText = nullptr;
QWidget * spacerWidget = nullptr;
KLineEdit *searchText = nullptr;
QWidget *spacerWidget = nullptr;
// The toolbar
QWidgetAction * searchAction = nullptr;
QWidgetAction * spacerAction = nullptr;
QAction * configureAction = nullptr;
QAction * quitAction = nullptr;
QWidgetAction *searchAction = nullptr;
QWidgetAction *spacerAction = nullptr;
QAction *configureAction = nullptr;
QAction *quitAction = nullptr;
// The help menu
QAction * aboutViewAction = nullptr;
QAction * aboutModuleAction = nullptr;
KActionMenu * helpActionMenu = nullptr;
QAction *aboutViewAction = nullptr;
QAction *aboutModuleAction = nullptr;
KActionMenu *helpActionMenu = nullptr;
// The configuration
KConfigDialog * configDialog = nullptr;
KConfigDialog *configDialog = nullptr;
Ui::ConfigDialog configWidget;
QButtonGroup viewSelection;
// The control module
QStackedWidget * stackedWidget = nullptr;
QStackedWidget *stackedWidget = nullptr;
// The module list
MenuItem * rootModule = nullptr;
MenuItem * homeModule = nullptr;
MenuItem * lostFound = nullptr;
MenuItem *rootModule = nullptr;
MenuItem *homeModule = nullptr;
MenuItem *lostFound = nullptr;
KService::List categories;
KService::List modules;
// The about dialog
KAboutApplicationDialog * aboutDialog = nullptr;
KAboutApplicationDialog *aboutDialog = nullptr;
BaseMode::ApplicationMode m_mode = BaseMode::SystemSettings;
QString m_startupModule;
QStringList m_startupModuleArgs;
......
......@@ -21,17 +21,17 @@
#include "MenuItem.h"
#include <QRect>
#include <QAbstractItemView>
#include <QApplication>
#include <QGridLayout>
#include <QLabel>
#include <QTimer>
#include <QRect>
#include <QScrollBar>
#include <QGridLayout>
#include <QApplication>
#include <QAbstractItemView>
#include <QStyle>
#include <QTimer>
#include <KIconLoader>
#include <KColorScheme>
#include <KIconLoader>
#include <KLocalizedString>
#include <KToolTipWidget>
......@@ -48,22 +48,23 @@ Q_GLOBAL_STATIC(IconLoaderSingleton, privateIconLoaderSelf)
class ToolTipManager::Private
{
public:
Private() :
tooltip(nullptr),
view(nullptr),
timer(nullptr),
delay(QApplication::style()->styleHint(QStyle::SH_ToolTip_WakeUpDelay))
{ }
Private()
: tooltip(nullptr)
, view(nullptr)
, timer(nullptr)
, delay(QApplication::style()->styleHint(QStyle::SH_ToolTip_WakeUpDelay))
{
}
KToolTipWidget *tooltip;
QAbstractItemView* view;
QTimer* timer;
QAbstractItemView *view;
QTimer *timer;
QModelIndex item;
QRect itemRect;
int delay;
};
ToolTipManager::ToolTipManager(QAbstractItemView* parent)
ToolTipManager::ToolTipManager(QAbstractItemView *parent)
: QObject(parent)
, d(new ToolTipManager::Private)
{
......@@ -92,27 +93,27 @@ ToolTipManager::~ToolTipManager()
delete d;
}
bool ToolTipManager::eventFilter(QObject* watched, QEvent* event)
bool ToolTipManager::eventFilter(QObject *watched, QEvent *event)
{
if (watched == d->view->viewport()) {
switch (event->type()) {
case QEvent::Leave:
case QEvent::MouseButtonPress:
hideToolTip();
break;
default:
break;
case QEvent::Leave:
case QEvent::MouseButtonPress:
hideToolTip();
break;
default:
break;
}
}
return QObject::eventFilter(watched, event);
}
void ToolTipManager::requestToolTip(const QModelIndex& index)
void ToolTipManager::requestToolTip(const QModelIndex &index)
{
// only request a tooltip for the name column and when no selection or
// drag & drop operation is done (indicated by the left mouse button)
if ( !(QApplication::mouseButtons() & Qt::LeftButton) ) {
if (!(QApplication::mouseButtons() & Qt::LeftButton)) {
d->tooltip->hide();
d->itemRect = d->view->visualRect(index);
......@@ -133,101 +134,99 @@ void ToolTipManager::hideToolTip()
void ToolTipManager::prepareToolTip()
{
showToolTip( d->item );
showToolTip(d->item);
}
void ToolTipManager::showToolTip( const QModelIndex &menuItem )
void ToolTipManager::showToolTip(const QModelIndex &menuItem)
{
if (QApplication::mouseButtons() & Qt::LeftButton) {
return;
}
QWidget * tip = createTipContent( menuItem );
QWidget *tip = createTipContent(menuItem);
d->tooltip->showBelow(d->itemRect, tip, d->view->nativeParentWidget()->windowHandle());
connect(d->tooltip, &KToolTipWidget::hidden, tip, &QObject::deleteLater);
}
QWidget * ToolTipManager::createTipContent( QModelIndex item )
QWidget *ToolTipManager::createTipContent(QModelIndex item)
{
const QSize dialogIconSize = QSize(IconSize(KIconLoader::Dialog), IconSize(KIconLoader::Dialog));
const QSize toolbarIconSize = QSize(IconSize(KIconLoader::MainToolbar), IconSize(KIconLoader::MainToolbar));
QWidget * tipContent = new QWidget();
QGridLayout* tipLayout = new QGridLayout();
tipLayout->setAlignment( Qt::AlignLeft );
QWidget *tipContent = new QWidget();
QGridLayout *tipLayout = new QGridLayout();
tipLayout->setAlignment(Qt::AlignLeft);
QLayout * primaryLine = generateToolTipLine( &item, tipContent, dialogIconSize, true );
primaryLine->setAlignment( Qt::AlignLeft );
tipLayout->addLayout( primaryLine, 0, 0, Qt::AlignLeft );
QLayout *primaryLine = generateToolTipLine(&item, tipContent, dialogIconSize, true);
primaryLine->setAlignment(Qt::AlignLeft);
tipLayout->addLayout(primaryLine, 0, 0, Qt::AlignLeft);
for ( int done = 0; d->view->model()->rowCount( item ) > done; done = 1 + done ) {
QModelIndex childItem = d->view->model()->index( done, 0, item );
QLayout * subLine = generateToolTipLine( &childItem, tipContent, toolbarIconSize, false );
subLine->setAlignment( Qt::AlignLeft );
tipLayout->addLayout( subLine, done + 2, 0, Qt::AlignLeft );
for (int done = 0; d->view->model()->rowCount(item) > done; done = 1 + done) {
QModelIndex childItem = d->view->model()->index(done, 0, item);
QLayout *subLine = generateToolTipLine(&childItem, tipContent, toolbarIconSize, false);
subLine->setAlignment(Qt::AlignLeft);
tipLayout->addLayout(subLine, done + 2, 0, Qt::AlignLeft);
}
tipLayout->setVerticalSpacing( tipContent->fontMetrics().height() / 3 );
tipContent->setLayout( tipLayout );
tipLayout->setVerticalSpacing(tipContent->fontMetrics().height() / 3);
tipContent->setLayout(tipLayout);
if( d->view->model()->rowCount( item ) > 0 ) {
QFrame * separatorLine = new QFrame( tipContent );
separatorLine->setFrameStyle( QFrame::HLine );
tipLayout->addWidget( separatorLine, 1, 0 );
if (d->view->model()->rowCount(item) > 0) {
QFrame *separatorLine = new QFrame(tipContent);
separatorLine->setFrameStyle(QFrame::HLine);
tipLayout->addWidget(separatorLine, 1, 0);
}
return tipContent;
}
QLayout * ToolTipManager::generateToolTipLine( QModelIndex * item, QWidget * toolTip, QSize iconSize, bool comment )
QLayout *ToolTipManager::generateToolTipLine(QModelIndex *item, QWidget *toolTip, QSize iconSize, bool comment)
{
// Get MenuItem
MenuItem * menuItem = d->view->model()->data( *item, Qt::UserRole ).value<MenuItem*>();
MenuItem *menuItem = d->view->model()->data(*item, Qt::UserRole).value<MenuItem *>();
QString text = menuItem->name();
if ( comment ) {
text = QStringLiteral( "<b>%1</b>" ).arg( menuItem->name() );
if (comment) {
text = QStringLiteral("<b>%1</b>").arg(menuItem->name());
}
// Generate text
if ( comment ) {
if (comment) {
text += QStringLiteral("<br />");
if ( !menuItem->service()->comment().isEmpty() ) {
if (!menuItem->service()->comment().isEmpty()) {
text += menuItem->service()->comment();
} else {
int childCount = d->view->model()->rowCount( *item );
text += i18np( "Contains 1 item", "Contains %1 items", childCount );
int childCount = d->view->model()->rowCount(*item);
text += i18np("Contains 1 item", "Contains %1 items", childCount);
}
}
QLabel * textLabel = new QLabel( toolTip );
textLabel->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
QLabel *textLabel = new QLabel(toolTip);
textLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
textLabel->setForegroundRole(QPalette::ToolTipText);
textLabel->setText( text );
textLabel->setText(text);
// Get icon
QPalette pal = textLabel->palette();
for (auto state : { QPalette::Active, QPalette::Inactive, QPalette::Disabled }) {
pal.setBrush(state, QPalette::WindowText, pal.toolTipText());
for (auto state : {QPalette::Active, QPalette::Inactive, QPalette::Disabled}) {
pal.setBrush(state, QPalette::WindowText, pal.toolTipText());
pal.setBrush(state, QPalette::Window, pal.toolTipBase());
}
privateIconLoaderSelf->self.setCustomPalette(pal);
QIcon icon = KDE::icon(menuItem->service()->icon(), &privateIconLoaderSelf->self);
QLabel * iconLabel = new QLabel( toolTip );
iconLabel->setPixmap( icon.pixmap(iconSize) );
iconLabel->setMaximumSize( iconSize );
QLabel *iconLabel = new QLabel(toolTip);
iconLabel->setPixmap(icon.pixmap(iconSize));
iconLabel->setMaximumSize(iconSize);
// Generate layout
QHBoxLayout * layout = new QHBoxLayout();
layout->setSpacing( textLabel->fontMetrics().height() / 3 );
layout->setAlignment( Qt::AlignLeft );
layout->addWidget( iconLabel, Qt::AlignLeft );
layout->addWidget( textLabel, Qt::AlignLeft );
QHBoxLayout *layout = new QHBoxLayout();
layout->setSpacing(textLabel->fontMetrics().height() / 3);
layout->setAlignment(Qt::AlignLeft);
layout->addWidget(iconLabel, Qt::AlignLeft);
layout->addWidget(textLabel, Qt::AlignLeft);
return layout;
}
......@@ -20,8 +20,8 @@
#ifndef TOOLTIPMANAGER_H
#define TOOLTIPMANAGER_H
#include <QObject>
#include <QModelIndex>
#include <QObject>
class QLayout;
class QAbstractItemView;
......@@ -39,12 +39,12 @@ class ToolTipManager : public QObject
public:
/**
* Standard constructor. The ToolTipManager will start handling ToolTip events on the provided
* view immediately.
*
* @param parent The view which will have the tooltips displayed for.
*/
explicit ToolTipManager(QAbstractItemView* parent);
* Standard constructor. The ToolTipManager will start handling ToolTip events on the provided
* view immediately.
*
* @param parent The view which will have the tooltips displayed for.
*/
explicit ToolTipManager(QAbstractItemView *parent);
~ToolTipManager() override;
public Q_SLOTS:
......@@ -56,19 +56,19 @@ public Q_SLOTS:
void hideToolTip();
protected:
bool eventFilter(QObject* watched, QEvent* event) override;
bool eventFilter(QObject *watched, QEvent *event) override;
private Q_SLOTS:
void prepareToolTip();
void requestToolTip(const QModelIndex& index);
void requestToolTip(const QModelIndex &index);
private:
void showToolTip( const QModelIndex &menuItem );
QWidget * createTipContent( QModelIndex item );
QLayout * generateToolTipLine( QModelIndex * item, QWidget * toolTip, QSize iconSize, bool comment );
void showToolTip(const QModelIndex &menuItem);
QWidget *createTipContent(QModelIndex item);
QLayout *generateToolTipLine(QModelIndex *item, QWidget *toolTip, QSize iconSize, bool comment);
class Private;
ToolTipManager::Private* d;
ToolTipManager::Private *d;
};
#endif
......@@ -21,17 +21,17 @@
* Boston, MA 02110-1301, USA.
*/
#include <QCommandLineParser>
#include <KAboutData>
#include <KCrash>
#include <QCommandLineParser>
#include <iostream>
#include <kworkspace.h>
#include <KAuthorized>
#include <KDBusService>
#include <KQuickAddons/QtQuickSettings>
#include <KServiceTypeTrader>
#include <KAuthorized>
#include <KWindowSystem>
#include <iostream>
#include <kworkspace.h>
#include "SettingsBase.h"
......@@ -39,9 +39,7 @@ KService::List m_modules;
static bool caseInsensitiveLessThan(const KService::Ptr s1, const KService::Ptr s2)
{
const int compare = QString::compare(s1->desktopEntryName(),
s2->desktopEntryName(),
Qt::CaseInsensitive);
const int compare = QString::compare(s1->desktopEntryName(), s2->desktopEntryName(), Qt::CaseInsensitive);
return (compare < 0);
}
......@@ -49,8 +47,11 @@ static void listModules()
{
// First condition is what systemsettings does, second what kinfocenter does, make sure this is kept in sync
// We need the exist calls because otherwise the trader language aborts if the property doesn't exist and the second part of the or is not evaluated
const KService::List services = KServiceTypeTrader::self()->query( QStringLiteral("KCModule"), QStringLiteral("(exist [X-KDE-System-Settings-Parent-Category] and [X-KDE-System-Settings-Parent-Category] != '') or (exist [X-KDE-ParentApp] and [X-KDE-ParentApp] == 'kinfocenter')") );
for( KService::List::const_iterator it = services.constBegin(); it != services.constEnd(); ++it) {
const KService::List services =
KServiceTypeTrader::self()->query(QStringLiteral("KCModule"),
QStringLiteral("(exist [X-KDE-System-Settings-Parent-Category] and [X-KDE-System-Settings-Parent-Category] != '') or "
"(exist [X-KDE-ParentApp] and [X-KDE-ParentApp] == 'kinfocenter')"));
for (KService::List::const_iterator it = services.constBegin(); it != services.constEnd(); ++it) {
const KService::Ptr s = (*it);
if (!KAuthorized::authorizeControlModule(s->menuId()))
continue;
......@@ -60,7 +61,7 @@ static void listModules()
std::stable_sort(m_modules.begin(), m_modules.end(), caseInsensitiveLessThan);
}
int main( int argc, char *argv[] )
int main(int argc, char *argv[])
{
// Make sure the binary name is either kinfocenter or systemsettings,
// Anything else will just be considered as "systemsettings"
......@@ -72,8 +73,8 @@ int main( int argc, char *argv[] )
mode = BaseMode::InfoCenter;
}
//exec is systemsettings5, but we need the QPT to use the right config from the qApp constructor
//which is before KAboutData::setApplicationData
// exec is systemsettings5, but we need the QPT to use the right config from the qApp constructor
// which is before KAboutData::setApplicationData
QCoreApplication::setApplicationName(binaryName);
// This has to be before the QApplication is created.
......@@ -89,13 +90,23 @@ int main( int argc, char *argv[] )
if (mode == BaseMode::InfoCenter) {
// About data
aboutData = KAboutData(QStringLiteral("kinfocenter"), i18n("Info Center"), QLatin1String(PROJECT_VERSION), i18n("Centralized and convenient overview of system information."), KAboutLicense::GPL, i18n("(c) 2009, Ben Cooksley"));
aboutData = KAboutData(QStringLiteral("kinfocenter"),
i18n("Info Center"),
QLatin1String(PROJECT_VERSION),
i18n("Centralized and convenient overview of system information."),
KAboutLicense::GPL,
i18n("(c) 2009, Ben Cooksley"));
aboutData.setDesktopFileName(QStringLiteral("org.kde.kinfocenter"));
application.setWindowIcon(QIcon::fromTheme(QStringLiteral("hwinfo")));
} else {
aboutData = KAboutData(QStringLiteral("systemsettings"), i18n("System Settings"), QLatin1String(PROJECT_VERSION), i18n("Central configuration center by KDE."), KAboutLicense::GPL, i18n("(c) 2009, Ben Cooksley"));
aboutData = KAboutData(QStringLiteral("systemsettings"),
i18n("System Settings"),
QLatin1String(PROJECT_VERSION),
i18n("Central configuration center by KDE."),
KAboutLicense::GPL,
i18n("(c) 2009, Ben Cooksley"));
if (qEnvironmentVariableIsSet("KDE_FULL_SESSION")) {
aboutData.setDesktopFileName(QStringLiteral("systemsettings"));
......@@ -130,7 +141,7 @@ int main( int argc, char *argv[] )
listModules();
int maxLen=0;
int maxLen = 0;
for (KService::List::ConstIterator it = m_modules.constBegin(); it != m_modules.constEnd(); ++it) {
int len = (*it)->desktopEntryName().length();
......@@ -142,8 +153,7 @@ int main( int argc, char *argv[] )
QString entry(QStringLiteral("%1 - %2"));
entry = entry.arg((*it)->desktopEntryName().leftJustified(maxLen, QLatin1Char(' ')))
.arg(!(*it)->comment().isEmpty() ? (*it)->comment()
: i18n("No description available"));
.arg(!(*it)->comment().isEmpty() ? (*it)->comment() : i18n("No description available"));
std::cout << entry.toLocal8Bit().data() << std::endl;
}
......
......@@ -24,14 +24,17 @@
#include <KConfigGroup>
#include <KSharedConfig>
class DataHelper {
class DataHelper
{
public:
DataHelper() {}
~DataHelper() {
DataHelper()
{
}
~DataHelper()
{
delete object;
}
BaseData * object = nullptr;
BaseData *object = nullptr;
};
Q_GLOBAL_STATIC(DataHelper, internalInstance)
......@@ -47,35 +50,33 @@ BaseData::~BaseData()
BaseData *BaseData::instance()
{
if( !internalInstance->object ) {
if (!internalInstance->object) {
new BaseData();
}
return internalInstance->object;
}
MenuItem * BaseData::menuItem()
MenuItem *BaseData::menuItem()
{
return rootMenu;
}
void BaseData::setMenuItem( MenuItem * item )
void BaseData::setMenuItem(MenuItem *item)
{
rootMenu = item;
}
MenuItem * BaseData::homeItem()
MenuItem *BaseData::homeItem()
{
return m_homeItem;
}
void BaseData::setHomeItem( MenuItem * item )
void BaseData::setHomeItem(MenuItem *item)
{
m_homeItem = item;
}
KConfigGroup BaseData::configGroup( const QString& pluginName )
KConfigGroup BaseData::configGroup(const QString &pluginName)
{
return KSharedConfig::openConfig()->group( pluginName );
return KSharedConfig::openConfig()->group(pluginName);
}
......@@ -30,10 +30,10 @@ class KConfigGroup;
* @brief Provides a interface sharing common data between modules in System Settings
*
* BaseData is a standard interface in System Settings to retrieve information that is shared between all modules.
* It is a singleton, and will be automatically cleaned up.
* It is a singleton, and will be automatically cleaned up.
*
* @author Ben Cooksley <bcooksley@kde.org>
*/
*/
class BaseData : public QObject
{
Q_OBJECT
......@@ -48,35 +48,35 @@ public:
*
* @returns Access to the shared instance of BaseData.
*/
static BaseData* instance();
static BaseData *instance();
/**
* Normal destructor that handles cleanup. Any objects created through BaseData must be assumed
* to be invalid afterwards.
*/
* Normal destructor that handles cleanup. Any objects created through BaseData must be assumed
* to be invalid afterwards.
*/
~BaseData() override;
/**
* Provides the shared MenuItem which lists all categories and modules, for use with MenuModel.
*
* @returns the shared MenuItem.
*/
MenuItem * menuItem();
* Provides the shared MenuItem which lists all categories and modules, for use with MenuModel.