mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 10:22:48 +00:00
kdeui: new KTimeEdit widget
inspired by QTimeEdit but ment for timers Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
b323e4a95d
commit
4de3537a82
7 changed files with 205 additions and 0 deletions
|
@ -274,6 +274,7 @@ install(
|
|||
KTempDir
|
||||
KTemporaryFile
|
||||
KTextEdit
|
||||
KTimeEdit
|
||||
KTimeZone
|
||||
KTimeZoneWidget
|
||||
KTipDatabase
|
||||
|
|
1
includes/KTimeEdit
Normal file
1
includes/KTimeEdit
Normal file
|
@ -0,0 +1 @@
|
|||
#include "../ktimeedit.h"
|
|
@ -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
|
||||
|
|
|
@ -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()));
|
||||
|
|
131
kdeui/widgets/ktimeedit.cpp
Normal file
131
kdeui/widgets/ktimeedit.cpp
Normal file
|
@ -0,0 +1,131 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2023 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
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 <QSpinBox>
|
||||
#include <QHBoxLayout>
|
||||
|
||||
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"
|
64
kdeui/widgets/ktimeedit.h
Normal file
64
kdeui/widgets/ktimeedit.h
Normal file
|
@ -0,0 +1,64 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2023 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
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 <kdeui_export.h>
|
||||
|
||||
#include <QWidget>
|
||||
#include <QTime>
|
||||
|
||||
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
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue