diff --git a/kcmkwin/kwindecoration/declarative-plugin/buttonsmodel.h b/kcmkwin/kwindecoration/declarative-plugin/buttonsmodel.h --- a/kcmkwin/kwindecoration/declarative-plugin/buttonsmodel.h +++ b/kcmkwin/kwindecoration/declarative-plugin/buttonsmodel.h @@ -45,6 +45,7 @@ return m_buttons; } + Q_INVOKABLE void clear(); Q_INVOKABLE void remove(int index); Q_INVOKABLE void up(int index); Q_INVOKABLE void down(int index); diff --git a/kcmkwin/kwindecoration/declarative-plugin/buttonsmodel.cpp b/kcmkwin/kwindecoration/declarative-plugin/buttonsmodel.cpp --- a/kcmkwin/kwindecoration/declarative-plugin/buttonsmodel.cpp +++ b/kcmkwin/kwindecoration/declarative-plugin/buttonsmodel.cpp @@ -153,8 +153,8 @@ void ButtonsModel::add(int index, int type) { - beginInsertRows(QModelIndex(), index + 1, index+1); - m_buttons.insert(index+1, KDecoration2::DecorationButtonType(type)); + beginInsertRows(QModelIndex(), index, index); + m_buttons.insert(index, KDecoration2::DecorationButtonType(type)); endInsertRows(); } @@ -178,6 +178,13 @@ endMoveRows(); } +void ButtonsModel::clear() +{ + beginResetModel(); + m_buttons.clear(); + endResetModel(); +} + } } diff --git a/kcmkwin/kwindecoration/kcm.cpp b/kcmkwin/kwindecoration/kcm.cpp --- a/kcmkwin/kwindecoration/kcm.cpp +++ b/kcmkwin/kwindecoration/kcm.cpp @@ -64,6 +64,17 @@ static const QString s_borderSizeNormal = QStringLiteral("Normal"); static const QString s_ghnsIcon = QStringLiteral("get-hot-new-stuff"); +static const QVector s_defaultButtonsOnLeft { + KDecoration2::DecorationButtonType::Menu, + KDecoration2::DecorationButtonType::OnAllDesktops +}; +static const QVector s_defaultButtonsOnRight { + KDecoration2::DecorationButtonType::ContextHelp, + KDecoration2::DecorationButtonType::Minimize, + KDecoration2::DecorationButtonType::Maximize, + KDecoration2::DecorationButtonType::Close +}; + ConfigurationForm::ConfigurationForm(QWidget *parent) : QWidget(parent) { @@ -317,25 +328,13 @@ m_quickView->rootContext()->setContextProperty("initialThemeIndex", themeIndex); // buttons - const auto &left = readDecorationButtons(config, "ButtonsOnLeft", QVector{ - KDecoration2::DecorationButtonType::Menu, - KDecoration2::DecorationButtonType::OnAllDesktops - }); - while (m_leftButtons->rowCount() > 0) { - m_leftButtons->remove(0); - } + const auto &left = readDecorationButtons(config, "ButtonsOnLeft", s_defaultButtonsOnLeft); + m_leftButtons->clear(); for (auto it = left.begin(); it != left.end(); ++it) { m_leftButtons->add(*it); } - const auto &right = readDecorationButtons(config, "ButtonsOnRight", QVector{ - KDecoration2::DecorationButtonType::ContextHelp, - KDecoration2::DecorationButtonType::Minimize, - KDecoration2::DecorationButtonType::Maximize, - KDecoration2::DecorationButtonType::Close - }); - while (m_rightButtons->rowCount() > 0) { - m_rightButtons->remove(0); - } + const auto &right = readDecorationButtons(config, "ButtonsOnRight", s_defaultButtonsOnRight); + m_rightButtons->clear(); for (auto it = right.begin(); it != right.end(); ++it) { m_rightButtons->add(*it); } @@ -383,6 +382,17 @@ } m_ui->borderSizesCombo->setCurrentIndex(m_ui->borderSizesCombo->findData(QVariant::fromValue(stringToSize(s_borderSizeNormal)))); m_ui->closeWindowsDoubleClick->setChecked(false); + + // Buttons reset + m_leftButtons->clear(); + for (auto it = s_defaultButtonsOnLeft.begin(); it != s_defaultButtonsOnLeft.end(); ++it) { + m_leftButtons->add(*it); + } + m_rightButtons->clear(); + for (auto it = s_defaultButtonsOnRight.begin(); it != s_defaultButtonsOnRight.end(); ++it) { + m_rightButtons->add(*it); + } + KCModule::defaults(); } @@ -426,8 +436,9 @@ void ConfigurationModule::updateColors() { m_quickView->rootContext()->setContextProperty("backgroundColor", m_ui->palette().color(QPalette::Active, QPalette::Window)); - m_quickView->rootContext()->setContextProperty("highlightColor", m_ui->palette().color(QPalette::Active, QPalette::Shadow)); - m_quickView->rootContext()->setContextProperty("baseColor", m_ui->palette().color(QPalette::Active, QPalette::Base)); + m_quickView->rootContext()->setContextProperty("borderColor", m_ui->palette().color(QPalette::Active, QPalette::Shadow)); + m_quickView->rootContext()->setContextProperty("highlightColor", m_ui->palette().color(QPalette::Active, QPalette::Highlight)); + m_quickView->rootContext()->setContextProperty("titleBarColor", m_ui->palette().color(QPalette::Active, QPalette::Base)); } } diff --git a/kcmkwin/kwindecoration/kcm.ui b/kcmkwin/kwindecoration/kcm.ui --- a/kcmkwin/kwindecoration/kcm.ui +++ b/kcmkwin/kwindecoration/kcm.ui @@ -59,7 +59,7 @@ 0 - 100 + 200 diff --git a/kcmkwin/kwindecoration/qml/ButtonGroup.qml b/kcmkwin/kwindecoration/qml/ButtonGroup.qml --- a/kcmkwin/kwindecoration/qml/ButtonGroup.qml +++ b/kcmkwin/kwindecoration/qml/ButtonGroup.qml @@ -30,11 +30,11 @@ orientation: ListView.Horizontal interactive: false spacing: units.smallSpacing - implicitHeight: units.iconSizes.small - implicitWidth: count * (units.iconSizes.small + units.smallSpacing) - Math.min(1, count) * units.smallSpacing + implicitHeight: units.iconSizes.medium + implicitWidth: count * (units.iconSizes.medium + units.smallSpacing) - Math.min(1, count) * units.smallSpacing delegate: Item { - width: units.iconSizes.small - height: units.iconSizes.small + width: units.iconSizes.medium + height: units.iconSizes.medium KDecoration.Button { id: button property int itemIndex: index diff --git a/kcmkwin/kwindecoration/qml/Buttons.qml b/kcmkwin/kwindecoration/qml/Buttons.qml --- a/kcmkwin/kwindecoration/qml/Buttons.qml +++ b/kcmkwin/kwindecoration/qml/Buttons.qml @@ -35,30 +35,31 @@ id: settingsItem bridge: bridgeItem.bridge } + property int iconSize + property int itemSpacing + iconSize: units.iconSizes.medium + itemSpacing: units.smallSpacing Rectangle { anchors.fill: parent - border.width: Math.ceil(units.gridUnit / 16.0) - border.color: highlightColor - color: baseColor + color: backgroundColor ColumnLayout { id: layout width: parent.width - height: titlebarRect.height + availableGrid.height + dragHint.height + 5*layout.spacing + height: parent.height Rectangle { id: titlebarRect - height: buttonPreviewRow.height + units.smallSpacing + height: buttonPreviewRow.height + itemSpacing border.width: Math.ceil(units.gridUnit / 16.0) - border.color: highlightColor - color: backgroundColor + border.color: borderColor + color: titleBarColor Layout.fillWidth: true - Layout.topMargin: -border.width // prevent a double top border RowLayout { id: buttonPreviewRow anchors.top: parent.top; anchors.left: parent.left; anchors.right: parent.right; - anchors.margins: units.smallSpacing / 2 - height: Math.max(units.iconSizes.small, titlebar.implicitHeight) + units.smallSpacing/2 + anchors.margins: itemSpacing / 2 + height: Math.max(iconSize, titlebar.implicitHeight) + itemSpacing/2 ButtonGroup { id: leftButtonsView height: buttonPreviewRow.height @@ -69,7 +70,10 @@ id: titlebar Layout.fillWidth: true horizontalAlignment: Text.AlignHCenter - font: titleFont + font.pointSize: titleFont.pointSize * 1.5 + font.family: titleFont.family + font.bold: font.bold + font.italic: font.italic text: i18n("Titlebar") } @@ -83,10 +87,10 @@ DropArea { anchors { fill: titlebarRect - leftMargin: -units.iconSizes.small - topMargin: -units.iconSizes.small - rightMargin: +units.iconSizes.small - bottomMargin: +units.iconSizes.small + leftMargin: -iconSize + topMargin: -itemSpacing + rightMargin: -iconSize + bottomMargin: -itemSpacing } keys: [ "decoButtonAdd", "decoButtonRight", "decoButtonLeft" ] onEntered: { @@ -105,9 +109,13 @@ return; } var point = mapToItem(view, drag.x, drag.y); - var index = view.indexAt(point.x, point.y); - if (index == -1 && (view.x + view.width <= drag.x)) { - index = view.count - 1; + var index = 0 + for(var childIndex = 0 ; childIndex < (view.count - 1) ; childIndex++) { + var child = view.contentItem.children[childIndex] + if (child.x > point.x) { + break + } + index = childIndex + 1 } if (drop.keys.indexOf("decoButtonAdd") != -1) { view.model.add(index, drag.source.type); @@ -137,12 +145,24 @@ } } } + Text { + id: dragHint + opacity: (leftButtonsView.dragging || rightButtonsView.dragging || availableGrid.dragging) ? 0.0 : 0.50 + color: highlightColor + Layout.fillWidth: true + Layout.topMargin: itemSpacing + Layout.bottomMargin: itemSpacing + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignTop + wrapMode: Text.NoWrap + text: i18n("Drag buttons between here and the titlebar") + } GridView { id: availableGrid Layout.fillWidth: true + Layout.fillHeight: true model: availableButtons interactive: false - height: Math.ceil(cellHeight * 3) delegate: Item { id: availableDelegate Layout.margins: units.gridUnit @@ -155,8 +175,8 @@ bridge: bridgeItem.bridge settings: settingsItem type: model["button"] - width: units.iconSizes.small - height: units.iconSizes.small + width: iconSize + height: iconSize Drag.keys: [ "decoButtonAdd" ] Drag.active: dragArea.drag.active } @@ -201,12 +221,12 @@ QQC2.Label { text: i18n("Drop here to remove button") font.weight: Font.Bold - Layout.bottomMargin: units.smallSpacing + Layout.bottomMargin: itemSpacing } KQuickControlsAddons.QIconItem { id: icon - width: units.iconSizes.smallMedium - height: units.iconSizes.smallMedium + width: iconSize + height: iconSize icon: "emblem-remove" Layout.alignment: Qt.AlignHCenter } @@ -216,16 +236,6 @@ } } } - Text { - id: dragHint - opacity: (leftButtonsView.dragging || rightButtonsView.dragging || availableGrid.dragging) ? 0.0 : 0.50 - Layout.fillWidth: true - Layout.bottomMargin: units.smallSpacing - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignTop - wrapMode: Text.NoWrap - text: i18n("Drag buttons between here and the titlebar") - } } } } diff --git a/kcmkwin/kwindecoration/qml/Previews.qml b/kcmkwin/kwindecoration/qml/Previews.qml --- a/kcmkwin/kwindecoration/qml/Previews.qml +++ b/kcmkwin/kwindecoration/qml/Previews.qml @@ -42,7 +42,7 @@ Rectangle { z: -1 anchors.fill: parent - color: baseColor + color: backgroundColor } highlight: Rectangle { color: highlightColor diff --git a/kcmkwin/kwindecoration/qml/main.qml b/kcmkwin/kwindecoration/qml/main.qml --- a/kcmkwin/kwindecoration/qml/main.qml +++ b/kcmkwin/kwindecoration/qml/main.qml @@ -21,17 +21,14 @@ import QtQuick.Controls 1.2 import QtQuick.Layouts 1.1 -Rectangle { - color: backgroundColor - ColumnLayout { - anchors.fill: parent - Previews { - Layout.fillWidth: true - Layout.fillHeight: true - } - Buttons { - Layout.alignment: Qt.AlignTop - Layout.fillWidth: true - } +ColumnLayout { + anchors.fill: parent + Previews { + Layout.fillWidth: true + Layout.fillHeight: true + } + Buttons { + Layout.fillWidth: true + Layout.fillHeight: true } }