Improve SNI text

Summary:
Allow the user to see if rotation lock is enabled by reading the text.
Alternatively one has to hover it and wait for the tooltip.

Reviewers: #plasma, #kwin, ngraham

Reviewed By: ngraham

Subscribers: ngraham, arvidhansson, bruns, niccolove, ndavis, zzag, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D19690
This commit is contained in:
Aleix Pol 2019-03-19 18:29:26 +01:00
parent 9e42ff2f48
commit c192d35192
2 changed files with 35 additions and 13 deletions

View file

@ -63,18 +63,37 @@ OrientationSensor::OrientationSensor(QObject *parent)
}
}
);
connect(m_sensor, &QOrientationSensor::activeChanged, this,
[this] {
if (!m_sni) {
return;
}
if (m_sensor->isActive()) {
m_sni->setToolTipTitle(i18n("Automatic screen rotation is enabled"));
} else {
m_sni->setToolTipTitle(i18n("Automatic screen rotation is disabled"));
}
connect(m_sensor, &QOrientationSensor::activeChanged, this, &OrientationSensor::refresh);
}
void OrientationSensor::refresh()
{
if (!m_sni) {
return;
}
if (m_sensor->isActive()) {
m_sni->setTitle(i18n("Allow Rotation"));
m_sni->setToolTipTitle(i18n("Automatic screen rotation is enabled"));
} else {
QString text;
switch(m_orientation) {
case FaceUp:
case FaceDown:
case Undefined:
text = i18n("Undefined");
break;
case TopUp:
case TopDown:
text = i18n("Vertical");
break;
case LeftUp:
case RightUp:
text = i18n("Horizontal");
break;
}
);
m_sni->setTitle(text);
m_sni->setToolTipTitle(i18n("Automatic screen rotation is disabled"));
}
}
OrientationSensor::~OrientationSensor() = default;
@ -115,11 +134,11 @@ void OrientationSensor::setupStatusNotifier()
m_sni->setStandardActionsEnabled(false);
m_sni->setCategory(KStatusNotifierItem::Hardware);
m_sni->setStatus(KStatusNotifierItem::Passive);
m_sni->setTitle(i18n("Automatic Screen Rotation"));
// TODO: proper icon with state
m_sni->setIconByName(QStringLiteral("preferences-desktop-display"));
// we start disabled, it gets updated when the sensor becomes active
m_sni->setToolTipTitle(i18n("Automatic screen rotation is disabled"));
refresh();
connect(m_sni, &KStatusNotifierItem::activateRequested, this,
[this] {
m_userEnabled = !m_userEnabled;

View file

@ -56,6 +56,7 @@ public:
FaceUp,
FaceDown
};
Q_ENUM(Orientation)
Orientation orientation() const {
return m_orientation;
@ -78,6 +79,8 @@ private:
void setupStatusNotifier();
void startStopSensor();
void loadConfig();
void refresh();
QOrientationSensor *m_sensor;
bool m_enabled = false;
bool m_userEnabled = true;