Skip to content

Commit

Permalink
refactor: modernize QML code to make it work with Qt 6
Browse files Browse the repository at this point in the history
This cherry-picks several changes from KScreen to make KDisplay work with Qt 6.
  • Loading branch information
romangg committed Apr 19, 2023
1 parent 9abba36 commit ff194dc
Show file tree
Hide file tree
Showing 7 changed files with 334 additions and 224 deletions.
14 changes: 2 additions & 12 deletions kcm/kcm.cpp
Expand Up @@ -85,17 +85,7 @@ void KCMKDisplay::configReady(ConfigOperation* op)
Q_EMIT outputRetentionChanged();
}

void KCMKDisplay::forceSave()
{
doSave(true);
}

void KCMKDisplay::save()
{
doSave(false);
}

void KCMKDisplay::doSave(bool force)
{
if (!m_config) {
Q_EMIT errorOnSave();
Expand Down Expand Up @@ -134,8 +124,8 @@ void KCMKDisplay::doSave(bool force)
<< (output->replication_source() == 0 ? "no" : "yes");
}

if (!atLeastOneEnabledOutput && !force) {
Q_EMIT dangerousSave();
if (!atLeastOneEnabledOutput) {
Q_EMIT invalidConfig(InvalidConfigReason::NoEnabledOutputs);
m_config->checkNeedsSave();
return;
}
Expand Down
11 changes: 7 additions & 4 deletions kcm/kcm.h
Expand Up @@ -53,6 +53,12 @@ class KCMKDisplay : public KQuickManagedConfigModule
Q_PROPERTY(bool tabletModeAvailable READ tabletModeAvailable NOTIFY tabletModeAvailableChanged)

public:
enum InvalidConfigReason {
NoEnabledOutputs,
ConfigHasGaps,
};
Q_ENUM(InvalidConfigReason)

KCMKDisplay(QObject* parent, const KPluginMetaData& data, const QVariantList& args);
~KCMKDisplay() override = default;

Expand Down Expand Up @@ -84,9 +90,6 @@ class KCMKDisplay : public KQuickManagedConfigModule
bool orientationSensorAvailable() const;
bool tabletModeAvailable() const;

Q_INVOKABLE void forceSave();
void doSave(bool force);

Q_SIGNALS:
void backendReadyChanged();
void backendError();
Expand All @@ -102,7 +105,7 @@ class KCMKDisplay : public KQuickManagedConfigModule
void autoRotationSupportedChanged();
void orientationSensorAvailableChanged();
void tabletModeAvailableChanged();
void dangerousSave();
void invalidConfig(InvalidConfigReason);
void errorOnSave();
void globalScaleWritten();
void outputConnect(bool connected);
Expand Down
46 changes: 29 additions & 17 deletions kcm/package/contents/ui/Orientation.qml
Expand Up @@ -14,14 +14,14 @@ 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 <http://www.gnu.org/licenses/>.
*********************************************************************/
import QtQuick 2.9
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.3 as Controls
import org.kde.kirigami 2.4 as Kirigami
import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15 as QQC2
import org.kde.kirigami 2.20 as Kirigami

ColumnLayout {
Kirigami.FormData.label: i18n("Orientation:")
Kirigami.FormData.buddyFor: auto_rotate_switch
Kirigami.FormData.buddyFor: autoRotateColumn.visible ? autoRotateRadio : orientation
spacing: Kirigami.Units.smallSpacing

ColumnLayout {
Expand All @@ -31,26 +31,38 @@ ColumnLayout {
enabled: element.internal
visible: kcm.autoRotationSupported && kcm.orientationSensorAvailable

Controls.Switch {
id: auto_rotate_switch
text: i18n("Auto")
checked: enabled && element.autoRotate
onToggled: element.autoRotate = checked
ColumnLayout {
QQC2.RadioButton {
id: autoRotateRadio
text: i18n("Automatic")
checked: autoRotateColumn.enabled && element.autoRotate
onToggled: element.autoRotate = true
}

QQC2.CheckBox {
id: autoRotateOnlyInTabletMode
Layout.leftMargin: Kirigami.Units.gridUnit

text: i18n("Only when in tablet mode")
enabled: autoRotateRadio.checked
checked: enabled && element.autoRotateOnlyInTabletMode
onToggled: element.autoRotateOnlyInTabletMode = checked
}
}

Controls.Switch {
text: i18n("Only when in tablet mode.")
visible: auto_rotate_switch.checked
checked: element.autoRotateOnlyInTabletMode
onToggled: element.autoRotateOnlyInTabletMode = checked
QQC2.RadioButton {
id: manualRotateRadio
text: i18n("Manual")
checked: !element.autoRotate || !autoRotateColumn.enabled
onToggled: element.autoRotate = false
}
}

RowLayout {
id: orientation
visible: !auto_rotate_switch.checked || !kcm.autoRotationSupported
enabled: !element.autoRotate || !autoRotateColumn.enabled || !autoRotateColumn.visible

Controls.ButtonGroup {
QQC2.ButtonGroup {
buttons: orientation.children
}

Expand Down

0 comments on commit ff194dc

Please sign in to comment.