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,19 +63,38 @@ OrientationSensor::OrientationSensor(QObject *parent)
} }
} }
); );
connect(m_sensor, &QOrientationSensor::activeChanged, this, connect(m_sensor, &QOrientationSensor::activeChanged, this, &OrientationSensor::refresh);
[this] { }
void OrientationSensor::refresh()
{
if (!m_sni) { if (!m_sni) {
return; return;
} }
if (m_sensor->isActive()) { if (m_sensor->isActive()) {
m_sni->setTitle(i18n("Allow Rotation"));
m_sni->setToolTipTitle(i18n("Automatic screen rotation is enabled")); m_sni->setToolTipTitle(i18n("Automatic screen rotation is enabled"));
} else { } 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")); m_sni->setToolTipTitle(i18n("Automatic screen rotation is disabled"));
} }
} }
);
}
OrientationSensor::~OrientationSensor() = default; OrientationSensor::~OrientationSensor() = default;
@ -115,11 +134,11 @@ void OrientationSensor::setupStatusNotifier()
m_sni->setStandardActionsEnabled(false); m_sni->setStandardActionsEnabled(false);
m_sni->setCategory(KStatusNotifierItem::Hardware); m_sni->setCategory(KStatusNotifierItem::Hardware);
m_sni->setStatus(KStatusNotifierItem::Passive); m_sni->setStatus(KStatusNotifierItem::Passive);
m_sni->setTitle(i18n("Automatic Screen Rotation"));
// TODO: proper icon with state // TODO: proper icon with state
m_sni->setIconByName(QStringLiteral("preferences-desktop-display")); m_sni->setIconByName(QStringLiteral("preferences-desktop-display"));
// we start disabled, it gets updated when the sensor becomes active // 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, connect(m_sni, &KStatusNotifierItem::activateRequested, this,
[this] { [this] {
m_userEnabled = !m_userEnabled; m_userEnabled = !m_userEnabled;

View file

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