1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-07 03:22:33 +01:00

Big cleanup. Now we have a list of monitors in qml

This commit is contained in:
kelteseth 2017-04-28 14:43:43 +02:00
parent 6c1e3f62fb
commit a3615a0974
8 changed files with 226 additions and 94 deletions

View File

@ -17,39 +17,40 @@
#include "backend.h"
#include "installedlistmodel.h"
#include "monitors.h"
#include "monitorlistmodel.h"
#include "screenplay.h"
int main(int argc, char* argv[])
{
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QCoreApplication::setOrganizationName("Aimber");
QCoreApplication::setOrganizationDomain("aimber.net");
QCoreApplication::setApplicationName("ScreenPlay");
app.setWindowIcon(QIcon(":/assets/icons/favicon.ico"));
InstalledListModel ilm;
InstalledListModel installedListModel;
MonitorListModel monitorListModel;
Backend backend;
Monitors monitors;
QQmlApplicationEngine mainWindow;
mainWindow.rootContext()->setContextProperty("monitorList", &monitors);
mainWindow.rootContext()->setContextProperty("installedListModel", &ilm);
mainWindow.rootContext()->setContextProperty("monitorListModel", &monitorListModel);
mainWindow.rootContext()->setContextProperty("installedListModel", &installedListModel);
mainWindow.rootContext()->setContextProperty("backend", &backend);
mainWindow.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
QObject::connect(&mainWindow, SIGNAL(exitScreenPlay()), &app, SLOT(app.exit()));
ScreenPlay sp(GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
sp.context()->setContextProperty("installedListModel", &ilm);
sp.context()->setContextProperty("installedListModel", &installedListModel);
sp.context()->setContextProperty("backend", &backend);
sp.loadQQuickView(QUrl(QStringLiteral("qrc:/qml/Components/ScreenPlay.qml")));
sp.showQQuickView(GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
QObject::connect(&ilm, &InstalledListModel::setScreenVisible,
QObject::connect(&installedListModel, &InstalledListModel::setScreenVisible,
&sp, &ScreenPlay::setVisible);
int status = app.exec();

View File

@ -24,8 +24,10 @@ Page {
delegate: ScreenPlayItem {
id:delegate
focus: true
customTitle: title
customTitle: screenTitle
screenId: screenFolderId
Connections {
target: delegate
onItemClicked: {

View File

@ -9,8 +9,6 @@ Item {
Component.onCompleted: {
var a = monitorList.get();
print(a[0]);
}
@ -52,6 +50,36 @@ Item {
anchors.leftMargin: 20
anchors.top: parent.top
anchors.topMargin: 20
Row {
Repeater {
id:rp
anchors.fill: parent
model:monitorListModel
delegate: Item {
height: 200
width: 200
Column {
spacing: 5
Text {
text: monitorNumber
anchors.horizontalCenter: parent.horizontalCenter
}
Text {
text: monitorAvailableGeometryRole.x + " " + monitorAvailableGeometryRole.y
anchors.horizontalCenter: parent.horizontalCenter
}
}
}
}
}
}
}
}

View File

@ -29,7 +29,7 @@ public:
QVariant data(const QModelIndex& index,
int role = Qt::DisplayRole) const override;
void append(const QJsonObject, const QString);
QHash<int, QByteArray> roleNames() const;
QHash<int, QByteArray> roleNames() const override;
Q_INVOKABLE void loadScreens();
Q_INVOKABLE QVariantMap get(QString folderId);

113
src/monitorlistmodel.cpp Normal file
View File

@ -0,0 +1,113 @@
#include "monitorlistmodel.h"
MonitorListModel::MonitorListModel(QObject *parent)
: QAbstractListModel(parent)
{
for (int i = 0; i < QApplication::screens().count(); i++) {
QScreen* screen = QApplication::screens().at(i);
_monitorList.append(Monitor(screen->name(),screen->size(),screen->availableGeometry(),i));
}
}
QHash<int, QByteArray> MonitorListModel::roleNames() const
{
static const QHash<int, QByteArray> roles{
{ NameRole, "monitorName" },
{ SizeRole, "monitorSize" },
{ AvailableGeometryRole, "monitorAvailableGeometryRole" },
{ NumberRole, "monitorNumber" },
};
return roles;
}
QVariant MonitorListModel::headerData(int section, Qt::Orientation orientation, int role) const
{
// FIXME: Implement me!
}
bool MonitorListModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)
{
if (value != headerData(section, orientation, role)) {
// FIXME: Implement me!
emit headerDataChanged(orientation, section, section);
return true;
}
return false;
}
int MonitorListModel::rowCount(const QModelIndex &parent) const
{
// For list models only the root node (an invalid parent) should return the list's size. For all
// other (valid) parents, rowCount() should return 0 so that it does not become a tree model.
if (parent.isValid())
return 0;
return _monitorList.count();
}
QVariant MonitorListModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (index.row() < rowCount())
switch (role) {
case NameRole:
return _monitorList.at(index.row())._name;
case SizeRole:
return _monitorList.at(index.row())._size;
case AvailableGeometryRole:
return _monitorList.at(index.row())._availableGeometry;
case NumberRole:
return _monitorList.at(index.row())._number;
default:
return QVariant();
}
return QVariant();
}
bool MonitorListModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (data(index, role) != value) {
// FIXME: Implement me!
emit dataChanged(index, index, QVector<int>() << role);
return true;
}
return false;
}
Qt::ItemFlags MonitorListModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return Qt::NoItemFlags;
return Qt::ItemIsEditable; // FIXME: Implement me!
}
bool MonitorListModel::insertRows(int row, int count, const QModelIndex &parent)
{
beginInsertRows(parent, row, row + count - 1);
// FIXME: Implement me!
endInsertRows();
}
bool MonitorListModel::removeRows(int row, int count, const QModelIndex &parent)
{
beginRemoveRows(parent, row, row + count - 1);
// FIXME: Implement me!
endRemoveRows();
}
Monitor::Monitor()
{
}
Monitor::Monitor(QString name, QSize size, QRect availableGeometry, int number)
{
_name = name;
_size = size;
_availableGeometry = availableGeometry;
_number = number;
}

70
src/monitorlistmodel.h Normal file
View File

@ -0,0 +1,70 @@
#ifndef MONITORLISTMODEL_H
#define MONITORLISTMODEL_H
#include <QAbstractListModel>
#include <QSize>
#include <QRect>
#include <QString>
#include <QVector>
#include <QScreen>
#include <QDebug>
#include <QApplication>
class Monitor;
class MonitorListModel : public QAbstractListModel
{
Q_OBJECT
public:
explicit MonitorListModel(QObject *parent = nullptr);
QHash<int, QByteArray> roleNames() const override;
enum MonitorRole {
NameRole,
SizeRole,
AvailableGeometryRole,
NumberRole,
};
Q_ENUM(MonitorRole)
// Header:
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override;
// Basic functionality:
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
// Editable:
bool setData(const QModelIndex &index, const QVariant &value,
int role = Qt::EditRole) override;
Qt::ItemFlags flags(const QModelIndex& index) const override;
// Add data:
bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
// Remove data:
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
private:
QVector<Monitor> _monitorList;
};
class Monitor {
public:
Monitor();
Monitor(QString name, QSize size, QRect availableGeometry, int number);
QString _name;
QSize _size;
QRect _availableGeometry;
int _number;
bool _isVirtualDesktop;
};
#endif // MONITORLISTMODEL_H

View File

@ -1,34 +0,0 @@
#include "monitors.h"
Monitors::Monitors(QObject* parent)
: QObject(parent)
{
loadScreens();
}
void Monitors::loadScreens()
{
for (int i = 0; i < QApplication::screens().count(); i++) {
QScreen* screen = QApplication::screens().at(i);
qDebug() << screen->geometry();
_screen.append(QApplication::screens().at(i));
_monitors.append(Monitor(screen->name(), screen->size(), screen->availableGeometry(), i, false));
}
}
QVariantList Monitors::get()
{
QVariantList list;
return list;
}
Monitor::Monitor(QString name, QSize size, QRect availableGeometry, int number, bool isVirtualDesktop)
{
_name = name;
_size = size;
_availableGeometry = availableGeometry;
_number = number;
_isVirtualDesktop = isVirtualDesktop;
}

View File

@ -1,48 +0,0 @@
#ifndef MONITORS_H
#define MONITORS_H
#include <QApplication>
#include <QDebug>
#include <QList>
#include <QObject>
#include <QRect>
#include <QScreen>
#include <QSize>
#include <QVariantList>
class Monitor;
class Monitors : public QObject {
Q_OBJECT
public:
explicit Monitors(QObject* parent = nullptr);
Q_INVOKABLE void loadScreens();
Q_INVOKABLE QVariantList get();
signals:
public slots:
private:
QList<Monitor> _monitors;
QList<QScreen *> _screen;
int primaryScreen;
};
class Monitor {
public:
Monitor(QString name, QSize size, QRect availableGeometry, int number, bool isVirtualDesktop);
QString _name;
QSize _size;
QRect _availableGeometry;
int _number;
bool _isVirtualDesktop;
QScreen* _screen = nullptr;
};
#endif // MONITORS_H