Screen: Support settings

pull/2/head
cutefishd 5 years ago
parent 1516be627a
commit b50ce88c28

@ -14,7 +14,9 @@ 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/>.
*********************************************************************/
#pragma once
#ifndef CONFIGHANDLER_H
#define CONFIGHANDLER_H
#include "./common/control.h"
@ -27,6 +29,7 @@ class OutputModel;
class ConfigHandler : public QObject
{
Q_OBJECT
public:
explicit ConfigHandler (QObject *parent = nullptr);
~ConfigHandler() override = default;
@ -93,3 +96,5 @@ private:
Undefined;
QSize m_lastNormalizedScreenSize;
};
#endif

@ -14,6 +14,7 @@ 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/>.
*********************************************************************/
#include "outputmodel.h"
#include "./common/utils.h"
@ -173,7 +174,8 @@ bool OutputModel::setData(const QModelIndex &index,
return false;
}
QHash<int, QByteArray> OutputModel::roleNames() const {
QHash<int, QByteArray> OutputModel::roleNames() const
{
QHash<int, QByteArray> roles = QAbstractItemModel::roleNames();
roles[EnabledRole] = "enabled";
roles[InternalRole] = "internal";
@ -483,6 +485,7 @@ static int greatestCommonDivisor(int a, int b) {
QVariantList OutputModel::resolutionsStrings(const KScreen::OutputPtr &output) const
{
QVariantList ret;
for (const QSize &size : resolutions(output)) {
int divisor = greatestCommonDivisor(size.width(), size.height());
@ -491,17 +494,12 @@ QVariantList OutputModel::resolutionsStrings(const KScreen::OutputPtr &output) c
divisor /= 2;
}
const QString text;
// const QString text = i18nc("Width x height (aspect ratio)", "%1x%2 (%3:%4)",
// // Explicitly not have it add thousand-separators.
// QString::number(size.width()),
// QString::number(size.height()),
// size.width() / divisor,
// size.height() / divisor);
const QString text = QString("%1x%2").arg(QString::number(size.width()))
.arg(QString::number(size.height()));
ret << text;
}
return ret;
}

@ -14,7 +14,9 @@ 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/>.
*********************************************************************/
#pragma once
#ifndef OUTPUTMODEL_H
#define OUTPUTMODEL_H
#include <kscreen/config.h>
#include <kscreen/output.h>
@ -148,3 +150,5 @@ private:
ConfigHandler *m_config;
};
#endif

@ -11,7 +11,7 @@ class QmlPlugins : public QQmlExtensionPlugin
public:
void registerTypes(const char * uri) override {
// qmlRegisterType<OutputModel>(uri, 1, 0, "Screen");
// qmlRegisterType<OutputModel>(uri, 1, 0, "OutputModel");
qmlRegisterType<Screen>(uri, 1, 0, "Screen");
qmlRegisterType<KScreen::Output>(uri, 1, 0, "Output");
}

@ -1,6 +1,8 @@
#include "screen.h"
#include "outputmodel.h"
#include <kscreen/setconfigoperation.h>
#include <QQmlExtensionPlugin>
#include <QQmlEngine>
@ -29,6 +31,22 @@ void Screen::load()
connect(new KScreen::GetConfigOperation(), &KScreen::GetConfigOperation::finished, this, &Screen::configReady);
}
void Screen::save()
{
auto config = m_config->config();
bool atLeastOneEnabledOutput = false;
for (const KScreen::OutputPtr &output : config->outputs()) {
KScreen::ModePtr mode = output->currentMode();
atLeastOneEnabledOutput |= output->isEnabled();
}
m_config->writeControl();
auto *op = new KScreen::SetConfigOperation(config);
op->exec();
}
OutputModel *Screen::outputModel() const
{
if (!m_config) {

@ -20,6 +20,7 @@ public:
OutputModel *outputModel() const;
void load();
Q_INVOKABLE void save();
private:
void configReady(KScreen::ConfigOperation *op);

Loading…
Cancel
Save