diff --git a/CMakeLists.txt b/CMakeLists.txt index 98adba9..fb56d4b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,105 +1,105 @@ cmake_minimum_required(VERSION 3.5) set(PIM_VERSION "5.14.40") project(eventviews VERSION ${PIM_VERSION}) # ECM setup set(KF5_MIN_VERSION "5.69.0") find_package(ECM ${KF5_MIN_VERSION} CONFIG REQUIRED) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH}) set(LIBRARY_NAMELINK) if(POLICY CMP0053) cmake_policy(SET CMP0053 NEW) endif() include(KDEInstallDirs) include(KDECMakeSettings) include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE) include(GenerateExportHeader) include(ECMSetupVersion) include(ECMGenerateHeaders) include(ECMGeneratePriFile) include(FeatureSummary) include(ECMQtDeclareLoggingCategory) include(ECMAddTests) set(EVENTVIEW_LIB_VERSION ${PIM_VERSION}) set(CALENDARUTILS_LIB_VERSION "5.14.40") -set(AKONADI_LIB_VERSION "5.14.40") +set(AKONADI_LIB_VERSION "5.14.43") set(QT_REQUIRED_VERSION "5.12.0") set(AKONADICALENDAR_LIB_VERSION "5.14.40") set(KMIME_LIB_VERSION "5.14.40") set(LIBKDEPIM_LIB_VERSION "5.14.40") set(CALENDARSUPPORT_LIB_VERSION "5.14.40") find_package(KF5Akonadi ${AKONADI_LIB_VERSION} CONFIG REQUIRED) find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED Widgets) find_package(KF5I18n ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5Codecs ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5GuiAddons ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5IconThemes ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5Service ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5Completion ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5Holidays ${KF5_MIN_VERSION} CONFIG REQUIRED) set(KDIAGRAM_LIB_VERSION "1.4.0") find_package(KGantt ${KDIAGRAM_LIB_VERSION} CONFIG REQUIRED) find_package(KF5LibkdepimAkonadi ${LIBKDEPIM_LIB_VERSION} CONFIG REQUIRED) find_package(KF5CalendarUtils ${CALENDARUTILS_LIB_VERSION} CONFIG REQUIRED) find_package(KF5CalendarCore ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5CalendarSupport ${CALENDARSUPPORT_LIB_VERSION} CONFIG REQUIRED) find_package(KF5AkonadiCalendar ${AKONADICALENDAR_LIB_VERSION} CONFIG REQUIRED) find_package(KF5Mime ${KMIME_LIB_VERSION} CONFIG REQUIRED) ecm_setup_version(PROJECT VARIABLE_PREFIX EVENTVIEWS VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/eventviews_version.h" PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KF5EventViewsConfigVersion.cmake" SOVERSION 5 ) ########### Targets ########### if (EXISTS "${CMAKE_SOURCE_DIR}/.git") add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x050e00) add_definitions(-DKF_DISABLE_DEPRECATED_BEFORE_AND_AT=0x054500) endif() add_definitions(-DQT_NO_FOREACH) add_definitions(-DQT_NO_KEYWORDS) ########### CMake Config Files ########### 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(FILES "${CMAKE_CURRENT_BINARY_DIR}/KF5EventViewsConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/KF5EventViewsConfigVersion.cmake" DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel ) install(EXPORT KF5EventViewsTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE KF5EventViewsTargets.cmake NAMESPACE KF5::) install(FILES ${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) endif() feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/src/todo/tododelegates.cpp b/src/todo/tododelegates.cpp index 4cde7a6..e20b6c8 100644 --- a/src/todo/tododelegates.cpp +++ b/src/todo/tododelegates.cpp @@ -1,392 +1,370 @@ /* This file is part of KOrganizer. Copyright (c) 2008 Thomas Thrainer This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #include "tododelegates.h" #include "todomodel.h" #include "todoviewview.h" +#include #include #include #include -#include #include #include #include #include #include #include #include // ---------------- COMPLETION DELEGATE -------------------------- // --------------------------------------------------------------- TodoCompleteDelegate::TodoCompleteDelegate(QObject *parent) : QStyledItemDelegate(parent) { } -TodoCompleteDelegate::~TodoCompleteDelegate() -{ -} - void TodoCompleteDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItem opt = option; initStyleOption(&opt, index); QStyle *style = opt.widget ? opt.widget->style() : QApplication::style(); style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter); if (index.data(Qt::EditRole).toInt() > 0) { bool isEditing = false; TodoViewView *view = qobject_cast(parent()); if (view) { isEditing = view->isEditing(index); } // TODO QTreeView does not set State_Editing. Qt task id 205051 // should be fixed with Qt 4.5, but wasn't. According to the // task tracker the fix arrives in "Some future release". if (!(opt.state & QStyle::State_Editing) && !isEditing) { QStyleOptionProgressBar pbOption; pbOption.QStyleOption::operator=(option); initStyleOptionProgressBar(&pbOption, index); style->drawControl(QStyle::CE_ProgressBar, &pbOption, painter); } } } QSize TodoCompleteDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItem opt = option; initStyleOption(&opt, index); QStyle *style = opt.widget ? opt.widget->style() : QApplication::style(); QStyleOptionProgressBar pbOption; pbOption.QStyleOption::operator=(option); initStyleOptionProgressBar(&pbOption, index); return style->sizeFromContents(QStyle::CT_ProgressBar, &pbOption, QSize(), opt.widget); } void TodoCompleteDelegate::initStyleOptionProgressBar( QStyleOptionProgressBar *option, const QModelIndex &index) const { option->rect.adjust(0, 1, 0, -1); option->maximum = 100; option->minimum = 0; option->progress = index.data().toInt(); option->text = index.data().toString() + QChar::fromLatin1('%'); option->textAlignment = Qt::AlignCenter; option->textVisible = true; } QWidget *TodoCompleteDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { Q_UNUSED(option); Q_UNUSED(index); TodoCompleteSlider *slider = new TodoCompleteSlider(parent); slider->setRange(0, 100); slider->setOrientation(Qt::Horizontal); return slider; } void TodoCompleteDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { QSlider *slider = static_cast(editor); slider->setValue(index.data(Qt::EditRole).toInt()); } void TodoCompleteDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { QSlider *slider = static_cast(editor); model->setData(index, slider->value()); } void TodoCompleteDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const { Q_UNUSED(index); editor->setGeometry(option.rect); } TodoCompleteSlider::TodoCompleteSlider(QWidget *parent) : QSlider(parent) { connect(this, &TodoCompleteSlider::valueChanged, this, &TodoCompleteSlider::updateTip); } void TodoCompleteSlider::updateTip(int value) { QPoint p; p.setY(height() / 2); p.setX(style()->sliderPositionFromValue(minimum(), maximum(), value, width())); const QString text = QStringLiteral("%1%").arg(value); QToolTip::showText(mapToGlobal(p), text, this); } // ---------------- PRIORITY DELEGATE ---------------------------- // --------------------------------------------------------------- TodoPriorityDelegate::TodoPriorityDelegate(QObject *parent) : QStyledItemDelegate(parent) { } -TodoPriorityDelegate::~TodoPriorityDelegate() -{ -} - QWidget *TodoPriorityDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { Q_UNUSED(option); Q_UNUSED(index); QComboBox *combo = new QComboBox(parent); combo->addItem(i18nc("@action:inmenu Unspecified priority", "unspecified")); combo->addItem(i18nc("@action:inmenu highest priority", "1 (highest)")); combo->addItem(i18nc("@action:inmenu", "2")); combo->addItem(i18nc("@action:inmenu", "3")); combo->addItem(i18nc("@action:inmenu", "4")); combo->addItem(i18nc("@action:inmenu medium priority", "5 (medium)")); combo->addItem(i18nc("@action:inmenu", "6")); combo->addItem(i18nc("@action:inmenu", "7")); combo->addItem(i18nc("@action:inmenu", "8")); combo->addItem(i18nc("@action:inmenu lowest priority", "9 (lowest)")); return combo; } void TodoPriorityDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { QComboBox *combo = static_cast(editor); combo->setCurrentIndex(index.data(Qt::EditRole).toInt()); } void TodoPriorityDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { QComboBox *combo = static_cast(editor); model->setData(index, combo->currentIndex()); } void TodoPriorityDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const { Q_UNUSED(index); editor->setGeometry(option.rect); } // ---------------- DUE DATE DELEGATE ---------------------------- // --------------------------------------------------------------- TodoDueDateDelegate::TodoDueDateDelegate(QObject *parent) : QStyledItemDelegate(parent) { } -TodoDueDateDelegate::~TodoDueDateDelegate() -{ -} - QWidget *TodoDueDateDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { Q_UNUSED(option); Q_UNUSED(index); KDateComboBox *dateEdit = new KDateComboBox(parent); return dateEdit; } void TodoDueDateDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { KDateComboBox *dateEdit = static_cast(editor); dateEdit->setDate(index.data(Qt::EditRole).toDate()); } void TodoDueDateDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { KDateComboBox *dateEdit = static_cast(editor); model->setData(index, dateEdit->date()); } void TodoDueDateDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const { Q_UNUSED(index); editor->setGeometry(QStyle::alignedRect(QApplication::layoutDirection(), Qt::AlignCenter, editor->size(), option.rect)); } // ---------------- CATEGORIES DELEGATE -------------------------- // --------------------------------------------------------------- TodoCategoriesDelegate::TodoCategoriesDelegate(QObject *parent) : QStyledItemDelegate(parent) , mCalendar(nullptr) { } -TodoCategoriesDelegate::~TodoCategoriesDelegate() -{ -} - QWidget *TodoCategoriesDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { Q_UNUSED(option); Q_UNUSED(index); - return new KPIM::TagSelectionCombo(parent); + return new Akonadi::TagSelectionComboBox(parent); } void TodoCategoriesDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { - KPIM::KCheckComboBox *combo = static_cast(editor); - - combo->setCheckedItems(index.data(Qt::EditRole).toStringList(), Qt::UserRole); + auto *combo = static_cast(editor); + combo->setSelection(index.data(Qt::EditRole).toStringList()); } void TodoCategoriesDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { - KPIM::KCheckComboBox *combo = static_cast(editor); - - model->setData(index, combo->checkedItems(Qt::UserRole)); + auto *combo = static_cast(editor); + model->setData(index, combo->selectionNames()); } void TodoCategoriesDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const { Q_UNUSED(index); editor->setGeometry(option.rect); } void TodoCategoriesDelegate::setCalendar(const Akonadi::ETMCalendar::Ptr &cal) { mCalendar = cal; } // ---------------- RICH TEXT DELEGATE --------------------------- // --------------------------------------------------------------- TodoRichTextDelegate::TodoRichTextDelegate(QObject *parent) : QStyledItemDelegate(parent) { m_textDoc = new QTextDocument(this); } -TodoRichTextDelegate::~TodoRichTextDelegate() -{ -} - void TodoRichTextDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { if (index.data(TodoModel::IsRichTextRole).toBool()) { QStyleOptionViewItem opt = option; initStyleOption(&opt, index); const QWidget *widget = opt.widget; QStyle *style = widget ? widget->style() : QApplication::style(); QRect textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &opt, widget); // draw the item without text opt.text.clear(); style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, widget); // draw the text (rich text) QPalette::ColorGroup cg = (opt.state & QStyle::State_Enabled) ? QPalette::Normal : QPalette::Disabled; if (cg == QPalette::Normal && !(opt.state & QStyle::State_Active)) { cg = QPalette::Inactive; } if (opt.state & QStyle::State_Selected) { painter->setPen( QPen(opt.palette.brush(cg, QPalette::HighlightedText), 0)); } else { painter->setPen( QPen(opt.palette.brush(cg, QPalette::Text), 0)); } if (opt.state & QStyle::State_Editing) { painter->setPen(QPen(opt.palette.brush(cg, QPalette::Text), 0)); painter->drawRect(textRect.adjusted(0, 0, -1, -1)); } m_textDoc->setHtml(index.data().toString()); painter->save(); painter->translate(textRect.topLeft()); QRect tmpRect = textRect; tmpRect.moveTo(0, 0); m_textDoc->setTextWidth(tmpRect.width()); m_textDoc->drawContents(painter, tmpRect); painter->restore(); } else { // align the text at top so that when it has more than two lines // it will just cut the extra lines out instead of aligning centered vertically QStyleOptionViewItem copy = option; copy.displayAlignment = Qt::AlignLeft | Qt::AlignTop; QStyledItemDelegate::paint(painter, copy, index); } } QSize TodoRichTextDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { QSize ret = QStyledItemDelegate::sizeHint(option, index); if (index.data(TodoModel::IsRichTextRole).toBool()) { m_textDoc->setHtml(index.data().toString()); ret = ret.expandedTo(m_textDoc->size().toSize()); } // limit height to max. 2 lines // TODO add graphical hint when truncating! make configurable height? if (ret.height() > option.fontMetrics.height() * 2) { ret.setHeight(option.fontMetrics.height() * 2); } // This row might not have a checkbox, so give it more height so it appears the same size as other rows. const int checkboxHeight = QApplication::style()->sizeFromContents(QStyle::CT_CheckBox, &option, QSize()).height(); return QSize(ret.width(), qMax(ret.height(), checkboxHeight)); } diff --git a/src/todo/tododelegates.h b/src/todo/tododelegates.h index 59875d1..02de83c 100644 --- a/src/todo/tododelegates.h +++ b/src/todo/tododelegates.h @@ -1,161 +1,151 @@ /* This file is part of KOrganizer. Copyright (c) 2008 Thomas Thrainer This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #ifndef CALENDARVIEWS_TODODELEGATES_H #define CALENDARVIEWS_TODODELEGATES_H #include #include class QPainter; class QSize; class QStyleOptionViewItem; class QTextDocument; /** This delegate is responsible for displaying progress bars for the completion status of indivitual todos. It also provides a slider to change the completion status of the todo when in editing mode. @author Thomas Thrainer */ class TodoCompleteDelegate : public QStyledItemDelegate { Q_OBJECT public: explicit TodoCompleteDelegate(QObject *parent = nullptr); - ~TodoCompleteDelegate() override; - void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override; QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; void setEditorData(QWidget *editor, const QModelIndex &index) const override; void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override; void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override; private: void initStyleOptionProgressBar(QStyleOptionProgressBar *option, const QModelIndex &index) const; }; class TodoCompleteSlider : public QSlider { Q_OBJECT public: explicit TodoCompleteSlider(QWidget *parent); private Q_SLOTS: void updateTip(int value); }; /** This delegate is responsible for displaying the priority of todos. It also provides a combo box to change the priority of the todo when in editing mode. @author Thomas Thrainer */ class TodoPriorityDelegate : public QStyledItemDelegate { Q_OBJECT public: explicit TodoPriorityDelegate(QObject *parent = nullptr); - ~TodoPriorityDelegate() override; - QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; void setEditorData(QWidget *editor, const QModelIndex &index) const override; void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override; void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override; }; /** This delegate is responsible for displaying the due date of todos. It also provides a combo box to change the due date of the todo when in editing mode. @author Thomas Thrainer */ class TodoDueDateDelegate : public QStyledItemDelegate { Q_OBJECT public: explicit TodoDueDateDelegate(QObject *parent = nullptr); - ~TodoDueDateDelegate() override; - QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; void setEditorData(QWidget *editor, const QModelIndex &index) const override; void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override; void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override; }; /** This delegate is responsible for displaying the categories of todos. It also provides a combo box to change the categories of the todo when in editing mode. @author Thomas Thrainer */ class TodoCategoriesDelegate : public QStyledItemDelegate { Q_OBJECT public: explicit TodoCategoriesDelegate(QObject *parent = nullptr); - ~TodoCategoriesDelegate() override; - QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; void setEditorData(QWidget *editor, const QModelIndex &index) const override; void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override; void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override; void setCalendar(const Akonadi::ETMCalendar::Ptr &cal); private: Akonadi::ETMCalendar::Ptr mCalendar; }; /** This delegate is responsible for displaying possible rich text elements of a todo. That's the summary and the description. @author Thomas Thrainer */ class TodoRichTextDelegate : public QStyledItemDelegate { Q_OBJECT public: explicit TodoRichTextDelegate(QObject *parent = nullptr); - ~TodoRichTextDelegate() override; - void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override; private: QTextDocument *m_textDoc = nullptr; }; #endif diff --git a/src/todo/todoviewquicksearch.cpp b/src/todo/todoviewquicksearch.cpp index f7a61db..91e8935 100644 --- a/src/todo/todoviewquicksearch.cpp +++ b/src/todo/todoviewquicksearch.cpp @@ -1,153 +1,148 @@ /* This file is part of KOrganizer. Copyright (c) 2004 Till Adam Copyright (c) 2005 Rafal Rzepecki Copyright (c) 2008 Thomas Thrainer This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #include "todoviewquicksearch.h" #include +#include #include #include #include -#include #include #include #include #include #include TodoViewQuickSearch::TodoViewQuickSearch(const Akonadi::ETMCalendar::Ptr &calendar, QWidget *parent) : QWidget(parent) , mCalendar(calendar) { QHBoxLayout *layout = new QHBoxLayout(this); // no special margin because it is added by the view layout->setContentsMargins(0, 0, 0, 0); mSearchLine = new QLineEdit(this); mSearchLine->setToolTip( i18nc("@info:tooltip", "Filter on matching summaries")); mSearchLine->setWhatsThis( i18nc("@info:whatsthis", "Enter text here to filter the to-dos that are shown by matching summaries.")); mSearchLine->setPlaceholderText(i18nc("@label in QuickSearchLine", "Search Summaries...")); mSearchLine->setClearButtonEnabled(true); connect(mSearchLine, &QLineEdit::textChanged, this, &TodoViewQuickSearch::searchTextChanged); layout->addWidget(mSearchLine, 3); - mCategoryCombo = new KPIM::TagSelectionCombo(this); + mCategoryCombo = new Akonadi::TagSelectionComboBox(this); + mCategoryCombo->setCheckable(true); mCategoryCombo->setToolTip( i18nc("@info:tooltip", "Filter on these categories")); mCategoryCombo->setWhatsThis( i18nc("@info:whatsthis", "Use this combobox to filter the to-dos that are shown by " "a list of selected categories.")); const QString defaultText = i18nc("@item:inlistbox", "Select Categories"); - mCategoryCombo->setDefaultText(defaultText); - mCategoryCombo->setSeparator(i18nc("@item:intext delimiter for joining category names", ",")); + mCategoryCombo->lineEdit()->setPlaceholderText(defaultText); - connect(mCategoryCombo, &KPIM::TagSelectionCombo::checkedItemsChanged, this, - &TodoViewQuickSearch::emitFilterCategoryChanged); + connect(mCategoryCombo, &Akonadi::TagSelectionComboBox::selectionChanged, + this, [this]() { + Q_EMIT filterCategoryChanged(mCategoryCombo->selectionNames()); + }); layout->addWidget(mCategoryCombo, 1); { // Make the combo big enough so that "Select Categories" fits. QFontMetrics fm = mCategoryCombo->lineEdit()->fontMetrics(); // QLineEdit::sizeHint() returns a nice size to fit 17 'x' chars. const int currentPreferedWidth = mCategoryCombo->lineEdit()->sizeHint().width(); // Calculate a nice size for "Select Categories" const int newPreferedWidth = currentPreferedWidth -fm.boundingRect(QLatin1Char('x')).width() * 17 +fm.boundingRect(defaultText).width(); const int pixelsToAdd = newPreferedWidth - mCategoryCombo->lineEdit()->width(); mCategoryCombo->setMinimumWidth(mCategoryCombo->width() + pixelsToAdd); } mPriorityCombo = new KPIM::KCheckComboBox(this); mPriorityCombo->setToolTip( i18nc("@info:tooltip", "Filter on these priorities")); mPriorityCombo->setWhatsThis( i18nc("@info:whatsthis", "Use this combobox to filter the to-dos that are shown by " "a list of selected priorities.")); mPriorityCombo->setDefaultText(i18nc("@item:inlistbox", "Select Priority")); - connect(mPriorityCombo, &KPIM::KCheckComboBox::checkedItemsChanged, this, - &TodoViewQuickSearch::emitFilterPriorityChanged); + connect(mPriorityCombo, &KPIM::KCheckComboBox::checkedItemsChanged, + this, [this]() { + Q_EMIT filterPriorityChanged(mPriorityCombo->checkedItems(Qt::UserRole)); + }); layout->addWidget(mPriorityCombo, 1); fillPriorities(); } void TodoViewQuickSearch::setCalendar(const Akonadi::ETMCalendar::Ptr &calendar) { if (calendar != mCalendar) { mCalendar = calendar; } } void TodoViewQuickSearch::reset() { mSearchLine->clear(); mCategoryCombo->setCurrentIndex(0); mPriorityCombo->setCurrentIndex(0); } void TodoViewQuickSearch::fillPriorities() { QStringList priorityValues; priorityValues.append(i18nc("@action:inmenu priority is unspecified", "unspecified")); priorityValues.append(i18nc("@action:inmenu highest priority", "%1 (highest)", 1)); for (int p = 2; p < 10; ++p) { if (p == 5) { priorityValues.append(i18nc("@action:inmenu medium priority", "%1 (medium)", p)); } else if (p == 9) { priorityValues.append(i18nc("@action:inmenu lowest priority", "%1 (lowest)", p)); } else { priorityValues.append(i18nc("@action:inmenu", "%1", p)); } } // TODO: Using the same method as for categories to fill mPriorityCombo CalendarSupport::CategoryHierarchyReaderQComboBox(mPriorityCombo).read(priorityValues); } -void TodoViewQuickSearch::emitFilterCategoryChanged() -{ - Q_EMIT filterCategoryChanged(mCategoryCombo->checkedItems()); -} - -void TodoViewQuickSearch::emitFilterPriorityChanged() -{ - Q_EMIT filterPriorityChanged(mPriorityCombo->checkedItems(Qt::UserRole)); -} diff --git a/src/todo/todoviewquicksearch.h b/src/todo/todoviewquicksearch.h index 0597590..6c4ec47 100644 --- a/src/todo/todoviewquicksearch.h +++ b/src/todo/todoviewquicksearch.h @@ -1,81 +1,77 @@ /* This file is part of KOrganizer. Copyright (c) 2004 Till Adam Copyright (c) 2005 Rafal Rzepecki Copyright (c) 2008 Thomas Thrainer This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #ifndef CALENDARVIEWS_TODOVIEWQUICKSEARCH_H #define CALENDARVIEWS_TODOVIEWQUICKSEARCH_H #include #include namespace KPIM { class KCheckComboBox; -class TagSelectionCombo; +} + +namespace Akonadi { +class TagSelectionComboBox; } class QLineEdit; class TodoViewQuickSearch : public QWidget { Q_OBJECT public: TodoViewQuickSearch(const Akonadi::ETMCalendar::Ptr &calendar, QWidget *parent); - ~TodoViewQuickSearch() - { - } void setCalendar(const Akonadi::ETMCalendar::Ptr &calendar); Q_SIGNALS: void searchTextChanged(const QString &); /** * The string list contains the new categories which are set on the filter. * All values belong to the Qt::UserRole of the combo box, not the Qt::DisplayRole, * so, if someone checks a subcategory, the value will be "ParentCategory:subCategory" * and not " subcategory". * */ void filterCategoryChanged(const QStringList &); void filterPriorityChanged(const QStringList &); public Q_SLOTS: void reset(); -private Q_SLOTS: - void emitFilterCategoryChanged(); - void emitFilterPriorityChanged(); - private: /** Helper method for the filling of the priority combo. */ void fillPriorities(); Akonadi::ETMCalendar::Ptr mCalendar; QLineEdit *mSearchLine = nullptr; - KPIM::TagSelectionCombo *mCategoryCombo = nullptr; + Akonadi::TagSelectionComboBox *mCategoryCombo = nullptr; KPIM::KCheckComboBox *mPriorityCombo = nullptr; }; #endif