Skip to content

Commit cba778e

Browse files
committed
del menu
1 parent c9f9d11 commit cba778e

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

SmartTimer/alertwidget.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ alertwidget::alertwidget(int msecs, const QString& name, bool turnedOn, QWidget
6565
<< QTime::currentTime().hour() <<":" << QTime::currentTime().minute() << std::endl;
6666
alertTick.start(calculateDuration(alertTime));
6767
}
68+
69+
70+
this->setContextMenuPolicy(Qt::CustomContextMenu);
71+
72+
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)),
73+
this, SLOT(ShowContextMenu(const QPoint &)));
74+
6875
}
6976

7077
alertwidget::~alertwidget()
@@ -158,14 +165,34 @@ void alertwidget::closeAlarm()
158165
this->close();
159166
}
160167

168+
void alertwidget::changeAlarm()
169+
{
170+
171+
}
172+
173+
void alertwidget::ShowContextMenu(const QPoint &pos)
174+
{
175+
QMenu contextMenu(tr("Context menu"), this);
176+
177+
QAction action1("Delete alarm", this);
178+
QAction action2("Change alarm", this);
179+
connect(&action1, SIGNAL(triggered()), this, SLOT(closeAlarm()));
180+
connect(&action2, SIGNAL(triggered()), this, SLOT(changeAlarm()));
181+
contextMenu.addAction(&action1);
182+
contextMenu.addAction(&action2);
183+
184+
contextMenu.exec(mapToGlobal(pos));
185+
}
186+
161187

162188
void alertwidget::mousePressEvent(QMouseEvent *e)
163189
{
164190
if (e->button() == Qt::RightButton)
165191
{
166192
player->stop();
167193

168-
emit closeAlarm();
194+
ShowContextMenu(e->pos());
195+
//emit closeAlarm();
169196
}
170197
}
171198

SmartTimer/alertwidget.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,16 @@ public slots:
3232
void stopBlinking();
3333
void closeAlarm();
3434

35+
void changeAlarm();
36+
37+
void ShowContextMenu(const QPoint &);
38+
3539
signals:
3640
void alarmFinished();
3741
void del(const alertwidget*);
3842

43+
void customContextMenuRequested(const QPoint &);
44+
3945
private:
4046
Ui::alertwidget *ui;
4147

0 commit comments

Comments
 (0)