mirror of
https://github.com/tnodir/fort
synced 2024-11-15 10:35:10 +00:00
TrayIcon: Simplify onTrayActivated()
This commit is contained in:
parent
ea94865f62
commit
fc51a44eb0
@ -196,44 +196,20 @@ WindowManager *TrayIcon::windowManager() const
|
|||||||
return ctrl()->windowManager();
|
return ctrl()->windowManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrayIcon::onMouseClicked(TrayIcon::ClickType clickType)
|
|
||||||
{
|
|
||||||
QAction *action = clickAction(clickType);
|
|
||||||
if (action) {
|
|
||||||
action->trigger();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TrayIcon::onTrayActivated(QSystemTrayIcon::ActivationReason reason)
|
void TrayIcon::onTrayActivated(QSystemTrayIcon::ActivationReason reason)
|
||||||
{
|
{
|
||||||
switch (reason) {
|
switch (reason) {
|
||||||
case QSystemTrayIcon::Trigger: {
|
case QSystemTrayIcon::Trigger: {
|
||||||
if (clickAction(DoubleClick)) {
|
onTrayActivatedByTrigger();
|
||||||
m_trayTriggered = true;
|
|
||||||
QTimer::singleShot(QApplication::doubleClickInterval(), this, [&] {
|
|
||||||
if (m_trayTriggered) {
|
|
||||||
m_trayTriggered = false;
|
|
||||||
onMouseClicked(SingleClick);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
m_trayTriggered = false;
|
|
||||||
onMouseClicked(SingleClick);
|
|
||||||
}
|
|
||||||
} break;
|
} break;
|
||||||
case QSystemTrayIcon::DoubleClick: {
|
case QSystemTrayIcon::DoubleClick: {
|
||||||
if (m_trayTriggered) {
|
onTrayActivatedByDoubleClick();
|
||||||
m_trayTriggered = false;
|
|
||||||
onMouseClicked(DoubleClick);
|
|
||||||
}
|
|
||||||
} break;
|
} break;
|
||||||
case QSystemTrayIcon::MiddleClick: {
|
case QSystemTrayIcon::MiddleClick: {
|
||||||
m_trayTriggered = false;
|
onTrayActivatedByMiddleClick();
|
||||||
onMouseClicked(MiddleClick);
|
|
||||||
} break;
|
} break;
|
||||||
case QSystemTrayIcon::Context: {
|
case QSystemTrayIcon::Context: {
|
||||||
m_trayTriggered = false;
|
onTrayActivatedByContext();
|
||||||
onMouseClicked(RightClick);
|
|
||||||
} break;
|
} break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -626,3 +602,47 @@ QAction *TrayIcon::clickActionByType(ActionType actionType) const
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TrayIcon::onMouseClicked(TrayIcon::ClickType clickType)
|
||||||
|
{
|
||||||
|
QAction *action = clickAction(clickType);
|
||||||
|
if (action) {
|
||||||
|
action->trigger();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TrayIcon::onTrayActivatedByTrigger()
|
||||||
|
{
|
||||||
|
if (clickAction(DoubleClick)) {
|
||||||
|
m_trayTriggered = true;
|
||||||
|
QTimer::singleShot(QApplication::doubleClickInterval(), this, [&] {
|
||||||
|
if (m_trayTriggered) {
|
||||||
|
m_trayTriggered = false;
|
||||||
|
onMouseClicked(SingleClick);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
m_trayTriggered = false;
|
||||||
|
onMouseClicked(SingleClick);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TrayIcon::onTrayActivatedByDoubleClick()
|
||||||
|
{
|
||||||
|
if (m_trayTriggered) {
|
||||||
|
m_trayTriggered = false;
|
||||||
|
onMouseClicked(DoubleClick);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TrayIcon::onTrayActivatedByMiddleClick()
|
||||||
|
{
|
||||||
|
m_trayTriggered = false;
|
||||||
|
onMouseClicked(MiddleClick);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TrayIcon::onTrayActivatedByContext()
|
||||||
|
{
|
||||||
|
m_trayTriggered = false;
|
||||||
|
onMouseClicked(RightClick);
|
||||||
|
}
|
||||||
|
@ -65,7 +65,6 @@ public slots:
|
|||||||
protected slots:
|
protected slots:
|
||||||
void switchTrayMenu(bool checked);
|
void switchTrayMenu(bool checked);
|
||||||
|
|
||||||
void onMouseClicked(TrayIcon::ClickType clickType);
|
|
||||||
void onTrayActivated(QSystemTrayIcon::ActivationReason reason);
|
void onTrayActivated(QSystemTrayIcon::ActivationReason reason);
|
||||||
|
|
||||||
void saveTrayFlags();
|
void saveTrayFlags();
|
||||||
@ -97,6 +96,12 @@ private:
|
|||||||
QAction *clickActionFromIni(ClickType clickType) const;
|
QAction *clickActionFromIni(ClickType clickType) const;
|
||||||
QAction *clickActionByType(ActionType actionType) const;
|
QAction *clickActionByType(ActionType actionType) const;
|
||||||
|
|
||||||
|
void onMouseClicked(TrayIcon::ClickType clickType);
|
||||||
|
void onTrayActivatedByTrigger();
|
||||||
|
void onTrayActivatedByDoubleClick();
|
||||||
|
void onTrayActivatedByMiddleClick();
|
||||||
|
void onTrayActivatedByContext();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_trayTriggered : 1;
|
bool m_trayTriggered : 1;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user