diff --git a/kcm/src/collapsablebutton.cpp b/kcm/src/collapsablebutton.cpp index 6be807e..f4a3b2b 100644 --- a/kcm/src/collapsablebutton.cpp +++ b/kcm/src/collapsablebutton.cpp @@ -1,116 +1,116 @@ /* * Copyright 2013 Daniel Vrátil * * 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) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * 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 "collapsablebutton.h" #include #include #include #include #include CollapsableButton::CollapsableButton(const QString &text, QWidget *parent) : QWidget(parent) , mCollapsed(false) - , mWidget(0) + , mWidget(nullptr) { QHBoxLayout *layout = new QHBoxLayout(this); mLabel = new QLabel(text, this); layout->addWidget(mLabel); QFont f = mLabel->font(); f.setBold(true); mLabel->setFont(f); mLabel->setIndent(20); } CollapsableButton::~CollapsableButton() { } void CollapsableButton::mouseReleaseEvent(QMouseEvent *ev) { if (ev->button() == Qt::LeftButton) { toggle(); Q_EMIT toggled(); } QWidget::mouseReleaseEvent(ev); } void CollapsableButton::paintEvent(QPaintEvent *ev) { QPainter painter(this); QStyleOption opt; const int h = 20; opt.rect = QRect(0, (height() - h) / 2, h, h); opt.palette = palette(); QStyle::PrimitiveElement pe = mCollapsed ? QStyle::PE_IndicatorArrowRight : QStyle::PE_IndicatorArrowDown; style()->drawPrimitive(pe, &opt, &painter); painter.end(); QWidget::paintEvent(ev); } bool CollapsableButton::isCollapsed() const { return mCollapsed; } void CollapsableButton::setCollapsed(bool collapsed) { if (mCollapsed == collapsed) { return; } mCollapsed = collapsed; if (mWidget) { mWidget->setHidden(collapsed); } update(); } QLabel* CollapsableButton::label() const { return mLabel; } void CollapsableButton::setWidget(QWidget *widget) { mWidget = widget; if (mWidget) { mWidget->setHidden(isCollapsed()); } } QWidget *CollapsableButton::widget() const { return mWidget; } void CollapsableButton::toggle() { setCollapsed(!isCollapsed()); Q_EMIT toggled(); } diff --git a/kcm/src/controlpanel.h b/kcm/src/controlpanel.h index ec18646..7bab7e4 100644 --- a/kcm/src/controlpanel.h +++ b/kcm/src/controlpanel.h @@ -1,68 +1,68 @@ /* * Copyright 2013 Daniel Vrátil * * 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) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * 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 . * */ #ifndef CONTROLPANEL_H #define CONTROLPANEL_H #include #include class QVBoxLayout; class OutputConfig; class UnifiedOutputConfig; class QLabel; class QCheckBox; class QSlider; class QComboBox; class ControlPanel : public QFrame { Q_OBJECT public: - explicit ControlPanel(QWidget *parent = 0); + explicit ControlPanel(QWidget *parent = nullptr); virtual ~ControlPanel(); void setConfig(const KScreen::ConfigPtr &config); void setUnifiedOutput(const KScreen::OutputPtr &output); public Q_SLOTS: void activateOutput(const KScreen::OutputPtr &output); Q_SIGNALS: void changed(); private Q_SLOTS: void addOutput(const KScreen::OutputPtr &output); void removeOutput(int outputId); private: KScreen::ConfigPtr mConfig; QList mOutputConfigs; QVBoxLayout *mLayout; UnifiedOutputConfig *mUnifiedOutputCfg; }; #endif // CONTROLPANEL_H diff --git a/kcm/src/declarative/qmloutputcomponent.cpp b/kcm/src/declarative/qmloutputcomponent.cpp index 98bf832..4dc6838 100644 --- a/kcm/src/declarative/qmloutputcomponent.cpp +++ b/kcm/src/declarative/qmloutputcomponent.cpp @@ -1,65 +1,62 @@ /* * Copyright (C) 2013 Daniel Vrátil * * 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 "qmloutputcomponent.h" #include "qmloutput.h" #include "qmlscreen.h" #include #include #include #include Q_DECLARE_METATYPE(KScreen::OutputPtr) Q_DECLARE_METATYPE(QMLScreen*) QMLOutputComponent::QMLOutputComponent(QQmlEngine *engine, QMLScreen *parent): QQmlComponent(engine, parent), m_engine(engine) { const QString qmlPath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kcm_kscreen/qml/Output.qml")); loadUrl(QUrl::fromLocalFile(qmlPath)); } QMLOutputComponent::~QMLOutputComponent() { } QMLOutput* QMLOutputComponent::createForOutput(const KScreen::OutputPtr &output) { - QObject *instance; - - instance = beginCreate(m_engine->rootContext()); + QObject *instance = beginCreate(m_engine->rootContext()); if (!instance) { qWarning() << errorString(); - return 0; + return nullptr; } - bool success = false; - success = instance->setProperty("outputPtr", QVariant::fromValue(output)); + bool success = instance->setProperty("outputPtr", QVariant::fromValue(output)); Q_ASSERT(success); success = instance->setProperty("screen", QVariant::fromValue(qobject_cast(parent()))); Q_ASSERT(success); Q_UNUSED(success); completeCreate(); return qobject_cast(instance); } diff --git a/kcm/src/declarative/qmlscreen.cpp b/kcm/src/declarative/qmlscreen.cpp index 6f44312..5b8e2f9 100644 --- a/kcm/src/declarative/qmlscreen.cpp +++ b/kcm/src/declarative/qmlscreen.cpp @@ -1,362 +1,362 @@ /* * Copyright (C) 2013 Daniel Vrátil * * 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 "qmlscreen.h" #include "qmloutputcomponent.h" #include "qmloutput.h" #include #include #include #include #include //static void NullDeleter(KScreen::Output */*output*/) { } QMLScreen::QMLScreen(QQuickItem *parent): QQuickItem(parent), - m_config(0), + m_config(nullptr), m_connectedOutputsCount(0), m_enabledOutputsCount(0), - m_leftmost(0), - m_topmost(0), - m_rightmost(0), - m_bottommost(0) + m_leftmost(nullptr), + m_topmost(nullptr), + m_rightmost(nullptr), + m_bottommost(nullptr) { connect(this, &QMLScreen::widthChanged, this, &QMLScreen::viewSizeChanged); connect(this, &QMLScreen::heightChanged, this, &QMLScreen::viewSizeChanged); } QMLScreen::~QMLScreen() { } KScreen::ConfigPtr QMLScreen::config() const { return m_config; } void QMLScreen::setConfig(const KScreen::ConfigPtr &config) { qDeleteAll(m_outputMap); m_outputMap.clear(); m_bottommost = m_leftmost = m_rightmost = m_topmost = 0; m_connectedOutputsCount = 0; m_enabledOutputsCount = 0; if (m_config) { m_config->disconnect(this); } m_config = config; connect(m_config.data(), &KScreen::Config::outputAdded, this, [this](const KScreen::OutputPtr &output) { addOutput(output); updateOutputsPlacement(); }); connect(m_config.data(), &KScreen::Config::outputRemoved, this, &QMLScreen::removeOutput); for (const KScreen::OutputPtr &output : m_config->outputs()) { addOutput(output); } updateOutputsPlacement(); for (QMLOutput *qmlOutput : m_outputMap) { if (qmlOutput->output()->isConnected() && qmlOutput->output()->isEnabled()) { qmlOutput->dockToNeighbours(); } } } void QMLScreen::addOutput(const KScreen::OutputPtr &output) { //QQuickItem *container = findChild(QLatin1String("outputContainer")); QMLOutputComponent comp(m_engine, this); QMLOutput *qmloutput = comp.createForOutput(output); if (!qmloutput) { qWarning() << "Failed to create QMLOutput"; return; } m_outputMap.insert(output, qmloutput); qmloutput->setParentItem(this); qmloutput->setZ(m_outputMap.count()); connect(output.data(), &KScreen::Output::isConnectedChanged, this, &QMLScreen::outputConnectedChanged); connect(output.data(), &KScreen::Output::isEnabledChanged, this, &QMLScreen::outputEnabledChanged); connect(output.data(), &KScreen::Output::posChanged, this, &QMLScreen::outputPositionChanged); connect(qmloutput, &QMLOutput::yChanged, [this, qmloutput]() { qmlOutputMoved(qmloutput); }); connect(qmloutput, &QMLOutput::xChanged, [this, qmloutput]() { qmlOutputMoved(qmloutput); }); connect(qmloutput, SIGNAL(clicked()), this, SLOT(setActiveOutput())); qmloutput->updateRootProperties(); } void QMLScreen::removeOutput(int outputId) { for (const KScreen::OutputPtr &output : m_outputMap.keys()) { if (output->id() == outputId) { QMLOutput *qmlOutput = m_outputMap.take(output); qmlOutput->setParentItem(Q_NULLPTR); qmlOutput->setParent(Q_NULLPTR); qmlOutput->deleteLater(); return; } } } int QMLScreen::connectedOutputsCount() const { return m_connectedOutputsCount; } int QMLScreen::enabledOutputsCount() const { return m_enabledOutputsCount; } QMLOutput *QMLScreen::primaryOutput() const { Q_FOREACH (QMLOutput *qmlOutput, m_outputMap) { if (qmlOutput->output()->isPrimary()) { return qmlOutput; } } return 0; } QList QMLScreen::outputs() const { return m_outputMap.values(); } void QMLScreen::setActiveOutput(QMLOutput *output) { Q_FOREACH (QMLOutput *qmlOutput, m_outputMap) { if (qmlOutput->z() > output->z()) { qmlOutput->setZ(qmlOutput->z() - 1); } } output->setZ(m_outputMap.count()); output->setFocus(true); Q_EMIT focusedOutputChanged(output); } QSize QMLScreen::maxScreenSize() const { return m_config->screen()->maxSize(); } float QMLScreen::outputScale() const { return 1.0 / 8.0; } void QMLScreen::outputConnectedChanged() { int connectedCount = 0; Q_FOREACH (const KScreen::OutputPtr &output, m_outputMap.keys()) { if (output->isConnected()) { ++connectedCount; } } if (connectedCount != m_connectedOutputsCount) { m_connectedOutputsCount = connectedCount; Q_EMIT connectedOutputsCountChanged(); updateOutputsPlacement(); } } void QMLScreen::outputEnabledChanged() { const KScreen::OutputPtr output(qobject_cast(sender()), [](void *){}); if (output->isEnabled()) { updateOutputsPlacement(); } int enabledCount = 0; Q_FOREACH (const KScreen::OutputPtr &output, m_outputMap.keys()) { if (output->isEnabled()) { ++enabledCount; } } if (enabledCount == m_enabledOutputsCount) { m_enabledOutputsCount = enabledCount; Q_EMIT enabledOutputsCountChanged(); } } void QMLScreen::outputPositionChanged() { /* TODO: Reposition the QMLOutputs */ } void QMLScreen::qmlOutputMoved(QMLOutput *qmlOutput) { updateCornerOutputs(); if (m_leftmost) { m_leftmost->setOutputX(0); } if (m_topmost) { m_topmost->setOutputY(0); } if (qmlOutput == m_leftmost) { Q_FOREACH (QMLOutput *other, m_outputMap) { if (other == m_leftmost) { continue; } if (!other->output()->isConnected() || !other->output()->isEnabled()) { continue; } other->setOutputX(float(other->x() - m_leftmost->x()) / outputScale()); } } else if (m_leftmost) { qmlOutput->setOutputX(float(qmlOutput->x() - m_leftmost->x()) / outputScale()); } if (qmlOutput == m_topmost) { Q_FOREACH (QMLOutput *other, m_outputMap) { if (other == m_topmost) { continue; } if (!other->output()->isConnected() || !other->output()->isEnabled()) { continue; } other->setOutputY(float(other->y() - m_topmost->y()) / outputScale()); } } else if (m_topmost) { qmlOutput->setOutputY(float(qmlOutput->y() - m_topmost->y()) / outputScale()); } } void QMLScreen::viewSizeChanged() { updateOutputsPlacement(); } void QMLScreen::updateCornerOutputs() { m_leftmost = 0; m_topmost = 0; m_rightmost = 0; m_bottommost = 0; Q_FOREACH (QMLOutput *output, m_outputMap) { if (!output->output()->isConnected() || !output->output()->isEnabled()) { continue; } QMLOutput *other = m_leftmost; if (!other || output->x() < other->x()) { m_leftmost = output; } if (!other || output->y() < other->y()) { m_topmost = output; } if (!other || output->x() + output->width() > other->x() + other->width()) { m_rightmost = output; } if (!other || output->y() + output->height() > other->y() + other->height()) { m_bottommost = output; } } } void QMLScreen::updateOutputsPlacement() { int disabledOffsetX = width(); QSizeF activeScreenSize; Q_FOREACH (QQuickItem *item, childItems()) { QMLOutput *qmlOutput = qobject_cast(item); if (!qmlOutput->output()->isConnected()) { continue; } if (!qmlOutput->output()->isEnabled()) { qmlOutput->blockSignals(true); disabledOffsetX -= qmlOutput->width(); qmlOutput->setPosition(QPoint(disabledOffsetX, 0)); qmlOutput->blockSignals(false); continue; } if (qmlOutput->outputX() + qmlOutput->currentOutputWidth() > activeScreenSize.width()) { activeScreenSize.setWidth(qmlOutput->outputX() + qmlOutput->currentOutputWidth()); } if (qmlOutput->outputY() + qmlOutput->currentOutputHeight() > activeScreenSize.height()) { activeScreenSize.setHeight(qmlOutput->outputY() + qmlOutput->currentOutputHeight()); } } activeScreenSize *= outputScale(); const QPointF offset((width() - activeScreenSize.width()) / 2.0, (height() - activeScreenSize.height()) / 2.0); Q_FOREACH (QQuickItem *item, childItems()) { QMLOutput *qmlOutput = qobject_cast(item); if (!qmlOutput->output()->isConnected() || !qmlOutput->output()->isEnabled()) { continue; } qmlOutput->blockSignals(true); qmlOutput->setPosition(QPointF(offset.x() + (qmlOutput->outputX() * outputScale()), offset.y() + (qmlOutput->outputY() * outputScale()))); qmlOutput->blockSignals(false); } } void QMLScreen::setEngine(QQmlEngine* engine) { m_engine = engine; } diff --git a/kcm/src/declarative/qmlscreen.h b/kcm/src/declarative/qmlscreen.h index d74fbbc..1c3d54b 100644 --- a/kcm/src/declarative/qmlscreen.h +++ b/kcm/src/declarative/qmlscreen.h @@ -1,119 +1,122 @@ /* * Copyright (C) 2013 Daniel Vrátil * * 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. * */ #ifndef QMLSCREEN_H #define QMLSCREEN_H #include #include #include "qmloutput.h" class QQmlEngine; namespace KScreen { class Output; class Config; } class QMLScreen : public QQuickItem { Q_OBJECT Q_PROPERTY(QSize maxScreenSize READ maxScreenSize CONSTANT) Q_PROPERTY(int connectedOutputsCount READ connectedOutputsCount NOTIFY connectedOutputsCountChanged) Q_PROPERTY(int enabledOutputsCount READ enabledOutputsCount NOTIFY enabledOutputsCountChanged) Q_PROPERTY(float outputScale READ outputScale NOTIFY outputScaleChanged) Q_PROPERTY(QQmlEngine* engine MEMBER m_engine) public: - explicit QMLScreen(QQuickItem *parent = 0); + explicit QMLScreen(QQuickItem *parent = nullptr); virtual ~QMLScreen(); int connectedOutputsCount() const; int enabledOutputsCount() const; QMLOutput* primaryOutput() const; QList outputs() const; QSize maxScreenSize() const; float outputScale() const; KScreen::ConfigPtr config() const; void setConfig(const KScreen::ConfigPtr &config); void updateOutputsPlacement(); void setEngine(QQmlEngine* engine); void setActiveOutput(QMLOutput *output); public Q_SLOTS: void setActiveOutput() { setActiveOutput(qobject_cast(sender())); } Q_SIGNALS: void connectedOutputsCountChanged(); void enabledOutputsCountChanged(); void outputScaleChanged(); void focusedOutputChanged(QMLOutput *output); private Q_SLOTS: void addOutput(const KScreen::OutputPtr &output); void removeOutput(int outputId); void outputConnectedChanged(); void outputEnabledChanged(); void outputPositionChanged(); void viewSizeChanged(); private: void qmlOutputMoved(QMLOutput *qmlOutput); void updateCornerOutputs(); KScreen::ConfigPtr m_config; QHash m_outputMap; int m_connectedOutputsCount; int m_enabledOutputsCount; - QQmlEngine* m_engine; - QMLOutput *m_leftmost, *m_topmost, *m_rightmost, *m_bottommost; + QQmlEngine* m_engine = nullptr; + QMLOutput *m_leftmost = nullptr; + QMLOutput *m_topmost = nullptr; + QMLOutput *m_rightmost = nullptr; + QMLOutput *m_bottommost = nullptr; }; #endif // QMLSCREEN_H diff --git a/kcm/src/kcm_kscreen.h b/kcm/src/kcm_kscreen.h index 93837c4..fc72ab8 100644 --- a/kcm/src/kcm_kscreen.h +++ b/kcm/src/kcm_kscreen.h @@ -1,57 +1,57 @@ /* Copyright (C) 2012 Dan Vratil This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef KCM_KSCREEN_H #define KCM_KSCREEN_H #include class Widget; class QTimer; class QHBoxLayout; namespace KScreen { class ConfigOperation; } class KCMKScreen : public KCModule { Q_OBJECT public: - explicit KCMKScreen (QWidget* parent = 0, const QVariantList& args = QVariantList()); + explicit KCMKScreen (QWidget* parent = nullptr, const QVariantList& args = QVariantList()); virtual ~KCMKScreen(); virtual QSize sizeHint() const Q_DECL_OVERRIDE; public Q_SLOTS: void load() Q_DECL_OVERRIDE; void save() Q_DECL_OVERRIDE; void defaults() Q_DECL_OVERRIDE; void changed(); private: void configReady(KScreen::ConfigOperation *op); - Widget *mKScreenWidget; + Widget *mKScreenWidget = nullptr; bool m_blockChanges = false; QHBoxLayout *mMainLayout = nullptr; }; #endif // DisplayConfiguration_H diff --git a/kcm/src/outputconfig.h b/kcm/src/outputconfig.h index 08535df..b85dfda 100644 --- a/kcm/src/outputconfig.h +++ b/kcm/src/outputconfig.h @@ -1,76 +1,76 @@ /* * Copyright 2013 Daniel Vrátil * * 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) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * 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 . * */ #ifndef OUTPUTCONFIG_H #define OUTPUTCONFIG_H #include #include #include #include class CollapsableButton; class QCheckBox; class ResolutionSlider; class QLabel; class OutputConfig : public QWidget { Q_OBJECT public: explicit OutputConfig(QWidget *parent); - explicit OutputConfig(const KScreen::OutputPtr &output, QWidget *parent = 0); + explicit OutputConfig(const KScreen::OutputPtr &output, QWidget *parent = nullptr); virtual ~OutputConfig(); virtual void setOutput(const KScreen::OutputPtr &output); KScreen::OutputPtr output() const; void setTitle(const QString &title); void setShowScaleOption(bool showScaleOption); bool showScaleOption() const; protected Q_SLOTS: void slotResolutionChanged(const QSize &size); void slotRotationChanged(int index); void slotRefreshRateChanged(int index); void slotScaleChanged(int index); Q_SIGNALS: void changed(); protected: virtual void initUi(); protected: - QLabel *mTitle; + QLabel *mTitle = nullptr; KScreen::OutputPtr mOutput; - QCheckBox *mEnabled; - ResolutionSlider *mResolution; - QComboBox *mRotation; - QComboBox *mScale; - QComboBox *mRefreshRate; + QCheckBox *mEnabled = nullptr; + ResolutionSlider *mResolution = nullptr; + QComboBox *mRotation = nullptr; + QComboBox *mScale = nullptr; + QComboBox *mRefreshRate = nullptr; bool mShowScaleOption = false; }; #endif // OUTPUTCONFIG_H diff --git a/kcm/src/previewwidget.h b/kcm/src/previewwidget.h index f0c07a8..7b81e9c 100644 --- a/kcm/src/previewwidget.h +++ b/kcm/src/previewwidget.h @@ -1,42 +1,42 @@ /* * Copyright (C) 2015 David Edmundson * * 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) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * 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 . * */ #ifndef PREVIEWWIDGET_H #define PREVIEWWIDGET_H #include class PreviewWidget : public QLabel { Q_OBJECT public: - PreviewWidget(QWidget *parent=0); + explicit PreviewWidget(QWidget *parent=nullptr); ~PreviewWidget(); void setScale(qreal scale); public Q_SLOTS: QPixmap updatePixmapCache(); private: qreal pointSizeToPixelSize(qreal pointSize) const; qreal m_scale; - QWidget *m_internalPreview; + QWidget *m_internalPreview = nullptr; }; #endif // PREVIEWWIDGET_H diff --git a/kcm/src/primaryoutputcombo.h b/kcm/src/primaryoutputcombo.h index 8077534..eb7a223 100644 --- a/kcm/src/primaryoutputcombo.h +++ b/kcm/src/primaryoutputcombo.h @@ -1,58 +1,58 @@ /* * Copyright 2015 Daniel Vrátil * * 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) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * 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 . * */ #ifndef PRIMARYOUTPUTCOMBO_H #define PRIMARYOUTPUTCOMBO_H #include #include class PrimaryOutputCombo : public QComboBox { Q_OBJECT public: - explicit PrimaryOutputCombo(QWidget *parent = 0); + explicit PrimaryOutputCombo(QWidget *parent = nullptr); virtual ~PrimaryOutputCombo(); void setConfig(const KScreen::ConfigPtr &config); KScreen::OutputPtr primaryOutput() const; Q_SIGNALS: void changed(); private Q_SLOTS: void addOutput(const KScreen::OutputPtr &output); void removeOutput(int outputId); void setPrimaryOutput(const KScreen::OutputPtr &output); void outputChanged(const KScreen::OutputPtr &output); void onCurrentIndexChanged(int currentIndex); private: void addOutputItem(const KScreen::OutputPtr &output); void removeOutputItem(int outputId); private: KScreen::ConfigPtr mConfig; }; -#endif \ No newline at end of file +#endif diff --git a/kcm/src/resolutionslider.h b/kcm/src/resolutionslider.h index 0224416..403314d 100644 --- a/kcm/src/resolutionslider.h +++ b/kcm/src/resolutionslider.h @@ -1,63 +1,63 @@ /* * Copyright 2013 Daniel Vrátil * * 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) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * 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 . * */ #ifndef RESOLUTIONSLIDER_H #define RESOLUTIONSLIDER_H #include #include #include class QSlider; class QLabel; class QComboBox; class ResolutionSlider : public QWidget { Q_OBJECT public: - explicit ResolutionSlider(const KScreen::OutputPtr &output, QWidget *parent = 0); + explicit ResolutionSlider(const KScreen::OutputPtr &output, QWidget *parent = nullptr); virtual ~ResolutionSlider(); QSize currentResolution() const; Q_SIGNALS: void resolutionChanged(const QSize &size); private Q_SLOTS: void slotValueChanged(int); void slotOutputModeChanged(); private: KScreen::OutputPtr mOutput; QList mModes; - QLabel *mSmallestLabel; - QLabel *mBiggestLabel; - QLabel *mCurrentLabel; - QSlider *mSlider; - QComboBox *mComboBox; + QLabel *mSmallestLabel = nullptr; + QLabel *mBiggestLabel = nullptr; + QLabel *mCurrentLabel = nullptr; + QSlider *mSlider = nullptr; + QComboBox *mComboBox = nullptr; }; #endif // RESOLUTIONSLIDER_H diff --git a/kcm/src/widget.cpp b/kcm/src/widget.cpp index 248f5bd..b5a8ab1 100644 --- a/kcm/src/widget.cpp +++ b/kcm/src/widget.cpp @@ -1,484 +1,484 @@ /* * Copyright (C) 2013 Daniel Vr??til * * 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 "widget.h" #include "controlpanel.h" #ifdef WITH_PROFILES #include "profilesmodel.h" #endif #include "primaryoutputcombo.h" #include #include #include #include #include #include "declarative/qmloutput.h" #include "declarative/qmlscreen.h" #include "utils.h" #include "scalingconfig.h" #include #include #include #include #include #include #include #include #include #include #include #include #define QML_PATH "kcm_kscreen/qml/" Widget::Widget(QWidget *parent): QWidget(parent), mScreen(nullptr), mConfig(nullptr), mPrevConfig(nullptr) { qRegisterMetaType(); setMinimumHeight(550); QVBoxLayout *layout = new QVBoxLayout(this); QSplitter *splitter = new QSplitter(Qt::Vertical, this); layout->addWidget(splitter); mDeclarativeView = new QQuickView(); QWidget *container = QWidget::createWindowContainer(mDeclarativeView, this); mDeclarativeView->setResizeMode(QQuickView::SizeRootObjectToView); mDeclarativeView->setMinimumHeight(280); container->setMinimumHeight(280); splitter->addWidget(container); QWidget *widget = new QWidget(this); splitter->addWidget(widget); splitter->setStretchFactor(1, 1); widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); QVBoxLayout *vbox = new QVBoxLayout(widget); const int topMargin = style()->pixelMetric(QStyle::PM_LayoutTopMargin, 0, this); vbox->setContentsMargins(0, topMargin, 0, 0); widget->setLayout(vbox); QHBoxLayout *hbox = new QHBoxLayout; vbox->addLayout(hbox); mPrimaryCombo = new PrimaryOutputCombo(this); connect(mPrimaryCombo, &PrimaryOutputCombo::changed, this, &Widget::changed); hbox->addWidget(new QLabel(i18n("Primary display:"))); hbox->addWidget(mPrimaryCombo); hbox->addStretch(); #ifdef WITH_PROFILES mProfilesModel = new ProfilesModel(this); connect(mProfilesModel, &ProfilesModel::modelUpdated()), this, &Widget::slotProfilesUpdated); mProfilesCombo = new QComboBox(this); mProfilesCombo->setModel(mProfilesModel); mProfilesCombo->setSizeAdjustPolicy(QComboBox::AdjustToContents); hbox->addWidget(new QLabel(i18n("Active profile"))); hbox->addWidget(mProfilesCombo); #endif mControlPanel = new ControlPanel(this); connect(mControlPanel, &ControlPanel::changed, this, &Widget::changed); vbox->addWidget(mControlPanel); mUnifyButton = new QPushButton(i18n("Unify Outputs"), this); connect(mUnifyButton, &QPushButton::released, [this]{ slotUnifyOutputs(); }); vbox->addWidget(mUnifyButton); mScaleAllOutputsButton = new QPushButton(i18n("Scale Display"), this); connect(mScaleAllOutputsButton, &QPushButton::released, [this] { QPointer dialog = new ScalingConfig(mConfig->outputs(), this); dialog->exec(); delete dialog; }); vbox->addWidget(mScaleAllOutputsButton); mOutputTimer = new QTimer(this); connect(mOutputTimer, &QTimer::timeout, this, &Widget::clearOutputIdentifiers); loadQml(); } Widget::~Widget() { clearOutputIdentifiers(); } bool Widget::eventFilter(QObject* object, QEvent* event) { if (event->type() == QEvent::Resize) { if (mOutputIdentifiers.contains(qobject_cast(object))) { QResizeEvent *e = static_cast(event); const QRect screenSize = object->property("screenSize").toRect(); QRect geometry(QPoint(0, 0), e->size()); geometry.moveCenter(screenSize.center()); static_cast(object)->setGeometry(geometry); // Pass the event further } } return QObject::eventFilter(object, event); } void Widget::setConfig(const KScreen::ConfigPtr &config) { if (mConfig) { KScreen::ConfigMonitor::instance()->removeConfig(mConfig); for (const KScreen::OutputPtr &output : mConfig->outputs()) { output->disconnect(this); } } mConfig = config; KScreen::ConfigMonitor::instance()->addConfig(mConfig); mScreen->setConfig(mConfig); mControlPanel->setConfig(mConfig); mPrimaryCombo->setConfig(mConfig); mUnifyButton->setEnabled(mConfig->outputs().count() > 1); mScaleAllOutputsButton->setVisible(!mConfig->supportedFeatures().testFlag(KScreen::Config::Feature::PerOutputScaling)); for (const KScreen::OutputPtr &output : mConfig->outputs()) { connect(output.data(), &KScreen::Output::isEnabledChanged, this, &Widget::slotOutputEnabledChanged); connect(output.data(), &KScreen::Output::posChanged, this, &Widget::changed); } // Select the primary (or only) output by default QMLOutput *qmlOutput = mScreen->primaryOutput(); if (qmlOutput) { mScreen->setActiveOutput(qmlOutput); } else { - if (mScreen->outputs().count() > 0) { + if (!mScreen->outputs().isEmpty()) { mScreen->setActiveOutput(mScreen->outputs()[0]); } } slotOutputEnabledChanged(); } KScreen::ConfigPtr Widget::currentConfig() const { return mConfig; } void Widget::loadQml() { qmlRegisterType("org.kde.kscreen", 1, 0, "QMLOutput"); qmlRegisterType("org.kde.kscreen", 1, 0, "QMLScreen"); qmlRegisterType("org.kde.kscreen", 1, 0, "KScreenOutput"); qmlRegisterType("org.kde.kscreen", 1, 0, "KScreenEdid"); qmlRegisterType("org.kde.kscreen", 1, 0, "KScreenMode"); //const QString file = QDir::currentPath() + "/main.qml"; const QString file = QStandardPaths::locate(QStandardPaths::QStandardPaths::GenericDataLocation, QStringLiteral("kcm_kscreen/qml/main.qml")); mDeclarativeView->setSource(QUrl::fromLocalFile(file)); QQuickItem* rootObject = mDeclarativeView->rootObject(); mScreen = rootObject->findChild(QStringLiteral("outputView")); if (!mScreen) { return; } mScreen->setEngine(mDeclarativeView->engine()); connect(mScreen, &QMLScreen::focusedOutputChanged, this, &Widget::slotFocusedOutputChanged); connect(rootObject->findChild(QStringLiteral("identifyButton")), SIGNAL(clicked()), this, SLOT(slotIdentifyButtonClicked())); } void Widget::slotFocusedOutputChanged(QMLOutput *output) { mControlPanel->activateOutput(output->outputPtr()); } void Widget::slotOutputEnabledChanged() { int enabledOutputsCnt = 0; Q_FOREACH (const KScreen::OutputPtr &output, mConfig->outputs()) { if (output->isEnabled()) { ++enabledOutputsCnt; } if (enabledOutputsCnt > 1) { break; } } mUnifyButton->setEnabled(enabledOutputsCnt > 1); } void Widget::slotUnifyOutputs() { QMLOutput *base = mScreen->primaryOutput(); QList clones; if (!base) { Q_FOREACH (QMLOutput *output, mScreen->outputs()) { if (output->output()->isConnected() && output->output()->isEnabled()) { base = output; break; } } if (!base) { // WTF? return; } } if (base->isCloneMode()) { setConfig(mPrevConfig); mPrevConfig.clear(); mPrimaryCombo->setEnabled(true); mUnifyButton->setText(i18n("Unify Outputs")); } else { // Clone the current config, so that we can restore it in case user // breaks the cloning mPrevConfig = mConfig->clone(); Q_FOREACH (QMLOutput *output, mScreen->outputs()) { if (!output->output()->isConnected()) { continue; } if (!output->output()->isEnabled()) { output->setVisible(false); continue; } if (base == 0) { base = output; } output->setOutputX(0); output->setOutputY(0); output->output()->setPos(QPoint(0, 0)); output->output()->setClones(QList()); if (base != output) { clones << output->output()->id(); output->setCloneOf(base); output->setVisible(false); } } base->output()->setClones(clones); base->setIsCloneMode(true); mScreen->updateOutputsPlacement(); mPrimaryCombo->setEnabled(false); mControlPanel->setUnifiedOutput(base->outputPtr()); mUnifyButton->setText(i18n("Break Unified Outputs")); } Q_EMIT changed(); } void Widget::slotProfileChanged(int index) { #ifdef WITH_PROFILES const QVariantMap profile = mProfilesCombo->itemData(index, ProfilesModel::ProfileRole).toMap(); const QVariantList outputs = profile[QLatin1String("outputs")].toList(); // FIXME: Copy-pasted from KDED's Serializer::config() KScreen::Config *config = KScreen::Config::current(); KScreen::OutputList outputList = config->outputs(); Q_FOREACH(KScreen::Output * output, outputList) { if (!output->isConnected() && output->isEnabled()) { output->setEnabled(false); } } KScreen::Config *outputsConfig = config->clone(); Q_FOREACH(const QVariant & info, outputs) { KScreen::Output *output = findOutput(outputsConfig, info.toMap()); if (!output) { continue; } delete outputList.take(output->id()); outputList.insert(output->id(), output); } config->setOutputs(outputList); setConfig(config); #else Q_UNUSED(index) #endif } // FIXME: Copy-pasted from KDED's Serializer::findOutput() KScreen::OutputPtr Widget::findOutput(const KScreen::ConfigPtr &config, const QVariantMap &info) { KScreen::OutputList outputs = config->outputs(); Q_FOREACH(const KScreen::OutputPtr &output, outputs) { if (!output->isConnected()) { continue; } const QString outputId = (output->edid() && output->edid()->isValid()) ? output->edid()->hash() : output->name(); if (outputId != info[QStringLiteral("id")].toString()) { continue; } QVariantMap posInfo = info[QStringLiteral("pos")].toMap(); QPoint point(posInfo[QStringLiteral("x")].toInt(), posInfo[QStringLiteral("y")].toInt()); output->setPos(point); output->setPrimary(info[QStringLiteral("primary")].toBool()); output->setEnabled(info[QStringLiteral("enabled")].toBool()); output->setRotation(static_cast(info[QStringLiteral("rotation")].toInt())); QVariantMap modeInfo = info[QStringLiteral("mode")].toMap(); QVariantMap modeSize = modeInfo[QStringLiteral("size")].toMap(); QSize size(modeSize[QStringLiteral("width")].toInt(), modeSize[QStringLiteral("height")].toInt()); const KScreen::ModeList modes = output->modes(); Q_FOREACH(const KScreen::ModePtr &mode, modes) { if (mode->size() != size) { continue; } if (QString::number(mode->refreshRate()) != modeInfo[QStringLiteral("refresh")].toString()) { continue; } output->setCurrentModeId(mode->id()); break; } return output; } return KScreen::OutputPtr(); } void Widget::slotProfilesAboutToUpdate() { #ifdef WITH_PROFILES disconnect(mProfilesCombo, &QComboBox::currentIndexChanged, this, &Widget::slotProfileChanged); #endif } void Widget::slotProfilesUpdated() { #ifdef WITH_PROFILES connect(mProfilesCombo, &QComboBox::currentIndexChanged, this, &Widget::slotProfileChanged); const int index = mProfilesModel->activeProfileIndex(); mProfilesCombo->setCurrentIndex(index); #endif } void Widget::clearOutputIdentifiers() { mOutputTimer->stop(); qDeleteAll(mOutputIdentifiers); mOutputIdentifiers.clear(); } void Widget::slotIdentifyButtonClicked(bool checked) { Q_UNUSED(checked); connect(new KScreen::GetConfigOperation(), &KScreen::GetConfigOperation::finished, this, &Widget::slotIdentifyOutputs); } void Widget::slotIdentifyOutputs(KScreen::ConfigOperation *op) { if (op->hasError()) { return; } const KScreen::ConfigPtr config = qobject_cast(op)->config(); const QString qmlPath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral(QML_PATH "OutputIdentifier.qml")); mOutputTimer->stop(); clearOutputIdentifiers(); /* Obtain the current active configuration from KScreen */ Q_FOREACH (const KScreen::OutputPtr &output, config->outputs()) { if (!output->isConnected() || !output->currentMode()) { continue; } const KScreen::ModePtr mode = output->currentMode(); QQuickView *view = new QQuickView(); view->setFlags(Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint); view->setResizeMode(QQuickView::SizeViewToRootObject); view->setSource(QUrl::fromLocalFile(qmlPath)); view->installEventFilter(this); QQuickItem *rootObj = view->rootObject(); if (!rootObj) { qWarning() << "Failed to obtain root item"; continue; } QSize realSize; if (output->isHorizontal()) { realSize = mode->size(); } else { realSize = QSize(mode->size().height(), mode->size().width()); } rootObj->setProperty("outputName", Utils::outputName(output)); rootObj->setProperty("modeName", Utils::sizeToString(realSize)); view->setProperty("screenSize", QRect(output->pos(), realSize)); mOutputIdentifiers << view; } Q_FOREACH (QQuickView *view, mOutputIdentifiers) { view->show(); } mOutputTimer->start(2500); } diff --git a/kcm/src/widget.h b/kcm/src/widget.h index 326349a..d95df89 100644 --- a/kcm/src/widget.h +++ b/kcm/src/widget.h @@ -1,103 +1,103 @@ /* * Copyright (C) 2013 Daniel Vrátil * * 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. * */ #ifndef WIDGET_H #define WIDGET_H #include #include #include class ProfilesModel; class QMLOutput; class QMLScreen; class ControlPanel; class PrimaryOutputCombo; class QPushButton; class QComboBox; class QQuickView; namespace KScreen { class ConfigOperation; } class Widget : public QWidget { Q_OBJECT public: - explicit Widget(QWidget *parent = 0); + explicit Widget(QWidget *parent = nullptr); virtual ~Widget(); void setConfig(const KScreen::ConfigPtr &config); KScreen::ConfigPtr currentConfig() const; protected: bool eventFilter(QObject *object, QEvent *event) Q_DECL_OVERRIDE; Q_SIGNALS: void changed(); private Q_SLOTS: void slotFocusedOutputChanged(QMLOutput *output); void slotOutputEnabledChanged(); void slotUnifyOutputs(); void slotProfileChanged(int index); void slotProfilesAboutToUpdate(); void slotProfilesUpdated(); void slotIdentifyButtonClicked(bool checked = true); void slotIdentifyOutputs(KScreen::ConfigOperation *op); void clearOutputIdentifiers(); private: void loadQml(); void initPrimaryCombo(); KScreen::OutputPtr findOutput(const KScreen::ConfigPtr &config, const QVariantMap &info); private: - QMLScreen *mScreen; + QMLScreen *mScreen = nullptr; KScreen::ConfigPtr mConfig; KScreen::ConfigPtr mPrevConfig; - QQuickView *mDeclarativeView; - ControlPanel *mControlPanel; + QQuickView *mDeclarativeView = nullptr; + ControlPanel *mControlPanel = nullptr; - ProfilesModel *mProfilesModel; - PrimaryOutputCombo *mPrimaryCombo; - QComboBox *mProfilesCombo; + ProfilesModel *mProfilesModel = nullptr; + PrimaryOutputCombo *mPrimaryCombo = nullptr; + QComboBox *mProfilesCombo = nullptr; - QPushButton *mScaleAllOutputsButton; - QPushButton *mUnifyButton; - QPushButton *mSaveProfileButton; + QPushButton *mScaleAllOutputsButton = nullptr; + QPushButton *mUnifyButton = nullptr; + QPushButton *mSaveProfileButton = nullptr; QList mOutputIdentifiers; - QTimer *mOutputTimer; + QTimer *mOutputTimer = nullptr; }; #endif // WIDGET_H