diff --git a/includes/CMakeLists.txt b/includes/CMakeLists.txt index 8912ef5e..1c462f77 100644 --- a/includes/CMakeLists.txt +++ b/includes/CMakeLists.txt @@ -260,7 +260,6 @@ install( KTextEdit KTimeEdit KTimeZone - KTimeZoneWidget KTimerDialog KTipDatabase KTipDialog diff --git a/includes/KTimeZoneWidget b/includes/KTimeZoneWidget deleted file mode 100644 index 68b4eca3..00000000 --- a/includes/KTimeZoneWidget +++ /dev/null @@ -1 +0,0 @@ -#include "../ktimezonewidget.h" diff --git a/kdeui/CMakeLists.txt b/kdeui/CMakeLists.txt index 76ddcf26..53098642 100644 --- a/kdeui/CMakeLists.txt +++ b/kdeui/CMakeLists.txt @@ -221,7 +221,6 @@ set(kdeui_LIB_SRCS widgets/ktabwidget.cpp widgets/ktextedit.cpp widgets/ktimeedit.cpp - widgets/ktimezonewidget.cpp widgets/ktitlewidget.cpp widgets/ktoolbar.cpp widgets/kurllabel.cpp @@ -490,7 +489,6 @@ install( widgets/ksqueezedtextlabel.h widgets/ktextedit.h widgets/ktimeedit.h - widgets/ktimezonewidget.h widgets/ktitlewidget.h widgets/ktabbar.h widgets/ktabwidget.h diff --git a/kdeui/tests/CMakeLists.txt b/kdeui/tests/CMakeLists.txt index 143e15e4..f20e03e2 100644 --- a/kdeui/tests/CMakeLists.txt +++ b/kdeui/tests/CMakeLists.txt @@ -48,7 +48,6 @@ KDEUI_UNIT_TESTS( kstartupinfo_unittest kcolorutilstest kxmlgui_unittest - ktimezonewidget_unittest kiconloader_unittest ktabwidget_unittest ktoolbar_unittest diff --git a/kdeui/tests/ktimezonewidget_unittest.cpp b/kdeui/tests/ktimezonewidget_unittest.cpp deleted file mode 100644 index ce03a2de..00000000 --- a/kdeui/tests/ktimezonewidget_unittest.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2007 David Faure - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - 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 "qtest_kde.h" -#include -#include - -class KTimeZoneWidgetTest : public QObject -{ - Q_OBJECT - -public: - void init() { initTestCase(); } - -private Q_SLOTS: - - void initTestCase() - { - } - - void cleanupTestCase() - { - } - - void testSetSelected() - { - KTimeZoneWidget tzw; - QVERIFY(tzw.topLevelItemCount() > 0); - QVERIFY(tzw.selectedItems().isEmpty()); - - // Single selection mode (default) - QVERIFY(tzw.selectionMode() == KTimeZoneWidget::SingleSelection); - tzw.setSelected("Europe/Paris", true); - QCOMPARE(tzw.selectedItems().count(), 1); - QCOMPARE(tzw.selection(), QStringList() << "Europe/Paris"); - tzw.setSelected("Africa/Cairo", true); - QCOMPARE(tzw.selectedItems().count(), 1); - QCOMPARE(tzw.selection(), QStringList() << "Africa/Cairo"); - - // Multiple selections explicitly allowed - tzw.setSelectionMode(KTimeZoneWidget::MultiSelection); - tzw.clearSelection(); - QVERIFY(tzw.selectedItems().isEmpty()); - tzw.setSelected("Europe/Paris", true); - QCOMPARE(tzw.selectedItems().count(), 1); - QCOMPARE(tzw.selection(), QStringList() << "Europe/Paris"); - tzw.setSelected("America/Los_Angeles", true); - QCOMPARE(tzw.selectedItems().count(), 2); - QCOMPARE(tzw.selection(), QStringList() << "America/Los_Angeles" << "Europe/Paris"); - } - - void testCheckableItems() - { - KTimeZoneWidget tzw; - tzw.setItemsCheckable(true); - QVERIFY(tzw.topLevelItemCount() > 0); - QVERIFY(tzw.selectedItems().isEmpty()); - QVERIFY(tzw.selection().isEmpty()); - - // Single selection mode (default) - QVERIFY(tzw.selectionMode() == KTimeZoneWidget::SingleSelection); - tzw.setSelected("Europe/Paris", true); - QCOMPARE(tzw.selectedItems().count(), 0); // it got checked, not selected - QCOMPARE(tzw.selection(), QStringList() << "Europe/Paris"); - tzw.setSelected("Africa/Cairo", true); - QCOMPARE(tzw.selection(), QStringList() << "Africa/Cairo"); - - // Multiple selections explicitly allowed - tzw.setSelectionMode(KTimeZoneWidget::MultiSelection); - tzw.clearSelection(); - tzw.setSelected("Europe/Paris", true); - QCOMPARE(tzw.selection(), QStringList() << "Europe/Paris"); - tzw.setSelected("America/Los_Angeles", true); - QCOMPARE(tzw.selection(), QStringList() << "America/Los_Angeles" << "Europe/Paris"); - } -}; - -// Tricky problem. The kded module writes out a config file, but unit tests have -// a different KDEHOME so they don't see those config files. -// Ideally unit tests should talk to their own kded instance, -// but that means starting a new DBus session bus for all (each?) unit tests, somehow... -//QTEST_KDEMAIN( KTimeZoneWidgetTest, GUI ) - -int main(int argc, char *argv[]) -{ - setenv("LC_ALL", "C", 1); - // The difference with QTEST_KDEMAIN is here: not setting $KDEHOME - KAboutData aboutData( "ktimezonewidgettest", 0, ki18n("qttest"), "version" ); - KComponentData cData(&aboutData); - QApplication app( argc, argv ); - app.setApplicationName( "ktimezonewidgettest" ); - - KTimeZoneWidgetTest tc; -#if 0 - tc.init(); - KTimeZoneWidget tzw; - tzw.setItemsCheckable(true); - tzw.setSelectionMode(KTimeZoneWidget::MultiSelection); - tzw.setSelected("Europe/Paris", true); - tzw.show(); - return app.exec(); -#else - return QTest::qExec( &tc, argc, argv ); -#endif -} - -#include "ktimezonewidget_unittest.moc" diff --git a/kdeui/widgets/ktimezonewidget.cpp b/kdeui/widgets/ktimezonewidget.cpp deleted file mode 100644 index 3dd85900..00000000 --- a/kdeui/widgets/ktimezonewidget.cpp +++ /dev/null @@ -1,233 +0,0 @@ -/* - Copyright (C) 2005, S.R.Haque . - Copyright (C) 2009, David Faure - This file is part of the KDE project - - 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 "ktimezonewidget.h" - -#include -#include - -#include -#include -#include -#include -#include - -class KTimeZoneWidget::Private -{ -public: - Private() : itemsCheckable(false), singleSelection(true) {} - - enum Columns - { - CityColumn = 0, - RegionColumn, - CommentColumn - }; - - enum Roles - { - ZoneRole = Qt::UserRole + 0xF3A3CB1 - }; - - bool itemsCheckable; - bool singleSelection; -}; - -// TODO: duplicate -static bool timeZoneLocaleLessThan (const QString &a, const QString &b) -{ - return QString::localeAwareCompare(a, b) < 0; -} - -KTimeZoneWidget::KTimeZoneWidget( QWidget *parent ) - : QTreeWidget( parent ), - d(new KTimeZoneWidget::Private) -{ - // If the user did not provide a timezone database, we'll use the system default. - setRootIsDecorated(false); - setHeaderLabels( QStringList() << i18nc("Define an area in the time zone, like a town area", "Area" ) << i18nc( "Time zone", "Region" ) << i18n( "Comment" ) ); - - // Collect zones by localized city names, so that they can be sorted properly. - QStringList cities; - QHash zonesByCity; - - foreach (const KTimeZone &zone, KSystemTimeZones::zones()) { - const QString continentCity = KSystemTimeZones::zoneName(zone.name()); - const int separator = continentCity.lastIndexOf('/'); - // Make up the localized key that will be used for sorting. - // Example: i18n(Asia/Tokyo) -> key = "i18n(Tokyo)|i18n(Asia)|Asia/Tokyo" - // The zone name is appended to ensure unicity even with equal translations (#174918) - const QString key = continentCity.mid(separator+1) + '|' - + continentCity.left(separator) + '|' + zone.name(); - cities.append( key ); - zonesByCity.insert( key, zone ); - } - qSort( cities.begin(), cities.end(), timeZoneLocaleLessThan ); - - foreach ( const QString &key, cities ) { - const KTimeZone zone = zonesByCity.value(key); - const QString tzName = zone.name(); - QString comment = zone.comment(); - - if ( !comment.isEmpty() ) - comment = KSystemTimeZones::zoneComment( tzName ); - - // Convert: - // - // "Europe/London", "GB" -> "London", "Europe/GB". - // "UTC", "" -> "UTC", "". - QStringList continentCity = KSystemTimeZones::zoneName(tzName).split( '/' ); - - QTreeWidgetItem *listItem = new QTreeWidgetItem( this ); - listItem->setText( Private::CityColumn, continentCity[ continentCity.count() - 1 ] ); - QString countryName = KGlobal::locale()->countryCodeToName( zone.countryCode() ); - if ( countryName.isEmpty() ) { - continentCity[ continentCity.count() - 1 ] = zone.countryCode(); - } else { - continentCity[ continentCity.count() - 1 ] = countryName; - } - - listItem->setText( Private::RegionColumn, continentCity.join( QChar('/') ) ); - listItem->setText( Private::CommentColumn, comment ); - listItem->setData( Private::CityColumn, Private::ZoneRole, tzName ); // store complete path in custom role - - // Locate the flag from /l10n/%1/flag.png. - QString flag = KStandardDirs::locate( "locale", QString( "l10n/%1/flag.png" ).arg( zone.countryCode().toLower() ) ); - if ( QFile::exists( flag ) ) - listItem->setIcon( Private::RegionColumn, QPixmap( flag ) ); - } -} - -KTimeZoneWidget::~KTimeZoneWidget() -{ - delete d; -} - -void KTimeZoneWidget::setItemsCheckable(bool enable) -{ - d->itemsCheckable = enable; - const int count = topLevelItemCount(); - for (int row = 0; row < count; ++row) { - QTreeWidgetItem* listItem = topLevelItem(row); - listItem->setCheckState(Private::CityColumn, Qt::Unchecked); - } - QTreeWidget::setSelectionMode(QAbstractItemView::NoSelection); -} - -bool KTimeZoneWidget::itemsCheckable() const -{ - return d->itemsCheckable; -} - -QStringList KTimeZoneWidget::selection() const -{ - QStringList selection; - - // Loop through all entries. - // Do not use selectedItems() because it skips hidden items, making it - // impossible to use a KTreeWidgetSearchLine. - // There is no QTreeWidgetItemConstIterator, hence the const_cast :/ - QTreeWidgetItemIterator it(const_cast(this), d->itemsCheckable ? QTreeWidgetItemIterator::Checked : QTreeWidgetItemIterator::Selected); - for (; *it; ++it) { - selection.append( (*it)->data( Private::CityColumn, Private::ZoneRole ).toString() ); - } - - return selection; -} - -void KTimeZoneWidget::setSelected( const QString &zone, bool selected ) -{ - bool found = false; - - // The code was using findItems( zone, Qt::MatchExactly, Private::ZoneColumn ) - // previously, but the underlying model only has 3 columns, the "hidden" column - // wasn't available in there. - - if (!d->itemsCheckable) { - // Runtime compatibility for < 4.3 apps, which don't call the setMultiSelection reimplementation. - d->singleSelection = (QTreeWidget::selectionMode() == QAbstractItemView::SingleSelection); - } - - // Loop through all entries. - const int rowCount = model()->rowCount(QModelIndex()); - for (int row = 0; row < rowCount; ++row) { - const QModelIndex index = model()->index(row, Private::CityColumn); - const QString tzName = index.data(Private::ZoneRole).toString(); - if (tzName == zone) { - - if (d->singleSelection && selected) { - clearSelection(); - } - - if (d->itemsCheckable) { - QTreeWidgetItem* listItem = itemFromIndex(index); - listItem->setCheckState(Private::CityColumn, selected ? Qt::Checked : Qt::Unchecked); - } else { - selectionModel()->select(index, selected ? (QItemSelectionModel::Select | QItemSelectionModel::Rows) : (QItemSelectionModel::Deselect | QItemSelectionModel::Rows)); - } - - // Ensure the selected item is visible as appropriate. - scrollTo( index ); - - found = true; - - if (d->singleSelection && selected) { - break; - } - } - } - - if ( !found ) - kDebug() << "No such zone: " << zone; -} - -void KTimeZoneWidget::clearSelection() -{ - if (d->itemsCheckable) { - // Un-select all items - const int rowCount = model()->rowCount(QModelIndex()); - for (int row = 0; row < rowCount; ++row) { - const QModelIndex index = model()->index(row, 0); - QTreeWidgetItem* listItem = itemFromIndex(index); - listItem->setCheckState(Private::CityColumn, Qt::Unchecked); - } - } else { - QTreeWidget::clearSelection(); - } -} - -void KTimeZoneWidget::setSelectionMode(QAbstractItemView::SelectionMode mode) -{ - d->singleSelection = (mode == QAbstractItemView::SingleSelection); - if (!d->itemsCheckable) { - QTreeWidget::setSelectionMode(mode); - } -} - -QAbstractItemView::SelectionMode KTimeZoneWidget::selectionMode() const -{ - if (d->itemsCheckable) { - return d->singleSelection ? QTreeWidget::SingleSelection : QTreeWidget::MultiSelection; - } else { - return QTreeWidget::selectionMode(); - } -} - -#include "moc_ktimezonewidget.cpp" diff --git a/kdeui/widgets/ktimezonewidget.h b/kdeui/widgets/ktimezonewidget.h deleted file mode 100644 index 3fdf27d3..00000000 --- a/kdeui/widgets/ktimezonewidget.h +++ /dev/null @@ -1,138 +0,0 @@ -/* - Copyright (C) 2005, S.R.Haque . - This file is part of the KDE project - - 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 KTIMEZONEWIDGET_H -#define KTIMEZONEWIDGET_H - -#include - -#include - -class KTimeZone; - -/** - * @brief A time zone selection widget. - * - * \b Detail: - * - * This class provides for selection of one or more time zones. - * - * \b Example: - * - * To use the class to implement a system timezone selection feature: - * \code - * - * // This adds a time zone widget to a dialog. - * m_timezones = new KTimeZoneWidget(this); - * ... - * \endcode - * - * To use the class to implement a multiple-choice custom time zone selector: - * \code - * - * m_timezones = new KTimeZoneWidget( this, "Time zones", vcalendarTimezones ); - * m_timezones->setSelectionMode( QTreeView::MultiSelection ); - * ... - * \endcode - * - * \image html ktimezonewidget.png "KDE Time Zone Widget" - * - * @author S.R.Haque - */ -class KDEUI_EXPORT KTimeZoneWidget : public QTreeWidget -{ - Q_OBJECT - Q_PROPERTY(bool itemsCheckable READ itemsCheckable WRITE setItemsCheckable) - Q_PROPERTY(QAbstractItemView::SelectionMode selectionMode READ selectionMode WRITE setSelectionMode) - - public: - /** - * Constructs a time zone selection widget. - * - * @param parent The parent widget. - */ - explicit KTimeZoneWidget( QWidget *parent = 0 ); - - /** - * Destroys the time zone selection widget. - */ - virtual ~KTimeZoneWidget(); - - /** - * Makes all items show a checkbox, so that the user can select multiple - * timezones by means of checking checkboxes, rather than via multi-selection. - * - * In "items checkable" mode, the selection(), setSelected() and clearSelection() - * methods work on the check states rather than on selecting/unselecting. - * - * @since 4.4 - */ - void setItemsCheckable(bool enable); - /** - * @return true if setItemsCheckable(true) was called. - * @since 4.4 - */ - bool itemsCheckable() const; - - /** - * Allows to select multiple timezones. This is the same as - * setSelectionMode(KTimeZoneWidget::MultiSelection) normally, - * but in "items checkable" mode, this is rather about allowing to - * check multiple items. In that case, the actual QTreeWidget selection - * mode remains unchanged. - * @since 4.4 - */ - void setSelectionMode(QAbstractItemView::SelectionMode mode); - - /** - * @return the selection mode set by setSelectionMode(). - * @since 4.4 - */ - QAbstractItemView::SelectionMode selectionMode() const; - - /** - * Returns the currently selected time zones. See QTreeView::selectionChanged(). - * - * @return a list of time zone names, in the format used by the database - * supplied to the {@link KTimeZoneWidget() } constructor. - */ - QStringList selection() const; - - /** - * Select/deselect the named time zone. - * - * @param zone The time zone name to be selected. Ignored if not recognized! - * @param selected The new selection state. - */ - void setSelected( const QString &zone, bool selected ); - - /** - * Unselect all timezones. - * This is the same as QTreeWidget::clearSelection, except in checkable items mode, - * where items are all unchecked. - * The overload is @since 4.4. - */ - void clearSelection(); - - private: - class Private; - Private* const d; -}; - -#endif diff --git a/kdewidgets/kde.widgets b/kdewidgets/kde.widgets index e0098460..156dbd70 100644 --- a/kdewidgets/kde.widgets +++ b/kdewidgets/kde.widgets @@ -241,12 +241,6 @@ ToolTip=Improved QTextEdit (KDE) WhatsThis=An improved version of the QTextEdit with mail or system browser invocation support Group=Input (KDE) -[KTimeZoneWidget] -ToolTip=This widget can be used to display or allow user selection of timezones. (KDE) -IncludeFile=ktimezonewidget.h -ConstructorArgs=(parent) -Group=Input (KDE) - [KTitleWidget] ToolTip=Title box with label and icon WhatsThis=A styled frame to be used in title positions in dialogs and other widgets