Skip to content

Commit d20c473

Browse files
committed
System Tray icon Created and App Icon Created
1 parent 657d4ff commit d20c473

13 files changed

+993
-750
lines changed

Diff for: GameScreens/HomeScreen.qml

+735-734
Large diffs are not rendered by default.

Diff for: Img/Basic/pngwing.com.png

176 KB
Loading

Diff for: Settings/AboutPage.qml

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ ScreenPage{
129129
buttonText: "Check For Updated";
130130
innerText.color: "#0570eb"
131131
color: "transparent"
132-
hoverColor: "#0570eb"
133-
pressColor: "#0570eb"
132+
hoverColor: "transparent"
133+
pressColor: "transparent"
134134
borderColor: "#0570eb"
135135
fontSize: 12
136136
borderWidth: 1

Diff for: Settings/AdvancedSettingsPage.qml

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ ScreenPage{
7474
buttonText: "Send Diagnostics";
7575
innerText.color: "#0570eb"
7676
color: "transparent"
77-
hoverColor: "#0570eb"
78-
pressColor: "#0570eb"
77+
hoverColor: "transparent"
78+
pressColor: "transparent"
7979
borderColor:"#0570eb"
8080
fontSize: 12
8181
borderWidth: 1

Diff for: Settings/AppearanceSettingsPage.qml

+8
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ ScreenPage{
5757
}
5858

5959
// Iterface increase
60+
PrefsSpinBox {
61+
id: spinBox
62+
width: 100
63+
height: 30
64+
minimumValue: 0
65+
maximumValue: 100
66+
}
67+
6068

6169
Label {
6270
opacity: 0.87

Diff for: common/PrefsButton.qml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Item {
1717
property color borderColor: "white"
1818
property string sourceIcon: ""
1919
property int fontSize: 16
20-
property int borderWidth: 1
20+
property real borderWidth: 1
2121
property int borderRadius: 2
2222
property int iconWidth: 20
2323
property int iconHeight: 20

Diff for: common/PrefsSpinBox.qml

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import QtQuick 2.15
2+
import QtQuick.Controls 2.15
3+
import QtQuick.Layouts 1.3
4+
Item {
5+
property int value: 100
6+
property int minimumValue: 75
7+
property int maximumValue: 175
8+
9+
width: 100
10+
height: 55
11+
12+
Rectangle {
13+
id: background
14+
color: "transparent"
15+
anchors.fill: parent
16+
}
17+
18+
RowLayout {
19+
id: row
20+
spacing: 0
21+
width: parent.width
22+
height: parent.height
23+
24+
PrefsButton{
25+
width: parent.height
26+
height: parent.height
27+
buttonText: "-"
28+
innerText.color: "black"
29+
color: "#dde4de"
30+
hoverColor: "#dde4de"
31+
pressColor: "#dde4de"
32+
borderColor: "grey"
33+
fontSize: 12
34+
borderWidth: 0.6
35+
borderRadius: 8
36+
onClicked: {
37+
if (value > minimumValue) {
38+
value = value - 25
39+
}
40+
}
41+
}
42+
43+
Rectangle{
44+
width: parent.width * 0.8
45+
height: parent.height
46+
radius: 12
47+
color: "transparent"
48+
Label {
49+
id: valueText
50+
text: value.toString() + "%"
51+
font.pointSize: 14
52+
anchors.centerIn: parent
53+
}
54+
}
55+
56+
PrefsButton{
57+
width: parent.height
58+
height: parent.height
59+
buttonText: "+";
60+
innerText.color: "black"
61+
color: "#dde4de"
62+
hoverColor: "#dde4de"
63+
pressColor: "#dde4de"
64+
borderColor: "grey"
65+
fontSize: 12
66+
borderWidth: 0.6
67+
borderRadius: 8
68+
onClicked: {
69+
if (value < maximumValue) {
70+
value = value + 25
71+
}
72+
}
73+
}
74+
}
75+
}

Diff for: main.cpp

+22-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
#include <QGuiApplication>
1+
#include <QScreen>
2+
#include <QApplication>
23
#include <QQmlApplicationEngine>
3-
#include <QDebug>
44
#include <QQmlContext>
5+
#include <QSystemTrayIcon>
6+
#include <QtQml/QQmlContext>
7+
#include<QIcon>
8+
#include <QDebug>
59
#include <QtCore/QUrl>
610
#include <QtCore/QCommandLineOption>
711
#include <QtCore/QCommandLineParser>
812
#include <QStyleHints>
9-
#include <QScreen>
10-
#include <QtQml/QQmlContext>
11-
#include<QIcon>
13+
14+
#include <systemtray.h>
15+
1216
class Utils : public QObject {
1317
Q_OBJECT
1418
public:
@@ -20,16 +24,25 @@ class Utils : public QObject {
2024
int main(int argc, char *argv[])
2125
{
2226
//! [0]
23-
QGuiApplication app(argc, argv);
24-
app.setWindowIcon(QIcon("qrc:/Img/Icons/hire-a-helper.svg"));
27+
QApplication app(argc, argv);
28+
29+
QQmlApplicationEngine engine;
30+
app.setOrganizationName("Aksh Software Solution");
31+
app.setOrganizationName("akshsoftsolution.com");
32+
app.setApplicationDisplayName("Aksh Software");
33+
app.setApplicationName("Aksh Software");
34+
app.setWindowIcon(QIcon(":/Img/Basic/pngwing.com.png"));
2535
//! [0]
26-
QGuiApplication::setApplicationDisplayName(QCoreApplication::translate("main","Game Example"));
2736
ApplicationUI appui;
2837
QCommandLineParser parser;
2938
QCoreApplication::setApplicationVersion(QT_VERSION_STR);
3039

31-
QQmlApplicationEngine engine;
40+
41+
3242
QQmlContext *context = engine.rootContext();
43+
SystemTray * systemTray = new SystemTray();
44+
45+
context->setContextProperty("systemTray", systemTray);
3346
context->setContextProperty("myApp", &appui);
3447

3548
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

Diff for: main.qml

+40
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,47 @@ ApplicationWindow {
119119
property bool showFavorites: true
120120
property bool highlightActiveNavigationButton : true
121121

122+
// Chance to ignore the checkbox
123+
property bool ignoreCheck: false
122124

125+
/* With help Connections object
126+
* set connections with System tray class
127+
* */
128+
129+
Connections {
130+
target: systemTray
131+
function onSignalShow() {
132+
root.show();
133+
}
134+
135+
// The signal - close the application by ignoring the check-box
136+
function onSignalQuit() {
137+
ignoreCheck = true
138+
close();
139+
}
140+
141+
// Minimize / maximize the window by clicking on the default system tray
142+
function onSignalIconActivated() {
143+
if(root.visibility === Window.Hidden) {
144+
root.show()
145+
} else {
146+
root.hide()
147+
}
148+
}
149+
}
150+
151+
// Handler window closing event
152+
onClosing: {
153+
/* If the check box should not be ignored and it is active,
154+
* then hide the application. Otherwise, close the application
155+
* */
156+
if(ignoreCheck === false){
157+
close.accepted = false
158+
root.hide()
159+
} else {
160+
Qt.quit()
161+
}
162+
}
123163

124164

125165

Diff for: medicalDevice.pro

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
QT += quick
1+
QT += qml quick widgets
22

33
# You can make your code fail to compile if it uses deprecated APIs.
44
# In order to do so, uncomment the following line.
55
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
66

77
SOURCES += \
88
applicationui.cpp \
9-
main.cpp
9+
main.cpp \
10+
systemtray.cpp
1011

1112
RESOURCES += qml.qrc
1213

@@ -23,4 +24,5 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
2324

2425
HEADERS += \
2526
applicationui.hpp \
27+
systemtray.h \
2628
uiconstants.hpp

Diff for: qml.qrc

+2
Original file line numberDiff line numberDiff line change
@@ -613,5 +613,7 @@
613613
<file>Settings/DeveloperSettingsPage.qml</file>
614614
<file>Settings/AboutPage.qml</file>
615615
<file>Img/Basic/undraw_programming_re_kg9v.svg</file>
616+
<file>common/PrefsSpinBox.qml</file>
617+
<file>Img/Basic/pngwing.com.png</file>
616618
</qresource>
617619
</RCC>

Diff for: systemtray.cpp

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#include "systemtray.h"
2+
#include <QMenu>
3+
#include <QSystemTrayIcon>
4+
5+
SystemTray::SystemTray(QObject *parent) : QObject(parent)
6+
{
7+
8+
// Create a context menu with two items
9+
QMenu *trayIconMenu = new QMenu();
10+
11+
QAction * viewWindow = new QAction("Open 1Password", this);
12+
viewWindow->setIcon(QIcon(":/Img/Basic/pngwing.com.png"));
13+
14+
QAction * quickWindow = new QAction("Open Quick Access", this);
15+
quickWindow->setIcon(QIcon(":/Img/Basic/pngwing.com.png"));
16+
quickWindow->setShortcut(QKeySequence(tr("Ctrl+S")));
17+
18+
QAction * settingsWindow = new QAction("Settings", this);
19+
settingsWindow->setIcon(QIcon(":/Img/Basic/pngwing.com.png"));
20+
21+
QAction * quitAction = new QAction("Quit", this);
22+
quitAction->setIcon(QIcon(":/Img/Basic/pngwing.com.png"));
23+
24+
/* to connect the signals clicks on menu items to the appropriate signals for QML.
25+
* */
26+
connect(viewWindow, &QAction::triggered, this, &SystemTray::signalShow);
27+
connect(settingsWindow, &QAction::triggered, this, &SystemTray::showSettingsWindow);
28+
connect(quickWindow, &QAction::triggered, this, &SystemTray::showQuickAccess);
29+
connect(quitAction, &QAction::triggered, this, &SystemTray::signalQuit);
30+
31+
trayIconMenu->addAction(viewWindow);
32+
trayIconMenu->addAction(quickWindow);
33+
trayIconMenu->addAction(settingsWindow);
34+
trayIconMenu->addAction(quitAction);
35+
36+
/* Initialize the tray icon, icon set, and specify the tooltip
37+
* */
38+
trayIcon = new QSystemTrayIcon();
39+
trayIcon->setContextMenu(trayIconMenu);
40+
trayIcon->setIcon(QIcon(":/Img/Basic/pngwing.com.png"));
41+
trayIcon->show();
42+
trayIcon->setToolTip("Adesh's Device");
43+
trayIcon->showMessage("Adesh's Device Tray App Created","Click On Tray App to open Device App",QSystemTrayIcon::Information,1000);
44+
45+
/* Also connect clicking on the icon to the signal handler of the pressing
46+
* */
47+
connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
48+
this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
49+
}
50+
51+
/* The method that handles click on the application icon in the system tray
52+
* */
53+
void SystemTray::iconActivated(QSystemTrayIcon::ActivationReason reason)
54+
{
55+
switch (reason){
56+
case QSystemTrayIcon::Trigger:
57+
// In the case of pressing the signal on the icon tray in the call signal QML layer
58+
emit signalIconActivated();
59+
break;
60+
default:
61+
break;
62+
}
63+
}
64+
65+
void SystemTray::hideIconTray()
66+
{
67+
trayIcon->hide();
68+
}

Diff for: systemtray.h

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#ifndef SYSTEMTRAY_H
2+
#define SYSTEMTRAY_H
3+
4+
#include <QObject>
5+
#include <QAction>
6+
#include <QSystemTrayIcon>
7+
8+
class SystemTray : public QObject
9+
{
10+
Q_OBJECT
11+
public:
12+
explicit SystemTray(QObject *parent = 0);
13+
14+
signals:
15+
void signalIconActivated();
16+
void signalShow();
17+
void signalQuit();
18+
void showSettingsWindow();
19+
void showQuickAccess();
20+
21+
private slots:
22+
/* The slot that will accept the signal from the event click on the application icon in the system tray
23+
*/
24+
void iconActivated(QSystemTrayIcon::ActivationReason reason);
25+
26+
public slots:
27+
void hideIconTray();
28+
29+
private:
30+
/* Declare the object of future applications for the tray icon*/
31+
QSystemTrayIcon * trayIcon;
32+
};
33+
34+
#endif // SYSTEMTRAY_H

0 commit comments

Comments
 (0)