Warning, file /utilities/rsibreak/src/breakcontrol.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2009-2010 Tom Albers <toma@kde.org>
0003     SPDX-FileCopyrightText: 2010 Juan Luis Baptiste <juan.baptiste@gmail.com>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #include "breakcontrol.h"
0009 
0010 #include <QApplication>
0011 #include <QIcon>
0012 #include <QLabel>
0013 #include <QPaintEvent>
0014 #include <QPainter>
0015 #include <QPainterPath>
0016 #include <QPushButton>
0017 #include <QScreen>
0018 #include <QVBoxLayout>
0019 
0020 #include <KLocalizedString>
0021 #include <QHBoxLayout>
0022 
0023 BreakControl::BreakControl(QWidget *parent, Qt::WindowType type)
0024     : QWidget(parent, type)
0025 {
0026     m_vbox = new QVBoxLayout;
0027     m_textLabel = new QLabel(this);
0028     m_textLabel->setAlignment(Qt::AlignHCenter);
0029 
0030     QWidget *hbox = new QWidget(this);
0031     QHBoxLayout *hboxHBoxLayout = new QHBoxLayout(hbox);
0032     hboxHBoxLayout->setContentsMargins(0, 0, 0, 0);
0033     hboxHBoxLayout->setSpacing(25);
0034 
0035     m_skipButton = new QPushButton(i18n("Skip Break"), hbox);
0036     hboxHBoxLayout->addWidget(m_skipButton);
0037     QSize sizeSkip(m_skipButton->size());
0038     m_skipButton->setIcon(QIcon::fromTheme("dialog-cancel"));
0039     m_skipButton->setFixedHeight(sizeSkip.height());
0040     connect(m_skipButton, &QPushButton::clicked, this, &BreakControl::skip);
0041 
0042     m_postponeButton = new QPushButton(i18n("Postpone Break"), hbox);
0043     hboxHBoxLayout->addWidget(m_postponeButton);
0044     QSize sizePostpone(m_postponeButton->size());
0045     m_postponeButton->setIcon(QIcon::fromTheme("go-next"));
0046     m_postponeButton->setFixedHeight(sizePostpone.height());
0047     connect(m_postponeButton, &QPushButton::clicked, this, &BreakControl::postpone);
0048 
0049     m_lockButton = new QPushButton(i18n("Lock Screen"), hbox);
0050     hboxHBoxLayout->addWidget(m_lockButton);
0051     QSize sizeLock(m_skipButton->size());
0052     m_lockButton->setFixedHeight(sizeLock.height());
0053     m_lockButton->setIcon(QIcon::fromTheme("system-lock-screen"));
0054     connect(m_lockButton, &QPushButton::clicked, this, &BreakControl::slotLock);
0055 
0056     m_vbox->addWidget(m_textLabel);
0057     m_vbox->addWidget(hbox);
0058 
0059     setLayout(m_vbox);
0060 
0061     connect(qApp, &QGuiApplication::screenAdded, this, &BreakControl::slotCenterIt);
0062     connect(qApp, &QGuiApplication::screenRemoved, this, &BreakControl::slotCenterIt);
0063 
0064     slotCenterIt();
0065 }
0066 
0067 void BreakControl::slotCenterIt()
0068 {
0069     const QRect r(QGuiApplication::primaryScreen()->geometry());
0070 
0071     const QPoint center(r.width() / 2 - sizeHint().width() / 2, r.y());
0072     move(center);
0073 }
0074 
0075 void BreakControl::slotLock()
0076 {
0077     emit lock();
0078 }
0079 
0080 void BreakControl::setText(const QString &text)
0081 {
0082     m_textLabel->setText(text);
0083 }
0084 
0085 void BreakControl::showMinimize(bool show)
0086 {
0087     m_skipButton->setVisible(show);
0088 }
0089 
0090 void BreakControl::showLock(bool show)
0091 {
0092     m_lockButton->setVisible(show);
0093 }
0094 
0095 void BreakControl::showPostpone(bool show)
0096 {
0097     m_postponeButton->setVisible(show);
0098 }
0099 
0100 void BreakControl::paintEvent(QPaintEvent *event)
0101 {
0102     if (event->type() == QEvent::Paint) {
0103         int margin = 3;
0104         QPainterPath box;
0105         box.moveTo(rect().topLeft());
0106         box.lineTo(rect().bottomLeft());
0107         box.lineTo(rect().bottomRight());
0108         box.lineTo(rect().topRight());
0109         box.closeSubpath();
0110 
0111         QColor highlight = palette().highlight().color();
0112         highlight.setAlphaF(0.7);
0113 
0114         QPen pen(highlight);
0115         pen.setWidth(margin);
0116 
0117         QPainter painter(this);
0118         painter.setPen(pen);
0119         painter.drawPath(box);
0120     }
0121 }