mirror of
https://github.com/vicr123/theshell.git
synced 2025-01-23 04:11:49 -05:00
Timers in new Overview UI
This commit is contained in:
parent
4862b7ab0e
commit
e1b80a3440
8 changed files with 415 additions and 10 deletions
|
@ -39,16 +39,19 @@ HEADERS += \
|
|||
plugin.h \
|
||||
overview.h \
|
||||
overviewsettings.h \
|
||||
Timers/timerpage.h
|
||||
Timers/timerpage.h \
|
||||
Timers/timeritem.h
|
||||
|
||||
SOURCES += \
|
||||
plugin.cpp \
|
||||
overview.cpp \
|
||||
overviewsettings.cpp \
|
||||
Timers/timerpage.cpp
|
||||
Timers/timerpage.cpp \
|
||||
Timers/timeritem.cpp
|
||||
|
||||
FORMS += \
|
||||
overview.ui \
|
||||
overviewsettings.ui \
|
||||
Timers/timerpage.ui
|
||||
Timers/timerpage.ui \
|
||||
Timers/timeritem.ui
|
||||
|
||||
|
|
98
statuscenter/OverviewPane/Timers/timeritem.cpp
Normal file
98
statuscenter/OverviewPane/Timers/timeritem.cpp
Normal file
|
@ -0,0 +1,98 @@
|
|||
#include "timeritem.h"
|
||||
#include "ui_timeritem.h"
|
||||
|
||||
#include <QTime>
|
||||
#include <tnotification.h>
|
||||
|
||||
TimerItem::TimerItem(QString timerName, int seconds, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::TimerItem)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->timerName->setText(timerName);
|
||||
|
||||
progressAnim = new tVariantAnimation();
|
||||
progressAnim->setForceAnimation(true);
|
||||
progressAnim->setStartValue(0);
|
||||
progressAnim->setEndValue(this->width());
|
||||
progressAnim->setDuration(seconds * 1000);
|
||||
connect(progressAnim, &tVariantAnimation::valueChanged, [=](QVariant value) {
|
||||
int msecsElapsed = progressAnim->currentTime();
|
||||
|
||||
QTime time = QTime::fromMSecsSinceStartOfDay(progressAnim->duration() - msecsElapsed);
|
||||
|
||||
ui->timeLeftLabel->setText(time.toString("HH:mm:ss"));
|
||||
this->update();
|
||||
});
|
||||
connect(progressAnim, &tVariantAnimation::finished, [=] {
|
||||
emit elapsed(timerName);
|
||||
//if (AudioMan->QuietMode() != AudioManager::notifications && AudioMan->QuietMode() != AudioManager::mute) { //Check if we should show the notification so the user isn't stuck listening to the tone
|
||||
|
||||
/*tNotification* notification = new tNotification(timerName, tr("Time's up!"));
|
||||
|
||||
QStringList actions;
|
||||
actions << "restart" << "Restart Timer";
|
||||
actions << "+0.5" << "+30 sec";
|
||||
actions << "+1" << "+1 min";
|
||||
actions << "+2" << "+2 min";
|
||||
actions << "+5" << "+5 min";
|
||||
actions << "+10" << "+10 min";
|
||||
|
||||
notification->insertHint("x-thesuite-timercomplete", true);
|
||||
notification->setSoundOn(false);
|
||||
|
||||
/*QVariantMap hints;
|
||||
hints.insert("x-thesuite-timercomplete", true);
|
||||
hints.insert("suppress-sound", true);
|
||||
timerNotificationId = ndbus->Notify("theShell", 0, "", tr("Timer Elapsed"),
|
||||
tr("Your timer has completed."),
|
||||
actions, hints, 0);*/
|
||||
|
||||
//notification->setTimeout(0);
|
||||
//notification->post();
|
||||
|
||||
/*QMediaPlaylist* playlist = new QMediaPlaylist();
|
||||
|
||||
#ifdef BLUEPRINT
|
||||
QString ringtonesPath = "/usr/share/sounds/theshellb/tones/";
|
||||
#else
|
||||
QString ringtonesPath = "/usr/share/sounds/theshell/tones/";
|
||||
#endif
|
||||
|
||||
/*if (ui->timerToneSelect->currentText() == tr("Happy Bee")) {
|
||||
playlist->addMedia(QMediaContent(QUrl::fromLocalFile(ringtonesPath + "happybee.ogg")));
|
||||
} else if (ui->timerToneSelect->currentText() == tr("Playing in the Dark")) {
|
||||
playlist->addMedia(QMediaContent(QUrl::fromLocalFile(ringtonesPath + "playinginthedark.ogg")));
|
||||
} else if (ui->timerToneSelect->currentText() == tr("Ice Cream Truck")) {
|
||||
playlist->addMedia(QMediaContent(QUrl::fromLocalFile(ringtonesPath + "icecream.ogg")));
|
||||
} else if (ui->timerToneSelect->currentText() == tr("Party Complex")) {
|
||||
playlist->addMedia(QMediaContent(QUrl::fromLocalFile(ringtonesPath + "party.ogg")));
|
||||
} else if (ui->timerToneSelect->currentText() == tr("Salty Ditty")) {
|
||||
playlist->addMedia(QMediaContent(QUrl::fromLocalFile(ringtonesPath + "saltyditty.ogg")));
|
||||
}
|
||||
playlist->setPlaybackMode(QMediaPlaylist::Loop);
|
||||
ringtone->setPlaylist(playlist);
|
||||
ringtone->play();*/
|
||||
|
||||
//AudioMan->attenuateStreams();
|
||||
//}
|
||||
});
|
||||
progressAnim->start();
|
||||
}
|
||||
|
||||
TimerItem::~TimerItem()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void TimerItem::paintEvent(QPaintEvent* event) {
|
||||
QPainter painter(this);
|
||||
painter.setBrush(this->palette().brush(QPalette::Highlight));
|
||||
painter.setPen(Qt::transparent);
|
||||
painter.drawRect(0, this->height() - 2 * theLibsGlobal::instance()->getDPIScaling(), progressAnim->currentValue().toInt(), 2 * theLibsGlobal::instance()->getDPIScaling());
|
||||
}
|
||||
|
||||
void TimerItem::resizeEvent(QResizeEvent* event) {
|
||||
progressAnim->setEndValue(this->width());
|
||||
}
|
32
statuscenter/OverviewPane/Timers/timeritem.h
Normal file
32
statuscenter/OverviewPane/Timers/timeritem.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
#ifndef TIMERITEM_H
|
||||
#define TIMERITEM_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPainter>
|
||||
#include <tvariantanimation.h>
|
||||
|
||||
namespace Ui {
|
||||
class TimerItem;
|
||||
}
|
||||
|
||||
class TimerItem : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TimerItem(QString timerName, int seconds, QWidget *parent = nullptr);
|
||||
~TimerItem();
|
||||
|
||||
signals:
|
||||
void elapsed(QString timerName);
|
||||
|
||||
private:
|
||||
Ui::TimerItem *ui;
|
||||
|
||||
tVariantAnimation* progressAnim;
|
||||
|
||||
void paintEvent(QPaintEvent* event);
|
||||
void resizeEvent(QResizeEvent* event);
|
||||
};
|
||||
|
||||
#endif // TIMERITEM_H
|
40
statuscenter/OverviewPane/Timers/timeritem.ui
Normal file
40
statuscenter/OverviewPane/Timers/timeritem.ui
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>TimerItem</class>
|
||||
<widget class="QWidget" name="TimerItem">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>229</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="timerName">
|
||||
<property name="text">
|
||||
<string notr="true">Timer 1</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="timeLeftLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>50</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -1,11 +1,20 @@
|
|||
#include "timerpage.h"
|
||||
#include "ui_timerpage.h"
|
||||
|
||||
#include <QScroller>
|
||||
#include <QDBusInterface>
|
||||
|
||||
TimerPage::TimerPage(QWidget *parent) :
|
||||
QStackedWidget(parent),
|
||||
ui(new Ui::TimerPage)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
this->setCurrentWidget(ui->noTimersPage);
|
||||
QScroller::grabGesture(ui->timersScroll->viewport(), QScroller::LeftMouseButtonGesture);
|
||||
|
||||
notificationInterface = new QDBusInterface("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications");
|
||||
QDBusConnection::sessionBus().connect(notificationInterface->service(), notificationInterface->path(), notificationInterface->interface(), "NotificationClosed", this, SLOT(notificationClosed(uint,uint)));
|
||||
}
|
||||
|
||||
TimerPage::~TimerPage()
|
||||
|
@ -15,10 +24,71 @@ TimerPage::~TimerPage()
|
|||
|
||||
void TimerPage::on_backButton_clicked()
|
||||
{
|
||||
this->setCurrentWidget(ui->noTimersPage);
|
||||
if (timersCreated == 0) {
|
||||
this->setCurrentWidget(ui->noTimersPage);
|
||||
} else {
|
||||
this->setCurrentWidget(ui->timersList);
|
||||
}
|
||||
}
|
||||
|
||||
void TimerPage::on_newTimerButton_clicked()
|
||||
{
|
||||
this->setCurrentWidget(ui->newTimerPage);
|
||||
|
||||
ui->newTimerBox->setTime(QTime::fromMSecsSinceStartOfDay(0));
|
||||
|
||||
ui->newTimerName->setText(tr("Timer %n", nullptr, timersCreated + 1));
|
||||
}
|
||||
|
||||
void TimerPage::on_setTimerButton_clicked()
|
||||
{
|
||||
TimerItem* item = new TimerItem(ui->newTimerName->text(), ui->newTimerBox->time().msecsSinceStartOfDay() / 1000, this);
|
||||
ui->timersLayout->addWidget(item);
|
||||
connect(item, SIGNAL(elapsed(QString)), this, SLOT(timerElapsed(QString)));
|
||||
this->setCurrentWidget(ui->timersList);
|
||||
timersCreated++;
|
||||
}
|
||||
|
||||
void TimerPage::timerElapsed(QString timerName) {
|
||||
timersElapsed.append(timerName);
|
||||
|
||||
if (timersElapsed.count() > 1) {
|
||||
QVariantMap hints;
|
||||
hints.insert("x-thesuite-timercomplete", true);
|
||||
hints.insert("suppress-sound", true);
|
||||
|
||||
QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(notificationInterface->asyncCall("Notify", "theShell", currentTimerId, "", tr("%n timers elapsed", nullptr, timersElapsed.count()), timersElapsed.join(" · "), QStringList(), hints, 0));
|
||||
connect(watcher, &QDBusPendingCallWatcher::finished, [=] {
|
||||
currentTimerId = watcher->reply().arguments().first().toUInt();
|
||||
});
|
||||
} else {
|
||||
QStringList actions;
|
||||
actions << "restart" << "Restart Timer";
|
||||
actions << "+0.5" << "+30 sec";
|
||||
actions << "+1" << "+1 min";
|
||||
actions << "+2" << "+2 min";
|
||||
actions << "+5" << "+5 min";
|
||||
actions << "+10" << "+10 min";
|
||||
|
||||
QVariantMap hints;
|
||||
hints.insert("x-thesuite-timercomplete", true);
|
||||
hints.insert("suppress-sound", true);
|
||||
|
||||
QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(notificationInterface->asyncCall("Notify", "theShell", currentTimerId, "", timerName, tr("Time's up!"), actions, hints, 0));
|
||||
connect(watcher, &QDBusPendingCallWatcher::finished, [=] {
|
||||
currentTimerId = watcher->reply().arguments().first().toUInt();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void TimerPage::notificationClosed(uint id, uint reason) {
|
||||
if (id == currentTimerId) {
|
||||
currentTimerId = 0;
|
||||
timersElapsed.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void TimerPage::on_newTimerButtonTop_clicked()
|
||||
{
|
||||
ui->newTimerButton->click();
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define TIMERPAGE_H
|
||||
|
||||
#include <QStackedWidget>
|
||||
#include "timeritem.h"
|
||||
|
||||
namespace Ui {
|
||||
class TimerPage;
|
||||
|
@ -20,8 +21,22 @@ class TimerPage : public QStackedWidget
|
|||
|
||||
void on_newTimerButton_clicked();
|
||||
|
||||
void on_setTimerButton_clicked();
|
||||
|
||||
void on_newTimerButtonTop_clicked();
|
||||
|
||||
void timerElapsed(QString timerName);
|
||||
|
||||
void notificationClosed(uint id, uint reason);
|
||||
|
||||
private:
|
||||
Ui::TimerPage *ui;
|
||||
|
||||
int timersCreated = 0;
|
||||
uint currentTimerId = 0;
|
||||
QStringList timersElapsed;
|
||||
|
||||
QDBusInterface* notificationInterface;
|
||||
};
|
||||
|
||||
#endif // TIMERPAGE_H
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<string>StackedWidget</string>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>2</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="noTimersPage">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
|
@ -77,7 +77,8 @@
|
|||
<string>New Timer</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="list-add"/>
|
||||
<iconset theme="list-add">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -111,7 +112,135 @@
|
|||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="timersList"/>
|
||||
<widget class="QWidget" name="timersList">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>15</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Timers</string>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="newTimerButtonTop">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="list-add"/>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line_2">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>1</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QScrollArea" name="timersScroll">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>386</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="timersLayout"/>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_5">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>381</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="newTimerPage">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<property name="spacing">
|
||||
|
@ -146,7 +275,8 @@
|
|||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="go-previous"/>
|
||||
<iconset theme="go-previous">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
|
@ -204,6 +334,22 @@
|
|||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="newTimerName">
|
||||
<property name="inputMask">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="frame">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>Timer Name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTimeEdit" name="newTimerBox">
|
||||
<property name="font">
|
||||
|
@ -272,7 +418,8 @@
|
|||
<string>Set</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="chronometer-start"/>
|
||||
<iconset theme="chronometer-start">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 4.7.0, 2018-08-29T16:47:04. -->
|
||||
<!-- Written by QtCreator 4.7.0, 2018-09-01T10:11:00. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
|
|
Loading…
Reference in a new issue