on xenial help sign in
Added more screen roles
commit6be92885ae276fa1f368cf6f1f0a4c79de39364c authorNick Dedekind <nick.dedekind@canonical.com> dateFri 13 Jan 2017, 17:06 (10 years ago) parentfc161c2
2 files changed+57−2
tests/mocks/Unity/Screens/screens.cpp+34−1 tests/mocks/Unity/Screens/screens.h+23−1
tests/mocks/Unity/Screens/screens.cpp+34−1
@@ -29,8 +29,16 @@ Screens::Screens(QObject *parent) :
2929 bool ok = false;
3030 int screenCount = qEnvironmentVariableIntValue("UNITY_MOCK_SCREEN_COUNT", &ok);
3131 if (!ok) screenCount = 1;
32+ QPoint lastPoint(0,0);
3233 for (int i = 0; i < screenCount; ++i) {
33− m_screenList.append(new Screen());
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 );
39+ m_screenList.append(screen);
40+
41+ lastPoint.rx() += screen->geometry.width();
3442 }
3543}
3644
@@ -45,6 +53,12 @@ QHash<int, QByteArray> Screens::roleNames() const
4553 QHash<int, QByteArray> roles;
4654 roles[ScreenRole] = "screen";
4755 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";
4862 return roles;
4963}
5064
@@ -59,6 +73,25 @@ QVariant Screens::data(const QModelIndex &index, int role) const
5973 return QVariant::fromValue(m_screenList.at(index.row())->qScreen);
6074 case OutputTypeRole:
6175 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+ }
6295 }
6396
6497 return QVariant();
tests/mocks/Unity/Screens/screens.h+23−1
@@ -26,13 +26,20 @@ class Screens : public QAbstractListModel
2626{
2727 Q_OBJECT
2828 Q_ENUMS(OutputTypes)
29+ Q_ENUMS(FormFactor)
2930
3031 Q_PROPERTY(int count READ count NOTIFY countChanged)
3132
3233public:
3334 enum ItemRoles {
3435 ScreenRole = Qt::UserRole + 1,
35− OutputTypeRole
36+ OutputTypeRole,
37+ EnabledRole,
38+ NameRole,
39+ ScaleRole,
40+ FormFactorRole,
41+ GeometryRole,
42+ SizesRole
3643 };
3744
3845 enum OutputTypes {
@@ -53,6 +60,15 @@ public:
5360 EDP
5461 };
5562
63+ enum FormFactor {
64+ FormFactorUnknown,
65+ FormFactorPhone,
66+ FormFactorTablet,
67+ FormFactorMonitor,
68+ FormFactorTV,
69+ FormFactorProjector,
70+ };
71+
5672 explicit Screens(QObject *parent = 0);
5773 virtual ~Screens() noexcept;
5874
@@ -77,6 +93,12 @@ class Screen
7793public:
7894 Screens::OutputTypes outputTypes = Screens::Unknown;
7995 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;
80102};
81103
82104#endif // SCREENS_H