File indexing completed on 2024-04-28 05:11:37

0001 /*
0002   SPDX-FileCopyrightText: 2007 Bruno Virlet <bruno.virlet@gmail.com>
0003   SPDX-FileCopyrightText: 2008-2009 Allen Winter <winter@kde.org>
0004 
0005   SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
0006 */
0007 
0008 #pragma once
0009 
0010 #include "incidenceeditor_export.h"
0011 
0012 #include <QComboBox>
0013 #include <QTimeZone>
0014 
0015 #include <memory>
0016 
0017 namespace IncidenceEditorNG
0018 {
0019 class KTimeZoneComboBoxPrivate;
0020 
0021 /**
0022  * A combobox that shows the system timezones available in QTimeZone
0023  * and provides methods to easily select the item corresponding to a given
0024  * QTimeZone or to retrieve the QTimeZone associated with the
0025  * selected item.
0026  */
0027 class INCIDENCEEDITOR_EXPORT KTimeZoneComboBox : public QComboBox
0028 {
0029     Q_OBJECT
0030 public:
0031     /**
0032      * Creates a new time zone combobox.
0033      *
0034      * @param parent The parent widget.
0035      */
0036     explicit KTimeZoneComboBox(QWidget *parent = nullptr);
0037 
0038     /**
0039      * Destroys the time zone combobox.
0040      */
0041     ~KTimeZoneComboBox() override;
0042 
0043     /**
0044      * Selects the item in the combobox corresponding to the given @p zone.
0045      */
0046     void selectTimeZone(const QTimeZone &zone);
0047 
0048     /**
0049      * Selects the item in the combobox corresponding to the zone for the given @p datetime.
0050      */
0051     void selectTimeZoneFor(const QDateTime &dateTime);
0052 
0053     /**
0054      * Convenience version of selectTimeZone(const QTimeZone &).
0055      * Selects the local time zone specified in the user settings.
0056      */
0057     void selectLocalTimeZone();
0058 
0059     /**
0060      * If @p floating is true, selects floating time zone, otherwise
0061      * if @zone is valid, selects @pzone time zone, if not selects
0062      * local time zone.
0063      */
0064     void setFloating(bool floating, const QTimeZone &zone = {});
0065 
0066     /**
0067      * Applies the selected timezone to the given QDateTime
0068      * This isn't the same as dt.setTimeZone(selectedTimeZone) because
0069      * of the "floating" special case.
0070      */
0071     void applyTimeZoneTo(QDateTime &dt) const;
0072 
0073     /**
0074      * Return the time zone associated with the currently selected item.
0075      */
0076     [[nodiscard]] QTimeZone selectedTimeZone() const;
0077 
0078     /**
0079      * Returns true if the selecting timezone is the floating time zone
0080      */
0081     [[nodiscard]] bool isFloating() const;
0082 
0083 private:
0084     //@cond PRIVATE
0085     std::unique_ptr<KTimeZoneComboBoxPrivate> const d;
0086     //@endcond
0087 };
0088 }