Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 53f2bbb7 authored by Allen Winter's avatar Allen Winter

timelabels.cpp - use new tzUTCOffsetStr from kcalutils

and some code styling improvements
parent 5a860074
......@@ -9,8 +9,8 @@ set(KF5_VERSION "5.41.0")
find_package(ECM ${KF5_VERSION} CONFIG REQUIRED)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
set(LIBRARY_NAMELINK)
if (POLICY CMP0053)
cmake_policy(SET CMP0053 NEW)
if(POLICY CMP0053)
cmake_policy(SET CMP0053 NEW)
endif()
include(GenerateExportHeader)
include(ECMSetupVersion)
......@@ -26,11 +26,8 @@ include(ECMQtDeclareLoggingCategory)
include(ECMAddTests)
include(ECMCoverageOption)
set(EVENTVIEW_LIB_VERSION ${PIM_VERSION})
set(CALENDARUTILS_LIB_VERSION "5.7.40")
set(CALENDARUTILS_LIB_VERSION "5.7.41")
set(AKONADI_LIB_VERSION "5.7.40")
set(QT_REQUIRED_VERSION "5.8.0")
set(KCALENDARCORE_LIB_VERSION "5.7.40")
......@@ -77,7 +74,7 @@ set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/KF5EventViews")
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/KF5EventViewsConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/KF5EventViewsConfig.cmake"
INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR}
INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR}
)
install(FILES
......@@ -90,15 +87,15 @@ install(FILES
install(EXPORT KF5EventViewsTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE KF5EventViewsTargets.cmake NAMESPACE KF5::)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/eventviews_version.h
${CMAKE_CURRENT_BINARY_DIR}/eventviews_version.h
DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5} COMPONENT Devel
)
add_subdirectory(src)
if (BUILD_TESTING)
find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED Test)
add_subdirectory(tests)
if(BUILD_TESTING)
find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED Test)
add_subdirectory(tests)
endif()
install( FILES eventviews.renamecategories eventviews.categories DESTINATION ${KDE_INSTALL_CONFDIR} )
install(FILES eventviews.renamecategories eventviews.categories DESTINATION ${KDE_INSTALL_CONFDIR})
feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
......@@ -27,6 +27,8 @@
#include "timelabelszone.h"
#include "timescaleconfigdialog.h"
#include <KCalUtils/Stringify>
#include <KLocalizedString>
#include <QFrame>
......@@ -184,13 +186,12 @@ void TimeLabels::paintEvent(QPaintEvent *)
// We won't paint parts that aren't visible
const int cy = -y();// y() returns a negative value.
const auto firstDay
= QDateTime(mAgenda->dateList().first(), QTime(0, 0, 0), Qt::LocalTime).toUTC();
const int beginning
= !mTimezone.isValid()
? 0
: (mTimezone.offsetFromUtc(firstDay)
-mTimeLabelsZone->preferences()->timeZone().offsetFromUtc(firstDay)) / (60 * 60);
const auto firstDay =
QDateTime(mAgenda->dateList().first(), QTime(0, 0, 0), Qt::LocalTime).toUTC();
const int beginning =
!mTimezone.isValid() ?
0 :
(mTimezone.offsetFromUtc(firstDay) - mTimeLabelsZone->preferences()->timeZone().offsetFromUtc(firstDay)) / 3600;
// bug: the parameters cx and cw are the areas that need to be
// redrawn, not the area of the widget. unfortunately, this
......@@ -302,22 +303,19 @@ void TimeLabels::contextMenuEvent(QContextMenuEvent *event)
Q_UNUSED(event);
QMenu popup(this);
QAction *editTimeZones
= popup.addAction(QIcon::fromTheme(QStringLiteral("document-properties")),
i18n("&Add Timezones..."));
QAction *removeTimeZone
= popup.addAction(QIcon::fromTheme(QStringLiteral("edit-delete")),
i18n("&Remove Timezone %1", i18n(mTimezone.id().constData())));
if (!mTimezone.isValid()
|| !mTimeLabelsZone->preferences()->timeScaleTimezones().count()
|| mTimezone == mTimeLabelsZone->preferences()->timeZone()) {
QAction *editTimeZones = popup.addAction(QIcon::fromTheme(QStringLiteral("document-properties")),
i18n("&Add Timezones..."));
QAction *removeTimeZone = popup.addAction(QIcon::fromTheme(QStringLiteral("edit-delete")),
i18n("&Remove Timezone %1", i18n(mTimezone.id().constData())));
if (!mTimezone.isValid() ||
!mTimeLabelsZone->preferences()->timeScaleTimezones().count() ||
mTimezone == mTimeLabelsZone->preferences()->timeZone()) {
removeTimeZone->setEnabled(false);
}
QAction *activatedAction = popup.exec(QCursor::pos());
if (activatedAction == editTimeZones) {
QPointer<TimeScaleConfigDialog> dialog
= new TimeScaleConfigDialog(mTimeLabelsZone->preferences(), this);
QPointer<TimeScaleConfigDialog> dialog = new TimeScaleConfigDialog(mTimeLabelsZone->preferences(), this);
if (dialog->exec() == QDialog::Accepted) {
mTimeLabelsZone->reset();
}
......@@ -345,32 +343,40 @@ QString TimeLabels::header() const
QString TimeLabels::headerToolTip() const
{
QDateTime now = QDateTime::currentDateTime();
QString toolTip;
toolTip += QLatin1String("<qt>");
toolTip += i18n("<b>%1</b>", i18n(mTimezone.id().constData()));
toolTip += i18nc("title for timezone info, the timezone id and utc offset",
"<b>%1 (%2)</b>", i18n(mTimezone.id().constData()),
KCalUtils::Stringify::tzUTCOffsetStr(mTimezone));
toolTip += QLatin1String("<hr>");
//TODO: Once string freeze is lifted, add UTC offset here
toolTip += i18nc("heading for timezone display name",
"<i>Name:</i> %1", mTimezone.displayName(now, QTimeZone::LongName));
toolTip += QLatin1String("<br/>");
if (mTimezone.country() != QLocale::AnyCountry) {
toolTip += i18n("<i>Country:</i> %1", QLocale::countryToString(mTimezone.country()));
toolTip += i18nc("heading for timezone country",
"<i>Country:</i> %1", QLocale::countryToString(mTimezone.country()));
toolTip += QLatin1String("<br/>");
}
auto abbreviations = QStringLiteral("&nbsp;");
foreach (const auto &transition,
mTimezone.transitions(QDateTime::currentDateTime(),
QDateTime::currentDateTime().addYears(1))) {
foreach (const auto &transition, mTimezone.transitions(now, now.addYears(1))) {
abbreviations += transition.abbreviation;
abbreviations += QLatin1String(",&nbsp;");
}
abbreviations.chop(7);
if (!abbreviations.isEmpty()) {
toolTip += i18n("<i>Abbreviations:</i>");
toolTip += i18nc("heading for comma-separated list of timezone abbreviations",
"<i>Abbreviations:</i>");
toolTip += abbreviations;
toolTip += QLatin1String("<br/>");
}
const QString timeZoneComment(mTimezone.comment());
if (!timeZoneComment.isEmpty()) {
toolTip += i18n("<i>Comment:</i> %1", timeZoneComment);
toolTip += i18nc("heading for the timezone comment",
"<i>Comment:</i> %1", timeZoneComment);
}
toolTip += QLatin1String("</qt>");
......
......@@ -22,7 +22,10 @@
#include "timescaleconfigdialog.h"
#include "prefs.h"
#include <KCalUtils/Stringify>
#include <KLocalizedString>
#include <QIcon>
#include <QDialogButtonBox>
#include <QPushButton>
......@@ -51,32 +54,12 @@ enum {
typedef QPair<QString, QByteArray> TimeZoneNamePair;
//TODO: move to KCalCore::Stringify
static QString tzUTCOffsetStr(const QTimeZone &tz)
{
auto currentOffset = tz.offsetFromUtc(QDateTime::currentDateTimeUtc());
int utcOffsetHrs = currentOffset / 3600; // in hours
int utcOffsetMins = (currentOffset % 3600) / 60; // in minutes
QString utcStr;
if (utcOffsetMins > 0) {
utcStr = utcOffsetHrs >= 0
? QStringLiteral("+%1:%2").arg(utcOffsetHrs).arg(utcOffsetMins)
: QStringLiteral("%1:%2").arg(utcOffsetHrs).arg(utcOffsetMins);
} else {
utcStr = utcOffsetHrs >= 0
? QStringLiteral("+%1").arg(utcOffsetHrs)
: QStringLiteral("%1").arg(utcOffsetHrs);
}
return utcStr;
}
//TODO: move to KCalCore::Stringify
static QString tzWithUTC(const QByteArray &zoneId)
{
auto tz = QTimeZone(zoneId);
return
QStringLiteral("%1 (UTC%2)").
arg(i18n(zoneId.constData()), tzUTCOffsetStr(tz));
QStringLiteral("%1 (%2)").
arg(i18n(zoneId.constData()), KCalUtils::Stringify::tzUTCOffsetStr(tz));
}
TimeScaleConfigDialog::TimeScaleConfigDialog(const PrefsPtr &preferences, QWidget *parent)
......@@ -133,11 +116,11 @@ TimeScaleConfigDialog::TimeScaleConfigDialog(const PrefsPtr &preferences, QWidge
connect(downButton, &QPushButton::clicked, this, &TimeScaleConfigDialog::down);
connect(okButton, &QPushButton::clicked, this, &TimeScaleConfigDialog::okClicked);
connect(buttonBox->button(
QDialogButtonBox::Cancel), &QPushButton::clicked, this,
&TimeScaleConfigDialog::reject);
connect(listWidget, &QListWidget::currentItemChanged, this,
&TimeScaleConfigDialog::slotUpdateButton);
connect(buttonBox->button(QDialogButtonBox::Cancel), &QPushButton::clicked,
this, &TimeScaleConfigDialog::reject);
connect(listWidget, &QListWidget::currentItemChanged,
this, &TimeScaleConfigDialog::slotUpdateButton);
for (const TimeZoneNamePair &item : qAsConst(selList)) {
QListWidgetItem *widgetItem = new QListWidgetItem(item.first);
widgetItem->setData(TimeZoneNameRole, item.second);
......@@ -156,8 +139,8 @@ void TimeScaleConfigDialog::slotUpdateButton()
removeButton->setEnabled(listWidget->currentItem());
const bool numberElementMoreThanOneElement = (listWidget->count() > 1);
upButton->setEnabled(numberElementMoreThanOneElement && (listWidget->currentRow() >= 1));
downButton->setEnabled(numberElementMoreThanOneElement
&& (listWidget->currentRow() < listWidget->count() - 1));
downButton->setEnabled(numberElementMoreThanOneElement &&
(listWidget->currentRow() < listWidget->count() - 1));
}
void TimeScaleConfigDialog::okClicked()
......@@ -173,8 +156,8 @@ void TimeScaleConfigDialog::add()
if (zoneCombo->currentIndex() >= 0) {
const int numberItem(listWidget->count());
for (int i = 0; i < numberItem; ++i) {
if (listWidget->item(i)->data(TimeZoneNameRole).toString()
== zoneCombo->itemData(zoneCombo->currentIndex(), TimeZoneNameRole).toString()) {
if (listWidget->item(i)->data(TimeZoneNameRole).toString() ==
zoneCombo->itemData(zoneCombo->currentIndex(), TimeZoneNameRole).toString()) {
return;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment