void Tomato::updateTimer() { elapsedSec += 1; QTime currentTime(0,elapsedSec/60,elapsedSec%60,0); trayIcon->setToolTip(currentTime.toString("mm:ss")); // time's up if (FOCUS == state && elapsedSec/60 >= focusDuration) { timer->stop(); elapsedSec = 0; trayIcon->showMessage("Tomato", "Focus time's up!\nTake a rest~~", QIcon(":/tomato"), 1000); state = REST; setIconState(REST); startRest(); } else if (REST == state && elapsedSec/60 >= restDuration) { timer->stop(); elapsedSec = 0; trayIcon->showMessage("Tomato", "Rest time's up!\nNeed another round?", QIcon(":/coffee"), 1000); state = IDLE; setIconState(IDLE); if ( ui->checkInfinity->isChecked() ) { // infinity mode startTomato(); } } }
Tomato::Tomato(QWidget *parent) : QDialog(parent), ui(new Ui::Tomato) { ui->setupUi(this); setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint); // remove "?" on dialog window focusDuration = focusDefault; restDuration = restDefault; elapsedSec = 0; state = IDLE; createActions(); createTrayIcon(); connect(trayIcon, &QSystemTrayIcon::activated, this, &Tomato::iconActivated); connect(trayIcon, &QSystemTrayIcon::messageClicked, this, &Tomato::iconMsgClicked); setIconState(IDLE); setWindowIcon(QIcon(":/sushi")); setWindowTitle(tr("Tomato です")); timer = new QTimer(this); connect(timer,SIGNAL(timeout()),this,SLOT(updateTimer())); verifyStartWithWindows(); QSettings settings("tomato.ini",QSettings::IniFormat); ui->checkInfinity->setChecked(settings.value("InfinityMode").toInt()); }
void Button::setIconWithSates(const QPixmap &pixmap, IconState s1, IconState s2, IconState s3, IconState s4) { int a = pixmap.width(); int b = pixmap.height(); int count = qMax(a, b)/qMin(a, b); bool hor = pixmap.height() < pixmap.width(); QPoint dp; if (hor) { a /= count; dp.setX(a); } else { b /= count; dp.setY(b); } QRect r(0, 0, a, b); setIconForState(s1, pixmap.copy(r)); if (count > 1) { r.translate(dp); setIconForState(s2, pixmap.copy(r)); if (count > 2) { r.translate(dp); setIconForState(s3, pixmap.copy(r)); if (count > 3) { r.translate(dp); setIconForState(s4, pixmap.copy(r)); } } } setIconState(iconState(), true); //TODO: other states set to existing icon }
void Button::mouseReleaseEvent(QMouseEvent *e) { QToolButton::mouseReleaseEvent(e); if (mIcons.isEmpty()) return; setIconState(Focused); }
void Button::mousePressEvent(QMouseEvent *e) { QToolButton::mousePressEvent(e); if (mIcons.isEmpty()) return; setIconState(Pressed); }
void Button::enterEvent(QEvent *e) { QToolButton::enterEvent(e); if (mIcons.isEmpty()) return; setIconState(Focused); emit entered(); }
void Button::leaveEvent(QEvent *e) { QToolButton::leaveEvent(e); if (mIcons.isEmpty()) return; setIconState(NotFocused); emit leaved(); }
void Tomato::cancelTomato() { if(FOCUS == state) { trayIcon->showMessage("Tomato", tr("Cancelled at %1 min").arg(elapsedSec/60), QIcon(":/coffee"), 1000); } timer->stop(); elapsedSec = 0; state = IDLE; setIconState(IDLE); }
void Tomato::continueTomato() { state = FOCUS; setIconState(state); timer->start(1000); }
void Tomato::pauseTomato() { state = PAUSE; setIconState(state); timer->stop(); }
void Tomato::startRest() { state = REST; setIconState(state); timer->start(1000); }
void Tomato::startTomato() { state = FOCUS; setIconState(state); timer->start(1000); // emit timeout signal every 1 second }