diff --git a/kcms/colors/editor/scmeditorcolors.cpp b/kcms/colors/editor/scmeditorcolors.cpp index fc94fec24..5b25123cb 100644 --- a/kcms/colors/editor/scmeditorcolors.cpp +++ b/kcms/colors/editor/scmeditorcolors.cpp @@ -1,527 +1,527 @@ /* KDE Display color scheme setup module * Copyright (C) 2007 Matthew Woehlke * Copyright (C) 2007 Jeremy Whiting * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "scmeditorcolors.h" #include #include #include //BEGIN WindecoColors SchemeEditorColors::WindecoColors::WindecoColors(const KSharedConfigPtr &config) { load(config); } void SchemeEditorColors::WindecoColors::load(const KSharedConfigPtr &config) { // NOTE: keep this in sync with kdelibs/kdeui/kernel/kglobalsettings.cpp KConfigGroup group(config, "WM"); m_colors[ActiveBackground] = group.readEntry("activeBackground", QColor(48, 174, 232)); m_colors[ActiveForeground] = group.readEntry("activeForeground", QColor(255, 255, 255)); m_colors[InactiveBackground] = group.readEntry("inactiveBackground", QColor(224, 223, 222)); m_colors[InactiveForeground] = group.readEntry("inactiveForeground", QColor(75, 71, 67)); m_colors[ActiveBlend] = group.readEntry("activeBlend", m_colors[ActiveForeground]); m_colors[InactiveBlend] = group.readEntry("inactiveBlend", m_colors[InactiveForeground]); } QColor SchemeEditorColors::WindecoColors::color(WindecoColors::Role role) const { return m_colors[role]; } //END WindecoColors SchemeEditorColors::SchemeEditorColors(KSharedConfigPtr config, QWidget *parent) : QWidget( parent ) , m_config( config ) { setupUi(this); setupColorTable(); connect(colorSet, static_cast(&QComboBox::currentIndexChanged), this, &SchemeEditorColors::updateColorTable); } void SchemeEditorColors::updateValues() { const int currentSet = colorSet->currentIndex() - 1; setPreview->setPalette(m_config, (KColorScheme::ColorSet)currentSet); colorPreview->setPalette(m_config); } void SchemeEditorColors::setupColorTable() { // first setup the common colors table commonColorTable->verticalHeader()->hide(); commonColorTable->horizontalHeader()->hide(); commonColorTable->setShowGrid(false); - commonColorTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch); + commonColorTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); int minWidth = QPushButton(i18n("Varies")).minimumSizeHint().width(); commonColorTable->horizontalHeader()->setMinimumSectionSize(minWidth); - commonColorTable->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents); + commonColorTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents); for (int i = 0; i < 26; ++i) { KColorButton * button = new KColorButton(this); commonColorTable->setRowHeight(i, button->sizeHint().height()); button->setObjectName(QString::number(i)); connect(button, &KColorButton::changed, this, &SchemeEditorColors::colorChanged); m_commonColorButtons << button; if (i > 8 && i < 18) { // Inactive Text row through Positive Text role all need a varies button QPushButton * variesButton = new QPushButton(nullptr); variesButton->setText(i18n("Varies")); variesButton->setObjectName(QString::number(i)); connect(variesButton, &QPushButton::clicked, this, &SchemeEditorColors::variesClicked); QStackedWidget * widget = new QStackedWidget(this); widget->addWidget(button); widget->addWidget(variesButton); m_stackedWidgets.append(widget); commonColorTable->setCellWidget(i, 1, widget); } else { commonColorTable->setCellWidget(i, 1, button); } } // then the colorTable that the colorSets will use colorTable->verticalHeader()->hide(); colorTable->horizontalHeader()->hide(); colorTable->setShowGrid(false); colorTable->setRowCount(12); colorTable->horizontalHeader()->setMinimumSectionSize(minWidth); - colorTable->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents); + colorTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents); createColorEntry(i18n("Normal Background"), QStringLiteral("BackgroundNormal"), m_backgroundButtons, 0); createColorEntry(i18n("Alternate Background"), QStringLiteral("BackgroundAlternate"), m_backgroundButtons, 1); createColorEntry(i18n("Normal Text"), QStringLiteral("ForegroundNormal"), m_foregroundButtons, 2); createColorEntry(i18n("Inactive Text"), QStringLiteral("ForegroundInactive"), m_foregroundButtons, 3); createColorEntry(i18n("Active Text"), QStringLiteral("ForegroundActive"), m_foregroundButtons, 4); createColorEntry(i18n("Link Text"), QStringLiteral("ForegroundLink"), m_foregroundButtons, 5); createColorEntry(i18n("Visited Text"), QStringLiteral("ForegroundVisited"), m_foregroundButtons, 6); createColorEntry(i18n("Negative Text"), QStringLiteral("ForegroundNegative"), m_foregroundButtons, 7); createColorEntry(i18n("Neutral Text"), QStringLiteral("ForegroundNeutral"), m_foregroundButtons, 8); createColorEntry(i18n("Positive Text"), QStringLiteral("ForegroundPositive"), m_foregroundButtons, 9); createColorEntry(i18n("Focus Decoration"), QStringLiteral("DecorationFocus"), m_decorationButtons, 10); createColorEntry(i18n("Hover Decoration"), QStringLiteral("DecorationHover"), m_decorationButtons, 11); - colorTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch); - colorTable->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents); + colorTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); + colorTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents); updateColorSchemes(); updateColorTable(); } void SchemeEditorColors::createColorEntry(const QString &text, const QString &key, QList &list, int index) { KColorButton *button = new KColorButton(this); button->setObjectName(QString::number(index)); connect(button, &KColorButton::changed, this, &SchemeEditorColors::colorChanged); list.append(button); m_colorKeys.insert(index, key); QTableWidgetItem *label = new QTableWidgetItem(text); colorTable->setItem(index, 0, label); colorTable->setCellWidget(index, 1, button); colorTable->setRowHeight(index, button->sizeHint().height()); } void SchemeEditorColors::variesClicked() { // find which button was changed const int row = sender()->objectName().toInt(); QColor color = QColorDialog::getColor(QColor(), this); if(color.isValid()) { changeColor(row, color); m_stackedWidgets[row - 9]->setCurrentIndex(0); } } void SchemeEditorColors::colorChanged( const QColor &newColor ) { // find which button was changed const int row = sender()->objectName().toInt(); changeColor(row, newColor); } void SchemeEditorColors::changeColor(int row, const QColor &newColor) { // update the m_colorSchemes for the selected colorSet const int currentSet = colorSet->currentIndex() - 1; if (currentSet == -1) { // common colors is selected switch (row) { case 0: // View Background button KConfigGroup(m_config, "Colors:View").writeEntry("BackgroundNormal", newColor); break; case 1: // View Text button KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundNormal", newColor); break; case 2: // Window Background Button KConfigGroup(m_config, "Colors:Window").writeEntry("BackgroundNormal", newColor); break; case 3: // Window Text Button KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundNormal", newColor); break; case 4: // Button Background button KConfigGroup(m_config, "Colors:Button").writeEntry("BackgroundNormal", newColor); break; case 5: // Button Text button KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundNormal", newColor); break; case 6: // Selection Background Button KConfigGroup(m_config, "Colors:Selection").writeEntry("BackgroundNormal", newColor); break; case 7: // Selection Text Button KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundNormal", newColor); break; case 8: // Selection Inactive Text Button KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundInactive", newColor); break; // buttons that could have varies in their place case 9: // Inactive Text Button (set all but Selection Inactive Text color) KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundInactive", newColor); KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundInactive", newColor); KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundInactive", newColor); KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundInactive", newColor); break; case 10: // Active Text Button (set all active text colors) KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundActive", newColor); KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundActive", newColor); KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundActive", newColor); KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundActive", newColor); KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundActive", newColor); break; case 11: // Link Text Button (set all link text colors) KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundLink", newColor); KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundLink", newColor); KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundLink", newColor); KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundLink", newColor); KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundLink", newColor); break; case 12: // Visited Text Button (set all visited text colors) KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundVisited", newColor); KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundVisited", newColor); KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundVisited", newColor); KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundVisited", newColor); KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundVisited", newColor); break; case 13: // Negative Text Button (set all negative text colors) KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundNegative", newColor); KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundNegative", newColor); KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundNegative", newColor); KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundNegative", newColor); KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundNegative", newColor); break; case 14: // Neutral Text Button (set all neutral text colors) KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundNeutral", newColor); KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundNeutral", newColor); KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundNeutral", newColor); KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundNeutral", newColor); KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundNeutral", newColor); break; case 15: // Positive Text Button (set all positive text colors) KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundPositive", newColor); KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundPositive", newColor); KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundPositive", newColor); KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundPositive", newColor); KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundPositive", newColor); break; case 16: // Focus Decoration Button (set all focus decoration colors) KConfigGroup(m_config, "Colors:View").writeEntry("DecorationFocus", newColor); KConfigGroup(m_config, "Colors:Window").writeEntry("DecorationFocus", newColor); KConfigGroup(m_config, "Colors:Selection").writeEntry("DecorationFocus", newColor); KConfigGroup(m_config, "Colors:Button").writeEntry("DecorationFocus", newColor); KConfigGroup(m_config, "Colors:Tooltip").writeEntry("DecorationFocus", newColor); break; case 17: // Hover Decoration Button (set all hover decoration colors) KConfigGroup(m_config, "Colors:View").writeEntry("DecorationHover", newColor); KConfigGroup(m_config, "Colors:Window").writeEntry("DecorationHover", newColor); KConfigGroup(m_config, "Colors:Selection").writeEntry("DecorationHover", newColor); KConfigGroup(m_config, "Colors:Button").writeEntry("DecorationHover", newColor); KConfigGroup(m_config, "Colors:Tooltip").writeEntry("DecorationHover", newColor); break; case 18: // Tooltip Background button KConfigGroup(m_config, "Colors:Tooltip").writeEntry("BackgroundNormal", newColor); break; case 19: // Tooltip Text button KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundNormal", newColor); break; case 20: // Active Title Background KConfigGroup(m_config, "WM").writeEntry("activeBackground", newColor); break; case 21: // Active Title Text KConfigGroup(m_config, "WM").writeEntry("activeForeground", newColor); break; case 22: // Active Title Secondary KConfigGroup(m_config, "WM").writeEntry("activeBlend", newColor); break; case 23: // Inactive Title Background KConfigGroup(m_config, "WM").writeEntry("inactiveBackground", newColor); break; case 24: // Inactive Title Text KConfigGroup(m_config, "WM").writeEntry("inactiveForeground", newColor); break; case 25: // Inactive Title Secondary KConfigGroup(m_config, "WM").writeEntry("inactiveBlend", newColor); break; } m_commonColorButtons[row]->blockSignals(true); m_commonColorButtons[row]->setColor(newColor); m_commonColorButtons[row]->blockSignals(false); } else { QString group = colorSetGroupKey(currentSet); KConfigGroup(m_config, group).writeEntry(m_colorKeys[row], newColor); } updateColorSchemes(); emit changed(true); } QString SchemeEditorColors::colorSetGroupKey(int colorSet) { QString group; switch (colorSet) { case KColorScheme::Window: group = QStringLiteral("Colors:Window"); break; case KColorScheme::Button: group = QStringLiteral("Colors:Button"); break; case KColorScheme::Selection: group = QStringLiteral("Colors:Selection"); break; case KColorScheme::Tooltip: group = QStringLiteral("Colors:Tooltip"); break; case KColorScheme::Complementary: group = QStringLiteral("Colors:Complementary"); break; default: group = QStringLiteral("Colors:View"); } return group; } void SchemeEditorColors::updateColorSchemes() { m_colorSchemes.clear(); m_colorSchemes.append(KColorScheme(QPalette::Active, KColorScheme::View, m_config)); m_colorSchemes.append(KColorScheme(QPalette::Active, KColorScheme::Window, m_config)); m_colorSchemes.append(KColorScheme(QPalette::Active, KColorScheme::Button, m_config)); m_colorSchemes.append(KColorScheme(QPalette::Active, KColorScheme::Selection, m_config)); m_colorSchemes.append(KColorScheme(QPalette::Active, KColorScheme::Tooltip, m_config)); m_colorSchemes.append(KColorScheme(QPalette::Active, KColorScheme::Complementary, m_config)); m_wmColors.load(m_config); } void SchemeEditorColors::updateColorTable() { // subtract one here since the 0 item is "Common Colors" const int currentSet = colorSet->currentIndex() - 1; if (currentSet == -1) { // common colors is selected stackColors->setCurrentIndex(0); stackPreview->setCurrentIndex(0); KColorButton * button; foreach (button, m_commonColorButtons) { button->blockSignals(true); } m_commonColorButtons[0]->setColor(m_colorSchemes[KColorScheme::View].background(KColorScheme::NormalBackground).color()); m_commonColorButtons[1]->setColor(m_colorSchemes[KColorScheme::View].foreground(KColorScheme::NormalText).color()); m_commonColorButtons[2]->setColor(m_colorSchemes[KColorScheme::Window].background(KColorScheme::NormalBackground).color()); m_commonColorButtons[3]->setColor(m_colorSchemes[KColorScheme::Window].foreground(KColorScheme::NormalText).color()); m_commonColorButtons[4]->setColor(m_colorSchemes[KColorScheme::Button].background(KColorScheme::NormalBackground).color()); m_commonColorButtons[5]->setColor(m_colorSchemes[KColorScheme::Button].foreground(KColorScheme::NormalText).color()); m_commonColorButtons[6]->setColor(m_colorSchemes[KColorScheme::Selection].background(KColorScheme::NormalBackground).color()); m_commonColorButtons[7]->setColor(m_colorSchemes[KColorScheme::Selection].foreground(KColorScheme::NormalText).color()); m_commonColorButtons[8]->setColor(m_colorSchemes[KColorScheme::Selection].foreground(KColorScheme::InactiveText).color()); setCommonForeground(KColorScheme::InactiveText, 0, 9); setCommonForeground(KColorScheme::ActiveText, 1, 10); setCommonForeground(KColorScheme::LinkText, 2, 11); setCommonForeground(KColorScheme::VisitedText, 3, 12); setCommonForeground(KColorScheme::NegativeText, 4, 13); setCommonForeground(KColorScheme::NeutralText, 5, 14); setCommonForeground(KColorScheme::PositiveText, 6, 15); setCommonDecoration(KColorScheme::FocusColor, 7, 16); setCommonDecoration(KColorScheme::HoverColor, 8, 17); m_commonColorButtons[18]->setColor(m_colorSchemes[KColorScheme::Tooltip].background(KColorScheme::NormalBackground).color()); m_commonColorButtons[19]->setColor(m_colorSchemes[KColorScheme::Tooltip].foreground(KColorScheme::NormalText).color()); m_commonColorButtons[20]->setColor(m_wmColors.color(WindecoColors::ActiveBackground)); m_commonColorButtons[21]->setColor(m_wmColors.color(WindecoColors::ActiveForeground)); m_commonColorButtons[22]->setColor(m_wmColors.color(WindecoColors::ActiveBlend)); m_commonColorButtons[23]->setColor(m_wmColors.color(WindecoColors::InactiveBackground)); m_commonColorButtons[24]->setColor(m_wmColors.color(WindecoColors::InactiveForeground)); m_commonColorButtons[25]->setColor(m_wmColors.color(WindecoColors::InactiveBlend)); foreach (button, m_commonColorButtons) { button->blockSignals(false); } } else { // a real color set is selected setPreview->setPalette(m_config, (KColorScheme::ColorSet)currentSet); stackColors->setCurrentIndex(1); stackPreview->setCurrentIndex(1); for (int i = KColorScheme::NormalBackground; i <= KColorScheme::AlternateBackground; ++i) { m_backgroundButtons[i]->blockSignals(true); m_backgroundButtons[i]->setColor(m_colorSchemes[currentSet].background(KColorScheme::BackgroundRole(i)).color()); m_backgroundButtons[i]->blockSignals(false); } for (int i = KColorScheme::NormalText; i <= KColorScheme::PositiveText; ++i) { m_foregroundButtons[i]->blockSignals(true); m_foregroundButtons[i]->setColor(m_colorSchemes[currentSet].foreground(KColorScheme::ForegroundRole(i)).color()); m_foregroundButtons[i]->blockSignals(false); } for (int i = KColorScheme::FocusColor; i <= KColorScheme::HoverColor; ++i) { m_decorationButtons[i]->blockSignals(true); m_decorationButtons[i]->setColor(m_colorSchemes[currentSet].decoration(KColorScheme::DecorationRole(i)).color()); m_decorationButtons[i]->blockSignals(false); } } } void SchemeEditorColors::setCommonForeground(KColorScheme::ForegroundRole role, int stackIndex, int buttonIndex) { QColor color = m_colorSchemes[KColorScheme::View].foreground(role).color(); for (int i = KColorScheme::Window; i < KColorScheme::Tooltip; ++i) { if (i == KColorScheme::Selection && role == KColorScheme::InactiveText) break; if (m_colorSchemes[i].foreground(role).color() != color) { m_stackedWidgets[stackIndex]->setCurrentIndex(1); return; } } m_stackedWidgets[stackIndex]->setCurrentIndex(0); m_commonColorButtons[buttonIndex]->setColor(color); } void SchemeEditorColors::setCommonDecoration(KColorScheme::DecorationRole role, int stackIndex, int buttonIndex) { QColor color = m_colorSchemes[KColorScheme::View].decoration(role).color(); for (int i = KColorScheme::Window; i < KColorScheme::Tooltip; ++i) { if (m_colorSchemes[i].decoration(role).color() != color) { m_stackedWidgets[stackIndex]->setCurrentIndex(1); return; } } m_stackedWidgets[stackIndex]->setCurrentIndex(0); m_commonColorButtons[buttonIndex]->setColor(color); } void SchemeEditorColors::updateFromColorSchemes() { for (int i = KColorScheme::View; i <= KColorScheme::Tooltip; ++i) { KConfigGroup group(m_config, colorSetGroupKey(i)); group.writeEntry("BackgroundNormal", m_colorSchemes[i].background(KColorScheme::NormalBackground).color()); group.writeEntry("BackgroundAlternate", m_colorSchemes[i].background(KColorScheme::AlternateBackground).color()); group.writeEntry("ForegroundNormal", m_colorSchemes[i].foreground(KColorScheme::NormalText).color()); group.writeEntry("ForegroundInactive", m_colorSchemes[i].foreground(KColorScheme::InactiveText).color()); group.writeEntry("ForegroundActive", m_colorSchemes[i].foreground(KColorScheme::ActiveText).color()); group.writeEntry("ForegroundLink", m_colorSchemes[i].foreground(KColorScheme::LinkText).color()); group.writeEntry("ForegroundVisited", m_colorSchemes[i].foreground(KColorScheme::VisitedText).color()); group.writeEntry("ForegroundNegative", m_colorSchemes[i].foreground(KColorScheme::NegativeText).color()); group.writeEntry("ForegroundNeutral", m_colorSchemes[i].foreground(KColorScheme::NeutralText).color()); group.writeEntry("ForegroundPositive", m_colorSchemes[i].foreground(KColorScheme::PositiveText).color()); group.writeEntry("DecorationFocus", m_colorSchemes[i].decoration(KColorScheme::FocusColor).color()); group.writeEntry("DecorationHover", m_colorSchemes[i].decoration(KColorScheme::HoverColor).color()); } KConfigGroup WMGroup(m_config, "WM"); WMGroup.writeEntry("activeBackground", m_wmColors.color(WindecoColors::ActiveBackground)); WMGroup.writeEntry("activeForeground", m_wmColors.color(WindecoColors::ActiveForeground)); WMGroup.writeEntry("inactiveBackground", m_wmColors.color(WindecoColors::InactiveBackground)); WMGroup.writeEntry("inactiveForeground", m_wmColors.color(WindecoColors::InactiveForeground)); WMGroup.writeEntry("activeBlend", m_wmColors.color(WindecoColors::ActiveBlend)); WMGroup.writeEntry("inactiveBlend", m_wmColors.color(WindecoColors::InactiveBlend)); } diff --git a/kcms/hardware/joystick/joywidget.cpp b/kcms/hardware/joystick/joywidget.cpp index bf5c8c258..3cb59653e 100644 --- a/kcms/hardware/joystick/joywidget.cpp +++ b/kcms/hardware/joystick/joywidget.cpp @@ -1,417 +1,417 @@ /*************************************************************************** * Copyright (C) 2003,2012 by Martin Koller * * kollix@aon.at * * This file is part of the KDE Control Center Module for Joysticks * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "joywidget.h" #include "joydevice.h" #include "poswidget.h" #include "caldialog.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //-------------------------------------------------------------- static QString PRESSED = I18N_NOOP("PRESSED"); //-------------------------------------------------------------- class TableWidget : public QTableWidget { public: TableWidget(int row, int col) : QTableWidget(row, col) {} QSize sizeHint() const override { return QSize(150, 100); // return a smaller size than the Qt default(256, 192) } }; //-------------------------------------------------------------- JoyWidget::JoyWidget(QWidget *parent) : QWidget(parent), idle(nullptr), joydev(nullptr) { QVBoxLayout *mainVbox = new QVBoxLayout(this); mainVbox->setSpacing(KDialog::spacingHint()); mainVbox->setContentsMargins(0, 0, 0, 0); // create area to show an icon + message if no joystick was detected { messageBox = new KMessageWidget(this); messageBox->setMessageType(KMessageWidget::Error); messageBox->setCloseButtonVisible(false); messageBox->hide(); mainVbox->addWidget(messageBox); } QHBoxLayout *devHbox = new QHBoxLayout; devHbox->setSpacing(KDialog::spacingHint()); devHbox->addWidget(new QLabel(i18n("Device:"))); devHbox->addWidget(device = new KComboBox(true)); device->setInsertPolicy(QComboBox::NoInsert); KUrlCompletion *kc = new KUrlCompletion(KUrlCompletion::FileCompletion); device->setCompletionObject(kc); device->setAutoDeleteCompletionObject(true); connect(device, SIGNAL(activated(QString)), this, SLOT(deviceChanged(QString))); connect(device, SIGNAL(returnPressed(QString)), this, SLOT(deviceChanged(QString))); devHbox->setStretchFactor(device, 3); QHBoxLayout *hbox = new QHBoxLayout; hbox->setSpacing(KDialog::spacingHint()); mainVbox->addLayout(devHbox); mainVbox->addLayout(hbox); QVBoxLayout *vboxLeft = new QVBoxLayout; vboxLeft->setSpacing(KDialog::spacingHint()); vboxLeft->addWidget(new QLabel(i18nc("Cue for deflection of the stick", "Position:"))); vboxLeft->addWidget(xyPos = new PosWidget); vboxLeft->addWidget(trace = new QCheckBox(i18n("Show trace"))); connect(trace, &QAbstractButton::toggled, this, &JoyWidget::traceChanged); QVBoxLayout *vboxMid = new QVBoxLayout; vboxMid->setSpacing(KDialog::spacingHint()); QVBoxLayout *vboxRight = new QVBoxLayout; vboxRight->setSpacing(KDialog::spacingHint()); // calculate the column width we need QFontMetrics fm(font()); int colWidth = qMax(fm.width(PRESSED), fm.width(QStringLiteral("-32767"))) + 10; // -32767 largest string vboxMid->addWidget(new QLabel(i18n("Buttons:"))); buttonTbl = new TableWidget(0, 1); buttonTbl->setSelectionMode(QAbstractItemView::NoSelection); buttonTbl->setEditTriggers(QAbstractItemView::NoEditTriggers); buttonTbl->setHorizontalHeaderLabels(QStringList(i18n("State"))); buttonTbl->setSortingEnabled(false); - buttonTbl->horizontalHeader()->setClickable(false); - buttonTbl->horizontalHeader()->setResizeMode(QHeaderView::Stretch); + buttonTbl->horizontalHeader()->setSectionsClickable(false); + buttonTbl->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); buttonTbl->horizontalHeader()->resizeSection(0, colWidth); - buttonTbl->verticalHeader()->setClickable(false); + buttonTbl->verticalHeader()->setSectionsClickable(false); vboxMid->addWidget(buttonTbl); vboxRight->addWidget(new QLabel(i18n("Axes:"))); axesTbl = new TableWidget(0, 1); axesTbl->setSelectionMode(QAbstractItemView::NoSelection); axesTbl->setEditTriggers(QAbstractItemView::NoEditTriggers); axesTbl->setHorizontalHeaderLabels(QStringList(i18n("Value"))); axesTbl->setSortingEnabled(false); - axesTbl->horizontalHeader()->setClickable(false); - axesTbl->horizontalHeader()->setResizeMode(QHeaderView::Stretch); + axesTbl->horizontalHeader()->setSectionsClickable(false); + axesTbl->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); axesTbl->horizontalHeader()->resizeSection(0, colWidth); - axesTbl->verticalHeader()->setClickable(false); + axesTbl->verticalHeader()->setSectionsClickable(false); vboxRight->addWidget(axesTbl); hbox->addLayout(vboxLeft); hbox->addLayout(vboxMid); hbox->addLayout(vboxRight); // calibrate button calibrate = new QPushButton(i18n("Calibrate")); connect(calibrate, &QAbstractButton::clicked, this, &JoyWidget::calibrateDevice); calibrate->setEnabled(false); vboxLeft->addStretch(); vboxLeft->addWidget(calibrate); // set up a timer for idle processing of joystick events idle = new QTimer(this); connect(idle, &QTimer::timeout, this, &JoyWidget::checkDevice); // check which devicefiles we have init(); } //-------------------------------------------------------------- JoyWidget::~JoyWidget() { delete joydev; } //-------------------------------------------------------------- void JoyWidget::init() { // check which devicefiles we have int i; bool first = true; char dev[30]; device->clear(); buttonTbl->setRowCount(0); axesTbl->setRowCount(0); for (i = 0; i < 5; i++) // check the first 5 devices { sprintf(dev, "/dev/js%d", i); // first look in /dev JoyDevice *joy = new JoyDevice(dev); if ( joy->open() != JoyDevice::SUCCESS ) { delete joy; sprintf(dev, "/dev/input/js%d", i); // then look in /dev/input joy = new JoyDevice(dev); if ( joy->open() != JoyDevice::SUCCESS ) { delete joy; continue; // try next number } } // we found one device->addItem(QStringLiteral("%1 (%2)").arg(joy->text()).arg(joy->device())); // display values for first device if ( first ) { showDeviceProps(joy); // this sets the joy object into this->joydev first = false; } else delete joy; } /* KDE 4: Remove this check(and i18n) when all KCM wrappers properly test modules */ if ( device->count() == 0 ) { messageBox->show(); messageBox->setText(QStringLiteral("%1").arg( i18n("No joystick device automatically found on this computer.
" "Checks were done in /dev/js[0-4] and /dev/input/js[0-4]
" "If you know that there is one attached, please enter the correct device file."))); } } //-------------------------------------------------------------- void JoyWidget::traceChanged(bool state) { xyPos->showTrace(state); } //-------------------------------------------------------------- void JoyWidget::restoreCurrDev() { if ( !joydev ) // no device open { device->setEditText(QLatin1String("")); calibrate->setEnabled(false); } else { // try to find the current open device in the combobox list int index = device->findText(joydev->device(), Qt::MatchContains); if ( index == -1 ) // the current open device is one the user entered (not in the list) device->setEditText(joydev->device()); else device->setEditText(device->itemText(index)); } } //-------------------------------------------------------------- void JoyWidget::deviceChanged(const QString &dev) { // find "/dev" in given string int start, stop; QString devName; if ( (start = dev.indexOf(QStringLiteral("/dev"))) == -1 ) { KMessageBox::sorry(this, i18n("The given device name is invalid (does not contain /dev).\n" "Please select a device from the list or\n" "enter a device file, like /dev/js0."), i18n("Unknown Device")); restoreCurrDev(); return; } if ( (stop = dev.indexOf(QStringLiteral(")"), start)) != -1 ) // seems to be text selected from our list devName = dev.mid(start, stop - start); else devName = dev.mid(start); if ( joydev && (devName == joydev->device()) ) return; // user selected the current device; ignore it JoyDevice *joy = new JoyDevice(devName); JoyDevice::ErrorCode ret = joy->open(); if ( ret != JoyDevice::SUCCESS ) { KMessageBox::error(this, joy->errText(ret), i18n("Device Error")); delete joy; restoreCurrDev(); return; } showDeviceProps(joy); } //-------------------------------------------------------------- void JoyWidget::showDeviceProps(JoyDevice *joy) { joydev = joy; buttonTbl->setRowCount(joydev->numButtons()); axesTbl->setRowCount(joydev->numAxes()); if ( joydev->numAxes() >= 2 ) { axesTbl->setVerticalHeaderItem(0, new QTableWidgetItem(i18n("1(x)"))); axesTbl->setVerticalHeaderItem(1, new QTableWidgetItem(i18n("2(y)"))); } calibrate->setEnabled(true); idle->start(0); // make both tables use the same space for header; this looks nicer // TODO: Don't know how to do this in Qt4; the following does no longer work // Probably by setting a sizeHint for every single header item ? /* buttonTbl->verticalHeader()->setFixedWidth(qMax(buttonTbl->verticalHeader()->width(), axesTbl->verticalHeader()->width())); axesTbl->verticalHeader()->setFixedWidth(buttonTbl->verticalHeader()->width()); */ } //-------------------------------------------------------------- void JoyWidget::checkDevice() { if ( !joydev ) return; // no open device yet JoyDevice::EventType type; int number, value; if ( !joydev->getEvent(type, number, value) ) return; if ( type == JoyDevice::BUTTON ) { if ( ! buttonTbl->item(number, 0) ) buttonTbl->setItem(number, 0, new QTableWidgetItem()); if ( value == 0 ) // button release buttonTbl->item(number, 0)->setText(QStringLiteral("-")); else buttonTbl->item(number, 0)->setText(PRESSED); } if ( type == JoyDevice::AXIS ) { if ( number == 0 ) // x-axis xyPos->changeX(value); if ( number == 1 ) // y-axis xyPos->changeY(value); if ( ! axesTbl->item(number, 0) ) axesTbl->setItem(number, 0, new QTableWidgetItem()); axesTbl->item(number, 0)->setText(QStringLiteral("%1").arg(int(value))); } } //-------------------------------------------------------------- void JoyWidget::calibrateDevice() { if ( !joydev ) return; // just to be save JoyDevice::ErrorCode ret = joydev->initCalibration(); if ( ret != JoyDevice::SUCCESS ) { KMessageBox::error(this, joydev->errText(ret), i18n("Communication Error")); return; } if ( KMessageBox::messageBox(this, KMessageBox::Information, i18n("Calibration is about to check the precision.

" "Please move all axes to their center position and then " "do not touch the joystick anymore.

" "Click OK to start the calibration.
"), i18n("Calibration"), KStandardGuiItem::ok(), KStandardGuiItem::cancel()) != KMessageBox::Ok ) return; idle->stop(); // stop the joystick event getting; this must be done inside the calibrate dialog CalDialog dlg(this, joydev); dlg.calibrate(); // user canceled somewhere during calibration, therefore the device is in a bad state if ( dlg.result() == QDialog::Rejected ) joydev->restoreCorr(); idle->start(0); // continue with event getting } //-------------------------------------------------------------- void JoyWidget::resetCalibration() { if ( !joydev ) return; // just to be save JoyDevice::ErrorCode ret = joydev->restoreCorr(); if ( ret != JoyDevice::SUCCESS ) { KMessageBox::error(this, joydev->errText(ret), i18n("Communication Error")); } else { KMessageBox::information(this, i18n("Restored all calibration values for joystick device %1.", joydev->device()), i18n("Calibration Success")); } } //-------------------------------------------------------------- diff --git a/kcms/krdb/krdb.cpp b/kcms/krdb/krdb.cpp index 29d429aca..e7939f8c1 100644 --- a/kcms/krdb/krdb.cpp +++ b/kcms/krdb/krdb.cpp @@ -1,729 +1,729 @@ /**************************************************************************** ** ** ** KRDB - puts current KDE color scheme into preprocessor statements ** cats specially written application default files and uses xrdb -merge to ** write to RESOURCE_MANAGER. Thus it gives a simple way to make non-KDE ** applications fit in with the desktop ** ** Copyright (C) 1998 by Mark Donohoe ** Copyright (C) 1999 by Dirk A. Mueller (reworked for KDE 2.0) ** Copyright (C) 2001 by Matthias Ettrich (add support for GTK applications ) ** Copyright (C) 2001 by Waldo Bastian ** Copyright (C) 2002 by Karol Szwed ** This application is freely distributable under the GNU Public License. ** *****************************************************************************/ #include #include #include #include #include #include #undef Unsorted #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "krdb.h" #if HAVE_X11 #include #include #endif inline const char * gtkEnvVar(int version) { return 2==version ? "GTK2_RC_FILES" : "GTK_RC_FILES"; } inline const char * sysGtkrc(int version) { if(2==version) { if(access("/etc/opt/gnome/gtk-2.0", F_OK) == 0) return "/etc/opt/gnome/gtk-2.0/gtkrc"; else return "/etc/gtk-2.0/gtkrc"; } else { if(access("/etc/opt/gnome/gtk", F_OK) == 0) return "/etc/opt/gnome/gtk/gtkrc"; else return "/etc/gtk/gtkrc"; } } inline const char * userGtkrc(int version) { return 2==version ? "/.gtkrc-2.0" : "/.gtkrc"; } // ----------------------------------------------------------------------------- static QString writableGtkrc(int version) { QString gtkrc = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation); QDir dir; dir.mkpath(gtkrc); gtkrc += 2==version?"/gtkrc-2.0":"/gtkrc"; return gtkrc; } // ----------------------------------------------------------------------------- static void applyGtkStyles(bool active, int version) { QString gtkkde = writableGtkrc(version); QByteArray gtkrc = getenv(gtkEnvVar(version)); QStringList list = QFile::decodeName(gtkrc).split( QLatin1Char(':')); QString userHomeGtkrc = QDir::homePath()+userGtkrc(version); if (!list.contains(userHomeGtkrc)) list.prepend(userHomeGtkrc); QLatin1String systemGtkrc = QLatin1String(sysGtkrc(version)); if (!list.contains(systemGtkrc)) list.prepend(systemGtkrc); list.removeAll(QLatin1String("")); list.removeAll(gtkkde); list.append(gtkkde); // Pass env. var to kdeinit. QString name = gtkEnvVar(version); QString value = list.join(QStringLiteral(":")); org::kde::KLauncher klauncher(QStringLiteral("org.kde.klauncher5"), QStringLiteral("/KLauncher"), QDBusConnection::sessionBus()); klauncher.setLaunchEnv(name, value); } // ----------------------------------------------------------------------------- static void applyQtColors( KSharedConfigPtr kglobalcfg, QSettings& settings, QPalette& newPal ) { QStringList actcg, inactcg, discg; /* export kde color settings */ int i; for (i = 0; i < QPalette::NColorRoles; i++) actcg << newPal.color(QPalette::Active, (QPalette::ColorRole) i).name(); for (i = 0; i < QPalette::NColorRoles; i++) inactcg << newPal.color(QPalette::Inactive, (QPalette::ColorRole) i).name(); for (i = 0; i < QPalette::NColorRoles; i++) discg << newPal.color(QPalette::Disabled, (QPalette::ColorRole) i).name(); settings.setValue(QStringLiteral("/qt/Palette/active"), actcg); settings.setValue(QStringLiteral("/qt/Palette/inactive"), inactcg); settings.setValue(QStringLiteral("/qt/Palette/disabled"), discg); // export kwin's colors to qtrc for kstyle to use KConfigGroup wmCfgGroup(kglobalcfg, "WM"); // active colors QColor clr = newPal.color( QPalette::Active, QPalette::Window ); clr = wmCfgGroup.readEntry("activeBackground", clr); settings.setValue(QStringLiteral("/qt/KWinPalette/activeBackground"), clr.name()); if (QPixmap::defaultDepth() > 8) - clr = clr.dark(110); + clr = clr.darker(110); clr = wmCfgGroup.readEntry("activeBlend", clr); settings.setValue(QStringLiteral("/qt/KWinPalette/activeBlend"), clr.name()); clr = newPal.color( QPalette::Active, QPalette::HighlightedText ); clr = wmCfgGroup.readEntry("activeForeground", clr); settings.setValue(QStringLiteral("/qt/KWinPalette/activeForeground"), clr.name()); clr = newPal.color( QPalette::Active,QPalette::Window ); clr = wmCfgGroup.readEntry("frame", clr); settings.setValue(QStringLiteral("/qt/KWinPalette/frame"), clr.name()); clr = wmCfgGroup.readEntry("activeTitleBtnBg", clr); settings.setValue(QStringLiteral("/qt/KWinPalette/activeTitleBtnBg"), clr.name()); // inactive colors clr = newPal.color(QPalette::Inactive, QPalette::Window); clr = wmCfgGroup.readEntry("inactiveBackground", clr); settings.setValue(QStringLiteral("/qt/KWinPalette/inactiveBackground"), clr.name()); if (QPixmap::defaultDepth() > 8) - clr = clr.dark(110); + clr = clr.darker(110); clr = wmCfgGroup.readEntry("inactiveBlend", clr); settings.setValue(QStringLiteral("/qt/KWinPalette/inactiveBlend"), clr.name()); - clr = newPal.color(QPalette::Inactive, QPalette::Window).dark(); + clr = newPal.color(QPalette::Inactive, QPalette::Window).darker(); clr = wmCfgGroup.readEntry("inactiveForeground", clr); settings.setValue(QStringLiteral("/qt/KWinPalette/inactiveForeground"), clr.name()); clr = newPal.color(QPalette::Inactive, QPalette::Window); clr = wmCfgGroup.readEntry("inactiveFrame", clr); settings.setValue(QStringLiteral("/qt/KWinPalette/inactiveFrame"), clr.name()); clr = wmCfgGroup.readEntry("inactiveTitleBtnBg", clr); settings.setValue(QStringLiteral("/qt/KWinPalette/inactiveTitleBtnBg"), clr.name()); KConfigGroup kdeCfgGroup(kglobalcfg, "KDE"); settings.setValue(QStringLiteral("/qt/KDE/contrast"), kdeCfgGroup.readEntry("contrast", 7)); } // ----------------------------------------------------------------------------- static void applyQtSettings( KSharedConfigPtr kglobalcfg, QSettings& settings ) { /* export font settings */ // NOTE keep this in sync with kfontsettingsdata in plasma-integration (cf. also Bug 378262) QFont defaultFont(QStringLiteral("Noto Sans"), 10, -1); defaultFont.setStyleHint(QFont::SansSerif); const KConfigGroup configGroup(KSharedConfig::openConfig(), QStringLiteral("General")); const QString fontInfo = configGroup.readEntry(QStringLiteral("font"), QString()); if (!fontInfo.isEmpty()) { defaultFont.fromString(fontInfo); } settings.setValue(QStringLiteral("/qt/font"), defaultFont.toString()); /* export effects settings */ KConfigGroup kdeCfgGroup(kglobalcfg, "General"); bool effectsEnabled = kdeCfgGroup.readEntry("EffectsEnabled", false); bool fadeMenus = kdeCfgGroup.readEntry("EffectFadeMenu", false); bool fadeTooltips = kdeCfgGroup.readEntry("EffectFadeTooltip", false); bool animateCombobox = kdeCfgGroup.readEntry("EffectAnimateCombo", false); QStringList guieffects; if (effectsEnabled) { guieffects << QStringLiteral("general"); if (fadeMenus) guieffects << QStringLiteral("fademenu"); if (animateCombobox) guieffects << QStringLiteral("animatecombo"); if (fadeTooltips) guieffects << QStringLiteral("fadetooltip"); } else guieffects << QStringLiteral("none"); settings.setValue(QStringLiteral("/qt/GUIEffects"), guieffects); } // ----------------------------------------------------------------------------- static void addColorDef(QString& s, const char* n, const QColor& col) { QString tmp; tmp.sprintf("#define %s #%02x%02x%02x\n", n, col.red(), col.green(), col.blue()); s += tmp; } // ----------------------------------------------------------------------------- static void copyFile(QFile& tmp, QString const& filename, bool ) { QFile f( filename ); if ( f.open(QIODevice::ReadOnly) ) { QByteArray buf( 8192, ' ' ); while ( !f.atEnd() ) { int read = f.read( buf.data(), buf.size() ); if ( read > 0 ) tmp.write( buf.data(), read ); } } } // ----------------------------------------------------------------------------- static QString item( int i ) { return QString::number( i / 255.0, 'f', 3 ); } static QString color( const QColor& col ) { return QStringLiteral( "{ %1, %2, %3 }" ).arg( item( col.red() ) ).arg( item( col.green() ) ).arg( item( col.blue() ) ); } static void createGtkrc( bool exportColors, const QPalette& cg, bool exportGtkTheme, const QString& gtkTheme, int version ) { // lukas: why does it create in ~/.kde/share/config ??? // pfeiffer: so that we don't overwrite the user's gtkrc. // it is found via the GTK_RC_FILES environment variable. QSaveFile saveFile( writableGtkrc(version) ); if ( !saveFile.open(QIODevice::WriteOnly) ) return; QTextStream t ( &saveFile ); t.setCodec( QTextCodec::codecForLocale () ); t << i18n( "# created by KDE Plasma, %1\n" "#\n" "# If you do not want Plasma to override your GTK settings, select\n" "# Colors in the System Settings and disable the checkbox\n" "# \"Apply colors to non-Qt applications\"\n" "#\n" "#\n", QDateTime::currentDateTime().toString()); if ( 2==version ) { // we should maybe check for MacOS settings here t << endl; t << "gtk-alternative-button-order = 1" << endl; t << endl; } if (exportGtkTheme) { QString gtkStyle; if (gtkTheme.toLower() == QLatin1String("oxygen")) gtkStyle = QStringLiteral("oxygen-gtk"); else gtkStyle = gtkTheme; bool exist_gtkrc = false; QByteArray gtkrc = getenv(gtkEnvVar(version)); QStringList listGtkrc = QFile::decodeName(gtkrc).split(QLatin1Char(':')); if (listGtkrc.contains(saveFile.fileName())) listGtkrc.removeAll(saveFile.fileName()); listGtkrc.append(QDir::homePath() + userGtkrc(version)); listGtkrc.append(QDir::homePath() + "/.gtkrc-2.0-kde"); listGtkrc.append(QDir::homePath() + "/.gtkrc-2.0-kde4"); listGtkrc.removeAll(QLatin1String("")); listGtkrc.removeDuplicates(); for (int i = 0; i < listGtkrc.size(); ++i) { if ((exist_gtkrc = QFile::exists(listGtkrc.at(i)))) break; } if (!exist_gtkrc) { QString gtk2ThemeFilename; gtk2ThemeFilename = QStringLiteral("%1/.themes/%2/gtk-2.0/gtkrc").arg(QDir::homePath()).arg(gtkStyle); if (!QFile::exists(gtk2ThemeFilename)) { QStringList gtk2ThemePath; gtk2ThemeFilename.clear(); QByteArray xdgDataDirs = getenv("XDG_DATA_DIRS"); gtk2ThemePath.append(QDir::homePath() + "/.local"); gtk2ThemePath.append(QFile::decodeName(xdgDataDirs).split(QLatin1Char(':'))); gtk2ThemePath.removeDuplicates(); for (int i = 0; i < gtk2ThemePath.size(); ++i) { gtk2ThemeFilename = QStringLiteral("%1/themes/%2/gtk-2.0/gtkrc").arg(gtk2ThemePath.at(i)).arg(gtkStyle); if (QFile::exists(gtk2ThemeFilename)) break; else gtk2ThemeFilename.clear(); } } if (!gtk2ThemeFilename.isEmpty()) { t << "include \"" << gtk2ThemeFilename << "\"" << endl; t << endl; t << "gtk-theme-name=\"" << gtkStyle << "\"" << endl; t << endl; if (gtkStyle == QLatin1String("oxygen-gtk")) exportColors = false; } } } if (exportColors) { t << "style \"default\"" << endl; t << "{" << endl; t << " bg[NORMAL] = " << color( cg.color( QPalette::Active, QPalette::Window ) ) << endl; t << " bg[SELECTED] = " << color( cg.color(QPalette::Active, QPalette::Highlight) ) << endl; t << " bg[INSENSITIVE] = " << color( cg.color( QPalette::Active, QPalette::Window ) ) << endl; t << " bg[ACTIVE] = " << color( cg.color( QPalette::Active, QPalette::Mid ) ) << endl; t << " bg[PRELIGHT] = " << color( cg.color( QPalette::Active, QPalette::Window ) ) << endl; t << endl; t << " base[NORMAL] = " << color( cg.color( QPalette::Active, QPalette::Base ) ) << endl; t << " base[SELECTED] = " << color( cg.color(QPalette::Active, QPalette::Highlight) ) << endl; t << " base[INSENSITIVE] = " << color( cg.color( QPalette::Active, QPalette::Window ) ) << endl; t << " base[ACTIVE] = " << color( cg.color(QPalette::Active, QPalette::Highlight) ) << endl; t << " base[PRELIGHT] = " << color( cg.color(QPalette::Active, QPalette::Highlight) ) << endl; t << endl; t << " text[NORMAL] = " << color( cg.color(QPalette::Active, QPalette::Text) ) << endl; t << " text[SELECTED] = " << color( cg.color(QPalette::Active, QPalette::HighlightedText) ) << endl; t << " text[INSENSITIVE] = " << color( cg.color( QPalette::Active, QPalette::Mid ) ) << endl; t << " text[ACTIVE] = " << color( cg.color(QPalette::Active, QPalette::HighlightedText) ) << endl; t << " text[PRELIGHT] = " << color( cg.color(QPalette::Active, QPalette::HighlightedText) ) << endl; t << endl; t << " fg[NORMAL] = " << color ( cg.color( QPalette::Active, QPalette::WindowText ) ) << endl; t << " fg[SELECTED] = " << color( cg.color(QPalette::Active, QPalette::HighlightedText) ) << endl; t << " fg[INSENSITIVE] = " << color( cg.color( QPalette::Active, QPalette::Mid ) ) << endl; t << " fg[ACTIVE] = " << color( cg.color( QPalette::Active, QPalette::WindowText ) ) << endl; t << " fg[PRELIGHT] = " << color( cg.color( QPalette::Active, QPalette::WindowText ) ) << endl; t << "}" << endl; t << endl; t << "class \"*\" style \"default\"" << endl; t << endl; // tooltips don't have the standard background color t << "style \"ToolTip\"" << endl; t << "{" << endl; t << " bg[NORMAL] = " << color( cg.color( QPalette::ToolTipBase ) ) << endl; t << " base[NORMAL] = " << color( cg.color( QPalette::ToolTipBase ) ) << endl; t << " text[NORMAL] = " << color( cg.color( QPalette::ToolTipText ) ) << endl; t << " fg[NORMAL] = " << color( cg.color( QPalette::ToolTipText ) ) << endl; t << "}" << endl; t << endl; t << "widget \"gtk-tooltip\" style \"ToolTip\"" << endl; t << "widget \"gtk-tooltips\" style \"ToolTip\"" << endl; t << "widget \"gtk-tooltip*\" style \"ToolTip\"" << endl; t << endl; // highlight the current (mouse-hovered) menu-item // not every button, checkbox, etc. t << "style \"MenuItem\"" << endl; t << "{" << endl; t << " bg[PRELIGHT] = " << color( cg.color(QPalette::Highlight) ) << endl; t << " fg[PRELIGHT] = " << color( cg.color(QPalette::HighlightedText) ) << endl; t << "}" << endl; t << endl; t << "class \"*MenuItem\" style \"MenuItem\"" << endl; t << endl; } saveFile.commit(); } // ----------------------------------------------------------------------------- void runRdb( uint flags ) { // Obtain the application palette that is about to be set. bool exportColors = flags & KRdbExportColors; bool exportQtColors = flags & KRdbExportQtColors; bool exportQtSettings = flags & KRdbExportQtSettings; bool exportXftSettings = flags & KRdbExportXftSettings; bool exportGtkTheme = flags & KRdbExportGtkTheme; KSharedConfigPtr kglobalcfg = KSharedConfig::openConfig( QStringLiteral("kdeglobals") ); KConfigGroup kglobals(kglobalcfg, "KDE"); QPalette newPal = KColorScheme::createApplicationPalette(kglobalcfg); QTemporaryFile tmpFile; if (!tmpFile.open()) { qDebug() << "Couldn't open temp file"; exit(0); } KConfigGroup generalCfgGroup(kglobalcfg, "General"); QString gtkTheme; if (kglobals.hasKey("widgetStyle")) gtkTheme = kglobals.readEntry("widgetStyle"); else gtkTheme = QStringLiteral("oxygen"); createGtkrc( exportColors, newPal, exportGtkTheme, gtkTheme, 1 ); createGtkrc( exportColors, newPal, exportGtkTheme, gtkTheme, 2 ); // Export colors to non-(KDE/Qt) apps (e.g. Motif, GTK+ apps) if (exportColors) { KConfigGroup g(KSharedConfig::openConfig(), "WM"); QString preproc; QColor backCol = newPal.color( QPalette::Active, QPalette::Window ); addColorDef(preproc, "FOREGROUND" , newPal.color( QPalette::Active, QPalette::WindowText ) ); addColorDef(preproc, "BACKGROUND" , backCol); - addColorDef(preproc, "HIGHLIGHT" , backCol.light(100+(2*KColorScheme::contrast()+4)*16/1)); - addColorDef(preproc, "LOWLIGHT" , backCol.dark(100+(2*KColorScheme::contrast()+4)*10)); + addColorDef(preproc, "HIGHLIGHT" , backCol.lighter(100+(2*KColorScheme::contrast()+4)*16/1)); + addColorDef(preproc, "LOWLIGHT" , backCol.darker(100+(2*KColorScheme::contrast()+4)*10)); addColorDef(preproc, "SELECT_BACKGROUND" , newPal.color( QPalette::Active, QPalette::Highlight)); addColorDef(preproc, "SELECT_FOREGROUND" , newPal.color( QPalette::Active, QPalette::HighlightedText)); addColorDef(preproc, "WINDOW_BACKGROUND" , newPal.color( QPalette::Active, QPalette::Base ) ); addColorDef(preproc, "WINDOW_FOREGROUND" , newPal.color( QPalette::Active, QPalette::Text ) ); addColorDef(preproc, "INACTIVE_BACKGROUND", g.readEntry("inactiveBackground", QColor(224, 223, 222))); addColorDef(preproc, "INACTIVE_FOREGROUND", g.readEntry("inactiveBackground", QColor(224, 223, 222))); addColorDef(preproc, "ACTIVE_BACKGROUND" , g.readEntry("activeBackground", QColor(48, 174, 232))); addColorDef(preproc, "ACTIVE_FOREGROUND" , g.readEntry("activeBackground", QColor(48, 174, 232))); //--------------------------------------------------------------- tmpFile.write( preproc.toLatin1(), preproc.length() ); QStringList list; const QStringList adPaths = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("kdisplay/app-defaults/"), QStandardPaths::LocateDirectory); for (QStringList::ConstIterator it = adPaths.constBegin(); it != adPaths.constEnd(); ++it) { QDir dSys( *it ); if ( dSys.exists() ) { dSys.setFilter( QDir::Files ); dSys.setSorting( QDir::Name ); dSys.setNameFilters(QStringList(QStringLiteral("*.ad"))); list += dSys.entryList(); } } for (QStringList::ConstIterator it = list.constBegin(); it != list.constEnd(); ++it) copyFile(tmpFile, QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kdisplay/app-defaults/"+(*it)), true); } // Merge ~/.Xresources or fallback to ~/.Xdefaults QString homeDir = QDir::homePath(); QString xResources = homeDir + "/.Xresources"; // very primitive support for ~/.Xresources by appending it if ( QFile::exists( xResources ) ) copyFile(tmpFile, xResources, true); else copyFile(tmpFile, homeDir + "/.Xdefaults", true); // Export the Xcursor theme & size settings KConfigGroup mousecfg(KSharedConfig::openConfig( QStringLiteral("kcminputrc") ), "Mouse" ); QString theme = mousecfg.readEntry("cursorTheme", QString()); QString size = mousecfg.readEntry("cursorSize", QString()); QString contents; if (!theme.isNull()) contents = "Xcursor.theme: " + theme + '\n'; if (!size.isNull()) contents += "Xcursor.size: " + size + '\n'; if (exportXftSettings) { if (generalCfgGroup.hasKey("XftAntialias")) { contents += QLatin1String("Xft.antialias: "); if(generalCfgGroup.readEntry("XftAntialias", true)) contents += QLatin1String("1\n"); else contents += QLatin1String("0\n"); } if (generalCfgGroup.hasKey("XftHintStyle")) { QString hintStyle = generalCfgGroup.readEntry("XftHintStyle", "hintmedium"); contents += QLatin1String("Xft.hinting: "); if(hintStyle.isEmpty()) contents += QLatin1String("-1\n"); else { if(hintStyle!=QLatin1String("hintnone")) contents += QLatin1String("1\n"); else contents += QLatin1String("0\n"); contents += "Xft.hintstyle: " + hintStyle + '\n'; } } if (generalCfgGroup.hasKey("XftSubPixel")) { QString subPixel = generalCfgGroup.readEntry("XftSubPixel"); if(!subPixel.isEmpty()) contents += "Xft.rgba: " + subPixel + '\n'; } KConfig _cfgfonts( QStringLiteral("kcmfonts") ); KConfigGroup cfgfonts(&_cfgfonts, "General"); int dpi; //even though this sets up the X rdb, we want to use the value the //user has set to use when under wayland - as X apps will be scaled by the compositor if (KWindowSystem::isPlatformWayland()) { dpi = cfgfonts.readEntry( "forceFontDPIWayland", 0); if (dpi == 0) { //with wayland we want xwayland to run at 96 dpi (unless set otherwise) as we have wayland scaling on top dpi = 96; } } else { dpi = cfgfonts.readEntry( "forceFontDPI", 0); } if( dpi != 0 ) contents += "Xft.dpi: " + QString::number(dpi) + '\n'; else { KProcess proc; proc << QStringLiteral("xrdb") << QStringLiteral("-quiet") << QStringLiteral("-remove") << QStringLiteral("-nocpp"); proc.start(); if (proc.waitForStarted()) { proc.write( QByteArray( "Xft.dpi\n" ) ); proc.closeWriteChannel(); proc.waitForFinished(); } } } if (contents.length() > 0) tmpFile.write( contents.toLatin1(), contents.length() ); tmpFile.flush(); KProcess proc; #ifndef NDEBUG proc << QStringLiteral("xrdb") << QStringLiteral("-merge") << tmpFile.fileName(); #else proc << "xrdb" << "-quiet" << "-merge" << tmpFile.fileName(); #endif proc.execute(); applyGtkStyles(exportColors, 1); applyGtkStyles(exportColors, 2); /* Qt exports */ if ( exportQtColors || exportQtSettings ) { QSettings* settings = new QSettings(QStringLiteral("Trolltech")); if ( exportQtColors ) applyQtColors( kglobalcfg, *settings, newPal ); // For kcmcolors if ( exportQtSettings ) applyQtSettings( kglobalcfg, *settings ); // For kcmstyle delete settings; QApplication::flush(); #if HAVE_X11 if (qApp->platformName() == QStringLiteral("xcb")) { // We let KIPC take care of ourselves, as we are in a KDE app with // QApp::setDesktopSettingsAware(false); // Instead of calling QApp::x11_apply_settings() directly, we instead // modify the timestamp which propagates the settings changes onto // Qt-only apps without adversely affecting ourselves. // Cheat and use the current timestamp, since we just saved to qtrc. QDateTime settingsstamp = QDateTime::currentDateTime(); static Atom qt_settings_timestamp = 0; if (!qt_settings_timestamp) { QString atomname(QStringLiteral("_QT_SETTINGS_TIMESTAMP_")); atomname += XDisplayName( nullptr ); // Use the $DISPLAY envvar. qt_settings_timestamp = XInternAtom( QX11Info::display(), atomname.toLatin1(), False); } QBuffer stamp; QDataStream s(&stamp.buffer(), QIODevice::WriteOnly); s << settingsstamp; XChangeProperty( QX11Info::display(), QX11Info::appRootWindow(), qt_settings_timestamp, qt_settings_timestamp, 8, PropModeReplace, (unsigned char*) stamp.buffer().data(), stamp.buffer().size() ); QApplication::flush(); } #endif } //Legacy support: //Try to sync kde4 settings with ours Kdelibs4Migration migration; //kf5 congig groups for general and icons KConfigGroup generalGroup(kglobalcfg, "General"); KConfigGroup iconsGroup(kglobalcfg, "Icons"); const QString colorSchemeName = generalGroup.readEntry("ColorScheme", QString()); //if no valid color scheme saved, something weird is going on, abort if (colorSchemeName.isEmpty()) { return; } QString colorSchemeSrcFile; if (colorSchemeName != QLatin1String("Default")) { //fix filename, copied from ColorsCM::saveScheme() QString colorSchemeFilename = colorSchemeName; colorSchemeFilename.remove('\''); // So Foo's does not become FooS QRegExp fixer(QStringLiteral("[\\W,.-]+(.?)")); int offset; while ((offset = fixer.indexIn(colorSchemeFilename)) >= 0) colorSchemeFilename.replace(offset, fixer.matchedLength(), fixer.cap(1).toUpper()); colorSchemeFilename.replace(0, 1, colorSchemeFilename.at(0).toUpper()); //clone the color scheme colorSchemeSrcFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "color-schemes/" + colorSchemeFilename + ".colors"); const QString dest = migration.saveLocation("data", QStringLiteral("color-schemes")) + colorSchemeName + ".colors"; QFile::remove(dest); QFile::copy(colorSchemeSrcFile, dest); } //Apply the color scheme QString configFilePath = migration.saveLocation("config") + "kdeglobals"; if (configFilePath.isEmpty()) { return; } KConfig kde4config(configFilePath, KConfig::SimpleConfig); KConfigGroup kde4generalGroup(&kde4config, "General"); kde4generalGroup.writeEntry("ColorScheme", colorSchemeName); //fonts QString font = generalGroup.readEntry("font", QString()); if (!font.isEmpty()) { kde4generalGroup.writeEntry("font", font); } font = generalGroup.readEntry("desktopFont", QString()); if (!font.isEmpty()) { kde4generalGroup.writeEntry("desktopFont", font); } font = generalGroup.readEntry("menuFont", QString()); if (!font.isEmpty()) { kde4generalGroup.writeEntry("menuFont", font); } font = generalGroup.readEntry("smallestReadableFont", QString()); if (!font.isEmpty()) { kde4generalGroup.writeEntry("smallestReadableFont", font); } font = generalGroup.readEntry("taskbarFont", QString()); if (!font.isEmpty()) { kde4generalGroup.writeEntry("taskbarFont", font); } font = generalGroup.readEntry("toolBarFont", QString()); if (!font.isEmpty()) { kde4generalGroup.writeEntry("toolBarFont", font); } //TODO: does exist any way to check if a qt4 widget style is present from a qt5 app? //kde4generalGroup.writeEntry("widgetStyle", "qtcurve"); kde4generalGroup.sync(); KConfigGroup kde4IconGroup(&kde4config, "Icons"); QString iconTheme = iconsGroup.readEntry("Theme", QString()); if (!iconTheme.isEmpty()) { kde4IconGroup.writeEntry("Theme", iconTheme); } kde4IconGroup.sync(); if (!colorSchemeSrcFile.isEmpty()) { //copy all the groups in the color scheme in kdeglobals KSharedConfigPtr kde4ColorConfig = KSharedConfig::openConfig(colorSchemeSrcFile, KConfig::SimpleConfig); foreach (const QString &grp, kde4ColorConfig->groupList()) { KConfigGroup cg(kde4ColorConfig, grp); KConfigGroup cg2(&kde4config, grp); cg.copyTo(&cg2); } } //widgets settings KConfigGroup kglobals4(&kde4config, "KDE"); kglobals4.writeEntry("ShowIconsInMenuItems", kglobals.readEntry("ShowIconsInMenuItems", true)); kglobals4.writeEntry("ShowIconsOnPushButtons", kglobals.readEntry("ShowIconsOnPushButtons", true)); kglobals4.writeEntry("contrast", kglobals.readEntry("contrast", 4)); //FIXME: this should somehow check if the kde4 version of the style is installed kde4generalGroup.writeEntry("widgetStyle", kglobals.readEntry("widgetStyle", "breeze")); //toolbar style KConfigGroup toolbars4(&kde4config, "Toolbar style"); KConfigGroup toolbars5(kglobalcfg, "Toolbar style"); toolbars4.writeEntry("ToolButtonStyle", toolbars5.readEntry("ToolButtonStyle", "TextBesideIcon")); toolbars4.writeEntry("ToolButtonStyleOtherToolbars", toolbars5.readEntry("ToolButtonStyleOtherToolbars", "TextBesideIcon")); }