diff --git a/includes/CMakeLists.txt b/includes/CMakeLists.txt index 02d4c2e0..4272e582 100644 --- a/includes/CMakeLists.txt +++ b/includes/CMakeLists.txt @@ -274,6 +274,7 @@ install( KTempDir KTemporaryFile KTextEdit + KTimeEdit KTimeZone KTimeZoneWidget KTipDatabase diff --git a/includes/KTimeEdit b/includes/KTimeEdit new file mode 100644 index 00000000..10226aca --- /dev/null +++ b/includes/KTimeEdit @@ -0,0 +1 @@ +#include "../ktimeedit.h" diff --git a/kdeui/CMakeLists.txt b/kdeui/CMakeLists.txt index 6c7ac9ce..10b328b7 100644 --- a/kdeui/CMakeLists.txt +++ b/kdeui/CMakeLists.txt @@ -236,6 +236,7 @@ set(kdeui_LIB_SRCS widgets/ktabbar.cpp widgets/ktabwidget.cpp widgets/ktextedit.cpp + widgets/ktimeedit.cpp widgets/ktimezonewidget.cpp widgets/ktitlewidget.cpp widgets/ktoolbar.cpp @@ -537,6 +538,7 @@ install( widgets/kseparator.h widgets/ksqueezedtextlabel.h widgets/ktextedit.h + widgets/ktimeedit.h widgets/ktimezonewidget.h widgets/ktitlewidget.h widgets/ktabbar.h diff --git a/kdeui/dialogs/kconfigdialogmanager.cpp b/kdeui/dialogs/kconfigdialogmanager.cpp index e6cb460c..c5c23104 100644 --- a/kdeui/dialogs/kconfigdialogmanager.cpp +++ b/kdeui/dialogs/kconfigdialogmanager.cpp @@ -134,6 +134,7 @@ void KConfigDialogManager::initMaps() s_changedMap->insert( "KColorButton", SIGNAL(changed(QColor))); s_changedMap->insert( "KCalendarWidget", SIGNAL(activated(QDate))); + s_changedMap->insert( "KTimeEdit", SIGNAL(timeChanged(QTime))); s_changedMap->insert( "KEditListBox", SIGNAL(changed())); s_changedMap->insert( "KEditListWidget", SIGNAL(changed())); s_changedMap->insert( "KListWidget", SIGNAL(itemSelectionChanged())); diff --git a/kdeui/widgets/ktimeedit.cpp b/kdeui/widgets/ktimeedit.cpp new file mode 100644 index 00000000..5132eb8e --- /dev/null +++ b/kdeui/widgets/ktimeedit.cpp @@ -0,0 +1,131 @@ +/* This file is part of the KDE libraries + Copyright (C) 2023 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "ktimeedit.h" +#include "klocale.h" +#include "kdebug.h" + +#include +#include + +class KTimeEditPrivate +{ +public: + KTimeEditPrivate(KTimeEdit *parent); + + void updateSuffixes(); + void slotValueChanged(const int value); + + KTimeEdit* ktimeedit; + QSpinBox* hourbox; + QSpinBox* minutebox; + QSpinBox* secondbox; +}; + +KTimeEditPrivate::KTimeEditPrivate(KTimeEdit *parent) + : ktimeedit(parent), + hourbox(nullptr), + minutebox(nullptr), + secondbox(nullptr) +{ +} + +void KTimeEditPrivate::updateSuffixes() +{ + hourbox->setSuffix(i18np(" hour", " hours", hourbox->value())); + minutebox->setSuffix(i18np(" minute", " minutes", minutebox->value())); + secondbox->setSuffix(i18np(" second", " seconds", secondbox->value())); +} + +void KTimeEditPrivate::slotValueChanged(const int value) +{ + updateSuffixes(); + const QTime currenttime = QTime(hourbox->value(), minutebox->value(), secondbox->value()); + emit ktimeedit->timeChanged(currenttime); +} + + +KTimeEdit::KTimeEdit(QWidget *parent) + : QWidget(parent), + d(new KTimeEditPrivate(this)) +{ + QHBoxLayout* timelayout = new QHBoxLayout(this); + d->hourbox = new QSpinBox(this); + d->hourbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + d->hourbox->setMaximum(23); + timelayout->addWidget(d->hourbox); + d->minutebox = new QSpinBox(this); + d->minutebox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + d->minutebox->setMaximum(59); + timelayout->addWidget(d->minutebox); + d->secondbox = new QSpinBox(this); + d->secondbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + d->secondbox->setMaximum(59); + timelayout->addWidget(d->secondbox); + setLayout(timelayout); + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + + d->updateSuffixes(); + + connect(d->hourbox, SIGNAL(valueChanged(int)), this, SLOT(slotValueChanged(int))); + connect(d->minutebox, SIGNAL(valueChanged(int)), this, SLOT(slotValueChanged(int))); + connect(d->secondbox, SIGNAL(valueChanged(int)), this, SLOT(slotValueChanged(int))); +} + +KTimeEdit::~KTimeEdit() +{ + delete d; +} + +QTime KTimeEdit::minimumTime() const +{ + return QTime(d->hourbox->minimum(), d->minutebox->minimum(), d->secondbox->minimum()); +} + +void KTimeEdit::setMinimumTime(const QTime &time) +{ + d->hourbox->setMinimum(time.hour()); + d->minutebox->setMinimum(time.minute()); + d->secondbox->setMinimum(time.second()); +} + +QTime KTimeEdit::maximumTime() const +{ + return QTime(d->hourbox->maximum(), d->minutebox->maximum(), d->secondbox->maximum()); +} + +void KTimeEdit::setMaximumTime(const QTime &time) +{ + d->hourbox->setMaximum(time.hour()); + d->minutebox->setMaximum(time.minute()); + d->secondbox->setMaximum(time.second()); +} + +QTime KTimeEdit::time() const +{ + return QTime(d->hourbox->value(), d->minutebox->value(), d->secondbox->value()); +} + +void KTimeEdit::setTime(const QTime &time) +{ + d->hourbox->setValue(time.hour()); + d->minutebox->setValue(time.minute()); + d->secondbox->setValue(time.second()); +} + +#include "moc_ktimeedit.cpp" diff --git a/kdeui/widgets/ktimeedit.h b/kdeui/widgets/ktimeedit.h new file mode 100644 index 00000000..77b39091 --- /dev/null +++ b/kdeui/widgets/ktimeedit.h @@ -0,0 +1,64 @@ +/* This file is part of the KDE libraries + Copyright (C) 2023 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KTIMEEDIT_H +#define KTIMEEDIT_H + +#include + +#include +#include + +class KTimeEditPrivate; + +/*! + Class to pick a time, suitable for timers. + + @since 4.23 + @warning the API is subject to change +*/ +class KDEUI_EXPORT KTimeEdit: public QWidget +{ + Q_OBJECT + Q_PROPERTY(QTime minimumTime READ minimumTime WRITE setMinimumTime) + Q_PROPERTY(QTime maximumTime READ maximumTime WRITE setMaximumTime) + Q_PROPERTY(QTime time READ time WRITE setTime NOTIFY timeChanged) +public: + KTimeEdit(QWidget *parent = nullptr); + ~KTimeEdit(); + + QTime minimumTime() const; + void setMinimumTime(const QTime &time); + QTime maximumTime() const; + void setMaximumTime(const QTime &time); + + QTime time() const; + void setTime(const QTime &time); + +Q_SIGNALS: + void timeChanged(const QTime &time); + +private: + friend KTimeEditPrivate; + Q_DISABLE_COPY(KTimeEdit); + KTimeEditPrivate *d; + + Q_PRIVATE_SLOT(d, void slotValueChanged(int)) +}; + +#endif // KTIMEEDIT_H diff --git a/kdewidgets/kde.widgets b/kdewidgets/kde.widgets index 9a75ac44..47e8a93a 100644 --- a/kdewidgets/kde.widgets +++ b/kdewidgets/kde.widgets @@ -59,6 +59,11 @@ ToolTip=A date selection widget (KDE) WhatsThis=Provides a widget for calendar date input Group=Date/Time (KDE) +[KTimeEdit] +ToolTip=A time edit widget (KDE) +WhatsThis=Provides a widget for time editing +Group=Date/Time (KDE) + [KDialog] IncludeFile=kdialog.h ToolTip=Class for simple Dialogs (KDE)