diff --git a/decorations/decorationpalette.cpp b/decorations/decorationpalette.cpp index e37eeaf88..5d7916d25 100644 --- a/decorations/decorationpalette.cpp +++ b/decorations/decorationpalette.cpp @@ -1,138 +1,138 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright 2014 Martin Gräßlin Copyright 2014 Hugo Pereira Da Costa Copyright 2015 Mika Allan Rauhala 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, see . *********************************************************************/ #include "decorationpalette.h" #include "decorations_logging.h" #include #include #include #include #include #include namespace KWin { namespace Decoration { DecorationPalette::DecorationPalette(const QString &colorScheme) : m_colorScheme(QFileInfo(colorScheme).isAbsolute() ? colorScheme : QStandardPaths::locate(QStandardPaths::GenericConfigLocation, colorScheme)) { if (m_colorScheme.isEmpty() && colorScheme == QStringLiteral("kdeglobals")) { // kdeglobals doesn't exist so create it. This is needed to monitor it using QFileSystemWatcher. auto config = KSharedConfig::openConfig(colorScheme, KConfig::SimpleConfig); KConfigGroup wmConfig(config, QStringLiteral("WM")); wmConfig.writeEntry("FakeEntryToKeepThisGroup", true); config->sync(); m_colorScheme = QStandardPaths::locate(QStandardPaths::GenericConfigLocation, colorScheme); } m_watcher.addPath(m_colorScheme); connect(&m_watcher, &QFileSystemWatcher::fileChanged, [this]() { m_watcher.addPath(m_colorScheme); update(); emit changed(); }); update(); } bool DecorationPalette::isValid() const { return m_activeTitleBarColor.isValid(); } QColor DecorationPalette::color(KDecoration2::ColorGroup group, KDecoration2::ColorRole role) const { using KDecoration2::ColorRole; using KDecoration2::ColorGroup; switch (role) { case ColorRole::Frame: switch (group) { case ColorGroup::Active: return m_activeFrameColor; case ColorGroup::Inactive: return m_inactiveFrameColor; default: return QColor(); } case ColorRole::TitleBar: switch (group) { case ColorGroup::Active: return m_activeTitleBarColor; case ColorGroup::Inactive: return m_inactiveTitleBarColor; default: return QColor(); } case ColorRole::Foreground: switch (group) { case ColorGroup::Active: return m_activeForegroundColor; case ColorGroup::Inactive: return m_inactiveForegroundColor; case ColorGroup::Warning: return m_warningForegroundColor; default: return QColor(); } default: return QColor(); } } QPalette DecorationPalette::palette() const { return m_palette; } void DecorationPalette::update() { auto config = KSharedConfig::openConfig(m_colorScheme, KConfig::SimpleConfig); KConfigGroup wmConfig(config, QStringLiteral("WM")); if (!wmConfig.exists() && !m_colorScheme.endsWith(QStringLiteral("/kdeglobals"))) { qCWarning(KWIN_DECORATIONS) << "Invalid color scheme" << m_colorScheme << "lacks WM group"; return; } m_palette = KColorScheme::createApplicationPalette(config); - m_activeFrameColor = wmConfig.readEntry("frame", m_palette.color(QPalette::Active, QPalette::Background)); + m_activeFrameColor = wmConfig.readEntry("frame", m_palette.color(QPalette::Active, QPalette::Window)); m_inactiveFrameColor = wmConfig.readEntry("inactiveFrame", m_activeFrameColor); m_activeTitleBarColor = wmConfig.readEntry("activeBackground", m_palette.color(QPalette::Active, QPalette::Highlight)); m_inactiveTitleBarColor = wmConfig.readEntry("inactiveBackground", m_inactiveFrameColor); m_activeForegroundColor = wmConfig.readEntry("activeForeground", m_palette.color(QPalette::Active, QPalette::HighlightedText)); m_inactiveForegroundColor = wmConfig.readEntry("inactiveForeground", m_activeForegroundColor.dark()); KConfigGroup windowColorsConfig(config, QStringLiteral("Colors:Window")); m_warningForegroundColor = windowColorsConfig.readEntry("ForegroundNegative", QColor(237, 21, 2)); } } } diff --git a/kcmkwin/kwincompositing/test/modeltest.cpp b/kcmkwin/kwincompositing/test/modeltest.cpp index 66fe0577f..ee92e9711 100644 --- a/kcmkwin/kwincompositing/test/modeltest.cpp +++ b/kcmkwin/kwincompositing/test/modeltest.cpp @@ -1,600 +1,600 @@ /**************************************************************************** ** ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and Digia. For licensing terms and ** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional ** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3.0 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU General Public License version 3.0 requirements will be ** met: http://www.gnu.org/copyleft/gpl.html. ** ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include #include "modeltest.h" #include /*! Connect to all of the models signals. Whenever anything happens recheck everything. */ ModelTest::ModelTest ( QAbstractItemModel *_model, QObject *parent ) : QObject ( parent ), model ( _model ), fetchingMore ( false ) { if (!model) qFatal("%s: model must not be null", Q_FUNC_INFO); connect(model, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)), this, SLOT(runAllTests()) ); connect(model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), this, SLOT(runAllTests()) ); connect(model, SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(runAllTests()) ); connect(model, SIGNAL(columnsRemoved(QModelIndex,int,int)), this, SLOT(runAllTests()) ); connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(runAllTests()) ); connect(model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), this, SLOT(runAllTests()) ); connect(model, SIGNAL(layoutAboutToBeChanged()), this, SLOT(runAllTests()) ); connect(model, SIGNAL(layoutChanged()), this, SLOT(runAllTests()) ); connect(model, SIGNAL(modelReset()), this, SLOT(runAllTests()) ); connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), this, SLOT(runAllTests()) ); connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), this, SLOT(runAllTests()) ); connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(runAllTests()) ); connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(runAllTests()) ); // Special checks for changes connect(model, SIGNAL(layoutAboutToBeChanged()), this, SLOT(layoutAboutToBeChanged()) ); connect(model, SIGNAL(layoutChanged()), this, SLOT(layoutChanged()) ); connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), this, SLOT(rowsAboutToBeInserted(QModelIndex,int,int)) ); connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), this, SLOT(rowsAboutToBeRemoved(QModelIndex,int,int)) ); connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(rowsInserted(QModelIndex,int,int)) ); connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(rowsRemoved(QModelIndex,int,int)) ); connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(dataChanged(QModelIndex,QModelIndex)) ); connect(model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), this, SLOT(headerDataChanged(Qt::Orientation,int,int)) ); runAllTests(); } void ModelTest::runAllTests() { if ( fetchingMore ) return; nonDestructiveBasicTest(); rowCount(); columnCount(); hasIndex(); index(); parent(); data(); } /*! nonDestructiveBasicTest tries to call a number of the basic functions (not all) to make sure the model doesn't outright segfault, testing the functions that makes sense. */ void ModelTest::nonDestructiveBasicTest() { QVERIFY( model->buddy ( QModelIndex() ) == QModelIndex() ); model->canFetchMore ( QModelIndex() ); QVERIFY( model->columnCount ( QModelIndex() ) >= 0 ); QVERIFY( model->data ( QModelIndex() ) == QVariant() ); fetchingMore = true; model->fetchMore ( QModelIndex() ); fetchingMore = false; Qt::ItemFlags flags = model->flags ( QModelIndex() ); QVERIFY( flags == Qt::ItemIsDropEnabled || flags == 0 ); model->hasChildren ( QModelIndex() ); model->hasIndex ( 0, 0 ); model->headerData ( 0, Qt::Horizontal ); model->index ( 0, 0 ); model->itemData ( QModelIndex() ); QVariant cache; model->match ( QModelIndex(), -1, cache ); model->mimeTypes(); QVERIFY( model->parent ( QModelIndex() ) == QModelIndex() ); QVERIFY( model->rowCount() >= 0 ); QVariant variant; model->setData ( QModelIndex(), variant, -1 ); model->setHeaderData ( -1, Qt::Horizontal, QVariant() ); model->setHeaderData ( 999999, Qt::Horizontal, QVariant() ); QMap roles; model->sibling ( 0, 0, QModelIndex() ); model->span ( QModelIndex() ); model->supportedDropActions(); } /*! Tests model's implementation of QAbstractItemModel::rowCount() and hasChildren() Models that are dynamically populated are not as fully tested here. */ void ModelTest::rowCount() { // qDebug() << "rc"; // check top row QModelIndex topIndex = model->index ( 0, 0, QModelIndex() ); int rows = model->rowCount ( topIndex ); QVERIFY( rows >= 0 ); if ( rows > 0 ) QVERIFY( model->hasChildren ( topIndex ) ); QModelIndex secondLevelIndex = model->index ( 0, 0, topIndex ); if ( secondLevelIndex.isValid() ) { // not the top level // check a row count where parent is valid rows = model->rowCount ( secondLevelIndex ); QVERIFY( rows >= 0 ); if ( rows > 0 ) QVERIFY( model->hasChildren ( secondLevelIndex ) ); } // The models rowCount() is tested more extensively in checkChildren(), // but this catches the big mistakes } /*! Tests model's implementation of QAbstractItemModel::columnCount() and hasChildren() */ void ModelTest::columnCount() { // check top row QModelIndex topIndex = model->index ( 0, 0, QModelIndex() ); QVERIFY( model->columnCount ( topIndex ) >= 0 ); // check a column count where parent is valid QModelIndex childIndex = model->index ( 0, 0, topIndex ); if ( childIndex.isValid() ) QVERIFY( model->columnCount ( childIndex ) >= 0 ); // columnCount() is tested more extensively in checkChildren(), // but this catches the big mistakes } /*! Tests model's implementation of QAbstractItemModel::hasIndex() */ void ModelTest::hasIndex() { // qDebug() << "hi"; // Make sure that invalid values returns an invalid index QVERIFY( !model->hasIndex ( -2, -2 ) ); QVERIFY( !model->hasIndex ( -2, 0 ) ); QVERIFY( !model->hasIndex ( 0, -2 ) ); int rows = model->rowCount(); int columns = model->columnCount(); // check out of bounds QVERIFY( !model->hasIndex ( rows, columns ) ); QVERIFY( !model->hasIndex ( rows + 1, columns + 1 ) ); if ( rows > 0 ) QVERIFY( model->hasIndex ( 0, 0 ) ); // hasIndex() is tested more extensively in checkChildren(), // but this catches the big mistakes } /*! Tests model's implementation of QAbstractItemModel::index() */ void ModelTest::index() { // qDebug() << "i"; // Make sure that invalid values returns an invalid index QVERIFY( model->index ( -2, -2 ) == QModelIndex() ); QVERIFY( model->index ( -2, 0 ) == QModelIndex() ); QVERIFY( model->index ( 0, -2 ) == QModelIndex() ); int rows = model->rowCount(); int columns = model->columnCount(); if ( rows == 0 ) return; // Catch off by one errors QVERIFY( model->index ( rows, columns ) == QModelIndex() ); QVERIFY( model->index ( 0, 0 ).isValid() ); // Make sure that the same index is *always* returned QModelIndex a = model->index ( 0, 0 ); QModelIndex b = model->index ( 0, 0 ); QVERIFY( a == b ); // index() is tested more extensively in checkChildren(), // but this catches the big mistakes } /*! Tests model's implementation of QAbstractItemModel::parent() */ void ModelTest::parent() { // qDebug() << "p"; // Make sure the model won't crash and will return an invalid QModelIndex // when asked for the parent of an invalid index. QVERIFY( model->parent ( QModelIndex() ) == QModelIndex() ); if ( model->rowCount() == 0 ) return; // Column 0 | Column 1 | // QModelIndex() | | // \- topIndex | topIndex1 | // \- childIndex | childIndex1 | // Common error test #1, make sure that a top level index has a parent // that is a invalid QModelIndex. QModelIndex topIndex = model->index ( 0, 0, QModelIndex() ); QVERIFY( model->parent ( topIndex ) == QModelIndex() ); // Common error test #2, make sure that a second level index has a parent // that is the first level index. if ( model->rowCount ( topIndex ) > 0 ) { QModelIndex childIndex = model->index ( 0, 0, topIndex ); QVERIFY( model->parent ( childIndex ) == topIndex ); } // Common error test #3, the second column should NOT have the same children // as the first column in a row. // Usually the second column shouldn't have children. QModelIndex topIndex1 = model->index ( 0, 1, QModelIndex() ); if ( model->rowCount ( topIndex1 ) > 0 ) { QModelIndex childIndex = model->index ( 0, 0, topIndex ); QModelIndex childIndex1 = model->index ( 0, 0, topIndex1 ); QVERIFY( childIndex != childIndex1 ); } // Full test, walk n levels deep through the model making sure that all // parent's children correctly specify their parent. checkChildren ( QModelIndex() ); } /*! Called from the parent() test. A model that returns an index of parent X should also return X when asking for the parent of the index. This recursive function does pretty extensive testing on the whole model in an effort to catch edge cases. This function assumes that rowCount(), columnCount() and index() already work. If they have a bug it will point it out, but the above tests should have already found the basic bugs because it is easier to figure out the problem in those tests then this one. */ void ModelTest::checkChildren ( const QModelIndex &parent, int currentDepth ) { // First just try walking back up the tree. QModelIndex p = parent; while ( p.isValid() ) p = p.parent(); // For models that are dynamically populated if ( model->canFetchMore ( parent ) ) { fetchingMore = true; model->fetchMore ( parent ); fetchingMore = false; } int rows = model->rowCount ( parent ); int columns = model->columnCount ( parent ); if ( rows > 0 ) QVERIFY( model->hasChildren ( parent ) ); // Some further testing against rows(), columns(), and hasChildren() QVERIFY( rows >= 0 ); QVERIFY( columns >= 0 ); if ( rows > 0 ) QVERIFY( model->hasChildren ( parent ) ); //qDebug() << "parent:" << model->data(parent).toString() << "rows:" << rows // << "columns:" << columns << "parent column:" << parent.column(); const QModelIndex topLeftChild = model->index( 0, 0, parent ); QVERIFY( !model->hasIndex ( rows + 1, 0, parent ) ); for ( int r = 0; r < rows; ++r ) { if ( model->canFetchMore ( parent ) ) { fetchingMore = true; model->fetchMore ( parent ); fetchingMore = false; } QVERIFY( !model->hasIndex ( r, columns + 1, parent ) ); for ( int c = 0; c < columns; ++c ) { QVERIFY( model->hasIndex ( r, c, parent ) ); QModelIndex index = model->index ( r, c, parent ); // rowCount() and columnCount() said that it existed... QVERIFY( index.isValid() ); // index() should always return the same index when called twice in a row QModelIndex modifiedIndex = model->index ( r, c, parent ); QVERIFY( index == modifiedIndex ); // Make sure we get the same index if we request it twice in a row QModelIndex a = model->index ( r, c, parent ); QModelIndex b = model->index ( r, c, parent ); QVERIFY( a == b ); { const QModelIndex sibling = model->sibling( r, c, topLeftChild ); QVERIFY( index == sibling ); } { const QModelIndex sibling = topLeftChild.sibling( r, c ); QVERIFY( index == sibling ); } // Some basic checking on the index that is returned QVERIFY( index.model() == model ); QCOMPARE( index.row(), r ); QCOMPARE( index.column(), c ); // While you can technically return a QVariant usually this is a sign // of a bug in data(). Disable if this really is ok in your model. // QVERIFY( model->data ( index, Qt::DisplayRole ).isValid() ); // If the next test fails here is some somewhat useful debug you play with. if (model->parent(index) != parent) { qDebug() << r << c << currentDepth << model->data(index).toString() << model->data(parent).toString(); qDebug() << index << parent << model->parent(index); // And a view that you can even use to show the model. // QTreeView view; // view.setModel(model); // view.show(); } // Check that we can get back our real parent. QCOMPARE( model->parent ( index ), parent ); // recursively go down the children if ( model->hasChildren ( index ) && currentDepth < 10 ) { //qDebug() << r << c << "has children" << model->rowCount(index); checkChildren ( index, ++currentDepth ); }/* else { if (currentDepth >= 10) qDebug() << "checked 10 deep"; };*/ // make sure that after testing the children that the index doesn't change. QModelIndex newerIndex = model->index ( r, c, parent ); QVERIFY( index == newerIndex ); } } } /*! Tests model's implementation of QAbstractItemModel::data() */ void ModelTest::data() { // Invalid index should return an invalid qvariant QVERIFY( !model->data ( QModelIndex() ).isValid() ); if ( model->rowCount() == 0 ) return; // A valid index should have a valid QVariant data QVERIFY( model->index ( 0, 0 ).isValid() ); // shouldn't be able to set data on an invalid index QVERIFY( !model->setData ( QModelIndex(), QLatin1String ( "foo" ), Qt::DisplayRole ) ); // General Purpose roles that should return a QString QVariant variant = model->data ( model->index ( 0, 0 ), Qt::ToolTipRole ); if ( variant.isValid() ) { QVERIFY( variant.canConvert() ); } variant = model->data ( model->index ( 0, 0 ), Qt::StatusTipRole ); if ( variant.isValid() ) { QVERIFY( variant.canConvert() ); } variant = model->data ( model->index ( 0, 0 ), Qt::WhatsThisRole ); if ( variant.isValid() ) { QVERIFY( variant.canConvert() ); } // General Purpose roles that should return a QSize variant = model->data ( model->index ( 0, 0 ), Qt::SizeHintRole ); if ( variant.isValid() ) { QVERIFY( variant.canConvert() ); } // General Purpose roles that should return a QFont QVariant fontVariant = model->data ( model->index ( 0, 0 ), Qt::FontRole ); if ( fontVariant.isValid() ) { QVERIFY( fontVariant.canConvert() ); } // Check that the alignment is one we know about QVariant textAlignmentVariant = model->data ( model->index ( 0, 0 ), Qt::TextAlignmentRole ); if ( textAlignmentVariant.isValid() ) { unsigned int alignment = textAlignmentVariant.toUInt(); QCOMPARE( alignment, ( alignment & ( Qt::AlignHorizontal_Mask | Qt::AlignVertical_Mask ) ) ); } // General Purpose roles that should return a QColor - QVariant colorVariant = model->data ( model->index ( 0, 0 ), Qt::BackgroundColorRole ); + QVariant colorVariant = model->data ( model->index ( 0, 0 ), Qt::BackgroundRole ); if ( colorVariant.isValid() ) { QVERIFY( colorVariant.canConvert() ); } - colorVariant = model->data ( model->index ( 0, 0 ), Qt::TextColorRole ); + colorVariant = model->data ( model->index ( 0, 0 ), Qt::ForegroundRole ); if ( colorVariant.isValid() ) { QVERIFY( colorVariant.canConvert() ); } // Check that the "check state" is one we know about. QVariant checkStateVariant = model->data ( model->index ( 0, 0 ), Qt::CheckStateRole ); if ( checkStateVariant.isValid() ) { int state = checkStateVariant.toInt(); QVERIFY( state == Qt::Unchecked || state == Qt::PartiallyChecked || state == Qt::Checked ); } } /*! Store what is about to be inserted to make sure it actually happens \sa rowsInserted() */ void ModelTest::rowsAboutToBeInserted ( const QModelIndex &parent, int start, int /* end */) { // Q_UNUSED(end); // qDebug() << "rowsAboutToBeInserted" << "start=" << start << "end=" << end << "parent=" << model->data ( parent ).toString() // << "current count of parent=" << model->rowCount ( parent ); // << "display of last=" << model->data( model->index(start-1, 0, parent) ); // qDebug() << model->index(start-1, 0, parent) << model->data( model->index(start-1, 0, parent) ); Changing c; c.parent = parent; c.oldSize = model->rowCount ( parent ); c.last = model->data ( model->index ( start - 1, 0, parent ) ); c.next = model->data ( model->index ( start, 0, parent ) ); insert.push ( c ); } /*! Confirm that what was said was going to happen actually did \sa rowsAboutToBeInserted() */ void ModelTest::rowsInserted ( const QModelIndex & parent, int start, int end ) { Changing c = insert.pop(); QVERIFY( c.parent == parent ); // qDebug() << "rowsInserted" << "start=" << start << "end=" << end << "oldsize=" << c.oldSize // << "parent=" << model->data ( parent ).toString() << "current rowcount of parent=" << model->rowCount ( parent ); // for (int ii=start; ii <= end; ii++) // { // qDebug() << "itemWasInserted:" << ii << model->data ( model->index ( ii, 0, parent )); // } // qDebug(); QVERIFY( c.oldSize + ( end - start + 1 ) == model->rowCount ( parent ) ); QVERIFY( c.last == model->data ( model->index ( start - 1, 0, c.parent ) ) ); if (c.next != model->data(model->index(end + 1, 0, c.parent))) { qDebug() << start << end; for (int i=0; i < model->rowCount(); ++i) qDebug() << model->index(i, 0).data().toString(); qDebug() << c.next << model->data(model->index(end + 1, 0, c.parent)); } QVERIFY( c.next == model->data ( model->index ( end + 1, 0, c.parent ) ) ); } void ModelTest::layoutAboutToBeChanged() { for ( int i = 0; i < qBound ( 0, model->rowCount(), 100 ); ++i ) changing.append ( QPersistentModelIndex ( model->index ( i, 0 ) ) ); } void ModelTest::layoutChanged() { for ( int i = 0; i < changing.count(); ++i ) { QPersistentModelIndex p = changing[i]; QVERIFY( p == model->index ( p.row(), p.column(), p.parent() ) ); } changing.clear(); } /*! Store what is about to be inserted to make sure it actually happens \sa rowsRemoved() */ void ModelTest::rowsAboutToBeRemoved ( const QModelIndex &parent, int start, int end ) { qDebug() << "ratbr" << parent << start << end; Changing c; c.parent = parent; c.oldSize = model->rowCount ( parent ); c.last = model->data ( model->index ( start - 1, 0, parent ) ); c.next = model->data ( model->index ( end + 1, 0, parent ) ); remove.push ( c ); } /*! Confirm that what was said was going to happen actually did \sa rowsAboutToBeRemoved() */ void ModelTest::rowsRemoved ( const QModelIndex & parent, int start, int end ) { qDebug() << "rr" << parent << start << end; Changing c = remove.pop(); QVERIFY( c.parent == parent ); QVERIFY( c.oldSize - ( end - start + 1 ) == model->rowCount ( parent ) ); QVERIFY( c.last == model->data ( model->index ( start - 1, 0, c.parent ) ) ); QVERIFY( c.next == model->data ( model->index ( start, 0, c.parent ) ) ); } void ModelTest::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) { QVERIFY(topLeft.isValid()); QVERIFY(bottomRight.isValid()); QModelIndex commonParent = bottomRight.parent(); QVERIFY(topLeft.parent() == commonParent); QVERIFY(topLeft.row() <= bottomRight.row()); QVERIFY(topLeft.column() <= bottomRight.column()); int rowCount = model->rowCount(commonParent); int columnCount = model->columnCount(commonParent); QVERIFY(bottomRight.row() < rowCount); QVERIFY(bottomRight.column() < columnCount); } void ModelTest::headerDataChanged(Qt::Orientation orientation, int start, int end) { QVERIFY(start >= 0); QVERIFY(end >= 0); QVERIFY(start <= end); int itemCount = orientation == Qt::Vertical ? model->rowCount() : model->columnCount(); QVERIFY(start < itemCount); QVERIFY(end < itemCount); } diff --git a/kcmkwin/kwinoptions/main.cpp b/kcmkwin/kwinoptions/main.cpp index 6bb1a61e2..9c1797622 100644 --- a/kcmkwin/kwinoptions/main.cpp +++ b/kcmkwin/kwinoptions/main.cpp @@ -1,249 +1,249 @@ /* * * Copyright (c) 2001 Waldo Bastian * * 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 "main.h" #include //Added by qt3to4: #include #include #include #include #include #include #include #include "mouse.h" #include "windows.h" K_PLUGIN_FACTORY_DECLARATION(KWinOptionsFactory) class KFocusConfigStandalone : public KFocusConfig { Q_OBJECT public: KFocusConfigStandalone(QWidget* parent, const QVariantList &) : KFocusConfig(true, new KConfig("kwinrc"), parent) {} }; class KMovingConfigStandalone : public KMovingConfig { Q_OBJECT public: KMovingConfigStandalone(QWidget* parent, const QVariantList &) : KMovingConfig(true, new KConfig("kwinrc"), parent) {} }; class KAdvancedConfigStandalone : public KAdvancedConfig { Q_OBJECT public: KAdvancedConfigStandalone(QWidget* parent, const QVariantList &) : KAdvancedConfig(true, new KConfig("kwinrc"), parent) {} }; KWinOptions::KWinOptions(QWidget *parent, const QVariantList &) : KCModule(parent) { mConfig = new KConfig("kwinrc"); QVBoxLayout *layout = new QVBoxLayout(this); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); tab = new QTabWidget(this); layout->addWidget(tab); mFocus = new KFocusConfig(false, mConfig, this); mFocus->setObjectName(QLatin1String("KWin Focus Config")); tab->addTab(mFocus, i18n("&Focus")); connect(mFocus, SIGNAL(changed(bool)), this, SLOT(moduleChanged(bool))); mTitleBarActions = new KTitleBarActionsConfig(false, mConfig, this); mTitleBarActions->setObjectName(QLatin1String("KWin TitleBar Actions")); tab->addTab(mTitleBarActions, i18n("&Titlebar Actions")); connect(mTitleBarActions, SIGNAL(changed(bool)), this, SLOT(moduleChanged(bool))); mWindowActions = new KWindowActionsConfig(false, mConfig, this); mWindowActions->setObjectName(QLatin1String("KWin Window Actions")); tab->addTab(mWindowActions, i18n("Window Actio&ns")); connect(mWindowActions, SIGNAL(changed(bool)), this, SLOT(moduleChanged(bool))); mMoving = new KMovingConfig(false, mConfig, this); mMoving->setObjectName(QLatin1String("KWin Moving")); tab->addTab(mMoving, i18n("&Moving")); connect(mMoving, SIGNAL(changed(bool)), this, SLOT(moduleChanged(bool))); mAdvanced = new KAdvancedConfig(false, mConfig, this); mAdvanced->setObjectName(QLatin1String("KWin Advanced")); tab->addTab(mAdvanced, i18n("Ad&vanced")); connect(mAdvanced, SIGNAL(changed(bool)), this, SLOT(moduleChanged(bool))); KAboutData *about = new KAboutData(QStringLiteral("kcmkwinoptions"), i18n("Window Behavior Configuration Module"), QString(), QString(), KAboutLicense::GPL, i18n("(c) 1997 - 2002 KWin and KControl Authors")); about->addAuthor(i18n("Matthias Ettrich"), QString(), "ettrich@kde.org"); about->addAuthor(i18n("Waldo Bastian"), QString(), "bastian@kde.org"); about->addAuthor(i18n("Cristian Tibirna"), QString(), "tibirna@kde.org"); about->addAuthor(i18n("Matthias Kalle Dalheimer"), QString(), "kalle@kde.org"); about->addAuthor(i18n("Daniel Molkentin"), QString(), "molkentin@kde.org"); about->addAuthor(i18n("Wynn Wilkes"), QString(), "wynnw@caldera.com"); about->addAuthor(i18n("Pat Dowler"), QString(), "dowler@pt1B1106.FSH.UVic.CA"); about->addAuthor(i18n("Bernd Wuebben"), QString(), "wuebben@kde.org"); about->addAuthor(i18n("Matthias Hoelzer-Kluepfel"), QString(), "hoelzer@kde.org"); setAboutData(about); } KWinOptions::~KWinOptions() { delete mConfig; } void KWinOptions::load() { mConfig->reparseConfiguration(); mFocus->load(); mTitleBarActions->load(); mWindowActions->load(); mMoving->load(); mAdvanced->load(); emit KCModule::changed(false); } void KWinOptions::save() { mFocus->save(); mTitleBarActions->save(); mWindowActions->save(); mMoving->save(); mAdvanced->save(); emit KCModule::changed(false); // Send signal to kwin mConfig->sync(); // Send signal to all kwin instances QDBusMessage message = QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig"); QDBusConnection::sessionBus().send(message); } void KWinOptions::defaults() { mFocus->defaults(); mTitleBarActions->defaults(); mWindowActions->defaults(); mMoving->defaults(); mAdvanced->defaults(); } QString KWinOptions::quickHelp() const { return i18n("

Window Behavior

Here you can customize the way windows behave when being" " moved, resized or clicked on. You can also specify a focus policy as well as a placement" " policy for new windows.

" "

Please note that this configuration will not take effect if you do not use" " KWin as your window manager. If you do use a different window manager, please refer to its documentation" " for how to customize window behavior.

"); } void KWinOptions::moduleChanged(bool state) { emit KCModule::changed(state); } KActionsOptions::KActionsOptions(QWidget *parent, const QVariantList &) : KCModule(parent) { mConfig = new KConfig("kwinrc"); QVBoxLayout *layout = new QVBoxLayout(this); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); tab = new QTabWidget(this); layout->addWidget(tab); mTitleBarActions = new KTitleBarActionsConfig(false, mConfig, this); mTitleBarActions->setObjectName(QLatin1String("KWin TitleBar Actions")); tab->addTab(mTitleBarActions, i18n("&Titlebar Actions")); connect(mTitleBarActions, SIGNAL(changed(bool)), this, SLOT(moduleChanged(bool))); mWindowActions = new KWindowActionsConfig(false, mConfig, this); mWindowActions->setObjectName(QLatin1String("KWin Window Actions")); tab->addTab(mWindowActions, i18n("Window Actio&ns")); connect(mWindowActions, SIGNAL(changed(bool)), this, SLOT(moduleChanged(bool))); } KActionsOptions::~KActionsOptions() { delete mConfig; } void KActionsOptions::load() { mTitleBarActions->load(); mWindowActions->load(); emit KCModule::changed(false); } void KActionsOptions::save() { mTitleBarActions->save(); mWindowActions->save(); emit KCModule::changed(false); // Send signal to kwin mConfig->sync(); // Send signal to all kwin instances QDBusMessage message = QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig"); QDBusConnection::sessionBus().send(message); } void KActionsOptions::defaults() { mTitleBarActions->defaults(); mWindowActions->defaults(); } void KActionsOptions::moduleChanged(bool state) { emit KCModule::changed(state); } K_PLUGIN_FACTORY_DEFINITION(KWinOptionsFactory, registerPlugin("kwinactions"); registerPlugin("kwinfocus"); registerPlugin("kwinmoving"); registerPlugin("kwinadvanced"); registerPlugin("kwinoptions"); ) #include "main.moc" #include "moc_main.cpp" diff --git a/kcmkwin/kwinrules/kcm.cpp b/kcmkwin/kwinrules/kcm.cpp index 11125f648..9dca089a9 100644 --- a/kcmkwin/kwinrules/kcm.cpp +++ b/kcmkwin/kwinrules/kcm.cpp @@ -1,106 +1,106 @@ /* * Copyright (c) 2004 Lubos Lunak * * 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 "kcm.h" #include //Added by qt3to4: #include #include #include #include #include #include "ruleslist.h" #include #include K_PLUGIN_FACTORY(KCMRulesFactory, registerPlugin(); ) namespace KWin { KCMRules::KCMRules(QWidget *parent, const QVariantList &) : KCModule(parent) , config("kwinrulesrc", KConfig::NoGlobals) { QVBoxLayout *layout = new QVBoxLayout(this); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); widget = new KCMRulesList(this); layout->addWidget(widget); connect(widget, SIGNAL(changed(bool)), SLOT(moduleChanged(bool))); KAboutData *about = new KAboutData(QStringLiteral("kcmkwinrules"), i18n("Window-Specific Settings Configuration Module"), QString(), QString(), KAboutLicense::GPL, i18n("(c) 2004 KWin and KControl Authors")); about->addAuthor(i18n("Lubos Lunak"), QString(), "l.lunak@kde.org"); setAboutData(about); } void KCMRules::load() { config.reparseConfiguration(); widget->load(); emit KCModule::changed(false); } void KCMRules::save() { widget->save(); emit KCModule::changed(false); // Send signal to kwin config.sync(); // Send signal to all kwin instances QDBusMessage message = QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig"); QDBusConnection::sessionBus().send(message); } void KCMRules::defaults() { widget->defaults(); } QString KCMRules::quickHelp() const { return i18n("

Window-specific Settings

Here you can customize window settings specifically only" " for some windows.

" "

Please note that this configuration will not take effect if you do not use" " KWin as your window manager. If you do use a different window manager, please refer to its documentation" " for how to customize window behavior.

"); } void KCMRules::moduleChanged(bool state) { emit KCModule::changed(state); } } // i18n freeze :-/ #if 0 I18N_NOOP("Remember settings separately for every window") I18N_NOOP("Show internal settings for remembering") I18N_NOOP("Internal setting for remembering") #endif #include "kcm.moc" diff --git a/plugins/kdecorations/aurorae/src/decorationoptions.cpp b/plugins/kdecorations/aurorae/src/decorationoptions.cpp index b0416342c..cc21d9c8b 100644 --- a/plugins/kdecorations/aurorae/src/decorationoptions.cpp +++ b/plugins/kdecorations/aurorae/src/decorationoptions.cpp @@ -1,269 +1,269 @@ /******************************************************************** Copyright (C) 2012 Martin Gräßlin 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, see . *********************************************************************/ #include "decorationoptions.h" #include #include #include #include #include #include namespace KWin { ColorSettings::ColorSettings(const QPalette &pal) { init(pal); } void ColorSettings::update(const QPalette &pal) { init(pal); } void ColorSettings::init(const QPalette &pal) { m_palette = pal; KConfigGroup wmConfig(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), QStringLiteral("WM")); - m_activeFrameColor = wmConfig.readEntry("frame", pal.color(QPalette::Active, QPalette::Background)); + m_activeFrameColor = wmConfig.readEntry("frame", pal.color(QPalette::Active, QPalette::Window)); m_inactiveFrameColor = wmConfig.readEntry("inactiveFrame", m_activeFrameColor); m_activeTitleBarColor = wmConfig.readEntry("activeBackground", pal.color(QPalette::Active, QPalette::Highlight)); m_inactiveTitleBarColor = wmConfig.readEntry("inactiveBackground", m_inactiveFrameColor); m_activeTitleBarBlendColor = wmConfig.readEntry("activeBlend", m_activeTitleBarColor.dark(110)); m_inactiveTitleBarBlendColor = wmConfig.readEntry("inactiveBlend", m_inactiveTitleBarColor.dark(110)); m_activeFontColor = wmConfig.readEntry("activeForeground", pal.color(QPalette::Active, QPalette::HighlightedText)); m_inactiveFontColor = wmConfig.readEntry("inactiveForeground", m_activeFontColor.dark()); m_activeButtonColor = wmConfig.readEntry("activeTitleBtnBg", m_activeFrameColor.light(130)); m_inactiveButtonColor = wmConfig.readEntry("inactiveTitleBtnBg", m_inactiveFrameColor.light(130)); m_activeHandle = wmConfig.readEntry("handle", m_activeFrameColor); m_inactiveHandle = wmConfig.readEntry("inactiveHandle", m_activeHandle); } DecorationOptions::DecorationOptions(QObject *parent) : QObject(parent) , m_active(true) , m_decoration(nullptr) , m_colors(ColorSettings(QPalette())) { connect(this, &DecorationOptions::decorationChanged, this, &DecorationOptions::slotActiveChanged); connect(this, &DecorationOptions::decorationChanged, this, &DecorationOptions::colorsChanged); connect(this, &DecorationOptions::decorationChanged, this, &DecorationOptions::fontChanged); connect(this, &DecorationOptions::decorationChanged, this, &DecorationOptions::titleButtonsChanged); } DecorationOptions::~DecorationOptions() { } QColor DecorationOptions::borderColor() const { return m_active ? m_colors.activeFrame() : m_colors.inactiveFrame(); } QColor DecorationOptions::buttonColor() const { return m_active ? m_colors.activeButtonColor() : m_colors.inactiveButtonColor(); } QColor DecorationOptions::fontColor() const { return m_active ? m_colors.activeFont() : m_colors.inactiveFont(); } QColor DecorationOptions::resizeHandleColor() const { return m_active ? m_colors.activeHandle() : m_colors.inactiveHandle(); } QColor DecorationOptions::titleBarBlendColor() const { return m_active ? m_colors.activeTitleBarBlendColor() : m_colors.inactiveTitleBarBlendColor(); } QColor DecorationOptions::titleBarColor() const { return m_active ? m_colors.activeTitleBarColor() : m_colors.inactiveTitleBarColor(); } QFont DecorationOptions::titleFont() const { return m_decoration ? m_decoration->settings()->font() : QFont(); } static int decorationButton(KDecoration2::DecorationButtonType type) { switch (type) { case KDecoration2::DecorationButtonType::Menu: return DecorationOptions::DecorationButtonMenu; case KDecoration2::DecorationButtonType::ApplicationMenu: return DecorationOptions::DecorationButtonApplicationMenu; case KDecoration2::DecorationButtonType::OnAllDesktops: return DecorationOptions::DecorationButtonOnAllDesktops; case KDecoration2::DecorationButtonType::Minimize: return DecorationOptions::DecorationButtonMinimize; case KDecoration2::DecorationButtonType::Maximize: return DecorationOptions::DecorationButtonMaximizeRestore; case KDecoration2::DecorationButtonType::Close: return DecorationOptions::DecorationButtonClose; case KDecoration2::DecorationButtonType::ContextHelp: return DecorationOptions::DecorationButtonQuickHelp; case KDecoration2::DecorationButtonType::Shade: return DecorationOptions::DecorationButtonShade; case KDecoration2::DecorationButtonType::KeepBelow: return DecorationOptions::DecorationButtonKeepBelow; case KDecoration2::DecorationButtonType::KeepAbove: return DecorationOptions::DecorationButtonKeepAbove; default: return DecorationOptions::DecorationButtonNone; } } QList DecorationOptions::titleButtonsLeft() const { QList ret; if (m_decoration) { for (auto it : m_decoration->settings()->decorationButtonsLeft()) { ret << decorationButton(it); } } return ret; } QList DecorationOptions::titleButtonsRight() const { QList ret; if (m_decoration) { for (auto it : m_decoration->settings()->decorationButtonsRight()) { ret << decorationButton(it); } } return ret; } KDecoration2::Decoration *DecorationOptions::decoration() const { return m_decoration; } void DecorationOptions::setDecoration(KDecoration2::Decoration *decoration) { if (m_decoration == decoration) { return; } if (m_decoration) { // disconnect from existing decoration disconnect(m_decoration->client().data(), &KDecoration2::DecoratedClient::activeChanged, this, &DecorationOptions::slotActiveChanged); auto s = m_decoration->settings(); disconnect(s.data(), &KDecoration2::DecorationSettings::fontChanged, this, &DecorationOptions::fontChanged); disconnect(s.data(), &KDecoration2::DecorationSettings::decorationButtonsLeftChanged, this, &DecorationOptions::titleButtonsChanged); disconnect(s.data(), &KDecoration2::DecorationSettings::decorationButtonsRightChanged, this, &DecorationOptions::titleButtonsChanged); disconnect(m_paletteConnection); } m_decoration = decoration; connect(m_decoration->client().data(), &KDecoration2::DecoratedClient::activeChanged, this, &DecorationOptions::slotActiveChanged); m_paletteConnection = connect(m_decoration->client().data(), &KDecoration2::DecoratedClient::paletteChanged, this, [this] (const QPalette &pal) { m_colors.update(pal); emit colorsChanged(); } ); auto s = m_decoration->settings(); connect(s.data(), &KDecoration2::DecorationSettings::fontChanged, this, &DecorationOptions::fontChanged); connect(s.data(), &KDecoration2::DecorationSettings::decorationButtonsLeftChanged, this, &DecorationOptions::titleButtonsChanged); connect(s.data(), &KDecoration2::DecorationSettings::decorationButtonsRightChanged, this, &DecorationOptions::titleButtonsChanged); emit decorationChanged(); } void DecorationOptions::slotActiveChanged() { if (!m_decoration) { return; } if (m_active == m_decoration->client().data()->isActive()) { return; } m_active = m_decoration->client().data()->isActive(); emit colorsChanged(); emit fontChanged(); } int DecorationOptions::mousePressAndHoldInterval() const { return QGuiApplication::styleHints()->mousePressAndHoldInterval(); } Borders::Borders(QObject *parent) : QObject(parent) , m_left(0) , m_right(0) , m_top(0) , m_bottom(0) { } Borders::~Borders() { } #define SETTER( methodName, name ) \ void Borders::methodName(int name) \ { \ if (m_##name == name) { \ return; \ } \ m_##name = name; \ emit name##Changed(); \ } SETTER(setLeft, left) SETTER(setRight, right) SETTER(setTop, top) SETTER(setBottom, bottom) #undef SETTER void Borders::setAllBorders(int border) { setBorders(border); setTitle(border); } void Borders::setBorders(int border) { setSideBorders(border); setBottom(border); } void Borders::setSideBorders(int border) { setLeft(border); setRight(border); } void Borders::setTitle(int value) { setTop(value); } Borders::operator QMargins() const { return QMargins(m_left, m_top, m_right, m_bottom); } } // namespace