Skip to content

Commit

Permalink
optimize tray menu
Browse files Browse the repository at this point in the history
  • Loading branch information
jansorg committed Jan 16, 2019
1 parent c218891 commit 7684237
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 33 deletions.
9 changes: 5 additions & 4 deletions resources/images/start.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 13 additions & 13 deletions resources/images/stop.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 3 additions & 4 deletions source/gotime/startStop_project_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,21 @@ StartProjectAction::StartProjectAction(Project &project, GotimeControl *control,

connect(control, SIGNAL(projectStarted(const Project &)),
this, SLOT(projectStarted(const Project &)));

connect(control, SIGNAL(projectStopped(const Project &)),
this, SLOT(projectStopped(const Project &)));
// connect(control, SIGNAL(projectCancelled(const Project &)),
// this, SLOT(projectStopped(const Project &)));
}

void StartProjectAction::projectStarted(const Project &project) {
if (project.getID() == _project.getID()) {
this->setText("Stop: " + project.getName());
this->setText(project.getName());
this->setIcon(QIcon(":/images/stop.svg"));
}
}

void StartProjectAction::projectStopped(const Project &project) {
if (project.getID() == _project.getID()) {
this->setText("Start: " + project.getName());
this->setText(project.getName());
this->setIcon(QIcon(":/images/start.svg"));
}
}
Expand Down
35 changes: 23 additions & 12 deletions source/gotime_tray_icon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@ GotimeTrayIcon::GotimeTrayIcon(GotimeControl *control, QMainWindow *mainWindow)
loadIcons();

_menu = new QMenu();
_menu->addSection(tr("Projects"));

_separatorAction = _menu->addSeparator();
_separatorAction->setText("Actions");
_stopTaskAction = new QAction("Stop active project...");
_stopTaskAction->setToolTip("Stop the current project and record data.");
connect(_stopTaskAction, SIGNAL(triggered()), control, SLOT(stopActivity()));
_menu->addAction(_stopTaskAction);

QAction *stopAction = new QAction("Stop timer...");
connect(stopAction, SIGNAL(triggered()), control, SLOT(stopActivity()));
_menu->addAction(stopAction);
_cancelTaskAction = new QAction("Cancel active project...");
_cancelTaskAction->setToolTip("Stop the active project without recording new data.");
connect(_cancelTaskAction, SIGNAL(triggered()), control, SLOT(cancelActivity()));
_menu->addAction(_cancelTaskAction);

QAction *cancelAction = new QAction("Cancel timer...");
connect(cancelAction, SIGNAL(triggered()), control, SLOT(cancelActivity()));
_menu->addAction(cancelAction);
_menu->addSection(tr("Projects"));

_menu->addSeparator();
_separatorAction = _menu->addSeparator();
_separatorAction->setText("Actions");
QAction *showWindowAction = new QAction("&Show window", this);
connect(showWindowAction, &QAction::triggered, mainWindow, &QMainWindow::show);
_menu->addAction(showWindowAction);
Expand Down Expand Up @@ -57,7 +58,6 @@ GotimeTrayIcon::GotimeTrayIcon(GotimeControl *control, QMainWindow *mainWindow)

projectStarted(project);
} else {

projectStopped(project);
}
}
Expand Down Expand Up @@ -90,7 +90,6 @@ void GotimeTrayIcon::updateStatus() {

void GotimeTrayIcon::loadIcons() {
_stoppedIcon = QPixmap(":/images/trayicon-stopped.svg");

_activeIcons << QPixmap(":/images/trayicon-1.svg");
_activeIcons << QPixmap(":/images/trayicon-2.svg");
_activeIcons << QPixmap(":/images/trayicon-3.svg");
Expand All @@ -108,13 +107,25 @@ void GotimeTrayIcon::projectStarted(const Project &) {
if (!_statusUpdateTimer->isActive()) {
_statusUpdateTimer->start(2500);
}

_stopTaskAction->setEnabled(true);
_cancelTaskAction->setEnabled(true);

updateStatus();
updateProjects();
}

void GotimeTrayIcon::projectStopped(const Project &) {
_trayIcon->setIcon(_stoppedIcon);

_iconTimer->stop();
_statusUpdateTimer->stop();

_stopTaskAction->setEnabled(false);
_cancelTaskAction->setEnabled(false);

updateStatus();
updateProjects();
}

void GotimeTrayIcon::updateIcon() {
Expand Down
2 changes: 2 additions & 0 deletions source/gotime_tray_icon.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ private slots:
GotimeControl *_control;
QSystemTrayIcon *_trayIcon;
QList<QAction *> _projectActions;
QAction *_stopTaskAction;
QAction *_cancelTaskAction;
QAction *_separatorAction;

int _activeIconIndex;
Expand Down

0 comments on commit 7684237

Please sign in to comment.