on xenial help sign in
Added more screen roles
6be9288Nick Dedekind
tests/mocks/Unity/Screens/screens.cpp+34−1
@@ -29,8 +29,16 @@ Screens::Screens(QObject *parent) :
29 bool ok = false;
29 bool ok = false;
30 int screenCount = qEnvironmentVariableIntValue("UNITY_MOCK_SCREEN_COUNT", &ok);
30 int screenCount = qEnvironmentVariableIntValue("UNITY_MOCK_SCREEN_COUNT", &ok);
31 if (!ok) screenCount = 1;
31 if (!ok) screenCount = 1;
32+ QPoint lastPoint(0,0);
32 for (int i = 0; i < screenCount; ++i) {
33 for (int i = 0; i < screenCount; ++i) {
34+ auto screen = new Screen();
35+ screen->enabled = i == 0;
36+ screen->name = QString("Monitor %1").arg(i);
37+ screen->sizes = { QSize(640,480), QSize(1024,748), QSize(1280,1024), QSize(1440,900), QSize(1920,1080) };
38+ screen->geometry = QRect(lastPoint.x(), lastPoint.y(), 1024, 786 );
33− m_screenList.append(new Screen());
39+ m_screenList.append(screen);
40+
41+ lastPoint.rx() += screen->geometry.width();
34 }
42 }
35}
43}
36
44
@@ -45,6 +53,12 @@ QHash<int, QByteArray> Screens::roleNames() const
45 QHash<int, QByteArray> roles;
53 QHash<int, QByteArray> roles;
46 roles[ScreenRole] = "screen";
54 roles[ScreenRole] = "screen";
47 roles[OutputTypeRole] = "outputType";
55 roles[OutputTypeRole] = "outputType";
56+ roles[EnabledRole] = "enabled";
57+ roles[NameRole] = "name";
58+ roles[ScaleRole] = "scale";
59+ roles[FormFactorRole] = "formFactor";
60+ roles[GeometryRole] = "geometry";
61+ roles[SizesRole] = "sizes";
48 return roles;
62 return roles;
49}
63}
50
64
@@ -59,6 +73,25 @@ QVariant Screens::data(const QModelIndex &index, int role) const
59 return QVariant::fromValue(m_screenList.at(index.row())->qScreen);
73 return QVariant::fromValue(m_screenList.at(index.row())->qScreen);
60 case OutputTypeRole:
74 case OutputTypeRole:
61 return m_screenList.at(index.row())->outputTypes;
75 return m_screenList.at(index.row())->outputTypes;
76+ case EnabledRole:
77+ return m_screenList.at(index.row())->enabled;
78+ case NameRole:
79+ return m_screenList.at(index.row())->name;
80+ case ScaleRole:
81+ return m_screenList.at(index.row())->scale;
82+ case FormFactorRole:
83+ return m_screenList.at(index.row())->formFactor;
84+ case GeometryRole:
85+ return m_screenList.at(index.row())->geometry;
86+ case SizesRole:
87+ {
88+ QVariantList sizes;
89+ auto availableSizes = m_screenList.at(index.row())->sizes;
90+ Q_FOREACH(auto size, availableSizes) {
91+ sizes.append(QVariant(size));
92+ }
93+ return sizes;
94+ }
62 }
95 }
63
96
64 return QVariant();
97 return QVariant();
tests/mocks/Unity/Screens/screens.h+23−1
@@ -26,13 +26,20 @@ class Screens : public QAbstractListModel
26{
26{
27 Q_OBJECT
27 Q_OBJECT
28 Q_ENUMS(OutputTypes)
28 Q_ENUMS(OutputTypes)
29+ Q_ENUMS(FormFactor)
29
30
30 Q_PROPERTY(int count READ count NOTIFY countChanged)
31 Q_PROPERTY(int count READ count NOTIFY countChanged)
31
32
32public:
33public:
33 enum ItemRoles {
34 enum ItemRoles {
34 ScreenRole = Qt::UserRole + 1,
35 ScreenRole = Qt::UserRole + 1,
35− OutputTypeRole
36+ OutputTypeRole,
37+ EnabledRole,
38+ NameRole,
39+ ScaleRole,
40+ FormFactorRole,
41+ GeometryRole,
42+ SizesRole
36 };
43 };
37
44
38 enum OutputTypes {
45 enum OutputTypes {
@@ -53,6 +60,15 @@ public:
53 EDP
60 EDP
54 };
61 };
55
62
63+ enum FormFactor {
64+ FormFactorUnknown,
65+ FormFactorPhone,
66+ FormFactorTablet,
67+ FormFactorMonitor,
68+ FormFactorTV,
69+ FormFactorProjector,
70+ };
71+
56 explicit Screens(QObject *parent = 0);
72 explicit Screens(QObject *parent = 0);
57 virtual ~Screens() noexcept;
73 virtual ~Screens() noexcept;
58
74
@@ -77,6 +93,12 @@ class Screen
77public:
93public:
78 Screens::OutputTypes outputTypes = Screens::Unknown;
94 Screens::OutputTypes outputTypes = Screens::Unknown;
79 QScreen *qScreen = nullptr;
95 QScreen *qScreen = nullptr;
96+ bool enabled = false;
97+ QString name = QString();
98+ float scale = 1.0;
99+ Screens::FormFactor formFactor = Screens::FormFactorMonitor;
100+ QRect geometry;
101+ QList<QSize> sizes;
80};
102};
81
103
82#endif // SCREENS_H
104#endif // SCREENS_H