Skip to content

Commit

Permalink
[alarm clock] add right click delete menu
Browse files Browse the repository at this point in the history
  • Loading branch information
HuaYaDong1 committed Jan 10, 2021
1 parent e0742d2 commit 54b7196
Show file tree
Hide file tree
Showing 7 changed files with 378 additions and 330 deletions.
30 changes: 26 additions & 4 deletions src/plugins/ukui-clock/clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ Clock::Clock(QWidget *parent) :
QPainterPath blurPath;
setProperty("useSystemStyleBlur", true);
setProperty("blurRegion", QRegion(blurPath.toFillPolygon().toPolygon()));//使用QPainterPath的api生成多边形Region
//mainColor = QColor(26, 26, 26,198);

mousePressed = 0;
buttonImageInit();
Expand All @@ -100,14 +99,14 @@ Clock::Clock(QWidget *parent) :
setupInit();
this->setFixedSize(390,580);
/*实现鼠标左键滑动效果
*Realize the sliding effect of left mouse button
*/
*Realize the sliding effect of left mouse button*/
ui->listWidget -> setFrameShape(QListWidget::NoFrame);
ui->listWidget_2 -> setFrameShape(QListWidget::NoFrame);
QScroller::grabGesture(ui->listWidget,QScroller::LeftMouseButtonGesture); /*设置鼠标左键拖动 Set left mouse drag*/
QScroller::grabGesture(ui->listWidget_2,QScroller::LeftMouseButtonGesture); /*设置鼠标左键拖动 Set left mouse drag*/
ui->listWidget -> setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); /*设置像素级滑动 Set pixel level slide*/
ui->listWidget_2 -> setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); /*设置像素级滑动 Set pixel level slide*/
ui->listWidget->setProperty("contextMenuPolicy", Qt::CustomContextMenu); /*重要:设置QListWidget的contextMenuPolicy属性,不然不能显示右键菜单*/
ui->listWidget ->setGridSize(QSize(340, 108+15));
ui->listWidget_2 ->setGridSize(QSize(340, 58+10));

Expand Down Expand Up @@ -217,6 +216,7 @@ Clock::Clock(QWidget *parent) :
ui->min_60btn->hide();
ui->label_12->hide();
ui->label_13->hide();
ui->pushButton_8->hide();
}

Clock::~Clock()
Expand Down Expand Up @@ -453,6 +453,15 @@ void Clock::clockInit()
model_setup->setEditStrategy(QSqlTableModel::OnManualSubmit);
model_setup->select();

/*初始化一个包含两个Action(Delete和ClearAll)的菜单*/
popMenu_In_ListWidget_ = new QMenu(this);
action_Delete_In_ListWidget_ = new QAction(tr("Delete"), this);
action_Clear_In_ListWidget_ = new QAction(tr("ClearAll"), this);
popMenu_In_ListWidget_->addAction(action_Delete_In_ListWidget_);
// popMenu_In_ListWidget_->addAction(action_Clear_In_ListWidget_);

connect(this->action_Delete_In_ListWidget_, SIGNAL(triggered()), this, SLOT(deleteAlarm()));

connect(ui->listWidget,SIGNAL(itemDoubleClicked(QListWidgetItem*)),this,SLOT(listdoubleClickslot()));
connect(ui->listWidget,SIGNAL(itemClicked(QListWidgetItem*)),this,SLOT(listClickslot()));
connect(ui->pushButton_8, SIGNAL(clicked()), this, SLOT(deleteAlarm()) );
Expand All @@ -475,6 +484,9 @@ void Clock::clockInit()
connect(ui->min_60btn, SIGNAL(clicked()), this, SLOT(onMin_60btnClicked()));
connect(ui->count_push, SIGNAL(clicked()), this, SLOT(onCountPushClicked()));
connect(ui->pushButton_9, SIGNAL(clicked()), this, SLOT(alarmReEditClicked()));
/*绑定右键显示菜单:在单击右键之后会执行槽函数, 槽函数中负责弹出右键菜单*/
connect(ui->listWidget, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(onCustomContextMenuRequested(const QPoint &)));

/*单击时间提示计时器
Click time reminder timer*/
Expand Down Expand Up @@ -519,6 +531,16 @@ void Clock::clockInit()
connect(m_menuAction, SIGNAL(triggered()), this, SLOT(setUpPage()));
connect(m_closeAction, SIGNAL(triggered()), this, SLOT(windowClosingClicked()));
}

/*
* 事件处理函数
*/
void Clock::onCustomContextMenuRequested(const QPoint &pos)
{
/*弹出右键菜单*/
popMenu_In_ListWidget_->exec(QCursor::pos());
}

/*
* 默认初始设置
* Default initial settings
Expand Down Expand Up @@ -1480,7 +1502,7 @@ void Clock::listdoubleClickslot()
{
// ui->set_page->show();
ui->stackedWidget->setCurrentIndex(3);
ui->pushButton_8->show();
// ui->pushButton_8->show();
ui->pushButton_9->show();
ui->set_alarm_savebtn->hide();
timer_alarm_start24->m_currentValue=model->index(ui->listWidget->currentRow(), 0).data().toInt();
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/ukui-clock/clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ private slots:
// Calculate the next alarm ring interval
QString changeNumToStr(int alarmHour); //整型转字符
// Integer to character
void onCustomContextMenuRequested(const QPoint &pos); //闹钟右键删除事件处理函数

void countStatBtnGray();

private:
Expand Down Expand Up @@ -372,6 +374,10 @@ private slots:
Btn_new *ring_sel;
QMenu *m_menu; /*功能菜单*/
QAction *m_menuAction; /*菜单动作*/

QMenu *popMenu_In_ListWidget_; /*闹钟右键删除菜单*/
QAction *action_Delete_In_ListWidget_ ;
QAction *action_Clear_In_ListWidget_ ; /*闹钟右键删除动作*/
};


Expand Down
12 changes: 6 additions & 6 deletions src/plugins/ukui-clock/clock.ui
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<string notr="true"/>
</property>
<property name="currentIndex">
<number>1</number>
<number>3</number>
</property>
<widget class="QWidget" name="page">
<widget class="QStackedWidget" name="stackedWidget_4">
Expand Down Expand Up @@ -510,8 +510,8 @@ font: 19pt
<widget class="QPushButton" name="pushButton_8">
<property name="geometry">
<rect>
<x>164</x>
<y>401</y>
<x>20</x>
<y>360</y>
<width>72</width>
<height>34</height>
</rect>
Expand All @@ -526,7 +526,7 @@ font: 19pt
<widget class="QPushButton" name="pushButton_9">
<property name="geometry">
<rect>
<x>260</x>
<x>210</x>
<y>401</y>
<width>72</width>
<height>34</height>
Expand Down Expand Up @@ -564,7 +564,7 @@ opacity:0.45;
<widget class="QPushButton" name="set_alarm_cancelbtn">
<property name="geometry">
<rect>
<x>68</x>
<x>108</x>
<y>401</y>
<width>72</width>
<height>34</height>
Expand All @@ -580,7 +580,7 @@ opacity:0.45;
<widget class="QPushButton" name="set_alarm_savebtn">
<property name="geometry">
<rect>
<x>260</x>
<x>210</x>
<y>401</y>
<width>72</width>
<height>34</height>
Expand Down
Binary file modified translations/ukui-clock/ukui-clock_tr.qm
Binary file not shown.
Loading

0 comments on commit 54b7196

Please sign in to comment.